QR_Encode.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // QR_Encode.h : CQR_Encode クラス宣言およびインターフェイス定義
  2. // Date 2006/05/17 Ver. 1.22 Psytec Inc.
  3. #if !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
  4. #define AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_
  5. #if _MSC_VER > 1000
  6. #pragma once
  7. #endif // _MSC_VER > 1000
  8. /////////////////////////////////////////////////////////////////////////////
  9. // 定数
  10. // 错误订正水平
  11. #define QR_LEVEL_L 0
  12. #define QR_LEVEL_M 1
  13. #define QR_LEVEL_Q 2
  14. #define QR_LEVEL_H 3
  15. // 数据模式
  16. #define QR_MODE_NUMERAL 0
  17. #define QR_MODE_ALPHABET 1
  18. #define QR_MODE_8BIT 2
  19. #define QR_MODE_KANJI 3
  20. // 版本(型号)小组
  21. #define QR_VRESION_S 0 // 1 ~ 9
  22. #define QR_VRESION_M 1 // 10 ~ 26
  23. #define QR_VRESION_L 2 // 27 ~ 40
  24. #define MAX_ALLCODEWORD 3706 // 总codeword数最大值
  25. #define MAX_DATACODEWORD 2956 // data codeWord最大值(版本40-L)
  26. #define MAX_CODEBLOCK 153 // 块data code存储量最大值(包括RScodeword)
  27. #define MAX_MODULESIZE 177 // 一边组件数最大值
  28. // 位图绘画时,赚头
  29. #define QR_MARGIN 4
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Reed-Solomon error correction(里德-所罗门纠错算法)
  32. typedef struct tagRS_BLOCKINFO
  33. {
  34. int ncRSBlock; // RS块数
  35. int ncAllCodeWord; // 块内codeword数
  36. int ncDataCodeWord; // data code存储量(codeword数- RScodeword数)
  37. } RS_BLOCKINFO, *LPRS_BLOCKINFO;
  38. /////////////////////////////////////////////////////////////////////////////
  39. // QRcode bar约翰(型号)关联信息
  40. typedef struct tagQR_VERSIONINFO
  41. {
  42. int nVersionNo; // 版本(型号)号码(1~40);
  43. int ncAllCodeWord; // 版本对应的codeword数;
  44. // 以下排列添加字弄错订正率(0= L,1= M,2= Q,3= H)
  45. int ncDataCodeWord[4]; // data code存储量(总codeword数- RScodeword数)
  46. int ncAlignPoint; // alignment图形坐标数;
  47. int nAlignPoint[6]; // alignment图形中心坐标;
  48. RS_BLOCKINFO RS_BlockInfo1[4]; // RS块信息(1)
  49. RS_BLOCKINFO RS_BlockInfo2[4]; // RS块信息(2)
  50. } QR_VERSIONINFO, *LPQR_VERSIONINFO;
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CQR_Encode 类;
  53. class CQR_Encode
  54. {
  55. public:
  56. CQR_Encode();
  57. ~CQR_Encode();
  58. public:
  59. int m_nLevel; // 错误订正水平;
  60. int m_nVersion; // 版本(型号);
  61. BOOL m_bAutoExtent; // 版本(型号)自动扩张指定标志;
  62. int m_nMaskingNo; // 掩蔽图形号码;
  63. public:
  64. int m_nSymbleSize;
  65. BYTE m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE]; // [x][y]
  66. // bit5∶功能模块(掩蔽不适用)标志
  67. // bit4∶功能模块绘画数据
  68. // bit1∶编码数据
  69. // bit0∶面具后编码绘画数据 根据
  70. //20h或功能模块判断,根据11h或绘画(最终BOOL价值化)
  71. private:
  72. int m_ncDataCodeWordBit; // // data codeWord位长
  73. BYTE m_byDataCodeWord[MAX_DATACODEWORD]; //输入数据编码区域
  74. int m_ncDataBlock;
  75. BYTE m_byBlockMode[MAX_DATACODEWORD];
  76. int m_nBlockLength[MAX_DATACODEWORD];
  77. int m_ncAllCodeWord; //总codeword数(包括RS错误订正数据)
  78. BYTE m_byAllCodeWord[MAX_ALLCODEWORD]; //总codeword算出区域
  79. BYTE m_byRSWork[MAX_CODEBLOCK]; // RScodeword算出工作
  80. // 数据编码关联机能
  81. public:
  82. BOOL EncodeData(int nLevel, int nVersion, BOOL bAutoExtent, int nMaskingNo, LPCSTR lpsSource, int ncSource = 0);
  83. private:
  84. int GetEncodeVersion(int nVersion, LPCSTR lpsSource, int ncLength);
  85. BOOL EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup);
  86. int GetBitLength(BYTE nMode, int ncData, int nVerGroup);
  87. int SetBitStream(int nIndex, WORD wData, int ncData);
  88. BOOL IsNumeralData(unsigned char c);
  89. BOOL IsAlphabetData(unsigned char c);
  90. BOOL IsKanjiData(unsigned char c1, unsigned char c2);
  91. BYTE AlphabetToBinaly(unsigned char c);
  92. WORD KanjiToBinaly(WORD wc);
  93. void GetRSCodeWord(LPBYTE lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord);
  94. // 组件配置关联机能
  95. private:
  96. void FormatModule();
  97. void SetFunctionModule();
  98. void SetFinderPattern(int x, int y);
  99. void SetAlignmentPattern(int x, int y);
  100. void SetVersionPattern();
  101. void SetCodeWordPattern();
  102. void SetMaskingPattern(int nPatternNo);
  103. void SetFormatInfoPattern(int nPatternNo);
  104. int CountPenalty();
  105. };
  106. /////////////////////////////////////////////////////////////////////////////
  107. #endif // !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)