120 likes | 303 Views
Digital Image Processing. Dongseo Univ. d5302010@dongseo.ac.kr Kim Nam_Woo. BITMAPFILEHEADER. File Header. BITMAPINFOHEADER. 20. 20. 20. 20. 20. 20. 20. +. RGBQUAD. Image Header. +. 50. 50. 60. 60. 60. 60. 60. Palette information. +. 50. 50. 60. 70. 70. 70. 60. 60.
E N D
Digital Image Processing Dongseo Univ. d5302010@dongseo.ac.kr Kim Nam_Woo
BITMAPFILEHEADER File Header BITMAPINFOHEADER 20 20 20 20 20 20 20 + RGBQUAD Image Header + 50 50 60 60 60 60 60 Palette information + 50 50 60 70 70 70 60 60 60 60 70 70 80 70 60 70 70 70 80 80 70 Bitmap Image Kim Nam_Woo (d5302010@dongseo.ac.kr)
BITMAPFILEHEADER BITMAPINFOHEADER 20 20 20 20 20 20 20 RGBQUAD 50 50 60 60 60 60 60 50 50 60 70 70 70 60 60 60 60 70 70 80 70 60 70 70 70 80 80 70 HEADER INFORMATION BMP Header BMP Body Kim Nam_Woo (d5302010@dongseo.ac.kr)
BITMAPFILEHEADER BITMAPFILEHEADER typedef struct tagBITMATFILEHEADER { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; }BITMAPFILEHEADER; Kim Nam_Woo (d5302010@dongseo.ac.kr)
BITMAPFILEHEADER #include <stdio.h> #include <windows.h> #define WIDTHBYTES(bits) (((bits)+31)/32*4) #define BYTE unsigned char void main() { FILE *infile; infile=fopen("talent.bmp", "rb"); if(infile==NULL) { printf("There is no file!!!\n"); exit(1); } BITMAPFILEHEADER hf; fread(&hf,sizeof(BITMAPFILEHEADER),1,infile); if(hf.bfType!=0x4D42) exit(1); printf("bfType\t\t: %ox\n",hf.bfType); printf("bfSize\t\t: %d\n",hf.bfSize); printf("bfReserved1\t: %d\n",hf.bfReserved1); printf("bfReserved2\t: %d\n",hf.bfReserved2); printf("bfOffBits\t: %d\n",hf.bfOffBits); fclose(infile); } Kim Nam_Woo (d5302010@dongseo.ac.kr)
BITMAPFILEHEADER BITMAPINFOHEADER typedef struct tagBITMATINFOHEADER { DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD bicompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; WORD biClrUsed; WORD biClrImportant; }BITMAPFILEHEADER; Kim Nam_Woo (d5302010@dongseo.ac.kr)
BITMAPINFOHEADER #include <stdio.h> #include <windows.h> #define WIDTHBYTES(bits) (((bits)+31)/32*4) #define BYTE unsigned char void main() { FILE *infile; infile=fopen("talent.bmp", "rb"); if(infile==NULL) { printf("There is no file!!!\n"); exit(1); } BITMAPFILEHEADER hf; fread(&hf,sizeof(BITMAPFILEHEADER),1,infile); if(hf.bfType!=0x4D42) exit(1); BITMAPINFOHEADER hInfo; fread(&hInfo,sizeof(BITMAPINFOHEADER),1,infile); printf("Image Size: (%3dx%3d)\n",hInfo.biWidth,hInfo.biHeight); printf("Pallete Type: %dbit Colors\n",hInfo.biBitCount); } Kim Nam_Woo (d5302010@dongseo.ac.kr)
RGBQUAD RGBQUAD typedef struct tagBITMATFILEHEADER { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE bfReserved2; }RGBQUAD; Kim Nam_Woo (d5302010@dongseo.ac.kr)
BITMAPINFOHEADER #include <stdio.h> #include <windows.h> #define WIDTHBYTES(bits) (((bits)+31)/32*4) #define BYTE unsigned char void main() { FILE *infile; infile=fopen("talent.bmp", "rb"); if(infile==NULL) { printf("There is no file!!!\n"); exit(1); } BITMAPFILEHEADER hf; fread(&hf,sizeof(BITMAPFILEHEADER),1,infile); if(hf.bfType!=0x4D42) exit(1); BITMAPINFOHEADER hInfo; fread(&hInfo,sizeof(BITMAPINFOHEADER),1,infile); printf("Image Size: (%3dx%3d)\n",hInfo.biWidth,hInfo.biHeight); printf("Pallete Type: %dbit Colors\n",hInfo.biBitCount); if(hInfo.biBitCount!=8 ) { printf("Bad File format!!"); exit(1); } RGBQUAD hRGB[256]; fread(hRGB,sizeof(RGBQUAD),256,infile); } Kim Nam_Woo (d5302010@dongseo.ac.kr)
Example • #include <stdio.h> • #include <windows.h> • #define WIDTHBYTES(bits) (((bits)+31)/32*4) // 영상 가로길이는 4바이트의 배수여야 함 • #define BYTE unsigned char • void main() • { • FILE *infile; • infile=fopen("talent.bmp", "rb"); • if(infile==NULL) { printf("There is no file!!!\n"); exit(1); } • BITMAPFILEHEADER hf; • fread(&hf,sizeof(BITMAPFILEHEADER),1,infile); // 파일헤드를 읽음 • if(hf.bfType!=0x4D42) exit(1); • BITMAPINFOHEADER hInfo; • fread(&hInfo,sizeof(BITMAPINFOHEADER),1,infile); // 영상헤드를 읽음 • printf("Image Size: (%3dx%3d)\n",hInfo.biWidth,hInfo.biHeight); • printf("Pallete Type: %dbit Colors\n",hInfo.biBitCount); • // 256칼라 이하의 경우는 취급하지 않음 • if(hInfo.biBitCount!=8 ) { printf("Bad File format!!"); exit(1); } • RGBQUAD hRGB[256]; • fread(hRGB,sizeof(RGBQUAD),256,infile); // 팔레트를 파일에서 읽음 • // 영상데이타를 저장할 메모리 할당 • BYTE *lpImg = new BYTE [hInfo.biSizeImage]; • fread(lpImg,sizeof(char),hInfo.biSizeImage,infile); • fclose(infile); • // 역상의 이미지 구하기 • int rwsize = WIDTHBYTES(hInfo.biBitCount*hInfo.biWidth); • for(int i=0; i<hInfo.biHeight; i++) • { • for(int j=0; j<hInfo.biWidth; j++) • { • lpImg[i*rwsize+j] = 255-lpImg[i*rwsize+j]; • } • } • // 영상 출력 • FILE *outfile = fopen("OutImg.bmp","wb"); • fwrite(&hf,sizeof(char),sizeof(BITMAPFILEHEADER),outfile); • fwrite(&hInfo,sizeof(char),sizeof(BITMAPINFOHEADER),outfile); • fwrite(hRGB,sizeof(RGBQUAD),256,outfile); • fwrite(lpImg,sizeof(char),hInfo.biSizeImage,outfile); • fclose(outfile); • // 메모리 해제 • delete []lpImg; • } Kim Nam_Woo (d5302010@dongseo.ac.kr)