ImageObserver/util/BMP.h

Go to the documentation of this file.
00001 //
00002 // Copyright 2002 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 
00012 #ifndef _BMP_h_DEFINED
00013 #define _BMP_h_DEFINED
00014 
00015 #include <stdio.h>
00016 
00017 typedef unsigned char   byte;       /* must be 8-bit quantity */
00018 typedef unsigned short  word;       /* must be 16-bit quantity */
00019 typedef unsigned long   longword;   /* must be 32-bit quantity */
00020 typedef char            sbyte;      /* must be signed 8-bit quantity */
00021 typedef short           sword;      /* must be signed 16-bit quantity */
00022 typedef long            slongword;  /* must be signed 32-bit quantity */
00023 
00024 struct BMPHeader {
00025     byte      magic[2];         // Magic number 'BM'
00026     longword  size;             // File size
00027     word      reserved1;        // Reserved
00028     word      reserved2;        // Reserved
00029     longword  offset;           // Offset to image data
00030 
00031     BMPHeader() {
00032         magic[0] = 'B';
00033         magic[1] = 'M';
00034         size = 0;
00035         reserved1 = 0;
00036         reserved2 = 0;
00037         offset = 14 + 40;
00038     }
00039 };
00040 
00041 const longword bmpcompressionRGB      = 0; // No compression - RGB bitmap
00042 const longword bmpcompressionRLE8     = 1; // 8-bit run-length compression
00043 const longword bmpcompressionRLE4     = 2; // 4-bit run-length compression
00044 const longword bmpcompressionRGB_MASK = 3; // RGB bitmap with RGB masks
00045 
00046 struct BMPInfoHeader {          // 40 bytes (total)
00047     longword  size;             // Info header size
00048     slongword width;            // Width of image
00049     slongword height;           // Height of image
00050     word      planes;           // Number of color planes
00051     word      bits;             // Bits per pixel
00052     longword  compression;      // Compression type
00053     longword  imagesize;        // Image size
00054     slongword xresolution;      // X pixels per meter
00055     slongword yresolution;      // Y pixels per meter
00056     longword  ncolors;          // Number of colors
00057     longword  nimportantcolors; // Number of important colors
00058 
00059     BMPInfoHeader() {
00060         size             = 40;  // sizeof(BMPInfoHeader)
00061         width            = 0;
00062         height           = 0;
00063         planes           = 1;
00064         bits             = 24;
00065         compression      = bmpcompressionRGB;
00066         imagesize        = 0;
00067         xresolution      = 5904; // 144dpi
00068         yresolution      = 5904; // 144dpi
00069         ncolors          = 0;
00070         nimportantcolors = 0;
00071     }
00072 };
00073 
00074 class BMP {
00075 public:
00076     BMP() {}
00077     ~BMP() {}
00078     
00079     bool SaveCDT(char* path, byte y_segment,
00080                  byte cr_max, byte cr_min, byte cb_max, byte cb_min);
00081     bool SaveRawDataAsCDT(char* basepath, byte* data, size_t w, size_t h);
00082 
00083 private:
00084     //
00085     // Image pixels are ordered B,G,R,B,G,R,... instead of R,G,B,R,G,B,...
00086     //
00087     static const int B_PIXEL = 0;
00088     static const int G_PIXEL = 1;
00089     static const int R_PIXEL = 2;
00090 
00091     void SaveBMPHeader(FILE* fp, const BMPHeader& header);
00092     void SaveBMPInfoHeader(FILE* fp, const BMPInfoHeader& infoheader);
00093     void YCrCb2RGB(byte y, byte cr, byte cb, byte* r, byte* g, byte* b);
00094     
00095     void write_word(FILE* fp, word w);
00096     void write_longword(FILE* fp, longword l);
00097     void write_slongword(FILE* fp, slongword sl);
00098 };
00099 
00100 #endif // _BMP_h_DEFINED

Generated on Sun Dec 2 23:04:28 2007 for openSDK by  doxygen 1.3.9.1