Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

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 #include <OPENR/ODataFormats.h>
00017 
00018 struct BMPHeader {
00019     byte      magic[2];         // Magic number 'BM'
00020     longword  size;             // File size
00021     word      reserved1;        // Reserved
00022     word      reserved2;        // Reserved
00023     longword  offset;           // Offset to image data
00024 
00025     BMPHeader() {
00026         magic[0] = 'B';
00027         magic[1] = 'M';
00028         size = 0;
00029         reserved1 = 0;
00030         reserved2 = 0;
00031         offset = 14 + 40;
00032     }
00033 };
00034 
00035 const longword bmpcompressionRGB      = 0; // No compression - RGB bitmap
00036 const longword bmpcompressionRLE8     = 1; // 8-bit run-length compression
00037 const longword bmpcompressionRLE4     = 2; // 4-bit run-length compression
00038 const longword bmpcompressionRGB_MASK = 3; // RGB bitmap with RGB masks
00039 
00040 struct BMPInfoHeader {          // 40 bytes (total)
00041     longword  size;             // Info header size
00042     slongword width;            // Width of image
00043     slongword height;           // Height of image
00044     word      planes;           // Number of color planes
00045     word      bits;             // Bits per pixel
00046     longword  compression;      // Compression type
00047     longword  imagesize;        // Image size
00048     slongword xresolution;      // X pixels per meter
00049     slongword yresolution;      // Y pixels per meter
00050     longword  ncolors;          // Number of colors
00051     longword  nimportantcolors; // Number of important colors
00052 
00053     BMPInfoHeader() {
00054         size             = 40;  // sizeof(BMPInfoHeader)
00055         width            = 0;
00056         height           = 0;
00057         planes           = 1;
00058         bits             = 24;
00059         compression      = bmpcompressionRGB;
00060         imagesize        = 0;
00061         xresolution      = 5706; // 144dpi
00062         yresolution      = 5706; // 144dpi
00063         ncolors          = 0;
00064         nimportantcolors = 0;
00065     }
00066 };
00067 
00068 class BMP {
00069 public:
00070     BMP() {}
00071     ~BMP() {}
00072     
00073     bool SaveYCrCb2RGB(char* path, 
00074                        OFbkImageVectorData* imageVec, OFbkImageLayer layer);
00075 
00076     bool SaveLayerC(char* basepath, OFbkImageVectorData* imageVec);
00077 
00078     bool SaveRaw2Gray(char* path,
00079                       byte* image, int width, int height, int skip);
00080 
00081 
00082 private:
00083     //
00084     // Image pixels are ordered B,G,R,B,G,R,... instead of R,G,B,R,G,B,...
00085     //
00086     static const int B_PIXEL = 0;
00087     static const int G_PIXEL = 1;
00088     static const int R_PIXEL = 2;
00089 
00090     void SaveBMPHeader(FILE* fp, const BMPHeader& header);
00091     void SaveBMPInfoHeader(FILE* fp, const BMPInfoHeader& infoheader);
00092     void YCrCb2RGB(byte y, byte cr, byte cb, byte* r, byte* g, byte* b);
00093     
00094     void write_word(FILE* fp, word w);
00095     void write_longword(FILE* fp, longword l);
00096     void write_slongword(FILE* fp, slongword sl);
00097 };
00098 
00099 #endif // BMP_h_DEFINED


tams Tim Baier AiboLib v0.2.4
Generated Thu Jan 19 11:54:29 2006 by doxygen 1.4.3