이 코드 설명좀 부탁드려요.
새누
질문 제목 : 이 프로그래밍 주석과 어떤 역할을하는지 설명 좀 부탁드려요.ㅠ질문 요약 :프로그래밍 주석과 설명좀 부탁드려요.ㅠ질문 내용 : 헤더
//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;
}
}
}
부탁드려요 ㅠ 이번에도 답변해주시면 정말 감사하겠습니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2652198 | 연결 list 질문요~ | Sweeety | 2024-04-20 |
2652168 | 배열 정렬에서.. (6) | 비 | 2024-04-20 |
2652137 | scanf에서 나는 의문점입니다 (2) | 말글 | 2024-04-19 |
2652084 | timeGetTime질문이요 | 환찬 | 2024-04-19 |
2652058 | 포인터의 기본적인 질문입니다! (3) | 해뜰참 | 2024-04-19 |
2652031 | 더블포인터.... (1) | 눈 | 2024-04-18 |
2652003 | bmp 파일 이미지 축소와 픽셀 줄이기 코드짜는법!!! (1) | PinkPearl | 2024-04-18 |
2651981 | system("taskkill")명령어는 안전한 명령어인가요? | 수예 | 2024-04-18 |
2651930 | printf 함수가 입력은 있지만 반환값이 없는 함수라는게 무슨소리..? (1) | 두동 | 2024-04-17 |
2651904 | 스튜디오 2008에서 컴파일 어떻게 하죠? (3) | 햇햇 | 2024-04-17 |
2651875 | 이 책은 기본 베이스가 따로 있나요? (beginning linux programming) (3) | 은소라 | 2024-04-17 |
2651847 | 정수 변수를 선언한후 출력할때... 궁금한게 있는데요 (2) | 도움 | 2024-04-17 |
2651776 | C언어로 미분 하는 방법에 대해서 힌트좀 부탁드립니다. (1) | 이플 | 2024-04-16 |
2651747 | 배열에서요~ | 소라 | 2024-04-16 |
2651721 | while 반복문 (2) | 동이 | 2024-04-15 |
2651700 | 초보 질문여~ | 카이 | 2024-04-15 |
2651674 | printf %f 출력 질문 | 청식 | 2024-04-15 |
2651649 | 이것좀 해결해주세요 ㅠ | 빛글 | 2024-04-15 |
2651619 | 씨언어 질문이요~~ | 다빈 | 2024-04-14 |
2651591 | 이번 방학 두달동안 c언어 배울수있을까요? (2) | 알찬해 | 2024-04-14 |