이 코드 설명좀 부탁드려요.
새누
질문 제목 : 이 프로그래밍 주석과 어떤 역할을하는지 설명 좀 부탁드려요.ㅠ질문 요약 :프로그래밍 주석과 설명좀 부탁드려요.ㅠ질문 내용 : 헤더
//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;
}
}
}
부탁드려요 ㅠ 이번에도 답변해주시면 정말 감사하겠습니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2676182 | 숫자 순서대로 배열하는법 | 권뉴 | 2024-11-24 |
2676152 | 기본적인거 하나 질문드립니다. | 개미 | 2024-11-24 |
2676124 | 함수선언관련 질문이에요~...털썩..수정완료 (2) | 가지 | 2024-11-24 |
2676092 | C언어 책 (2) | 아서 | 2024-11-24 |
2676065 | 웹사이트 또는 메신저 등에서 원하는 텍스트를 검사하는방법?? (1) | 모든 | 2024-11-23 |
2676033 | 배열 기초연습중 발생하는 에러 ㅠㅜ... | Creative | 2024-11-23 |
2676005 | keybd_event 게임 제어 | 영글 | 2024-11-23 |
2675900 | 진짜기본적인질문 | 글길 | 2024-11-22 |
2675845 | 수정좀해주세요ㅠㅠㅠ | 해골 | 2024-11-21 |
2675797 | 병합 정렬 소스 코드 질문입니다. (2) | 도래솔 | 2024-11-21 |
2675771 | 큐의 활용이 정확히 어떻게 되죠?? | 해긴 | 2024-11-21 |
2675745 | 도서관리 프로그램 질문이요 | 도리도리 | 2024-11-20 |
2675717 | 2진수로 변환하는것! (3) | 동생몬 | 2024-11-20 |
2675599 | for문 짝수 출력하는 법 (5) | 널위해 | 2024-11-19 |
2675575 | Linux 게시판이 없어서.. | 첫삥 | 2024-11-19 |
2675545 | 구조체 이용할 때 함수에 자료 넘겨주는 것은 어떻게 해야 하나요? | 아연 | 2024-11-19 |
2675518 | 사각형 가로로 어떻게 반복해서 만드는지좀.. 내용 | 신당 | 2024-11-18 |
2675491 | !느낌표를 입력하는것은 어떻게합니까~~?ㅠㅠ (5) | 사지타리우스 | 2024-11-18 |
2675411 | 파일입출력으로 받아온 파일의 중복문자열을 제거한 뒤 파일출력 | 앨버트 | 2024-11-17 |
2675385 | 링크드리스트 주소록 질문드립니다. (1) | 겨루 | 2024-11-17 |