QR_Encode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __QRENCODE_H
  2. #define __QRENCODE_H
  3. typedef unsigned char bool; /* 8-bit*/
  4. #ifndef NULL
  5. #define NULL 0
  6. #endif
  7. #ifndef TRUE
  8. #define TRUE 1
  9. #endif
  10. #ifndef FALSE
  11. #define FALSE 0
  12. #endif
  13. //#ifndef BYTE
  14. //typedef unsigned char BYTE;
  15. //#endif
  16. //#ifndef WORD
  17. // typedef unsigned int WORD;
  18. //#endif
  19. //typedef enum {FALSE = 0, TRUE = !FALSE} bool;
  20. #define min(a,b) (((a) < (b)) ? (a) : (b))
  21. //4种纠错等级,可恢复的码字比例为:
  22. #define QR_LEVEL_L 0 //7%的字码可被修正
  23. #define QR_LEVEL_M 1 //15%的字码可被修正
  24. #define QR_LEVEL_Q 2 //25%的字码可被修正
  25. #define QR_LEVEL_H 3 //30%的字码可被修正
  26. //编码形式
  27. #define QR_MODE_NUMERAL 0
  28. #define QR_MODE_ALPHABET 1
  29. #define QR_MODE_8BIT 2
  30. #define QR_MODE_KANJI 3
  31. #define QR_MODE_CHINESE 4
  32. //Number of bits per length field
  33. //Encoding Ver.1–9 10–26 27–40
  34. //Numeric 10 12 14
  35. //Alphanumeric 9 11 13
  36. //Byte 8 16 16
  37. //Kanji 8 10 12
  38. //Chinese
  39. //P17 字符计数指示的位数
  40. #define QR_VRESION_S 0
  41. #define QR_VRESION_M 1
  42. #define QR_VRESION_L 2
  43. #define QR_MARGIN 4
  44. #define QR_VER1_SIZE 29// 版本的行列数
  45. #define MAX_ALLCODEWORD 400//3706//400// //P14,P35 数据容量[码字]* (E) (VER:40), 所有码字为8位
  46. #define MAX_DATACODEWORD 400//2956//400// //P27 最大信息码子(Ver:40-L),所有码字为8位
  47. #define MAX_CODEBLOCK 153 //最大纠错码字 Ver:36.37.38_L_第二块
  48. #define MAX_MODULESIZE 61
  49. // 21:Version=1,最大字符=17(8.5个汉字)
  50. // 25:Version=2,最大字符=32(16个汉字)
  51. // 29:Version=3,最大字符=49(24.5个汉字)
  52. // 33:Version=4,最大字符=78(39个汉字)
  53. // 37:Version=5,最大字符=106(53个汉字)
  54. // 41:Version=6,最大字符=134(67个汉字)
  55. // 45:Version=7,最大字符=154(77个汉字)
  56. // 49:Version=8,最大字符=192(96个汉字)
  57. // 53:
  58. //#define MAX_MODULESIZE 177//P14 每边的模块数(A) (VER:40 ) Ver:40 = 21+(Ver-1)*4
  59. extern int m_nSymbleSize;
  60. extern unsigned char m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE];
  61. /////////////////////////////////////////////////////////////////////////////
  62. typedef struct
  63. {
  64. unsigned short int ncRSBlock; //纠错的块数
  65. unsigned short int ncAllCodeWord; //码字总数
  66. unsigned short int ncDataCodeWord; //指定纠错等级下的数据码字数
  67. }RS_BLOCKINFO;
  68. typedef struct
  69. {
  70. unsigned short int nVersionNo; //ver 1~40
  71. unsigned short int ncAllCodeWord; //码字总数=数据码字+纠错码字
  72. unsigned short int ncDataCodeWord[4]; //指定纠错等级下的数据码字(0=L,1=M,2=Q,3=H)
  73. unsigned short int ncAlignPoint; //P61 表E1 校正图形 个数
  74. unsigned short int nAlignPoint[6]; //P61 表E1 校正图形 行列坐标
  75. //(0=L,1=M,2=Q,3=H)
  76. RS_BLOCKINFO RS_BlockInfo1[4]; //纠错块1
  77. RS_BLOCKINFO RS_BlockInfo2[4]; //纠错块2
  78. }QR_VERSIONINFO;
  79. bool EncodeData(char *lpsSource);
  80. int GetEncodeVersion(int nVersion, char *lpsSource, int ncLength);
  81. //bool EncodeSourceData(char *lpsSource, int ncLength, int nVerGroup);
  82. int EncodeSourceData(char *lpsSource, int ncLength, int nVerGroup);
  83. int GetBitLength(unsigned char nMode, int ncData, int nVerGroup);
  84. int SetBitStream(int nIndex, unsigned short wData, int ncData);
  85. bool IsNumeralData(unsigned char c);
  86. bool IsAlphabetData(unsigned char c);
  87. bool IsKanjiData(unsigned char c1, unsigned char c2);
  88. bool IsChineseData(unsigned char c1, unsigned char c2);
  89. unsigned char AlphabetToBinaly(unsigned char c);
  90. unsigned short KanjiToBinaly(unsigned short wc);
  91. unsigned short ChineseToBinaly(unsigned short wc);
  92. void GetRSCodeWord(unsigned char *lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord);
  93. void FormatModule(void);
  94. void SetFunctionModule(void);
  95. void SetFinderPattern(int x, int y);
  96. void SetAlignmentPattern(int x, int y);
  97. void SetVersionPattern(void);
  98. void SetCodeWordPattern(void);
  99. void SetMaskingPattern(int nPatternNo);
  100. void SetFormatInfoPattern(int nPatternNo);
  101. int CountPenalty(void);
  102. void Print_2DCode(void);
  103. #endif