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
00017 typedef unsigned char byte;
00018 typedef unsigned short word;
00019 typedef unsigned long longword;
00020 typedef char sbyte;
00021 typedef short sword;
00022 typedef long slongword;
00023
00024 struct BMPHeader {
00025 byte magic[2];
00026 longword size;
00027 word reserved1;
00028 word reserved2;
00029 longword offset;
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;
00042 const longword bmpcompressionRLE8 = 1;
00043 const longword bmpcompressionRLE4 = 2;
00044 const longword bmpcompressionRGB_MASK = 3;
00045
00046 struct BMPInfoHeader {
00047 longword size;
00048 slongword width;
00049 slongword height;
00050 word planes;
00051 word bits;
00052 longword compression;
00053 longword imagesize;
00054 slongword xresolution;
00055 slongword yresolution;
00056 longword ncolors;
00057 longword nimportantcolors;
00058
00059 BMPInfoHeader() {
00060 size = 40;
00061 width = 0;
00062 height = 0;
00063 planes = 1;
00064 bits = 24;
00065 compression = bmpcompressionRGB;
00066 imagesize = 0;
00067 xresolution = 5904;
00068 yresolution = 5904;
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
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