PlotterHMI/machine/bmp/bwbmp.h
huahaiyan 3ce55cebbd 20240308
1、梳理代码,修改绘制会绘制两次的bug;
2、增加正向旋转功能,线宽设置功能;
3、测试压缩算法,完成;
2024-03-08 16:33:05 +08:00

77 lines
2.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef BWBMP_H
#define BWBMP_H
#include <QString>
#include <QFileInfo>
#include "machine/comm/protocol.h"
#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();
/*
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);
*/
private:
QByteArray m_bwDdat; // 单色BMP
QByteArray m_prDdat;
QByteArray m_rbwDdat;
QString m_fileName;
};
#endif // BWBMP_H