1 / 15

RAW File Format BMP File Format Gray / Color Image

02 장. 영상의 구성 방법. RAW File Format BMP File Format Gray / Color Image. Image format. File information. +. Image information. +. Palette information. No information. +. File information. Image information. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20. 20.

matteo
Download Presentation

RAW File Format BMP File Format Gray / Color Image

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 02장 영상의 구성 방법 • RAW File Format • BMP File Format • Gray / Color Image 한빛미디어(주)

  2. Image format File information + Image information + Palette information No information +

  3. File information Image information 20 20 20 20 20 20 20 20 20 20 20 20 20 20 Palette information 50 50 50 50 60 60 60 60 60 60 60 60 60 60 50 50 50 50 60 60 70 70 70 70 70 70 60 60 60 60 60 60 60 60 70 70 70 70 80 80 70 70 60 60 70 70 70 70 70 70 80 80 80 80 70 70 Raw Image

  4. Example #include <stdio.h> void main() { int i, j; unsigned char OrgImg[256][256]; FILE *infile = fopen("coin.raw","rb"); if(infile==NULL) { printf("File open error !!"); return; } fread(OrgImg,sizeof(char),256*256,infile); fclose(infile); for(i=0; i<256; i++) { for(j=0; j<256; j++) { OrgImg[i][j] = 255-OrgImg[i][j]; } } FILE *outfile = fopen("coin_inv.raw","wb"); fwrite(OrgImg,sizeof(char),256*256,outfile); fclose(outfile); }

  5. Preparation Image information 없음 Viewer Program 요구 Image Size

  6. 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

  7. 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

  8. BITMAPFILEHEADER BITMAPFILEHEADER typedefstructtagBITMATFILEHEADER {                 WORD           bfType;                 DWORD         bfSize;                 WORD           bfReserved1;                 WORD           bfReserved2;                 DWORD         bfOffBits; }BITMAPFILEHEADER;

  9. 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); }

  10. BITMAPFILEHEADER BITMAPINFOHEADER typedefstructtagBITMATINFOHEADER {                 DWORD         biSize;                 LONG           biWidth;                 LONG           biHeight;                 WORD           biPlanes;                 WORD           biBitCount;                 DWORD         bicompression;                 DWORD         biSizeImage;                 LONG           biXPelsPerMeter;                 LONG           biYPelsPerMeter;                 WORD           biClrUsed;                 WORD           biClrImportant; }BITMAPFILEHEADER;

  11. 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); }

  12. RGBQUAD RGBQUAD typedefstructtagBITMATFILEHEADER {                 BYTE           rgbBlue;                 BYTE           rgbGreen;                 BYTE           rgbRed;                 BYTE           bfReserved2; }RGBQUAD;

  13. 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); }

  14. 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; }

More Related