#ifndef BWBMP_H #define BWBMP_H #include #include #ifndef u8 #define u8 unsigned char #endif #ifndef u16 #define u16 unsigned short #endif #ifndef u32 #define u32 unsigned int #endif #pragma pack(push, 1) //设定为1字节对齐 // 位图的调色板 typedef union { u32 color; struct { u8 rgbBlue; u8 rgbGreen; u8 rgbRed; u8 rgbReserved; }__attribute__ ((packed)) rgb; } BmpRgbQuad; // 位图文件头 typedef struct { u16 identifier; // 类型 一般为 "BM" u32 fileSize; // 文件大小 u32 reserved; // 保留 u32 bitDatOffset; // 位图数据偏移,一般为 0x3E u32 biSize; // 位图信息头大小, 一般为 0x28 u32 biWidth; // 位图宽度,以像素为单位 u32 biHeight; // 位图高度,以像素为单位 u16 biPlanes; // 位图的位面数,必须为1 u16 biBitPerPixel; // 每个像素的位数, =1, 单色位图; =4, 16色; = 8, 256色; = 24 真彩色 u32 biCompression; // 位图压缩类型, =0, 不压缩(BI_RGB); =1, BI_RLE8; = 2, BI_RLE4; = 3 BI_BITFIELDS; = 4, BI_JPEG; = 5, BI_PNG u32 biBitmapDatSize;// 位图数据区的大小(字节数), 必须是4的整数倍 u32 biHResolution; // 水平分辨率, 像素/米 u32 biVResolution; // 垂直分辨率, 像素/米 u32 biColors; // 颜色数 u32 biImpColors; // 重要颜色数 BmpRgbQuad palette[2]; // 调色板 }__attribute__ ((packed)) BitmapHead; // 压缩位图文件头 typedef struct { // 0 u32 fileId; // 整个位图文件标识 u32 blkIdx; // 当前位图块号(位图分块后的编号) u32 datSize; // 本块位图数据区的大小(字节数) u32 biWidth; // 本块位图有效宽度,以像素为单位 u32 biHeight; // 本块位图有效高度,以像素为单位 u32 dataChecksum; // 本块位图数据累加校验和 u32 begPos; // 本块位图起始位置(像素单位) u32 endPos; // 本块位图结束位置(像素单位) // 32 u8 compType; // 本块位图压缩类型, =0, 不压缩; =1, 按字节压缩; u8 compDir; // 本块位图压缩方向, =0, 从上到下; =1, 从下到上;(喷墨方向) // 34 u8 rev[64-2-34]; // 保留 // 62 u16 checkCrc; // 前面字段的CRC校验 }__attribute__ ((packed)) CompBmpHead; #pragma pack(pop) class BWBmp { public: BWBmp(); public: int LoadBiBmp(QString filename); int SavePrBmp(QString filename); int Compress(int idx = 0, int dir = 1); int LoadPrBmp(QString filename); int Unpress(); int SaveBiBmp(QString filename); QByteArray getPrBmpDat(); private: QByteArray m_bwDdat; QByteArray m_prDdat; QByteArray m_rbwDdat; QString m_fileName; }; #endif // BWBMP_H