이 코드 설명좀 부탁드려요.
새누
질문 제목 : 이 프로그래밍 주석과 어떤 역할을하는지 설명 좀 부탁드려요.ㅠ질문 요약 :프로그래밍 주석과 설명좀 부탁드려요.ㅠ질문 내용 : 헤더
//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;
}
}
}
부탁드려요 ㅠ 이번에도 답변해주시면 정말 감사하겠습니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2653613 | 성별변수 | 뿡뿡 | 2024-05-03 |
2653584 | 16진수 변환 관련 질문 드립니다. | 매미꽃 | 2024-05-03 |
2653557 | 한글 완성형과 조합형의 전환 | 해지개 | 2024-05-02 |
2653506 | void형 포인터 이해안가요 ㅠㅠ (2) | 뭘봐요 | 2024-05-02 |
2653482 | 패턴매칭에 대한 질문하나 올립니다 | 미투리 | 2024-05-02 |
2653452 | main 함수 매개변수 문의드립니다. (2) | 딥레드 | 2024-05-01 |
2653425 | 간단한 포인터 설명좀 해주세요 ㅠㅠㅠ | 차분나래 | 2024-05-01 |
2653400 | 플로우 차트 작성 질문입니다. (2) | 아인 | 2024-05-01 |
2653370 | c언어 해석 부탁드립니다 ㅠ | 악당 | 2024-05-01 |
2653345 | 분수의 덧셈 질문이요 | 하늘 | 2024-04-30 |
2653313 | //정수 n을 입력받아 1부터 n까지의 합을 구하는 프로그램// (6) | 거북이 | 2024-04-30 |
2653284 | 알파벳 변수 관련(배열에서) | 나슬 | 2024-04-30 |
2653260 | C언어 scanf인데.. | 찬누리 | 2024-04-30 |
2653230 | 한글로 해석부탁드립니다. (1) | BlackCat | 2024-04-29 |
2653142 | 질문드립니다.. 부탁드립니다.. | 머슴밥 | 2024-04-29 |
2653119 | cmd창[도스창, 콘솔창]에 한글이 출력이 안되요. (2) | By은지 | 2024-04-28 |
2653096 | C언어와 C++, 베이직C++의 차이 (1) | 두동 | 2024-04-28 |
2653014 | 전기 분야에서는 C언어가 어떤, 어느 용도로 쓰이나요? (7) | 처녀자리 | 2024-04-27 |
2652986 | c언어 프로그램~~ (5) | 가장 | 2024-04-27 |
2652907 | mciSendString 함수 플레이 시간, (1) | 해나 | 2024-04-26 |