00001
00002
00003
00004
00005
00006
00007
00008
00009
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];
00020 longword size;
00021 word reserved1;
00022 word reserved2;
00023 longword offset;
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;
00036 const longword bmpcompressionRLE8 = 1;
00037 const longword bmpcompressionRLE4 = 2;
00038 const longword bmpcompressionRGB_MASK = 3;
00039
00040 struct BMPInfoHeader {
00041 longword size;
00042 slongword width;
00043 slongword height;
00044 word planes;
00045 word bits;
00046 longword compression;
00047 longword imagesize;
00048 slongword xresolution;
00049 slongword yresolution;
00050 longword ncolors;
00051 longword nimportantcolors;
00052
00053 BMPInfoHeader() {
00054 size = 40;
00055 width = 0;
00056 height = 0;
00057 planes = 1;
00058 bits = 24;
00059 compression = bmpcompressionRGB;
00060 imagesize = 0;
00061 xresolution = 5706;
00062 yresolution = 5706;
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
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