이 코드 설명좀 부탁드려요.
새누
질문 제목 : 이 프로그래밍 주석과 어떤 역할을하는지 설명 좀 부탁드려요.ㅠ질문 요약 :프로그래밍 주석과 설명좀 부탁드려요.ㅠ질문 내용 : 헤더
//bmp file header information
typedef struct _bmp_header
{
char charb;
char charm;
unsigned int filesize;
unsigned int reserved;
unsigned int pixel_offset;
unsigned int header_size;
unsigned int image_width;
unsigned int image_height;
unsigned int number_of_planes_and_number_of_bits_per_pixel;
unsigned int compression_type;
unsigned int image_size_with_padding_in_bytes;
unsigned int horizontal_resolution;
unsigned int veritical_resolution;
unsigned int number_of_colors;
unsigned int number_of_important_colors;
}bmp_header; //end of bmp header
void bmp_file_header_read (file * fp,bmp_header * bmp_header);
void bmp_file_header_write(file * wp,bmp_header * bmp_header);
void change_color_bluetozero(char * image_pixel_ptr,bmp_header * bmp_header,file * fp);
코드
#include stdio.h
#include bmp_header.h
#include malloc.h
//author:hyo jun kim,sejong univ
//date: 10 feb.2012
//this program will read a bmp image file
//and change the blue component of each pixel in that
//file to zero value
//and produce the chagnged bitmap into a new file
//input:a bmp image file
//output:a new bmp file with blue component set to zero
bmp_header bmp_header;
int main()
{
//first read a bitmap file
file * fp = fopen(d:\\blue.bmp,rb);//file open
//first prepare memory for the pixel data
//with image_size_with_padding_in_bytes
bmp_file_header_read (fp,&bmp_header);
char* image_pixel_ptr;
image_pixel_ptr=(char *)malloc(bmp_header.image_size_with_padding_in_bytes);
change_color_bluetozero(image_pixel_ptr,&bmp_header,fp);
//write a new bitmap file
file * wp = fopen(d:\\new_blue.bmp,wb);
bmp_file_header_write(wp,&bmp_header);
fwrite(image_pixel_ptr,bmp_header.image_size_with_padding_in_bytes,1,wp);
fclose(fp);
fclose(wp);
free(image_pixel_ptr);
return 0;
}
void bmp_file_header_read (file * fp,bmp_header * bmp_header)
{
fread(&bmp_header-charb,sizeof(char),1,fp);
fread(&bmp_header-charm,sizeof(char),1,fp);
fread(&bmp_header-filesize,sizeof(unsigned int),1,fp);
fread(&bmp_header-reserved,sizeof(unsigned int),1,fp);
fread(&bmp_header-pixel_offset,sizeof(unsigned int),1,fp);
fread(&bmp_header-header_size,sizeof(unsigned int),1,fp);
fread(&bmp_header-image_width,sizeof(unsigned int),1,fp);
fread(&bmp_header-image_height,sizeof(unsigned int),1,fp);
fread(&bmp_header-number_of_planes_and_number_of_bits_per_pixel,4,1,fp);
fread(&bmp_header-compression_type,sizeof(unsigned int),1,fp);
fread(&bmp_header-image_size_with_padding_in_bytes,sizeof(unsigned int),1,fp);
fread(&bmp_header-horizontal_resolution,sizeof(unsigned int),1,fp);
fread(&bmp_header-veritical_resolution,sizeof(unsigned int),1,fp);
fread(&bmp_header-number_of_colors,sizeof(unsigned int),1,fp);
fread(&bmp_header-number_of_important_colors,sizeof(unsigned int),1,fp);
//bmp header information completely read
//now read the pixel information
}
void bmp_file_header_write(file * wp,bmp_header * bmp_header)
{
fwrite(&bmp_header-charb,sizeof(char),1,wp);
fwrite(&bmp_header-charm,sizeof(char),1,wp);
fwrite(&bmp_header-filesize,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-reserved,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-pixel_offset,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-header_size,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-image_width,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-image_height,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-number_of_planes_and_number_of_bits_per_pixel,4,1,wp);
fwrite(&bmp_header-compression_type,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-image_size_with_padding_in_bytes,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-horizontal_resolution,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-veritical_resolution,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-number_of_colors,sizeof(unsigned int),1,wp);
fwrite(&bmp_header-number_of_important_colors,sizeof(unsigned int),1,wp);
}
void change_color_bluetozero(char * image_pixel_ptr,bmp_header * bmp_header,file * fp)
{
fread(image_pixel_ptr,bmp_header-image_size_with_padding_in_bytes,1,fp); //change the blue part of each pixel to zero
//first calculate the padding size
unsigned int pure_number_of_bytes_per_pixel_one_line=bmp_header-image_width * 3;
unsigned int padding_size=(pure_number_of_bytes_per_pixel_one_line%4);
unsigned int one_line_width_with_padding = bmp_header-image_width*3 +padding_size;
for(int i=0;i30;i++)
{
for(int j=0;jbmp_header-image_width*3;j++)
{
image_pixel_ptr[(one_line_width_with_padding*i) + j]=0;
}
}
}
부탁드려요 ㅠ 이번에도 답변해주시면 정말 감사하겠습니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700695 | 간단한 메모장 구현을 할려고 하는데요 (9) | 늘솜 | 2025-07-07 |
2700668 | c언어 질문입니다. 도와주세요~ (3) | 가자 | 2025-07-07 |
2700639 | 한글입력받아서 ㄱㄴㄷ순서대로출력하는법좀 | 두빛나래 | 2025-07-06 |
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |