| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- // QR_Encode.h : CQR_Encode クラス宣言およびインターフェイス定義
- // Date 2006/05/17 Ver. 1.22 Psytec Inc.
- #if !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
- #define AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- /////////////////////////////////////////////////////////////////////////////
- // 定数
- // 错误订正水平
- #define QR_LEVEL_L 0
- #define QR_LEVEL_M 1
- #define QR_LEVEL_Q 2
- #define QR_LEVEL_H 3
- // 数据模式
- #define QR_MODE_NUMERAL 0
- #define QR_MODE_ALPHABET 1
- #define QR_MODE_8BIT 2
- #define QR_MODE_KANJI 3
- // 版本(型号)小组
- #define QR_VRESION_S 0 // 1 ~ 9
- #define QR_VRESION_M 1 // 10 ~ 26
- #define QR_VRESION_L 2 // 27 ~ 40
- #define MAX_ALLCODEWORD 3706 // 总codeword数最大值
- #define MAX_DATACODEWORD 2956 // data codeWord最大值(版本40-L)
- #define MAX_CODEBLOCK 153 // 块data code存储量最大值(包括RScodeword)
- #define MAX_MODULESIZE 177 // 一边组件数最大值
- // 位图绘画时,赚头
- #define QR_MARGIN 4
- /////////////////////////////////////////////////////////////////////////////
- // Reed-Solomon error correction(里德-所罗门纠错算法)
- typedef struct tagRS_BLOCKINFO
- {
- int ncRSBlock; // RS块数
- int ncAllCodeWord; // 块内codeword数
- int ncDataCodeWord; // data code存储量(codeword数- RScodeword数)
- } RS_BLOCKINFO, *LPRS_BLOCKINFO;
- /////////////////////////////////////////////////////////////////////////////
- // QRcode bar约翰(型号)关联信息
- typedef struct tagQR_VERSIONINFO
- {
- int nVersionNo; // 版本(型号)号码(1~40);
- int ncAllCodeWord; // 版本对应的codeword数;
- // 以下排列添加字弄错订正率(0= L,1= M,2= Q,3= H)
- int ncDataCodeWord[4]; // data code存储量(总codeword数- RScodeword数)
- int ncAlignPoint; // alignment图形坐标数;
- int nAlignPoint[6]; // alignment图形中心坐标;
- RS_BLOCKINFO RS_BlockInfo1[4]; // RS块信息(1)
- RS_BLOCKINFO RS_BlockInfo2[4]; // RS块信息(2)
- } QR_VERSIONINFO, *LPQR_VERSIONINFO;
- /////////////////////////////////////////////////////////////////////////////
- // CQR_Encode 类;
- class CQR_Encode
- {
- public:
- CQR_Encode();
- ~CQR_Encode();
- public:
- int m_nLevel; // 错误订正水平;
- int m_nVersion; // 版本(型号);
- BOOL m_bAutoExtent; // 版本(型号)自动扩张指定标志;
- int m_nMaskingNo; // 掩蔽图形号码;
- public:
- int m_nSymbleSize;
- BYTE m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE]; // [x][y]
- // bit5∶功能模块(掩蔽不适用)标志
- // bit4∶功能模块绘画数据
- // bit1∶编码数据
- // bit0∶面具后编码绘画数据 根据
- //20h或功能模块判断,根据11h或绘画(最终BOOL价值化)
- private:
- int m_ncDataCodeWordBit; // // data codeWord位长
- BYTE m_byDataCodeWord[MAX_DATACODEWORD]; //输入数据编码区域
- int m_ncDataBlock;
- BYTE m_byBlockMode[MAX_DATACODEWORD];
- int m_nBlockLength[MAX_DATACODEWORD];
- int m_ncAllCodeWord; //总codeword数(包括RS错误订正数据)
- BYTE m_byAllCodeWord[MAX_ALLCODEWORD]; //总codeword算出区域
- BYTE m_byRSWork[MAX_CODEBLOCK]; // RScodeword算出工作
- // 数据编码关联机能
- public:
- BOOL EncodeData(int nLevel, int nVersion, BOOL bAutoExtent, int nMaskingNo, LPCSTR lpsSource, int ncSource = 0);
- private:
- int GetEncodeVersion(int nVersion, LPCSTR lpsSource, int ncLength);
- BOOL EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup);
- int GetBitLength(BYTE nMode, int ncData, int nVerGroup);
- int SetBitStream(int nIndex, WORD wData, int ncData);
- BOOL IsNumeralData(unsigned char c);
- BOOL IsAlphabetData(unsigned char c);
- BOOL IsKanjiData(unsigned char c1, unsigned char c2);
- BYTE AlphabetToBinaly(unsigned char c);
- WORD KanjiToBinaly(WORD wc);
- void GetRSCodeWord(LPBYTE lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord);
- // 组件配置关联机能
- private:
- void FormatModule();
- void SetFunctionModule();
- void SetFinderPattern(int x, int y);
- void SetAlignmentPattern(int x, int y);
- void SetVersionPattern();
- void SetCodeWordPattern();
- void SetMaskingPattern(int nPatternNo);
- void SetFormatInfoPattern(int nPatternNo);
- int CountPenalty();
- };
- /////////////////////////////////////////////////////////////////////////////
- #endif // !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
|