PlotterHMI/machine/bmp/bwbmp.h

77 lines
2.6 KiB
C
Raw Normal View History

2024-02-06 06:19:53 +00:00
#ifndef BWBMP_H
#define BWBMP_H
#include <QString>
#include <QFileInfo>
#include "machine/comm/protocol.h"
2024-02-06 06:19:53 +00:00
#pragma pack(1) //设定为1字节对齐
// 位图的调色板
typedef struct
{
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbReserved;
}__attribute__ ((packed)) BmpRgbQuad;
// 位图文件头
typedef struct
{
unsigned short int identifier; // 类型 一般为 "BM"
unsigned long int fileSize; // 文件大小
unsigned long int reserved; // 保留
unsigned long int bitDatOffset; // 位图数据偏移,一般为 0x3E
unsigned long int biSize; // 位图信息头大小, 一般为 0x28
unsigned long int biWidth; // 位图宽度,以像素为单位
unsigned long int biHeight; // 位图高度,以像素为单位
unsigned short int biPlanes; // 位图的位面数必须为1
unsigned short int biBitPerPixel; // 每个像素的位数, =1, 单色位图; =4, 16色; = 8, 256色; = 24 真彩色
unsigned long int biCompression; // 位图压缩类型, =0, 不压缩BI_RGB; =1, BI_RLE8; = 2, BI_RLE4; = 3 BI_BITFIELDS; = 4, BI_JPEG; = 5, BI_PNG
unsigned long int biBitmapDatSize;// 位图数据区的大小(字节数), 必须是4的整数倍
unsigned long int biHResolution; // 水平分辨率, 像素/米
unsigned long int biVResolution; // 垂直分辨率, 像素/米
unsigned long int biColors; // 颜色数
unsigned long int biImpColors; // 重要颜色数
BmpRgbQuad palette[2]; // 调色板
}__attribute__ ((packed)) BitmapHead;
class BWBmp
{
public:
BWBmp();
public:
int LoadBiBmp(QString filename);
int SavePrBmp(QString filename);
int Compress(int idx = 0, int dir = 1, int segWidth = 300, int segHeight = 50);
QByteArray getPrBmpDat();
2024-02-06 06:19:53 +00:00
/*
int CompressSeg(const unsigned char * pBitDatBeg,
unsigned int width, unsigned int height,
unsigned int segWidth, unsigned int segHeight, unsigned char fill,
int compDir,
QByteArray & prDat);
int UnpressSeg(const unsigned char * pBitDatBeg,
unsigned int width, unsigned int height,
unsigned int segWidth, unsigned int segHeight, unsigned char fill,
int compDir,
QByteArray & prDat);
2024-02-06 06:19:53 +00:00
*/
2024-02-06 06:19:53 +00:00
private:
QByteArray m_bwDdat; // 单色BMP
2024-02-06 06:19:53 +00:00
QByteArray m_prDdat;
QByteArray m_rbwDdat;
QString m_fileName;
};
#endif // BWBMP_H