-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathColorsBase.h
138 lines (117 loc) · 2.89 KB
/
ColorsBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* @file ColorsBase.h
* @brief 彩色二维码彩色编码解码基类
* @date 2016/10/15
*/
#pragma once
#include "DataTypes.h"
#include <vector>
using namespace std;
#ifndef MAX_MODULESIZE
#define MAX_MODULESIZE 177 /**< QR码最大尺寸 */
#endif
/**
* @enum EncodeModule
* @brief 彩色编码模块
* @details 1 - 在白色模块编码;0 - 在黑色模块编码
*/
enum EncodeModule
{
BlackModule = 0, /**< 在前景色编码(黑色) */
WhiteModule = 1, /**< 在背景色编码(白色) */
};
/// 掩码操作
const static int HEADER_MASK[90] = {
// 16 x 3 前48位为 Color Infomation
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
// 14 x 3 后42位为 Logo & Version
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
/// 采用新版
#define NEW_VERSION 1
/**
* @class ColorsBase
* @brief 彩色二维码编码解码基类
*/
class ColorsBase
{
protected:
BYTE* m_pBitMatrix[MAX_MODULESIZE]; /**< 原二维码 */
int m_nSymbolSize; /**< 二维码尺寸 */
vector<CPixelPoint> m_HeaderIndex; /**< 数据头索引 */
CLogoRect m_LogoRect; /**< 二维码LOGO */
private:
EncodeModule m_EncodeModule;/**< 彩色编码模块(1,默认为白色) */
vector<CPixelPoint> m_vColorsModuleIndex; /**< 彩色模块索引 */
public:
/**
* @brief 创建一个彩色编码解码基类对象
* @param[in] bMatrix 二维码数据
* @param[in] nSymbolSize 二维码尺寸
*/
ColorsBase(qrMat bMatrix[MAX_MODULESIZE], int nSymbolSize)
{
/// 采用for循环,将bMatrix的每行拷贝给m_pBitMatrix
/// @note 只能采用循环,不能使用memcpy
for (int i = 0; i < nSymbolSize; ++i)
{
m_pBitMatrix[i] = bMatrix[i];
}
/// 构造的对象默认无LOGO
m_LogoRect = 0;
/// 默认在白色模块编码色彩
m_EncodeModule = WhiteModule;
m_nSymbolSize = nSymbolSize;
}
/// 默认的析构函数
~ColorsBase() { }
/// 设置编码模块
inline void SetEncodeModule(EncodeModule Module)
{
m_EncodeModule = Module;
}
/// 获取编码模块
inline EncodeModule GetEncodeModule() const
{
return m_EncodeModule;
}
/// 设置二维码LOGO
inline void SetLogoRect(CMyRect logo)
{
m_LogoRect = logo;
}
/// 获取二维码LOGO
inline CMyRect GetLogoRect() const
{
return m_LogoRect;
}
/// 获取模块总数
inline int GetModulesCount() const
{
return m_nSymbolSize * m_nSymbolSize - m_LogoRect.Width() * m_LogoRect.Height();
}
// 获取编码模块总数
int GetColorsMoudlesCount() const
{
return m_vColorsModuleIndex.size();
}
/// 获取编码模块的索引
const vector<CPixelPoint>& GetColorsModuleIndex() const
{
return m_vColorsModuleIndex;
}
/// 获取彩色编码起始位置
int GetColorsStartIndex() const
{
return m_EncodeModule ? 0 : 90;
}
// 初始化编码模块的索引
void InitColorsModuleIndex(BOOL bFore = TRUE);
// (row, col)非数据头索引
BOOL NotHeaderIndex(int row, int col) const;
// 获取彩色数据头的索引
virtual void GetDataHeaderIndex() = 0;
};