new
Dependents: epaper_mbed_test_copy1
QR_Encode.c@0:9efeb5787ae9, 2014-04-08 (annotated)
- Committer:
- fenoth
- Date:
- Tue Apr 08 10:08:03 2014 +0000
- Revision:
- 0:9efeb5787ae9
qr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fenoth | 0:9efeb5787ae9 | 1 | #include <stdio.h> |
fenoth | 0:9efeb5787ae9 | 2 | #include "QR_Encode.h" |
fenoth | 0:9efeb5787ae9 | 3 | |
fenoth | 0:9efeb5787ae9 | 4 | |
fenoth | 0:9efeb5787ae9 | 5 | int m_nLevel; |
fenoth | 0:9efeb5787ae9 | 6 | int QR_m_nVersion; |
fenoth | 0:9efeb5787ae9 | 7 | int m_nMaskingNo; |
fenoth | 0:9efeb5787ae9 | 8 | |
fenoth | 0:9efeb5787ae9 | 9 | int m_ncDataCodeWordBit,m_ncAllCodeWord, nEncodeVersion; |
fenoth | 0:9efeb5787ae9 | 10 | |
fenoth | 0:9efeb5787ae9 | 11 | int m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 12 | |
fenoth | 0:9efeb5787ae9 | 13 | //BYTE m_byRSWork[MAX_CODEBLOCK]; //RS code word calculation work |
fenoth | 0:9efeb5787ae9 | 14 | |
fenoth | 0:9efeb5787ae9 | 15 | int m_nSymbolSize; |
fenoth | 0:9efeb5787ae9 | 16 | |
fenoth | 0:9efeb5787ae9 | 17 | static QR_VERSIONINFO QR_VersionInfo[] = {{0}, // (Ver.0) |
fenoth | 0:9efeb5787ae9 | 18 | { 1, // Ver.1 |
fenoth | 0:9efeb5787ae9 | 19 | 26, 19, 16, 13, 9, |
fenoth | 0:9efeb5787ae9 | 20 | 0, 0, 0, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 21 | 1, 26, 19, |
fenoth | 0:9efeb5787ae9 | 22 | 1, 26, 16, |
fenoth | 0:9efeb5787ae9 | 23 | 1, 26, 13, |
fenoth | 0:9efeb5787ae9 | 24 | 1, 26, 9, |
fenoth | 0:9efeb5787ae9 | 25 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 26 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 27 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 28 | 0, 0, 0}, |
fenoth | 0:9efeb5787ae9 | 29 | { 2, // Ver.2 |
fenoth | 0:9efeb5787ae9 | 30 | 44, 34, 28, 22, 16, |
fenoth | 0:9efeb5787ae9 | 31 | 1, 18, 0, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 32 | 1, 44, 34, |
fenoth | 0:9efeb5787ae9 | 33 | 1, 44, 28, |
fenoth | 0:9efeb5787ae9 | 34 | 1, 44, 22, |
fenoth | 0:9efeb5787ae9 | 35 | 1, 44, 16, |
fenoth | 0:9efeb5787ae9 | 36 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 37 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 38 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 39 | 0, 0, 0}, |
fenoth | 0:9efeb5787ae9 | 40 | { 3, // Ver.3 |
fenoth | 0:9efeb5787ae9 | 41 | 70, 55, 44, 34, 26, |
fenoth | 0:9efeb5787ae9 | 42 | 1, 22, 0, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 43 | 1, 70, 55, |
fenoth | 0:9efeb5787ae9 | 44 | 1, 70, 44, |
fenoth | 0:9efeb5787ae9 | 45 | 2, 35, 17, |
fenoth | 0:9efeb5787ae9 | 46 | 2, 35, 13, |
fenoth | 0:9efeb5787ae9 | 47 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 48 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 49 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 50 | 0, 0, 0}, |
fenoth | 0:9efeb5787ae9 | 51 | { 4, // Ver.4 |
fenoth | 0:9efeb5787ae9 | 52 | 100, 80, 64, 48, 36, |
fenoth | 0:9efeb5787ae9 | 53 | 1, 26, 0, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 54 | 1, 100, 80, |
fenoth | 0:9efeb5787ae9 | 55 | 2, 50, 32, |
fenoth | 0:9efeb5787ae9 | 56 | 2, 50, 24, |
fenoth | 0:9efeb5787ae9 | 57 | 4, 25, 9, |
fenoth | 0:9efeb5787ae9 | 58 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 59 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 60 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 61 | 0, 0, 0}, |
fenoth | 0:9efeb5787ae9 | 62 | { 5, // Ver.5 |
fenoth | 0:9efeb5787ae9 | 63 | 134, 108, 86, 62, 46, |
fenoth | 0:9efeb5787ae9 | 64 | 1, 30, 0, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 65 | 1, 134, 108, |
fenoth | 0:9efeb5787ae9 | 66 | 2, 67, 43, |
fenoth | 0:9efeb5787ae9 | 67 | 2, 33, 15, |
fenoth | 0:9efeb5787ae9 | 68 | 2, 33, 11, |
fenoth | 0:9efeb5787ae9 | 69 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 70 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 71 | 2, 34, 16, |
fenoth | 0:9efeb5787ae9 | 72 | 2, 34, 12}, |
fenoth | 0:9efeb5787ae9 | 73 | { 6, // Ver.6 |
fenoth | 0:9efeb5787ae9 | 74 | 172, 136, 108, 76, 60, |
fenoth | 0:9efeb5787ae9 | 75 | 1, 34, 0, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 76 | 2, 86, 68, |
fenoth | 0:9efeb5787ae9 | 77 | 4, 43, 27, |
fenoth | 0:9efeb5787ae9 | 78 | 4, 43, 19, |
fenoth | 0:9efeb5787ae9 | 79 | 4, 43, 15, |
fenoth | 0:9efeb5787ae9 | 80 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 81 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 82 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 83 | 0, 0, 0}, |
fenoth | 0:9efeb5787ae9 | 84 | { 7, // Ver.7 |
fenoth | 0:9efeb5787ae9 | 85 | 196, 156, 124, 88, 66, |
fenoth | 0:9efeb5787ae9 | 86 | 2, 22, 38, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 87 | 2, 98, 78, |
fenoth | 0:9efeb5787ae9 | 88 | 4, 49, 31, |
fenoth | 0:9efeb5787ae9 | 89 | 2, 32, 14, |
fenoth | 0:9efeb5787ae9 | 90 | 4, 39, 13, |
fenoth | 0:9efeb5787ae9 | 91 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 92 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 93 | 4, 33, 15, |
fenoth | 0:9efeb5787ae9 | 94 | 1, 40, 14}, |
fenoth | 0:9efeb5787ae9 | 95 | { 8, // Ver.8 |
fenoth | 0:9efeb5787ae9 | 96 | 242, 194, 154, 110, 86, |
fenoth | 0:9efeb5787ae9 | 97 | 2, 24, 42, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 98 | 2, 121, 97, |
fenoth | 0:9efeb5787ae9 | 99 | 2, 60, 38, |
fenoth | 0:9efeb5787ae9 | 100 | 4, 40, 18, |
fenoth | 0:9efeb5787ae9 | 101 | 4, 40, 14, |
fenoth | 0:9efeb5787ae9 | 102 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 103 | 2, 61, 39, |
fenoth | 0:9efeb5787ae9 | 104 | 2, 41, 19, |
fenoth | 0:9efeb5787ae9 | 105 | 2, 41, 15}, |
fenoth | 0:9efeb5787ae9 | 106 | { 9, // Ver.9 |
fenoth | 0:9efeb5787ae9 | 107 | 292, 232, 182, 132, 100, |
fenoth | 0:9efeb5787ae9 | 108 | 2, 26, 46, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 109 | 2, 146, 116, |
fenoth | 0:9efeb5787ae9 | 110 | 3, 58, 36, |
fenoth | 0:9efeb5787ae9 | 111 | 4, 36, 16, |
fenoth | 0:9efeb5787ae9 | 112 | 4, 36, 12, |
fenoth | 0:9efeb5787ae9 | 113 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 114 | 2, 59, 37, |
fenoth | 0:9efeb5787ae9 | 115 | 4, 37, 17, |
fenoth | 0:9efeb5787ae9 | 116 | 4, 37, 13}, |
fenoth | 0:9efeb5787ae9 | 117 | {10, // Ver.10 |
fenoth | 0:9efeb5787ae9 | 118 | 346, 274, 216, 154, 122, |
fenoth | 0:9efeb5787ae9 | 119 | 2, 28, 50, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 120 | 2, 86, 68, |
fenoth | 0:9efeb5787ae9 | 121 | 4, 69, 43, |
fenoth | 0:9efeb5787ae9 | 122 | 6, 43, 19, |
fenoth | 0:9efeb5787ae9 | 123 | 6, 43, 15, |
fenoth | 0:9efeb5787ae9 | 124 | 2, 87, 69, |
fenoth | 0:9efeb5787ae9 | 125 | 1, 70, 44, |
fenoth | 0:9efeb5787ae9 | 126 | 2, 44, 20, |
fenoth | 0:9efeb5787ae9 | 127 | 2, 44, 16}, |
fenoth | 0:9efeb5787ae9 | 128 | {11, // Ver.11 |
fenoth | 0:9efeb5787ae9 | 129 | 404, 324, 254, 180, 140, |
fenoth | 0:9efeb5787ae9 | 130 | 2, 30, 54, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 131 | 4, 101, 81, |
fenoth | 0:9efeb5787ae9 | 132 | 1, 80, 50, |
fenoth | 0:9efeb5787ae9 | 133 | 4, 50, 22, |
fenoth | 0:9efeb5787ae9 | 134 | 3, 36, 12, |
fenoth | 0:9efeb5787ae9 | 135 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 136 | 4, 81, 51, |
fenoth | 0:9efeb5787ae9 | 137 | 4, 51, 23, |
fenoth | 0:9efeb5787ae9 | 138 | 8, 37, 13}, |
fenoth | 0:9efeb5787ae9 | 139 | {12, // Ver.12 |
fenoth | 0:9efeb5787ae9 | 140 | 466, 370, 290, 206, 158, |
fenoth | 0:9efeb5787ae9 | 141 | 2, 32, 58, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 142 | 2, 116, 92, |
fenoth | 0:9efeb5787ae9 | 143 | 6, 58, 36, |
fenoth | 0:9efeb5787ae9 | 144 | 4, 46, 20, |
fenoth | 0:9efeb5787ae9 | 145 | 7, 42, 14, |
fenoth | 0:9efeb5787ae9 | 146 | 2, 117, 93, |
fenoth | 0:9efeb5787ae9 | 147 | 2, 59, 37, |
fenoth | 0:9efeb5787ae9 | 148 | 6, 47, 21, |
fenoth | 0:9efeb5787ae9 | 149 | 4, 43, 15}, |
fenoth | 0:9efeb5787ae9 | 150 | {13, // Ver.13 |
fenoth | 0:9efeb5787ae9 | 151 | 532, 428, 334, 244, 180, |
fenoth | 0:9efeb5787ae9 | 152 | 2, 34, 62, 0, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 153 | 4, 133, 107, |
fenoth | 0:9efeb5787ae9 | 154 | 8, 59, 37, |
fenoth | 0:9efeb5787ae9 | 155 | 8, 44, 20, |
fenoth | 0:9efeb5787ae9 | 156 | 12, 33, 11, |
fenoth | 0:9efeb5787ae9 | 157 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 158 | 1, 60, 38, |
fenoth | 0:9efeb5787ae9 | 159 | 4, 45, 21, |
fenoth | 0:9efeb5787ae9 | 160 | 4, 34, 12}, |
fenoth | 0:9efeb5787ae9 | 161 | {14, // Ver.14 |
fenoth | 0:9efeb5787ae9 | 162 | 581, 461, 365, 261, 197, |
fenoth | 0:9efeb5787ae9 | 163 | 3, 26, 46, 66, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 164 | 3, 145, 115, |
fenoth | 0:9efeb5787ae9 | 165 | 4, 64, 40, |
fenoth | 0:9efeb5787ae9 | 166 | 11, 36, 16, |
fenoth | 0:9efeb5787ae9 | 167 | 11, 36, 12, |
fenoth | 0:9efeb5787ae9 | 168 | 1, 146, 116, |
fenoth | 0:9efeb5787ae9 | 169 | 5, 65, 41, |
fenoth | 0:9efeb5787ae9 | 170 | 5, 37, 17, |
fenoth | 0:9efeb5787ae9 | 171 | 5, 37, 13}, |
fenoth | 0:9efeb5787ae9 | 172 | {15, // Ver.15 |
fenoth | 0:9efeb5787ae9 | 173 | 655, 523, 415, 295, 223, |
fenoth | 0:9efeb5787ae9 | 174 | 3, 26, 48, 70, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 175 | 5, 109, 87, |
fenoth | 0:9efeb5787ae9 | 176 | 5, 65, 41, |
fenoth | 0:9efeb5787ae9 | 177 | 5, 54, 24, |
fenoth | 0:9efeb5787ae9 | 178 | 11, 36, 12, |
fenoth | 0:9efeb5787ae9 | 179 | 1, 110, 88, |
fenoth | 0:9efeb5787ae9 | 180 | 5, 66, 42, |
fenoth | 0:9efeb5787ae9 | 181 | 7, 55, 25, |
fenoth | 0:9efeb5787ae9 | 182 | 7, 37, 13}, |
fenoth | 0:9efeb5787ae9 | 183 | {16, // Ver.16 |
fenoth | 0:9efeb5787ae9 | 184 | 733, 589, 453, 325, 253, |
fenoth | 0:9efeb5787ae9 | 185 | 3, 26, 50, 74, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 186 | 5, 122, 98, |
fenoth | 0:9efeb5787ae9 | 187 | 7, 73, 45, |
fenoth | 0:9efeb5787ae9 | 188 | 15, 43, 19, |
fenoth | 0:9efeb5787ae9 | 189 | 3, 45, 15, |
fenoth | 0:9efeb5787ae9 | 190 | 1, 123, 99, |
fenoth | 0:9efeb5787ae9 | 191 | 3, 74, 46, |
fenoth | 0:9efeb5787ae9 | 192 | 2, 44, 20, |
fenoth | 0:9efeb5787ae9 | 193 | 13, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 194 | {17, // Ver.17 |
fenoth | 0:9efeb5787ae9 | 195 | 815, 647, 507, 367, 283, |
fenoth | 0:9efeb5787ae9 | 196 | 3, 30, 54, 78, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 197 | 1, 135, 107, |
fenoth | 0:9efeb5787ae9 | 198 | 10, 74, 46, |
fenoth | 0:9efeb5787ae9 | 199 | 1, 50, 22, |
fenoth | 0:9efeb5787ae9 | 200 | 2, 42, 14, |
fenoth | 0:9efeb5787ae9 | 201 | 5, 136, 108, |
fenoth | 0:9efeb5787ae9 | 202 | 1, 75, 47, |
fenoth | 0:9efeb5787ae9 | 203 | 15, 51, 23, |
fenoth | 0:9efeb5787ae9 | 204 | 17, 43, 15}, |
fenoth | 0:9efeb5787ae9 | 205 | {18, // Ver.18 |
fenoth | 0:9efeb5787ae9 | 206 | 901, 721, 563, 397, 313, |
fenoth | 0:9efeb5787ae9 | 207 | 3, 30, 56, 82, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 208 | 5, 150, 120, |
fenoth | 0:9efeb5787ae9 | 209 | 9, 69, 43, |
fenoth | 0:9efeb5787ae9 | 210 | 17, 50, 22, |
fenoth | 0:9efeb5787ae9 | 211 | 2, 42, 14, |
fenoth | 0:9efeb5787ae9 | 212 | 1, 151, 121, |
fenoth | 0:9efeb5787ae9 | 213 | 4, 70, 44, |
fenoth | 0:9efeb5787ae9 | 214 | 1, 51, 23, |
fenoth | 0:9efeb5787ae9 | 215 | 19, 43, 15}, |
fenoth | 0:9efeb5787ae9 | 216 | {19, // Ver.19 |
fenoth | 0:9efeb5787ae9 | 217 | 991, 795, 627, 445, 341, |
fenoth | 0:9efeb5787ae9 | 218 | 3, 30, 58, 86, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 219 | 3, 141, 113, |
fenoth | 0:9efeb5787ae9 | 220 | 3, 70, 44, |
fenoth | 0:9efeb5787ae9 | 221 | 17, 47, 21, |
fenoth | 0:9efeb5787ae9 | 222 | 9, 39, 13, |
fenoth | 0:9efeb5787ae9 | 223 | 4, 142, 114, |
fenoth | 0:9efeb5787ae9 | 224 | 11, 71, 45, |
fenoth | 0:9efeb5787ae9 | 225 | 4, 48, 22, |
fenoth | 0:9efeb5787ae9 | 226 | 16, 40, 14}, |
fenoth | 0:9efeb5787ae9 | 227 | {20, // Ver.20 |
fenoth | 0:9efeb5787ae9 | 228 | 1085, 861, 669, 485, 385, |
fenoth | 0:9efeb5787ae9 | 229 | 3, 34, 62, 90, 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 230 | 3, 135, 107, |
fenoth | 0:9efeb5787ae9 | 231 | 3, 67, 41, |
fenoth | 0:9efeb5787ae9 | 232 | 15, 54, 24, |
fenoth | 0:9efeb5787ae9 | 233 | 15, 43, 15, |
fenoth | 0:9efeb5787ae9 | 234 | 5, 136, 108, |
fenoth | 0:9efeb5787ae9 | 235 | 13, 68, 42, |
fenoth | 0:9efeb5787ae9 | 236 | 5, 55, 25, |
fenoth | 0:9efeb5787ae9 | 237 | 10, 44, 16}, |
fenoth | 0:9efeb5787ae9 | 238 | {21, // Ver.21 |
fenoth | 0:9efeb5787ae9 | 239 | 1156, 932, 714, 512, 406, |
fenoth | 0:9efeb5787ae9 | 240 | 4, 28, 50, 72, 94, 0, 0, |
fenoth | 0:9efeb5787ae9 | 241 | 4, 144, 116, |
fenoth | 0:9efeb5787ae9 | 242 | 17, 68, 42, |
fenoth | 0:9efeb5787ae9 | 243 | 17, 50, 22, |
fenoth | 0:9efeb5787ae9 | 244 | 19, 46, 16, |
fenoth | 0:9efeb5787ae9 | 245 | 4, 145, 117, |
fenoth | 0:9efeb5787ae9 | 246 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 247 | 6, 51, 23, |
fenoth | 0:9efeb5787ae9 | 248 | 6, 47, 17}, |
fenoth | 0:9efeb5787ae9 | 249 | {22, // Ver.22 |
fenoth | 0:9efeb5787ae9 | 250 | 1258, 1006, 782, 568, 442, |
fenoth | 0:9efeb5787ae9 | 251 | 4, 26, 50, 74, 98, 0, 0, |
fenoth | 0:9efeb5787ae9 | 252 | 2, 139, 111, |
fenoth | 0:9efeb5787ae9 | 253 | 17, 74, 46, |
fenoth | 0:9efeb5787ae9 | 254 | 7, 54, 24, |
fenoth | 0:9efeb5787ae9 | 255 | 34, 37, 13, |
fenoth | 0:9efeb5787ae9 | 256 | 7, 140, 112, |
fenoth | 0:9efeb5787ae9 | 257 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 258 | 16, 55, 25, |
fenoth | 0:9efeb5787ae9 | 259 | 0, 0, 0}, |
fenoth | 0:9efeb5787ae9 | 260 | {23, // Ver.23 |
fenoth | 0:9efeb5787ae9 | 261 | 1364, 1094, 860, 614, 464, |
fenoth | 0:9efeb5787ae9 | 262 | 4, 30, 54, 78, 102, 0, 0, |
fenoth | 0:9efeb5787ae9 | 263 | 4, 151, 121, |
fenoth | 0:9efeb5787ae9 | 264 | 4, 75, 47, |
fenoth | 0:9efeb5787ae9 | 265 | 11, 54, 24, |
fenoth | 0:9efeb5787ae9 | 266 | 16, 45, 15, |
fenoth | 0:9efeb5787ae9 | 267 | 5, 152, 122, |
fenoth | 0:9efeb5787ae9 | 268 | 14, 76, 48, |
fenoth | 0:9efeb5787ae9 | 269 | 14, 55, 25, |
fenoth | 0:9efeb5787ae9 | 270 | 14, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 271 | {24, // Ver.24 |
fenoth | 0:9efeb5787ae9 | 272 | 1474, 1174, 914, 664, 514, |
fenoth | 0:9efeb5787ae9 | 273 | 4, 28, 54, 80, 106, 0, 0, |
fenoth | 0:9efeb5787ae9 | 274 | 6, 147, 117, |
fenoth | 0:9efeb5787ae9 | 275 | 6, 73, 45, |
fenoth | 0:9efeb5787ae9 | 276 | 11, 54, 24, |
fenoth | 0:9efeb5787ae9 | 277 | 30, 46, 16, |
fenoth | 0:9efeb5787ae9 | 278 | 4, 148, 118, |
fenoth | 0:9efeb5787ae9 | 279 | 14, 74, 46, |
fenoth | 0:9efeb5787ae9 | 280 | 16, 55, 25, |
fenoth | 0:9efeb5787ae9 | 281 | 2, 47, 17}, |
fenoth | 0:9efeb5787ae9 | 282 | {25, // Ver.25 |
fenoth | 0:9efeb5787ae9 | 283 | 1588, 1276, 1000, 718, 538, |
fenoth | 0:9efeb5787ae9 | 284 | 4, 32, 58, 84, 110, 0, 0, |
fenoth | 0:9efeb5787ae9 | 285 | 8, 132, 106, |
fenoth | 0:9efeb5787ae9 | 286 | 8, 75, 47, |
fenoth | 0:9efeb5787ae9 | 287 | 7, 54, 24, |
fenoth | 0:9efeb5787ae9 | 288 | 22, 45, 15, |
fenoth | 0:9efeb5787ae9 | 289 | 4, 133, 107, |
fenoth | 0:9efeb5787ae9 | 290 | 13, 76, 48, |
fenoth | 0:9efeb5787ae9 | 291 | 22, 55, 25, |
fenoth | 0:9efeb5787ae9 | 292 | 13, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 293 | {26, // Ver.26 |
fenoth | 0:9efeb5787ae9 | 294 | 1706, 1370, 1062, 754, 596, |
fenoth | 0:9efeb5787ae9 | 295 | 4, 30, 58, 86, 114, 0, 0, |
fenoth | 0:9efeb5787ae9 | 296 | 10, 142, 114, |
fenoth | 0:9efeb5787ae9 | 297 | 19, 74, 46, |
fenoth | 0:9efeb5787ae9 | 298 | 28, 50, 22, |
fenoth | 0:9efeb5787ae9 | 299 | 33, 46, 16, |
fenoth | 0:9efeb5787ae9 | 300 | 2, 143, 115, |
fenoth | 0:9efeb5787ae9 | 301 | 4, 75, 47, |
fenoth | 0:9efeb5787ae9 | 302 | 6, 51, 23, |
fenoth | 0:9efeb5787ae9 | 303 | 4, 47, 17}, |
fenoth | 0:9efeb5787ae9 | 304 | {27, // Ver.27 |
fenoth | 0:9efeb5787ae9 | 305 | 1828, 1468, 1128, 808, 628, |
fenoth | 0:9efeb5787ae9 | 306 | 4, 34, 62, 90, 118, 0, 0, |
fenoth | 0:9efeb5787ae9 | 307 | 8, 152, 122, |
fenoth | 0:9efeb5787ae9 | 308 | 22, 73, 45, |
fenoth | 0:9efeb5787ae9 | 309 | 8, 53, 23, |
fenoth | 0:9efeb5787ae9 | 310 | 12, 45, 15, |
fenoth | 0:9efeb5787ae9 | 311 | 4, 153, 123, |
fenoth | 0:9efeb5787ae9 | 312 | 3, 74, 46, |
fenoth | 0:9efeb5787ae9 | 313 | 26, 54, 24, |
fenoth | 0:9efeb5787ae9 | 314 | 28, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 315 | {28, // Ver.28 |
fenoth | 0:9efeb5787ae9 | 316 | 1921, 1531, 1193, 871, 661, |
fenoth | 0:9efeb5787ae9 | 317 | 5, 26, 50, 74, 98, 122, 0, |
fenoth | 0:9efeb5787ae9 | 318 | 3, 147, 117, |
fenoth | 0:9efeb5787ae9 | 319 | 3, 73, 45, |
fenoth | 0:9efeb5787ae9 | 320 | 4, 54, 24, |
fenoth | 0:9efeb5787ae9 | 321 | 11, 45, 15, |
fenoth | 0:9efeb5787ae9 | 322 | 10, 148, 118, |
fenoth | 0:9efeb5787ae9 | 323 | 23, 74, 46, |
fenoth | 0:9efeb5787ae9 | 324 | 31, 55, 25, |
fenoth | 0:9efeb5787ae9 | 325 | 31, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 326 | {29, // Ver.29 |
fenoth | 0:9efeb5787ae9 | 327 | 2051, 1631, 1267, 911, 701, |
fenoth | 0:9efeb5787ae9 | 328 | 5, 30, 54, 78, 102, 126, 0, |
fenoth | 0:9efeb5787ae9 | 329 | 7, 146, 116, |
fenoth | 0:9efeb5787ae9 | 330 | 21, 73, 45, |
fenoth | 0:9efeb5787ae9 | 331 | 1, 53, 23, |
fenoth | 0:9efeb5787ae9 | 332 | 19, 45, 15, |
fenoth | 0:9efeb5787ae9 | 333 | 7, 147, 117, |
fenoth | 0:9efeb5787ae9 | 334 | 7, 74, 46, |
fenoth | 0:9efeb5787ae9 | 335 | 37, 54, 24, |
fenoth | 0:9efeb5787ae9 | 336 | 26, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 337 | {30, // Ver.30 |
fenoth | 0:9efeb5787ae9 | 338 | 2185, 1735, 1373, 985, 745, |
fenoth | 0:9efeb5787ae9 | 339 | 5, 26, 52, 78, 104, 130, 0, |
fenoth | 0:9efeb5787ae9 | 340 | 5, 145, 115, |
fenoth | 0:9efeb5787ae9 | 341 | 19, 75, 47, |
fenoth | 0:9efeb5787ae9 | 342 | 15, 54, 24, |
fenoth | 0:9efeb5787ae9 | 343 | 23, 45, 15, |
fenoth | 0:9efeb5787ae9 | 344 | 10, 146, 116, |
fenoth | 0:9efeb5787ae9 | 345 | 10, 76, 48, |
fenoth | 0:9efeb5787ae9 | 346 | 25, 55, 25, |
fenoth | 0:9efeb5787ae9 | 347 | 25, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 348 | {31, // Ver.31 |
fenoth | 0:9efeb5787ae9 | 349 | 2323, 1843, 1455, 1033, 793, |
fenoth | 0:9efeb5787ae9 | 350 | 5, 30, 56, 82, 108, 134, 0, |
fenoth | 0:9efeb5787ae9 | 351 | 13, 145, 115, |
fenoth | 0:9efeb5787ae9 | 352 | 2, 74, 46, |
fenoth | 0:9efeb5787ae9 | 353 | 42, 54, 24, |
fenoth | 0:9efeb5787ae9 | 354 | 23, 45, 15, |
fenoth | 0:9efeb5787ae9 | 355 | 3, 146, 116, |
fenoth | 0:9efeb5787ae9 | 356 | 29, 75, 47, |
fenoth | 0:9efeb5787ae9 | 357 | 1, 55, 25, |
fenoth | 0:9efeb5787ae9 | 358 | 28, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 359 | {32, // Ver.32 |
fenoth | 0:9efeb5787ae9 | 360 | 2465, 1955, 1541, 1115, 845, |
fenoth | 0:9efeb5787ae9 | 361 | 5, 34, 60, 86, 112, 138, 0, |
fenoth | 0:9efeb5787ae9 | 362 | 17, 145, 115, |
fenoth | 0:9efeb5787ae9 | 363 | 10, 74, 46, |
fenoth | 0:9efeb5787ae9 | 364 | 10, 54, 24, |
fenoth | 0:9efeb5787ae9 | 365 | 19, 45, 15, |
fenoth | 0:9efeb5787ae9 | 366 | 0, 0, 0, |
fenoth | 0:9efeb5787ae9 | 367 | 23, 75, 47, |
fenoth | 0:9efeb5787ae9 | 368 | 35, 55, 25, |
fenoth | 0:9efeb5787ae9 | 369 | 35, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 370 | {33, // Ver.33 |
fenoth | 0:9efeb5787ae9 | 371 | 2611, 2071, 1631, 1171, 901, |
fenoth | 0:9efeb5787ae9 | 372 | 5, 30, 58, 86, 114, 142, 0, |
fenoth | 0:9efeb5787ae9 | 373 | 17, 145, 115, |
fenoth | 0:9efeb5787ae9 | 374 | 14, 74, 46, |
fenoth | 0:9efeb5787ae9 | 375 | 29, 54, 24, |
fenoth | 0:9efeb5787ae9 | 376 | 11, 45, 15, |
fenoth | 0:9efeb5787ae9 | 377 | 1, 146, 116, |
fenoth | 0:9efeb5787ae9 | 378 | 21, 75, 47, |
fenoth | 0:9efeb5787ae9 | 379 | 19, 55, 25, |
fenoth | 0:9efeb5787ae9 | 380 | 46, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 381 | {34, // Ver.34 |
fenoth | 0:9efeb5787ae9 | 382 | 2761, 2191, 1725, 1231, 961, |
fenoth | 0:9efeb5787ae9 | 383 | 5, 34, 62, 90, 118, 146, 0, |
fenoth | 0:9efeb5787ae9 | 384 | 13, 145, 115, |
fenoth | 0:9efeb5787ae9 | 385 | 14, 74, 46, |
fenoth | 0:9efeb5787ae9 | 386 | 44, 54, 24, |
fenoth | 0:9efeb5787ae9 | 387 | 59, 46, 16, |
fenoth | 0:9efeb5787ae9 | 388 | 6, 146, 116, |
fenoth | 0:9efeb5787ae9 | 389 | 23, 75, 47, |
fenoth | 0:9efeb5787ae9 | 390 | 7, 55, 25, |
fenoth | 0:9efeb5787ae9 | 391 | 1, 47, 17}, |
fenoth | 0:9efeb5787ae9 | 392 | {35, // Ver.35 |
fenoth | 0:9efeb5787ae9 | 393 | 2876, 2306, 1812, 1286, 986, |
fenoth | 0:9efeb5787ae9 | 394 | 6, 30, 54, 78, 102, 126, 150, |
fenoth | 0:9efeb5787ae9 | 395 | 12, 151, 121, |
fenoth | 0:9efeb5787ae9 | 396 | 12, 75, 47, |
fenoth | 0:9efeb5787ae9 | 397 | 39, 54, 24, |
fenoth | 0:9efeb5787ae9 | 398 | 22, 45, 15, |
fenoth | 0:9efeb5787ae9 | 399 | 7, 152, 122, |
fenoth | 0:9efeb5787ae9 | 400 | 26, 76, 48, |
fenoth | 0:9efeb5787ae9 | 401 | 14, 55, 25, |
fenoth | 0:9efeb5787ae9 | 402 | 41, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 403 | {36, // Ver.36 |
fenoth | 0:9efeb5787ae9 | 404 | 3034, 2434, 1914, 1354, 1054, |
fenoth | 0:9efeb5787ae9 | 405 | 6, 24, 50, 76, 102, 128, 154, |
fenoth | 0:9efeb5787ae9 | 406 | 6, 151, 121, |
fenoth | 0:9efeb5787ae9 | 407 | 6, 75, 47, |
fenoth | 0:9efeb5787ae9 | 408 | 46, 54, 24, |
fenoth | 0:9efeb5787ae9 | 409 | 2, 45, 15, |
fenoth | 0:9efeb5787ae9 | 410 | 14, 152, 122, |
fenoth | 0:9efeb5787ae9 | 411 | 34, 76, 48, |
fenoth | 0:9efeb5787ae9 | 412 | 10, 55, 25, |
fenoth | 0:9efeb5787ae9 | 413 | 64, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 414 | {37, // Ver.37 |
fenoth | 0:9efeb5787ae9 | 415 | 3196, 2566, 1992, 1426, 1096, |
fenoth | 0:9efeb5787ae9 | 416 | 6, 28, 54, 80, 106, 132, 158, |
fenoth | 0:9efeb5787ae9 | 417 | 17, 152, 122, |
fenoth | 0:9efeb5787ae9 | 418 | 29, 74, 46, |
fenoth | 0:9efeb5787ae9 | 419 | 49, 54, 24, |
fenoth | 0:9efeb5787ae9 | 420 | 24, 45, 15, |
fenoth | 0:9efeb5787ae9 | 421 | 4, 153, 123, |
fenoth | 0:9efeb5787ae9 | 422 | 14, 75, 47, |
fenoth | 0:9efeb5787ae9 | 423 | 10, 55, 25, |
fenoth | 0:9efeb5787ae9 | 424 | 46, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 425 | {38, // Ver.38 |
fenoth | 0:9efeb5787ae9 | 426 | 3362, 2702, 2102, 1502, 1142, |
fenoth | 0:9efeb5787ae9 | 427 | 6, 32, 58, 84, 110, 136, 162, |
fenoth | 0:9efeb5787ae9 | 428 | 4, 152, 122, |
fenoth | 0:9efeb5787ae9 | 429 | 13, 74, 46, |
fenoth | 0:9efeb5787ae9 | 430 | 48, 54, 24, |
fenoth | 0:9efeb5787ae9 | 431 | 42, 45, 15, |
fenoth | 0:9efeb5787ae9 | 432 | 18, 153, 123, |
fenoth | 0:9efeb5787ae9 | 433 | 32, 75, 47, |
fenoth | 0:9efeb5787ae9 | 434 | 14, 55, 25, |
fenoth | 0:9efeb5787ae9 | 435 | 32, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 436 | {39, // Ver.39 |
fenoth | 0:9efeb5787ae9 | 437 | 3532, 2812, 2216, 1582, 1222, |
fenoth | 0:9efeb5787ae9 | 438 | 6, 26, 54, 82, 110, 138, 166, |
fenoth | 0:9efeb5787ae9 | 439 | 20, 147, 117, |
fenoth | 0:9efeb5787ae9 | 440 | 40, 75, 47, |
fenoth | 0:9efeb5787ae9 | 441 | 43, 54, 24, |
fenoth | 0:9efeb5787ae9 | 442 | 10, 45, 15, |
fenoth | 0:9efeb5787ae9 | 443 | 4, 148, 118, |
fenoth | 0:9efeb5787ae9 | 444 | 7, 76, 48, |
fenoth | 0:9efeb5787ae9 | 445 | 22, 55, 25, |
fenoth | 0:9efeb5787ae9 | 446 | 67, 46, 16}, |
fenoth | 0:9efeb5787ae9 | 447 | {40, // Ver.40 |
fenoth | 0:9efeb5787ae9 | 448 | 3706, 2956, 2334, 1666, 1276, |
fenoth | 0:9efeb5787ae9 | 449 | 6, 30, 58, 86, 114, 142, 170, |
fenoth | 0:9efeb5787ae9 | 450 | 19, 148, 118, |
fenoth | 0:9efeb5787ae9 | 451 | 18, 75, 47, |
fenoth | 0:9efeb5787ae9 | 452 | 34, 54, 24, |
fenoth | 0:9efeb5787ae9 | 453 | 20, 45, 15, |
fenoth | 0:9efeb5787ae9 | 454 | 6, 149, 119, |
fenoth | 0:9efeb5787ae9 | 455 | 31, 76, 48, |
fenoth | 0:9efeb5787ae9 | 456 | 34, 55, 25, |
fenoth | 0:9efeb5787ae9 | 457 | 61, 46, 16} |
fenoth | 0:9efeb5787ae9 | 458 | }; |
fenoth | 0:9efeb5787ae9 | 459 | |
fenoth | 0:9efeb5787ae9 | 460 | //RS STUFF |
fenoth | 0:9efeb5787ae9 | 461 | |
fenoth | 0:9efeb5787ae9 | 462 | static BYTE byExpToInt[] = { 1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, |
fenoth | 0:9efeb5787ae9 | 463 | 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, |
fenoth | 0:9efeb5787ae9 | 464 | 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35, |
fenoth | 0:9efeb5787ae9 | 465 | 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 161, |
fenoth | 0:9efeb5787ae9 | 466 | 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 120, 240, |
fenoth | 0:9efeb5787ae9 | 467 | 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 91, 182, 113, 226, |
fenoth | 0:9efeb5787ae9 | 468 | 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 104, 208, 189, 103, 206, |
fenoth | 0:9efeb5787ae9 | 469 | 129, 31, 62, 124, 248, 237, 199, 147, 59, 118, 236, 197, 151, 51, 102, 204, |
fenoth | 0:9efeb5787ae9 | 470 | 133, 23, 46, 92, 184, 109, 218, 169, 79, 158, 33, 66, 132, 21, 42, 84, |
fenoth | 0:9efeb5787ae9 | 471 | 168, 77, 154, 41, 82, 164, 85, 170, 73, 146, 57, 114, 228, 213, 183, 115, |
fenoth | 0:9efeb5787ae9 | 472 | 230, 209, 191, 99, 198, 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, |
fenoth | 0:9efeb5787ae9 | 473 | 227, 219, 171, 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, |
fenoth | 0:9efeb5787ae9 | 474 | 130, 25, 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, |
fenoth | 0:9efeb5787ae9 | 475 | 81, 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, |
fenoth | 0:9efeb5787ae9 | 476 | 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 22, |
fenoth | 0:9efeb5787ae9 | 477 | 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 142, 1}; |
fenoth | 0:9efeb5787ae9 | 478 | |
fenoth | 0:9efeb5787ae9 | 479 | |
fenoth | 0:9efeb5787ae9 | 480 | static BYTE byIntToExp[] = { 0, 0, 1, 25, 2, 50, 26, 198, 3, 223, 51, 238, 27, 104, 199, 75, |
fenoth | 0:9efeb5787ae9 | 481 | 4, 100, 224, 14, 52, 141, 239, 129, 28, 193, 105, 248, 200, 8, 76, 113, |
fenoth | 0:9efeb5787ae9 | 482 | 5, 138, 101, 47, 225, 36, 15, 33, 53, 147, 142, 218, 240, 18, 130, 69, |
fenoth | 0:9efeb5787ae9 | 483 | 29, 181, 194, 125, 106, 39, 249, 185, 201, 154, 9, 120, 77, 228, 114, 166, |
fenoth | 0:9efeb5787ae9 | 484 | 6, 191, 139, 98, 102, 221, 48, 253, 226, 152, 37, 179, 16, 145, 34, 136, |
fenoth | 0:9efeb5787ae9 | 485 | 54, 208, 148, 206, 143, 150, 219, 189, 241, 210, 19, 92, 131, 56, 70, 64, |
fenoth | 0:9efeb5787ae9 | 486 | 30, 66, 182, 163, 195, 72, 126, 110, 107, 58, 40, 84, 250, 133, 186, 61, |
fenoth | 0:9efeb5787ae9 | 487 | 202, 94, 155, 159, 10, 21, 121, 43, 78, 212, 229, 172, 115, 243, 167, 87, |
fenoth | 0:9efeb5787ae9 | 488 | 7, 112, 192, 247, 140, 128, 99, 13, 103, 74, 222, 237, 49, 197, 254, 24, |
fenoth | 0:9efeb5787ae9 | 489 | 227, 165, 153, 119, 38, 184, 180, 124, 17, 68, 146, 217, 35, 32, 137, 46, |
fenoth | 0:9efeb5787ae9 | 490 | 55, 63, 209, 91, 149, 188, 207, 205, 144, 135, 151, 178, 220, 252, 190, 97, |
fenoth | 0:9efeb5787ae9 | 491 | 242, 86, 211, 171, 20, 42, 93, 158, 132, 60, 57, 83, 71, 109, 65, 162, |
fenoth | 0:9efeb5787ae9 | 492 | 31, 45, 67, 216, 183, 123, 164, 118, 196, 23, 73, 236, 127, 12, 111, 246, |
fenoth | 0:9efeb5787ae9 | 493 | 108, 161, 59, 82, 41, 157, 85, 170, 251, 96, 134, 177, 187, 204, 62, 90, |
fenoth | 0:9efeb5787ae9 | 494 | 203, 89, 95, 176, 156, 169, 160, 81, 11, 245, 22, 235, 122, 117, 44, 215, |
fenoth | 0:9efeb5787ae9 | 495 | 79, 174, 213, 233, 230, 231, 173, 232, 116, 214, 244, 234, 168, 80, 88, 175}; |
fenoth | 0:9efeb5787ae9 | 496 | |
fenoth | 0:9efeb5787ae9 | 497 | |
fenoth | 0:9efeb5787ae9 | 498 | |
fenoth | 0:9efeb5787ae9 | 499 | static BYTE byRSExp7[] = {87, 229, 146, 149, 238, 102, 21}; |
fenoth | 0:9efeb5787ae9 | 500 | static BYTE byRSExp10[] = {251, 67, 46, 61, 118, 70, 64, 94, 32, 45}; |
fenoth | 0:9efeb5787ae9 | 501 | static BYTE byRSExp13[] = { 74, 152, 176, 100, 86, 100, 106, 104, 130, 218, 206, 140, 78}; |
fenoth | 0:9efeb5787ae9 | 502 | static BYTE byRSExp15[] = { 8, 183, 61, 91, 202, 37, 51, 58, 58, 237, 140, 124, 5, 99, 105}; |
fenoth | 0:9efeb5787ae9 | 503 | static BYTE byRSExp16[] = {120, 104, 107, 109, 102, 161, 76, 3, 91, 191, 147, 169, 182, 194, 225, 120}; |
fenoth | 0:9efeb5787ae9 | 504 | static BYTE byRSExp17[] = { 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136}; |
fenoth | 0:9efeb5787ae9 | 505 | static BYTE byRSExp18[] = {215, 234, 158, 94, 184, 97, 118, 170, 79, 187, 152, 148, 252, 179, 5, 98, 96, 153}; |
fenoth | 0:9efeb5787ae9 | 506 | static BYTE byRSExp20[] = { 17, 60, 79, 50, 61, 163, 26, 187, 202, 180, 221, 225, 83, 239, 156, 164, 212, 212, 188, 190}; |
fenoth | 0:9efeb5787ae9 | 507 | static BYTE byRSExp22[] = {210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200, 74, 8, 172, 98, 80, 219, 134, 160, 105, |
fenoth | 0:9efeb5787ae9 | 508 | 165, 231}; |
fenoth | 0:9efeb5787ae9 | 509 | static BYTE byRSExp24[] = {229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 0, 117, 232, |
fenoth | 0:9efeb5787ae9 | 510 | 87, 96, 227, 21}; |
fenoth | 0:9efeb5787ae9 | 511 | static BYTE byRSExp26[] = {173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, |
fenoth | 0:9efeb5787ae9 | 512 | 48, 227, 153, 145, 218, 70}; |
fenoth | 0:9efeb5787ae9 | 513 | static BYTE byRSExp28[] = {168, 223, 200, 104, 224, 234, 108, 180, 110, 190, 195, 147, 205, 27, 232, 201, 21, 43, 245, 87, |
fenoth | 0:9efeb5787ae9 | 514 | 42, 195, 212, 119, 242, 37, 9, 123}; |
fenoth | 0:9efeb5787ae9 | 515 | static BYTE byRSExp30[] = { 41, 173, 145, 152, 216, 31, 179, 182, 50, 48, 110, 86, 239, 96, 222, 125, 42, 173, 226, 193, |
fenoth | 0:9efeb5787ae9 | 516 | 224, 130, 156, 37, 251, 216, 238, 40, 192, 180}; |
fenoth | 0:9efeb5787ae9 | 517 | static BYTE byRSExp32[] = { 10, 6, 106, 190, 249, 167, 4, 67, 209, 138, 138, 32, 242, 123, 89, 27, 120, 185, 80, 156, |
fenoth | 0:9efeb5787ae9 | 518 | 38, 69, 171, 60, 28, 222, 80, 52, 254, 185, 220, 241}; |
fenoth | 0:9efeb5787ae9 | 519 | static BYTE byRSExp34[] = {111, 77, 146, 94, 26, 21, 108, 19, 105, 94, 113, 193, 86, 140, 163, 125, 58, 158, 229, 239, |
fenoth | 0:9efeb5787ae9 | 520 | 218, 103, 56, 70, 114, 61, 183, 129, 167, 13, 98, 62, 129, 51}; |
fenoth | 0:9efeb5787ae9 | 521 | static BYTE byRSExp36[] = {200, 183, 98, 16, 172, 31, 246, 234, 60, 152, 115, 0, 167, 152, 113, 248, 238, 107, 18, 63, |
fenoth | 0:9efeb5787ae9 | 522 | 218, 37, 87, 210, 105, 177, 120, 74, 121, 196, 117, 251, 113, 233, 30, 120}; |
fenoth | 0:9efeb5787ae9 | 523 | static BYTE byRSExp38[] = {159, 34, 38, 228, 230, 59, 243, 95, 49, 218, 176, 164, 20, 65, 45, 111, 39, 81, 49, 118, |
fenoth | 0:9efeb5787ae9 | 524 | 113, 222, 193, 250, 242, 168, 217, 41, 164, 247, 177, 30, 238, 18, 120, 153, 60, 193}; |
fenoth | 0:9efeb5787ae9 | 525 | static BYTE byRSExp40[] = { 59, 116, 79, 161, 252, 98, 128, 205, 128, 161, 247, 57, 163, 56, 235, 106, 53, 26, 187, 174, |
fenoth | 0:9efeb5787ae9 | 526 | 226, 104, 170, 7, 175, 35, 181, 114, 88, 41, 47, 163, 125, 134, 72, 20, 232, 53, 35, 15}; |
fenoth | 0:9efeb5787ae9 | 527 | static BYTE byRSExp42[] = {250, 103, 221, 230, 25, 18, 137, 231, 0, 3, 58, 242, 221, 191, 110, 84, 230, 8, 188, 106, |
fenoth | 0:9efeb5787ae9 | 528 | 96, 147, 15, 131, 139, 34, 101, 223, 39, 101, 213, 199, 237, 254, 201, 123, 171, 162, 194, 117, |
fenoth | 0:9efeb5787ae9 | 529 | 50, 96}; |
fenoth | 0:9efeb5787ae9 | 530 | static BYTE byRSExp44[] = {190, 7, 61, 121, 71, 246, 69, 55, 168, 188, 89, 243, 191, 25, 72, 123, 9, 145, 14, 247, |
fenoth | 0:9efeb5787ae9 | 531 | 1, 238, 44, 78, 143, 62, 224, 126, 118, 114, 68, 163, 52, 194, 217, 147, 204, 169, 37, 130, |
fenoth | 0:9efeb5787ae9 | 532 | 113, 102, 73, 181}; |
fenoth | 0:9efeb5787ae9 | 533 | static BYTE byRSExp46[] = {112, 94, 88, 112, 253, 224, 202, 115, 187, 99, 89, 5, 54, 113, 129, 44, 58, 16, 135, 216, |
fenoth | 0:9efeb5787ae9 | 534 | 169, 211, 36, 1, 4, 96, 60, 241, 73, 104, 234, 8, 249, 245, 119, 174, 52, 25, 157, 224, |
fenoth | 0:9efeb5787ae9 | 535 | 43, 202, 223, 19, 82, 15}; |
fenoth | 0:9efeb5787ae9 | 536 | static BYTE byRSExp48[] = {228, 25, 196, 130, 211, 146, 60, 24, 251, 90, 39, 102, 240, 61, 178, 63, 46, 123, 115, 18, |
fenoth | 0:9efeb5787ae9 | 537 | 221, 111, 135, 160, 182, 205, 107, 206, 95, 150, 120, 184, 91, 21, 247, 156, 140, 238, 191, 11, |
fenoth | 0:9efeb5787ae9 | 538 | 94, 227, 84, 50, 163, 39, 34, 108}; |
fenoth | 0:9efeb5787ae9 | 539 | static BYTE byRSExp50[] = {232, 125, 157, 161, 164, 9, 118, 46, 209, 99, 203, 193, 35, 3, 209, 111, 195, 242, 203, 225, |
fenoth | 0:9efeb5787ae9 | 540 | 46, 13, 32, 160, 126, 209, 130, 160, 242, 215, 242, 75, 77, 42, 189, 32, 113, 65, 124, 69, |
fenoth | 0:9efeb5787ae9 | 541 | 228, 114, 235, 175, 124, 170, 215, 232, 133, 205}; |
fenoth | 0:9efeb5787ae9 | 542 | static BYTE byRSExp52[] = {116, 50, 86, 186, 50, 220, 251, 89, 192, 46, 86, 127, 124, 19, 184, 233, 151, 215, 22, 14, |
fenoth | 0:9efeb5787ae9 | 543 | 59, 145, 37, 242, 203, 134, 254, 89, 190, 94, 59, 65, 124, 113, 100, 233, 235, 121, 22, 76, |
fenoth | 0:9efeb5787ae9 | 544 | 86, 97, 39, 242, 200, 220, 101, 33, 239, 254, 116, 51}; |
fenoth | 0:9efeb5787ae9 | 545 | static BYTE byRSExp54[] = {183, 26, 201, 87, 210, 221, 113, 21, 46, 65, 45, 50, 238, 184, 249, 225, 102, 58, 209, 218, |
fenoth | 0:9efeb5787ae9 | 546 | 109, 165, 26, 95, 184, 192, 52, 245, 35, 254, 238, 175, 172, 79, 123, 25, 122, 43, 120, 108, |
fenoth | 0:9efeb5787ae9 | 547 | 215, 80, 128, 201, 235, 8, 153, 59, 101, 31, 198, 76, 31, 156}; |
fenoth | 0:9efeb5787ae9 | 548 | static BYTE byRSExp56[] = {106, 120, 107, 157, 164, 216, 112, 116, 2, 91, 248, 163, 36, 201, 202, 229, 6, 144, 254, 155, |
fenoth | 0:9efeb5787ae9 | 549 | 135, 208, 170, 209, 12, 139, 127, 142, 182, 249, 177, 174, 190, 28, 10, 85, 239, 184, 101, 124, |
fenoth | 0:9efeb5787ae9 | 550 | 152, 206, 96, 23, 163, 61, 27, 196, 247, 151, 154, 202, 207, 20, 61, 10}; |
fenoth | 0:9efeb5787ae9 | 551 | static BYTE byRSExp58[] = { 82, 116, 26, 247, 66, 27, 62, 107, 252, 182, 200, 185, 235, 55, 251, 242, 210, 144, 154, 237, |
fenoth | 0:9efeb5787ae9 | 552 | 176, 141, 192, 248, 152, 249, 206, 85, 253, 142, 65, 165, 125, 23, 24, 30, 122, 240, 214, 6, |
fenoth | 0:9efeb5787ae9 | 553 | 129, 218, 29, 145, 127, 134, 206, 245, 117, 29, 41, 63, 159, 142, 233, 125, 148, 123}; |
fenoth | 0:9efeb5787ae9 | 554 | static BYTE byRSExp60[] = {107, 140, 26, 12, 9, 141, 243, 197, 226, 197, 219, 45, 211, 101, 219, 120, 28, 181, 127, 6, |
fenoth | 0:9efeb5787ae9 | 555 | 100, 247, 2, 205, 198, 57, 115, 219, 101, 109, 160, 82, 37, 38, 238, 49, 160, 209, 121, 86, |
fenoth | 0:9efeb5787ae9 | 556 | 11, 124, 30, 181, 84, 25, 194, 87, 65, 102, 190, 220, 70, 27, 209, 16, 89, 7, 33, 240}; |
fenoth | 0:9efeb5787ae9 | 557 | static BYTE byRSExp62[] = { 65, 202, 113, 98, 71, 223, 248, 118, 214, 94, 0, 122, 37, 23, 2, 228, 58, 121, 7, 105, |
fenoth | 0:9efeb5787ae9 | 558 | 135, 78, 243, 118, 70, 76, 223, 89, 72, 50, 70, 111, 194, 17, 212, 126, 181, 35, 221, 117, |
fenoth | 0:9efeb5787ae9 | 559 | 235, 11, 229, 149, 147, 123, 213, 40, 115, 6, 200, 100, 26, 246, 182, 218, 127, 215, 36, 186, |
fenoth | 0:9efeb5787ae9 | 560 | 110, 106}; |
fenoth | 0:9efeb5787ae9 | 561 | static BYTE byRSExp64[] = { 45, 51, 175, 9, 7, 158, 159, 49, 68, 119, 92, 123, 177, 204, 187, 254, 200, 78, 141, 149, |
fenoth | 0:9efeb5787ae9 | 562 | 119, 26, 127, 53, 160, 93, 199, 212, 29, 24, 145, 156, 208, 150, 218, 209, 4, 216, 91, 47, |
fenoth | 0:9efeb5787ae9 | 563 | 184, 146, 47, 140, 195, 195, 125, 242, 238, 63, 99, 108, 140, 230, 242, 31, 204, 11, 178, 243, |
fenoth | 0:9efeb5787ae9 | 564 | 217, 156, 213, 231}; |
fenoth | 0:9efeb5787ae9 | 565 | static BYTE byRSExp66[] = { 5, 118, 222, 180, 136, 136, 162, 51, 46, 117, 13, 215, 81, 17, 139, 247, 197, 171, 95, 173, |
fenoth | 0:9efeb5787ae9 | 566 | 65, 137, 178, 68, 111, 95, 101, 41, 72, 214, 169, 197, 95, 7, 44, 154, 77, 111, 236, 40, |
fenoth | 0:9efeb5787ae9 | 567 | 121, 143, 63, 87, 80, 253, 240, 126, 217, 77, 34, 232, 106, 50, 168, 82, 76, 146, 67, 106, |
fenoth | 0:9efeb5787ae9 | 568 | 171, 25, 132, 93, 45, 105}; |
fenoth | 0:9efeb5787ae9 | 569 | static BYTE byRSExp68[] = {247, 159, 223, 33, 224, 93, 77, 70, 90, 160, 32, 254, 43, 150, 84, 101, 190, 205, 133, 52, |
fenoth | 0:9efeb5787ae9 | 570 | 60, 202, 165, 220, 203, 151, 93, 84, 15, 84, 253, 173, 160, 89, 227, 52, 199, 97, 95, 231, |
fenoth | 0:9efeb5787ae9 | 571 | 52, 177, 41, 125, 137, 241, 166, 225, 118, 2, 54, 32, 82, 215, 175, 198, 43, 238, 235, 27, |
fenoth | 0:9efeb5787ae9 | 572 | 101, 184, 127, 3, 5, 8, 163, 238}; |
fenoth | 0:9efeb5787ae9 | 573 | |
fenoth | 0:9efeb5787ae9 | 574 | static LPBYTE byRSExp[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, byRSExp7, NULL, NULL, |
fenoth | 0:9efeb5787ae9 | 575 | byRSExp10, NULL, NULL, byRSExp13, NULL, byRSExp15, byRSExp16, byRSExp17, byRSExp18, NULL, |
fenoth | 0:9efeb5787ae9 | 576 | byRSExp20, NULL, byRSExp22, NULL, byRSExp24, NULL, byRSExp26, NULL, byRSExp28, NULL, |
fenoth | 0:9efeb5787ae9 | 577 | byRSExp30, NULL, byRSExp32, NULL, byRSExp34, NULL, byRSExp36, NULL, byRSExp38, NULL, |
fenoth | 0:9efeb5787ae9 | 578 | byRSExp40, NULL, byRSExp42, NULL, byRSExp44, NULL, byRSExp46, NULL, byRSExp48, NULL, |
fenoth | 0:9efeb5787ae9 | 579 | byRSExp50, NULL, byRSExp52, NULL, byRSExp54, NULL, byRSExp56, NULL, byRSExp58, NULL, |
fenoth | 0:9efeb5787ae9 | 580 | byRSExp60, NULL, byRSExp62, NULL, byRSExp64, NULL, byRSExp66, NULL, byRSExp68}; |
fenoth | 0:9efeb5787ae9 | 581 | |
fenoth | 0:9efeb5787ae9 | 582 | |
fenoth | 0:9efeb5787ae9 | 583 | static int nIndicatorLenNumeral[] = {10, 12, 14}; |
fenoth | 0:9efeb5787ae9 | 584 | static int nIndicatorLenAlphabet[] = { 9, 11, 13}; |
fenoth | 0:9efeb5787ae9 | 585 | static int nIndicatorLen8Bit[] = { 8, 16, 16}; |
fenoth | 0:9efeb5787ae9 | 586 | static int nIndicatorLenKanji[] = { 8, 10, 12}; |
fenoth | 0:9efeb5787ae9 | 587 | |
fenoth | 0:9efeb5787ae9 | 588 | |
fenoth | 0:9efeb5787ae9 | 589 | int IsNumeralData(unsigned char c) |
fenoth | 0:9efeb5787ae9 | 590 | { |
fenoth | 0:9efeb5787ae9 | 591 | if (c >= '0' && c <= '9') |
fenoth | 0:9efeb5787ae9 | 592 | return 1; |
fenoth | 0:9efeb5787ae9 | 593 | |
fenoth | 0:9efeb5787ae9 | 594 | return 0; |
fenoth | 0:9efeb5787ae9 | 595 | } |
fenoth | 0:9efeb5787ae9 | 596 | |
fenoth | 0:9efeb5787ae9 | 597 | |
fenoth | 0:9efeb5787ae9 | 598 | ///////////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 599 | // APPLICATIONS: Check the appropriate alphanumeric mode |
fenoth | 0:9efeb5787ae9 | 600 | // Argument: research letter |
fenoth | 0:9efeb5787ae9 | 601 | // Returns: = true if applicable |
fenoth | 0:9efeb5787ae9 | 602 | |
fenoth | 0:9efeb5787ae9 | 603 | int IsAlphabetData(unsigned char c) |
fenoth | 0:9efeb5787ae9 | 604 | { |
fenoth | 0:9efeb5787ae9 | 605 | if (c >= '0' && c <= '9') |
fenoth | 0:9efeb5787ae9 | 606 | return 1; |
fenoth | 0:9efeb5787ae9 | 607 | |
fenoth | 0:9efeb5787ae9 | 608 | if (c >= 'A' && c <= 'Z') |
fenoth | 0:9efeb5787ae9 | 609 | return 1; |
fenoth | 0:9efeb5787ae9 | 610 | |
fenoth | 0:9efeb5787ae9 | 611 | if (c == ' ' || c == '$' || c == '%' || c == '*' || c == '+' || c == '-' || c == '.' || c == '/' || c == ':') |
fenoth | 0:9efeb5787ae9 | 612 | return 1; |
fenoth | 0:9efeb5787ae9 | 613 | |
fenoth | 0:9efeb5787ae9 | 614 | return 0; |
fenoth | 0:9efeb5787ae9 | 615 | } |
fenoth | 0:9efeb5787ae9 | 616 | |
fenoth | 0:9efeb5787ae9 | 617 | |
fenoth | 0:9efeb5787ae9 | 618 | ///////////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 619 | // APPLICATIONS: Check the appropriate kanji mode |
fenoth | 0:9efeb5787ae9 | 620 | // Arguments: The character study (16-bit characters) |
fenoth | 0:9efeb5787ae9 | 621 | // Returns: = true if applicable |
fenoth | 0:9efeb5787ae9 | 622 | // Remarks: S-JIS is excluded since the EBBFh |
fenoth | 0:9efeb5787ae9 | 623 | |
fenoth | 0:9efeb5787ae9 | 624 | int IsKanjiData(unsigned char c1, unsigned char c2) |
fenoth | 0:9efeb5787ae9 | 625 | { |
fenoth | 0:9efeb5787ae9 | 626 | if (((c1 >= 0x81 && c1 <= 0x9f) || (c1 >= 0xe0 && c1 <= 0xeb)) && (c2 >= 0x40)) |
fenoth | 0:9efeb5787ae9 | 627 | { |
fenoth | 0:9efeb5787ae9 | 628 | if ((c1 == 0x9f && c2 > 0xfc) || (c1 == 0xeb && c2 > 0xbf)) |
fenoth | 0:9efeb5787ae9 | 629 | return 0; |
fenoth | 0:9efeb5787ae9 | 630 | |
fenoth | 0:9efeb5787ae9 | 631 | return 1; |
fenoth | 0:9efeb5787ae9 | 632 | } |
fenoth | 0:9efeb5787ae9 | 633 | |
fenoth | 0:9efeb5787ae9 | 634 | return 0; |
fenoth | 0:9efeb5787ae9 | 635 | } |
fenoth | 0:9efeb5787ae9 | 636 | |
fenoth | 0:9efeb5787ae9 | 637 | |
fenoth | 0:9efeb5787ae9 | 638 | ///////////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 639 | // APPLICATIONS: Binary character alphanumeric mode |
fenoth | 0:9efeb5787ae9 | 640 | // Number of arguments: the target character |
fenoth | 0:9efeb5787ae9 | 641 | // Returns: binary value |
fenoth | 0:9efeb5787ae9 | 642 | |
fenoth | 0:9efeb5787ae9 | 643 | BYTE AlphabetToBinary(unsigned char c) |
fenoth | 0:9efeb5787ae9 | 644 | { |
fenoth | 0:9efeb5787ae9 | 645 | if (c >= '0' && c <= '9') return (unsigned char)(c - '0'); |
fenoth | 0:9efeb5787ae9 | 646 | |
fenoth | 0:9efeb5787ae9 | 647 | if (c >= 'A' && c <= 'Z') return (unsigned char)(c - 'A' + 10); |
fenoth | 0:9efeb5787ae9 | 648 | |
fenoth | 0:9efeb5787ae9 | 649 | if (c == ' ') return 36; |
fenoth | 0:9efeb5787ae9 | 650 | |
fenoth | 0:9efeb5787ae9 | 651 | if (c == '$') return 37; |
fenoth | 0:9efeb5787ae9 | 652 | |
fenoth | 0:9efeb5787ae9 | 653 | if (c == '%') return 38; |
fenoth | 0:9efeb5787ae9 | 654 | |
fenoth | 0:9efeb5787ae9 | 655 | if (c == '*') return 39; |
fenoth | 0:9efeb5787ae9 | 656 | |
fenoth | 0:9efeb5787ae9 | 657 | if (c == '+') return 40; |
fenoth | 0:9efeb5787ae9 | 658 | |
fenoth | 0:9efeb5787ae9 | 659 | if (c == '-') return 41; |
fenoth | 0:9efeb5787ae9 | 660 | |
fenoth | 0:9efeb5787ae9 | 661 | if (c == '.') return 42; |
fenoth | 0:9efeb5787ae9 | 662 | |
fenoth | 0:9efeb5787ae9 | 663 | if (c == '/') return 43; |
fenoth | 0:9efeb5787ae9 | 664 | |
fenoth | 0:9efeb5787ae9 | 665 | return 44; // c == ':' |
fenoth | 0:9efeb5787ae9 | 666 | } |
fenoth | 0:9efeb5787ae9 | 667 | |
fenoth | 0:9efeb5787ae9 | 668 | |
fenoth | 0:9efeb5787ae9 | 669 | ///////////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 670 | // APPLICATIONS: Binary Kanji character mode |
fenoth | 0:9efeb5787ae9 | 671 | // Number of arguments: the target character |
fenoth | 0:9efeb5787ae9 | 672 | // Returns: binary value |
fenoth | 0:9efeb5787ae9 | 673 | WORD KanjiToBinaly(WORD wc) |
fenoth | 0:9efeb5787ae9 | 674 | { |
fenoth | 0:9efeb5787ae9 | 675 | if (wc >= 0x8140 && wc <= 0x9ffc) |
fenoth | 0:9efeb5787ae9 | 676 | wc -= 0x8140; |
fenoth | 0:9efeb5787ae9 | 677 | else // (wc >= 0xe040 && wc <= 0xebbf) |
fenoth | 0:9efeb5787ae9 | 678 | wc -= 0xc140; |
fenoth | 0:9efeb5787ae9 | 679 | |
fenoth | 0:9efeb5787ae9 | 680 | return (WORD)(((wc >> 8) * 0xc0) + (wc & 0x00ff)); |
fenoth | 0:9efeb5787ae9 | 681 | } |
fenoth | 0:9efeb5787ae9 | 682 | |
fenoth | 0:9efeb5787ae9 | 683 | int SetBitStream(int nIndex, WORD wData, int ncData,BYTE m_byDataCodeWord[MAX_DATACODEWORD]) |
fenoth | 0:9efeb5787ae9 | 684 | { |
fenoth | 0:9efeb5787ae9 | 685 | int i; |
fenoth | 0:9efeb5787ae9 | 686 | |
fenoth | 0:9efeb5787ae9 | 687 | if (nIndex == -1 || nIndex + ncData > MAX_DATACODEWORD * 8) |
fenoth | 0:9efeb5787ae9 | 688 | return -1; |
fenoth | 0:9efeb5787ae9 | 689 | |
fenoth | 0:9efeb5787ae9 | 690 | for (i = 0; i < ncData; ++i) |
fenoth | 0:9efeb5787ae9 | 691 | { |
fenoth | 0:9efeb5787ae9 | 692 | if (wData & (1 << (ncData - i - 1))) |
fenoth | 0:9efeb5787ae9 | 693 | { |
fenoth | 0:9efeb5787ae9 | 694 | m_byDataCodeWord[(nIndex + i) / 8] |= 1 << (7 - ((nIndex + i) % 8)); |
fenoth | 0:9efeb5787ae9 | 695 | } |
fenoth | 0:9efeb5787ae9 | 696 | } |
fenoth | 0:9efeb5787ae9 | 697 | |
fenoth | 0:9efeb5787ae9 | 698 | return nIndex + ncData; |
fenoth | 0:9efeb5787ae9 | 699 | } |
fenoth | 0:9efeb5787ae9 | 700 | |
fenoth | 0:9efeb5787ae9 | 701 | |
fenoth | 0:9efeb5787ae9 | 702 | int GetBitLength(BYTE nMode, int ncData, int nVerGroup) |
fenoth | 0:9efeb5787ae9 | 703 | { |
fenoth | 0:9efeb5787ae9 | 704 | int ncBits = 0; |
fenoth | 0:9efeb5787ae9 | 705 | |
fenoth | 0:9efeb5787ae9 | 706 | switch (nMode) |
fenoth | 0:9efeb5787ae9 | 707 | { |
fenoth | 0:9efeb5787ae9 | 708 | case QR_MODE_NUMERAL: |
fenoth | 0:9efeb5787ae9 | 709 | ncBits = 4 + nIndicatorLenNumeral[nVerGroup] + (10 * (ncData / 3)); |
fenoth | 0:9efeb5787ae9 | 710 | switch (ncData % 3) |
fenoth | 0:9efeb5787ae9 | 711 | { |
fenoth | 0:9efeb5787ae9 | 712 | case 1: |
fenoth | 0:9efeb5787ae9 | 713 | ncBits += 4; |
fenoth | 0:9efeb5787ae9 | 714 | break; |
fenoth | 0:9efeb5787ae9 | 715 | case 2: |
fenoth | 0:9efeb5787ae9 | 716 | ncBits += 7; |
fenoth | 0:9efeb5787ae9 | 717 | break; |
fenoth | 0:9efeb5787ae9 | 718 | default: // case 0: |
fenoth | 0:9efeb5787ae9 | 719 | break; |
fenoth | 0:9efeb5787ae9 | 720 | } |
fenoth | 0:9efeb5787ae9 | 721 | |
fenoth | 0:9efeb5787ae9 | 722 | break; |
fenoth | 0:9efeb5787ae9 | 723 | |
fenoth | 0:9efeb5787ae9 | 724 | case QR_MODE_ALPHABET: |
fenoth | 0:9efeb5787ae9 | 725 | ncBits = 4 + nIndicatorLenAlphabet[nVerGroup] + (11 * (ncData / 2)) + (6 * (ncData % 2)); |
fenoth | 0:9efeb5787ae9 | 726 | break; |
fenoth | 0:9efeb5787ae9 | 727 | |
fenoth | 0:9efeb5787ae9 | 728 | case QR_MODE_8BIT: |
fenoth | 0:9efeb5787ae9 | 729 | ncBits = 4 + nIndicatorLen8Bit[nVerGroup] + (8 * ncData); |
fenoth | 0:9efeb5787ae9 | 730 | break; |
fenoth | 0:9efeb5787ae9 | 731 | |
fenoth | 0:9efeb5787ae9 | 732 | default: // case QR_MODE_KANJI: |
fenoth | 0:9efeb5787ae9 | 733 | ncBits = 4 + nIndicatorLenKanji[nVerGroup] + (13 * (ncData / 2)); |
fenoth | 0:9efeb5787ae9 | 734 | break; |
fenoth | 0:9efeb5787ae9 | 735 | } |
fenoth | 0:9efeb5787ae9 | 736 | |
fenoth | 0:9efeb5787ae9 | 737 | return ncBits; |
fenoth | 0:9efeb5787ae9 | 738 | } |
fenoth | 0:9efeb5787ae9 | 739 | |
fenoth | 0:9efeb5787ae9 | 740 | |
fenoth | 0:9efeb5787ae9 | 741 | |
fenoth | 0:9efeb5787ae9 | 742 | |
fenoth | 0:9efeb5787ae9 | 743 | int EncodeSourceData(LPCSTR lpsSource, int ncLength, int nVerGroup,int m_nBlockLength[MAX_DATACODEWORD],BYTE m_byBlockMode[MAX_DATACODEWORD],BYTE m_byDataCodeWord[MAX_DATACODEWORD]) |
fenoth | 0:9efeb5787ae9 | 744 | { |
fenoth | 0:9efeb5787ae9 | 745 | |
fenoth | 0:9efeb5787ae9 | 746 | ZeroMemory(m_nBlockLength, sizeof(m_nBlockLength)); |
fenoth | 0:9efeb5787ae9 | 747 | |
fenoth | 0:9efeb5787ae9 | 748 | int i, j; |
fenoth | 0:9efeb5787ae9 | 749 | |
fenoth | 0:9efeb5787ae9 | 750 | // Investigate whether continuing characters (bytes) which mode is what |
fenoth | 0:9efeb5787ae9 | 751 | for (m_ncDataBlock = i = 0; i < ncLength; ++i) |
fenoth | 0:9efeb5787ae9 | 752 | { |
fenoth | 0:9efeb5787ae9 | 753 | BYTE byMode; |
fenoth | 0:9efeb5787ae9 | 754 | |
fenoth | 0:9efeb5787ae9 | 755 | if (i < ncLength - 1 && IsKanjiData(lpsSource[i], lpsSource[i + 1])) |
fenoth | 0:9efeb5787ae9 | 756 | byMode = QR_MODE_KANJI; |
fenoth | 0:9efeb5787ae9 | 757 | else if (IsNumeralData(lpsSource[i])) |
fenoth | 0:9efeb5787ae9 | 758 | byMode = QR_MODE_NUMERAL; |
fenoth | 0:9efeb5787ae9 | 759 | else if (IsAlphabetData(lpsSource[i])) |
fenoth | 0:9efeb5787ae9 | 760 | byMode = QR_MODE_ALPHABET; |
fenoth | 0:9efeb5787ae9 | 761 | else |
fenoth | 0:9efeb5787ae9 | 762 | byMode = QR_MODE_8BIT; |
fenoth | 0:9efeb5787ae9 | 763 | |
fenoth | 0:9efeb5787ae9 | 764 | if (i == 0) |
fenoth | 0:9efeb5787ae9 | 765 | m_byBlockMode[0] = byMode; |
fenoth | 0:9efeb5787ae9 | 766 | if (m_byBlockMode[m_ncDataBlock] != byMode) |
fenoth | 0:9efeb5787ae9 | 767 | m_byBlockMode[++m_ncDataBlock] = byMode; |
fenoth | 0:9efeb5787ae9 | 768 | |
fenoth | 0:9efeb5787ae9 | 769 | ++m_nBlockLength[m_ncDataBlock]; |
fenoth | 0:9efeb5787ae9 | 770 | |
fenoth | 0:9efeb5787ae9 | 771 | if (byMode == QR_MODE_KANJI) |
fenoth | 0:9efeb5787ae9 | 772 | { |
fenoth | 0:9efeb5787ae9 | 773 | //Kanji characters rather than the number recorded in |
fenoth | 0:9efeb5787ae9 | 774 | ++m_nBlockLength[m_ncDataBlock]; |
fenoth | 0:9efeb5787ae9 | 775 | ++i; |
fenoth | 0:9efeb5787ae9 | 776 | } |
fenoth | 0:9efeb5787ae9 | 777 | } |
fenoth | 0:9efeb5787ae9 | 778 | |
fenoth | 0:9efeb5787ae9 | 779 | ++m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 780 | |
fenoth | 0:9efeb5787ae9 | 781 | ///////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 782 | // Linked by a sequence of conditional block alphanumeric mode and numeric mode block adjacent |
fenoth | 0:9efeb5787ae9 | 783 | |
fenoth | 0:9efeb5787ae9 | 784 | int ncSrcBits, ncDstBits; //The bit length of the block mode if you have over the original bit length and a single alphanumeric |
fenoth | 0:9efeb5787ae9 | 785 | int nBlock = 0; |
fenoth | 0:9efeb5787ae9 | 786 | |
fenoth | 0:9efeb5787ae9 | 787 | while (nBlock < m_ncDataBlock - 1) |
fenoth | 0:9efeb5787ae9 | 788 | { |
fenoth | 0:9efeb5787ae9 | 789 | int ncJoinFront, ncJoinBehind; //Bit length when combined with 8-bit byte block mode before and after |
fenoth | 0:9efeb5787ae9 | 790 | int nJoinPosition = 0; // Block the binding of 8-bit byte mode: combined with the previous -1 = 0 = do not bind, bind behind a = |
fenoth | 0:9efeb5787ae9 | 791 | |
fenoth | 0:9efeb5787ae9 | 792 | |
fenoth | 0:9efeb5787ae9 | 793 | // Sort of - "digit alphanumeric" - "or alphanumeric numbers" |
fenoth | 0:9efeb5787ae9 | 794 | if ((m_byBlockMode[nBlock] == QR_MODE_NUMERAL && m_byBlockMode[nBlock + 1] == QR_MODE_ALPHABET) || |
fenoth | 0:9efeb5787ae9 | 795 | (m_byBlockMode[nBlock] == QR_MODE_ALPHABET && m_byBlockMode[nBlock + 1] == QR_MODE_NUMERAL)) |
fenoth | 0:9efeb5787ae9 | 796 | { |
fenoth | 0:9efeb5787ae9 | 797 | |
fenoth | 0:9efeb5787ae9 | 798 | // If you compare the bit length of alphanumeric characters and a single block mode over the original bit length |
fenoth | 0:9efeb5787ae9 | 799 | ncSrcBits = GetBitLength(m_byBlockMode[nBlock], m_nBlockLength[nBlock], nVerGroup) + |
fenoth | 0:9efeb5787ae9 | 800 | GetBitLength(m_byBlockMode[nBlock + 1], m_nBlockLength[nBlock + 1], nVerGroup); |
fenoth | 0:9efeb5787ae9 | 801 | |
fenoth | 0:9efeb5787ae9 | 802 | ncDstBits = GetBitLength(QR_MODE_ALPHABET, m_nBlockLength[nBlock] + m_nBlockLength[nBlock + 1], nVerGroup); |
fenoth | 0:9efeb5787ae9 | 803 | |
fenoth | 0:9efeb5787ae9 | 804 | if (ncSrcBits > ncDstBits) |
fenoth | 0:9efeb5787ae9 | 805 | { |
fenoth | 0:9efeb5787ae9 | 806 | // If there is an 8-bit byte block mode back and forth, check whether they favor the binding of |
fenoth | 0:9efeb5787ae9 | 807 | if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_8BIT) |
fenoth | 0:9efeb5787ae9 | 808 | { |
fenoth | 0:9efeb5787ae9 | 809 | // There are 8-bit byte block mode before |
fenoth | 0:9efeb5787ae9 | 810 | ncJoinFront = GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock - 1] + m_nBlockLength[nBlock], nVerGroup) + |
fenoth | 0:9efeb5787ae9 | 811 | GetBitLength(m_byBlockMode[nBlock + 1], m_nBlockLength[nBlock + 1], nVerGroup); |
fenoth | 0:9efeb5787ae9 | 812 | |
fenoth | 0:9efeb5787ae9 | 813 | if (ncJoinFront > ncDstBits + GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock - 1], nVerGroup)) |
fenoth | 0:9efeb5787ae9 | 814 | ncJoinFront = 0; //8-bit byte and block mode does not bind |
fenoth | 0:9efeb5787ae9 | 815 | } |
fenoth | 0:9efeb5787ae9 | 816 | else |
fenoth | 0:9efeb5787ae9 | 817 | ncJoinFront = 0; |
fenoth | 0:9efeb5787ae9 | 818 | |
fenoth | 0:9efeb5787ae9 | 819 | if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_8BIT) |
fenoth | 0:9efeb5787ae9 | 820 | { |
fenoth | 0:9efeb5787ae9 | 821 | // There are 8-bit byte mode block behind |
fenoth | 0:9efeb5787ae9 | 822 | ncJoinBehind = GetBitLength(m_byBlockMode[nBlock], m_nBlockLength[nBlock], nVerGroup) + |
fenoth | 0:9efeb5787ae9 | 823 | GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock + 1] + m_nBlockLength[nBlock + 2], nVerGroup); |
fenoth | 0:9efeb5787ae9 | 824 | |
fenoth | 0:9efeb5787ae9 | 825 | if (ncJoinBehind > ncDstBits + GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock + 2], nVerGroup)) |
fenoth | 0:9efeb5787ae9 | 826 | ncJoinBehind = 0; //8-bit byte and block mode does not bind |
fenoth | 0:9efeb5787ae9 | 827 | } |
fenoth | 0:9efeb5787ae9 | 828 | else |
fenoth | 0:9efeb5787ae9 | 829 | ncJoinBehind = 0; |
fenoth | 0:9efeb5787ae9 | 830 | |
fenoth | 0:9efeb5787ae9 | 831 | if (ncJoinFront != 0 && ncJoinBehind != 0) |
fenoth | 0:9efeb5787ae9 | 832 | { |
fenoth | 0:9efeb5787ae9 | 833 | // If there is a 8-bit byte block mode has priority both before and after the way the data length is shorter |
fenoth | 0:9efeb5787ae9 | 834 | nJoinPosition = (ncJoinFront < ncJoinBehind) ? -1 : 1; |
fenoth | 0:9efeb5787ae9 | 835 | } |
fenoth | 0:9efeb5787ae9 | 836 | else |
fenoth | 0:9efeb5787ae9 | 837 | { |
fenoth | 0:9efeb5787ae9 | 838 | nJoinPosition = (ncJoinFront != 0) ? -1 : ((ncJoinBehind != 0) ? 1 : 0); |
fenoth | 0:9efeb5787ae9 | 839 | } |
fenoth | 0:9efeb5787ae9 | 840 | |
fenoth | 0:9efeb5787ae9 | 841 | if (nJoinPosition != 0) |
fenoth | 0:9efeb5787ae9 | 842 | { |
fenoth | 0:9efeb5787ae9 | 843 | // Block the binding of 8-bit byte mode |
fenoth | 0:9efeb5787ae9 | 844 | if (nJoinPosition == -1) |
fenoth | 0:9efeb5787ae9 | 845 | { |
fenoth | 0:9efeb5787ae9 | 846 | m_nBlockLength[nBlock - 1] += m_nBlockLength[nBlock]; |
fenoth | 0:9efeb5787ae9 | 847 | |
fenoth | 0:9efeb5787ae9 | 848 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 849 | for (i = nBlock; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 850 | { |
fenoth | 0:9efeb5787ae9 | 851 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 852 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 853 | } |
fenoth | 0:9efeb5787ae9 | 854 | } |
fenoth | 0:9efeb5787ae9 | 855 | else |
fenoth | 0:9efeb5787ae9 | 856 | { |
fenoth | 0:9efeb5787ae9 | 857 | m_byBlockMode[nBlock + 1] = QR_MODE_8BIT; |
fenoth | 0:9efeb5787ae9 | 858 | m_nBlockLength[nBlock + 1] += m_nBlockLength[nBlock + 2]; |
fenoth | 0:9efeb5787ae9 | 859 | |
fenoth | 0:9efeb5787ae9 | 860 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 861 | for (i = nBlock + 2; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 862 | { |
fenoth | 0:9efeb5787ae9 | 863 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 864 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 865 | } |
fenoth | 0:9efeb5787ae9 | 866 | } |
fenoth | 0:9efeb5787ae9 | 867 | |
fenoth | 0:9efeb5787ae9 | 868 | --m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 869 | } |
fenoth | 0:9efeb5787ae9 | 870 | else |
fenoth | 0:9efeb5787ae9 | 871 | { |
fenoth | 0:9efeb5787ae9 | 872 | // Block mode integrated into a single alphanumeric string of numbers and alphanumeric |
fenoth | 0:9efeb5787ae9 | 873 | |
fenoth | 0:9efeb5787ae9 | 874 | if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_ALPHABET) |
fenoth | 0:9efeb5787ae9 | 875 | { |
fenoth | 0:9efeb5787ae9 | 876 | // Binding mode of the block followed by alphanumeric block attempts to join |
fenoth | 0:9efeb5787ae9 | 877 | m_nBlockLength[nBlock + 1] += m_nBlockLength[nBlock + 2]; |
fenoth | 0:9efeb5787ae9 | 878 | |
fenoth | 0:9efeb5787ae9 | 879 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 880 | for (i = nBlock + 2; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 881 | { |
fenoth | 0:9efeb5787ae9 | 882 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 883 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 884 | } |
fenoth | 0:9efeb5787ae9 | 885 | |
fenoth | 0:9efeb5787ae9 | 886 | --m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 887 | } |
fenoth | 0:9efeb5787ae9 | 888 | |
fenoth | 0:9efeb5787ae9 | 889 | m_byBlockMode[nBlock] = QR_MODE_ALPHABET; |
fenoth | 0:9efeb5787ae9 | 890 | m_nBlockLength[nBlock] += m_nBlockLength[nBlock + 1]; |
fenoth | 0:9efeb5787ae9 | 891 | |
fenoth | 0:9efeb5787ae9 | 892 | |
fenoth | 0:9efeb5787ae9 | 893 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 894 | for (i = nBlock + 1; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 895 | { |
fenoth | 0:9efeb5787ae9 | 896 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 897 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 898 | } |
fenoth | 0:9efeb5787ae9 | 899 | |
fenoth | 0:9efeb5787ae9 | 900 | --m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 901 | |
fenoth | 0:9efeb5787ae9 | 902 | if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_ALPHABET) |
fenoth | 0:9efeb5787ae9 | 903 | { |
fenoth | 0:9efeb5787ae9 | 904 | |
fenoth | 0:9efeb5787ae9 | 905 | // Combined mode of alphanumeric block before the block bound |
fenoth | 0:9efeb5787ae9 | 906 | m_nBlockLength[nBlock - 1] += m_nBlockLength[nBlock]; |
fenoth | 0:9efeb5787ae9 | 907 | |
fenoth | 0:9efeb5787ae9 | 908 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 909 | for (i = nBlock; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 910 | { |
fenoth | 0:9efeb5787ae9 | 911 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 912 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 913 | } |
fenoth | 0:9efeb5787ae9 | 914 | |
fenoth | 0:9efeb5787ae9 | 915 | --m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 916 | } |
fenoth | 0:9efeb5787ae9 | 917 | } |
fenoth | 0:9efeb5787ae9 | 918 | |
fenoth | 0:9efeb5787ae9 | 919 | continue; |
fenoth | 0:9efeb5787ae9 | 920 | //Re-examine the block of the current position |
fenoth | 0:9efeb5787ae9 | 921 | } |
fenoth | 0:9efeb5787ae9 | 922 | } |
fenoth | 0:9efeb5787ae9 | 923 | |
fenoth | 0:9efeb5787ae9 | 924 | ++nBlock; //Investigate the next block |
fenoth | 0:9efeb5787ae9 | 925 | } |
fenoth | 0:9efeb5787ae9 | 926 | |
fenoth | 0:9efeb5787ae9 | 927 | ///////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 928 | // 8-bit byte block mode over the short block mode to continuous |
fenoth | 0:9efeb5787ae9 | 929 | |
fenoth | 0:9efeb5787ae9 | 930 | nBlock = 0; |
fenoth | 0:9efeb5787ae9 | 931 | |
fenoth | 0:9efeb5787ae9 | 932 | while (nBlock < m_ncDataBlock - 1) |
fenoth | 0:9efeb5787ae9 | 933 | { |
fenoth | 0:9efeb5787ae9 | 934 | ncSrcBits = GetBitLength(m_byBlockMode[nBlock], m_nBlockLength[nBlock], nVerGroup) |
fenoth | 0:9efeb5787ae9 | 935 | + GetBitLength(m_byBlockMode[nBlock + 1], m_nBlockLength[nBlock + 1], nVerGroup); |
fenoth | 0:9efeb5787ae9 | 936 | |
fenoth | 0:9efeb5787ae9 | 937 | ncDstBits = GetBitLength(QR_MODE_8BIT, m_nBlockLength[nBlock] + m_nBlockLength[nBlock + 1], nVerGroup); |
fenoth | 0:9efeb5787ae9 | 938 | |
fenoth | 0:9efeb5787ae9 | 939 | // If there is a 8-bit byte block mode before, subtract the duplicate indicator minute |
fenoth | 0:9efeb5787ae9 | 940 | if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_8BIT) |
fenoth | 0:9efeb5787ae9 | 941 | ncDstBits -= (4 + nIndicatorLen8Bit[nVerGroup]); |
fenoth | 0:9efeb5787ae9 | 942 | |
fenoth | 0:9efeb5787ae9 | 943 | // If there is a block behind the 8-bit byte mode, subtract the duplicate indicator minute |
fenoth | 0:9efeb5787ae9 | 944 | if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_8BIT) |
fenoth | 0:9efeb5787ae9 | 945 | ncDstBits -= (4 + nIndicatorLen8Bit[nVerGroup]); |
fenoth | 0:9efeb5787ae9 | 946 | |
fenoth | 0:9efeb5787ae9 | 947 | if (ncSrcBits > ncDstBits) |
fenoth | 0:9efeb5787ae9 | 948 | { |
fenoth | 0:9efeb5787ae9 | 949 | if (nBlock >= 1 && m_byBlockMode[nBlock - 1] == QR_MODE_8BIT) |
fenoth | 0:9efeb5787ae9 | 950 | { |
fenoth | 0:9efeb5787ae9 | 951 | // 8-bit byte mode coupling block in front of the block to join |
fenoth | 0:9efeb5787ae9 | 952 | m_nBlockLength[nBlock - 1] += m_nBlockLength[nBlock]; |
fenoth | 0:9efeb5787ae9 | 953 | |
fenoth | 0:9efeb5787ae9 | 954 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 955 | for (i = nBlock; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 956 | { |
fenoth | 0:9efeb5787ae9 | 957 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 958 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 959 | } |
fenoth | 0:9efeb5787ae9 | 960 | |
fenoth | 0:9efeb5787ae9 | 961 | --m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 962 | --nBlock; |
fenoth | 0:9efeb5787ae9 | 963 | } |
fenoth | 0:9efeb5787ae9 | 964 | |
fenoth | 0:9efeb5787ae9 | 965 | if (nBlock < m_ncDataBlock - 2 && m_byBlockMode[nBlock + 2] == QR_MODE_8BIT) |
fenoth | 0:9efeb5787ae9 | 966 | { |
fenoth | 0:9efeb5787ae9 | 967 | // 8-bit byte mode coupling block at the back of the block to join |
fenoth | 0:9efeb5787ae9 | 968 | m_nBlockLength[nBlock + 1] += m_nBlockLength[nBlock + 2]; |
fenoth | 0:9efeb5787ae9 | 969 | |
fenoth | 0:9efeb5787ae9 | 970 | |
fenoth | 0:9efeb5787ae9 | 971 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 972 | for (i = nBlock + 2; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 973 | { |
fenoth | 0:9efeb5787ae9 | 974 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 975 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 976 | } |
fenoth | 0:9efeb5787ae9 | 977 | |
fenoth | 0:9efeb5787ae9 | 978 | --m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 979 | } |
fenoth | 0:9efeb5787ae9 | 980 | |
fenoth | 0:9efeb5787ae9 | 981 | m_byBlockMode[nBlock] = QR_MODE_8BIT; |
fenoth | 0:9efeb5787ae9 | 982 | m_nBlockLength[nBlock] += m_nBlockLength[nBlock + 1]; |
fenoth | 0:9efeb5787ae9 | 983 | |
fenoth | 0:9efeb5787ae9 | 984 | |
fenoth | 0:9efeb5787ae9 | 985 | // The subsequent shift |
fenoth | 0:9efeb5787ae9 | 986 | for (i = nBlock + 1; i < m_ncDataBlock - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 987 | { |
fenoth | 0:9efeb5787ae9 | 988 | m_byBlockMode[i] = m_byBlockMode[i + 1]; |
fenoth | 0:9efeb5787ae9 | 989 | m_nBlockLength[i] = m_nBlockLength[i + 1]; |
fenoth | 0:9efeb5787ae9 | 990 | } |
fenoth | 0:9efeb5787ae9 | 991 | |
fenoth | 0:9efeb5787ae9 | 992 | --m_ncDataBlock; |
fenoth | 0:9efeb5787ae9 | 993 | |
fenoth | 0:9efeb5787ae9 | 994 | |
fenoth | 0:9efeb5787ae9 | 995 | // Re-examination in front of the block bound |
fenoth | 0:9efeb5787ae9 | 996 | if (nBlock >= 1) |
fenoth | 0:9efeb5787ae9 | 997 | --nBlock; |
fenoth | 0:9efeb5787ae9 | 998 | |
fenoth | 0:9efeb5787ae9 | 999 | continue; |
fenoth | 0:9efeb5787ae9 | 1000 | } |
fenoth | 0:9efeb5787ae9 | 1001 | |
fenoth | 0:9efeb5787ae9 | 1002 | ++nBlock;//Investigate the next block |
fenoth | 0:9efeb5787ae9 | 1003 | |
fenoth | 0:9efeb5787ae9 | 1004 | } |
fenoth | 0:9efeb5787ae9 | 1005 | |
fenoth | 0:9efeb5787ae9 | 1006 | ///////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 1007 | // Mosquito bit array |
fenoth | 0:9efeb5787ae9 | 1008 | int ncComplete = 0; //Data pre-processing counter |
fenoth | 0:9efeb5787ae9 | 1009 | |
fenoth | 0:9efeb5787ae9 | 1010 | WORD wBinCode; |
fenoth | 0:9efeb5787ae9 | 1011 | |
fenoth | 0:9efeb5787ae9 | 1012 | m_ncDataCodeWordBit = 0;//Bit counter processing unit |
fenoth | 0:9efeb5787ae9 | 1013 | |
fenoth | 0:9efeb5787ae9 | 1014 | |
fenoth | 0:9efeb5787ae9 | 1015 | ZeroMemory(m_byDataCodeWord, MAX_DATACODEWORD); |
fenoth | 0:9efeb5787ae9 | 1016 | |
fenoth | 0:9efeb5787ae9 | 1017 | for (i = 0; i < m_ncDataBlock && m_ncDataCodeWordBit != -1; ++i) |
fenoth | 0:9efeb5787ae9 | 1018 | { |
fenoth | 0:9efeb5787ae9 | 1019 | if (m_byBlockMode[i] == QR_MODE_NUMERAL) |
fenoth | 0:9efeb5787ae9 | 1020 | { |
fenoth | 0:9efeb5787ae9 | 1021 | ///////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 1022 | // Numeric mode |
fenoth | 0:9efeb5787ae9 | 1023 | // Indicator (0001b) |
fenoth | 0:9efeb5787ae9 | 1024 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 1, 4,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1025 | |
fenoth | 0:9efeb5787ae9 | 1026 | //Set number of characters |
fenoth | 0:9efeb5787ae9 | 1027 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)m_nBlockLength[i], nIndicatorLenNumeral[nVerGroup],m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1028 | |
fenoth | 0:9efeb5787ae9 | 1029 | // Save the bit string |
fenoth | 0:9efeb5787ae9 | 1030 | for (j = 0; j < m_nBlockLength[i]; j += 3) |
fenoth | 0:9efeb5787ae9 | 1031 | { |
fenoth | 0:9efeb5787ae9 | 1032 | if (j < m_nBlockLength[i] - 2) |
fenoth | 0:9efeb5787ae9 | 1033 | { |
fenoth | 0:9efeb5787ae9 | 1034 | wBinCode = (WORD)(((lpsSource[ncComplete + j] - '0') * 100) + |
fenoth | 0:9efeb5787ae9 | 1035 | ((lpsSource[ncComplete + j + 1] - '0') * 10) + |
fenoth | 0:9efeb5787ae9 | 1036 | (lpsSource[ncComplete + j + 2] - '0')); |
fenoth | 0:9efeb5787ae9 | 1037 | |
fenoth | 0:9efeb5787ae9 | 1038 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 10,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1039 | } |
fenoth | 0:9efeb5787ae9 | 1040 | else if (j == m_nBlockLength[i] - 2) |
fenoth | 0:9efeb5787ae9 | 1041 | { |
fenoth | 0:9efeb5787ae9 | 1042 | |
fenoth | 0:9efeb5787ae9 | 1043 | // 2 bytes fraction |
fenoth | 0:9efeb5787ae9 | 1044 | wBinCode = (WORD)(((lpsSource[ncComplete + j] - '0') * 10) + |
fenoth | 0:9efeb5787ae9 | 1045 | (lpsSource[ncComplete + j + 1] - '0')); |
fenoth | 0:9efeb5787ae9 | 1046 | |
fenoth | 0:9efeb5787ae9 | 1047 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 7,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1048 | } |
fenoth | 0:9efeb5787ae9 | 1049 | else if (j == m_nBlockLength[i] - 1) |
fenoth | 0:9efeb5787ae9 | 1050 | { |
fenoth | 0:9efeb5787ae9 | 1051 | |
fenoth | 0:9efeb5787ae9 | 1052 | // A fraction of bytes |
fenoth | 0:9efeb5787ae9 | 1053 | wBinCode = (WORD)(lpsSource[ncComplete + j] - '0'); |
fenoth | 0:9efeb5787ae9 | 1054 | |
fenoth | 0:9efeb5787ae9 | 1055 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 4,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1056 | } |
fenoth | 0:9efeb5787ae9 | 1057 | } |
fenoth | 0:9efeb5787ae9 | 1058 | |
fenoth | 0:9efeb5787ae9 | 1059 | ncComplete += m_nBlockLength[i]; |
fenoth | 0:9efeb5787ae9 | 1060 | } |
fenoth | 0:9efeb5787ae9 | 1061 | |
fenoth | 0:9efeb5787ae9 | 1062 | else if (m_byBlockMode[i] == QR_MODE_ALPHABET) |
fenoth | 0:9efeb5787ae9 | 1063 | { |
fenoth | 0:9efeb5787ae9 | 1064 | ///////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 1065 | // Alphanumeric mode |
fenoth | 0:9efeb5787ae9 | 1066 | // Mode indicator (0010b) |
fenoth | 0:9efeb5787ae9 | 1067 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 2, 4,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1068 | |
fenoth | 0:9efeb5787ae9 | 1069 | // Set number of characters |
fenoth | 0:9efeb5787ae9 | 1070 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)m_nBlockLength[i], nIndicatorLenAlphabet[nVerGroup],m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1071 | |
fenoth | 0:9efeb5787ae9 | 1072 | // Save the bit string |
fenoth | 0:9efeb5787ae9 | 1073 | for (j = 0; j < m_nBlockLength[i]; j += 2) |
fenoth | 0:9efeb5787ae9 | 1074 | { |
fenoth | 0:9efeb5787ae9 | 1075 | if (j < m_nBlockLength[i] - 1) |
fenoth | 0:9efeb5787ae9 | 1076 | { |
fenoth | 0:9efeb5787ae9 | 1077 | wBinCode = (WORD)((AlphabetToBinary(lpsSource[ncComplete + j]) * 45) + |
fenoth | 0:9efeb5787ae9 | 1078 | AlphabetToBinary(lpsSource[ncComplete + j + 1])); |
fenoth | 0:9efeb5787ae9 | 1079 | |
fenoth | 0:9efeb5787ae9 | 1080 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 11,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1081 | } |
fenoth | 0:9efeb5787ae9 | 1082 | else |
fenoth | 0:9efeb5787ae9 | 1083 | { |
fenoth | 0:9efeb5787ae9 | 1084 | // A fraction of bytes |
fenoth | 0:9efeb5787ae9 | 1085 | wBinCode = (WORD)AlphabetToBinary(lpsSource[ncComplete + j]); |
fenoth | 0:9efeb5787ae9 | 1086 | |
fenoth | 0:9efeb5787ae9 | 1087 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 6,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1088 | } |
fenoth | 0:9efeb5787ae9 | 1089 | } |
fenoth | 0:9efeb5787ae9 | 1090 | |
fenoth | 0:9efeb5787ae9 | 1091 | ncComplete += m_nBlockLength[i]; |
fenoth | 0:9efeb5787ae9 | 1092 | } |
fenoth | 0:9efeb5787ae9 | 1093 | |
fenoth | 0:9efeb5787ae9 | 1094 | else if (m_byBlockMode[i] == QR_MODE_8BIT) |
fenoth | 0:9efeb5787ae9 | 1095 | { |
fenoth | 0:9efeb5787ae9 | 1096 | ///////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 1097 | // 8-bit byte mode |
fenoth | 0:9efeb5787ae9 | 1098 | |
fenoth | 0:9efeb5787ae9 | 1099 | // Mode indicator (0100b) |
fenoth | 0:9efeb5787ae9 | 1100 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 4, 4,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1101 | |
fenoth | 0:9efeb5787ae9 | 1102 | |
fenoth | 0:9efeb5787ae9 | 1103 | // Set number of characters |
fenoth | 0:9efeb5787ae9 | 1104 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)m_nBlockLength[i], nIndicatorLen8Bit[nVerGroup],m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1105 | |
fenoth | 0:9efeb5787ae9 | 1106 | |
fenoth | 0:9efeb5787ae9 | 1107 | // Save the bit string |
fenoth | 0:9efeb5787ae9 | 1108 | for (j = 0; j < m_nBlockLength[i]; ++j) |
fenoth | 0:9efeb5787ae9 | 1109 | { |
fenoth | 0:9efeb5787ae9 | 1110 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)lpsSource[ncComplete + j], 8,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1111 | } |
fenoth | 0:9efeb5787ae9 | 1112 | |
fenoth | 0:9efeb5787ae9 | 1113 | ncComplete += m_nBlockLength[i]; |
fenoth | 0:9efeb5787ae9 | 1114 | } |
fenoth | 0:9efeb5787ae9 | 1115 | else // m_byBlockMode[i] == QR_MODE_KANJI |
fenoth | 0:9efeb5787ae9 | 1116 | { |
fenoth | 0:9efeb5787ae9 | 1117 | ///////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 1118 | |
fenoth | 0:9efeb5787ae9 | 1119 | |
fenoth | 0:9efeb5787ae9 | 1120 | |
fenoth | 0:9efeb5787ae9 | 1121 | // Kanji mode |
fenoth | 0:9efeb5787ae9 | 1122 | |
fenoth | 0:9efeb5787ae9 | 1123 | // Mode indicator (1000b) |
fenoth | 0:9efeb5787ae9 | 1124 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 8, 4,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1125 | |
fenoth | 0:9efeb5787ae9 | 1126 | |
fenoth | 0:9efeb5787ae9 | 1127 | // Set number of characters |
fenoth | 0:9efeb5787ae9 | 1128 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, (WORD)(m_nBlockLength[i] / 2), nIndicatorLenKanji[nVerGroup],m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1129 | |
fenoth | 0:9efeb5787ae9 | 1130 | |
fenoth | 0:9efeb5787ae9 | 1131 | |
fenoth | 0:9efeb5787ae9 | 1132 | // Save the bit string in character mode |
fenoth | 0:9efeb5787ae9 | 1133 | for (j = 0; j < m_nBlockLength[i] / 2; ++j) |
fenoth | 0:9efeb5787ae9 | 1134 | { |
fenoth | 0:9efeb5787ae9 | 1135 | WORD wBinCode = KanjiToBinaly((WORD)(((BYTE)lpsSource[ncComplete + (j * 2)] << 8) + (BYTE)lpsSource[ncComplete + (j * 2) + 1])); |
fenoth | 0:9efeb5787ae9 | 1136 | |
fenoth | 0:9efeb5787ae9 | 1137 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, wBinCode, 13,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1138 | } |
fenoth | 0:9efeb5787ae9 | 1139 | |
fenoth | 0:9efeb5787ae9 | 1140 | ncComplete += m_nBlockLength[i]; |
fenoth | 0:9efeb5787ae9 | 1141 | } |
fenoth | 0:9efeb5787ae9 | 1142 | } |
fenoth | 0:9efeb5787ae9 | 1143 | |
fenoth | 0:9efeb5787ae9 | 1144 | return (m_ncDataCodeWordBit != -1); |
fenoth | 0:9efeb5787ae9 | 1145 | } |
fenoth | 0:9efeb5787ae9 | 1146 | |
fenoth | 0:9efeb5787ae9 | 1147 | |
fenoth | 0:9efeb5787ae9 | 1148 | ///////////////////////////////////////////////////////////////////////////// |
fenoth | 0:9efeb5787ae9 | 1149 | // APPLICATIONS: To get the bit length |
fenoth | 0:9efeb5787ae9 | 1150 | // Args: data mode type, data length, group version (model number) |
fenoth | 0:9efeb5787ae9 | 1151 | // Returns: data bit length |
fenoth | 0:9efeb5787ae9 | 1152 | // Remarks: data length of argument in Kanji mode is the number of bytes, not characters |
fenoth | 0:9efeb5787ae9 | 1153 | |
fenoth | 0:9efeb5787ae9 | 1154 | |
fenoth | 0:9efeb5787ae9 | 1155 | |
fenoth | 0:9efeb5787ae9 | 1156 | int GetEncodeVersion(int nVersion, LPCSTR lpsSource, int ncLength,int m_nBlockLength[MAX_DATACODEWORD],BYTE m_byBlockMode[MAX_DATACODEWORD],BYTE m_byDataCodeWord[MAX_DATACODEWORD]) |
fenoth | 0:9efeb5787ae9 | 1157 | { |
fenoth | 0:9efeb5787ae9 | 1158 | int nVerGroup = nVersion >= 27 ? QR_VERSION_L : (nVersion >= 10 ? QR_VERSION_M : QR_VERSION_S); |
fenoth | 0:9efeb5787ae9 | 1159 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1160 | |
fenoth | 0:9efeb5787ae9 | 1161 | for (i = nVerGroup; i <= QR_VERSION_L; ++i) |
fenoth | 0:9efeb5787ae9 | 1162 | { |
fenoth | 0:9efeb5787ae9 | 1163 | if (EncodeSourceData(lpsSource, ncLength, i, m_nBlockLength, m_byBlockMode, m_byDataCodeWord)) |
fenoth | 0:9efeb5787ae9 | 1164 | { |
fenoth | 0:9efeb5787ae9 | 1165 | if (i == QR_VERSION_S) |
fenoth | 0:9efeb5787ae9 | 1166 | { |
fenoth | 0:9efeb5787ae9 | 1167 | for (j = 1; j <= 9; ++j) |
fenoth | 0:9efeb5787ae9 | 1168 | { |
fenoth | 0:9efeb5787ae9 | 1169 | if ((m_ncDataCodeWordBit + 7) / 8 <= QR_VersionInfo[j].ncDataCodeWord[m_nLevel]) |
fenoth | 0:9efeb5787ae9 | 1170 | return j; |
fenoth | 0:9efeb5787ae9 | 1171 | } |
fenoth | 0:9efeb5787ae9 | 1172 | } |
fenoth | 0:9efeb5787ae9 | 1173 | else if (i == QR_VERSION_M) |
fenoth | 0:9efeb5787ae9 | 1174 | { |
fenoth | 0:9efeb5787ae9 | 1175 | for (j = 10; j <= 26; ++j) |
fenoth | 0:9efeb5787ae9 | 1176 | { |
fenoth | 0:9efeb5787ae9 | 1177 | if ((m_ncDataCodeWordBit + 7) / 8 <= QR_VersionInfo[j].ncDataCodeWord[m_nLevel]) |
fenoth | 0:9efeb5787ae9 | 1178 | return j; |
fenoth | 0:9efeb5787ae9 | 1179 | } |
fenoth | 0:9efeb5787ae9 | 1180 | } |
fenoth | 0:9efeb5787ae9 | 1181 | else if (i == QR_VERSION_L) |
fenoth | 0:9efeb5787ae9 | 1182 | { |
fenoth | 0:9efeb5787ae9 | 1183 | for (j = 27; j <= 40; ++j) |
fenoth | 0:9efeb5787ae9 | 1184 | { |
fenoth | 0:9efeb5787ae9 | 1185 | if ((m_ncDataCodeWordBit + 7) / 8 <= QR_VersionInfo[j].ncDataCodeWord[m_nLevel]) |
fenoth | 0:9efeb5787ae9 | 1186 | return j; |
fenoth | 0:9efeb5787ae9 | 1187 | } |
fenoth | 0:9efeb5787ae9 | 1188 | } |
fenoth | 0:9efeb5787ae9 | 1189 | } |
fenoth | 0:9efeb5787ae9 | 1190 | } |
fenoth | 0:9efeb5787ae9 | 1191 | |
fenoth | 0:9efeb5787ae9 | 1192 | return 0; |
fenoth | 0:9efeb5787ae9 | 1193 | } |
fenoth | 0:9efeb5787ae9 | 1194 | |
fenoth | 0:9efeb5787ae9 | 1195 | |
fenoth | 0:9efeb5787ae9 | 1196 | int min(int a, int b) { |
fenoth | 0:9efeb5787ae9 | 1197 | if (a<=b) { |
fenoth | 0:9efeb5787ae9 | 1198 | return a; |
fenoth | 0:9efeb5787ae9 | 1199 | } |
fenoth | 0:9efeb5787ae9 | 1200 | else { |
fenoth | 0:9efeb5787ae9 | 1201 | return b; |
fenoth | 0:9efeb5787ae9 | 1202 | } |
fenoth | 0:9efeb5787ae9 | 1203 | } |
fenoth | 0:9efeb5787ae9 | 1204 | |
fenoth | 0:9efeb5787ae9 | 1205 | void GetRSCodeWord(LPBYTE lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord) |
fenoth | 0:9efeb5787ae9 | 1206 | { |
fenoth | 0:9efeb5787ae9 | 1207 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1208 | |
fenoth | 0:9efeb5787ae9 | 1209 | for (i = 0; i < ncDataCodeWord ; ++i) |
fenoth | 0:9efeb5787ae9 | 1210 | { |
fenoth | 0:9efeb5787ae9 | 1211 | if (lpbyRSWork[0] != 0) |
fenoth | 0:9efeb5787ae9 | 1212 | { |
fenoth | 0:9efeb5787ae9 | 1213 | BYTE nExpFirst = byIntToExp[lpbyRSWork[0]]; //Multiplier coefficient is calculated from the first term |
fenoth | 0:9efeb5787ae9 | 1214 | |
fenoth | 0:9efeb5787ae9 | 1215 | for (j = 0; j < ncRSCodeWord; ++j) |
fenoth | 0:9efeb5787ae9 | 1216 | { |
fenoth | 0:9efeb5787ae9 | 1217 | |
fenoth | 0:9efeb5787ae9 | 1218 | //Add (% 255 ^ 255 = 1) the first term multiplier to multiplier sections |
fenoth | 0:9efeb5787ae9 | 1219 | BYTE nExpElement = (BYTE)(((int)(byRSExp[ncRSCodeWord][j] + nExpFirst)) % 255); |
fenoth | 0:9efeb5787ae9 | 1220 | |
fenoth | 0:9efeb5787ae9 | 1221 | |
fenoth | 0:9efeb5787ae9 | 1222 | //Surplus calculated by the exclusive |
fenoth | 0:9efeb5787ae9 | 1223 | lpbyRSWork[j] = (BYTE)(lpbyRSWork[j + 1] ^ byExpToInt[nExpElement]); |
fenoth | 0:9efeb5787ae9 | 1224 | } |
fenoth | 0:9efeb5787ae9 | 1225 | |
fenoth | 0:9efeb5787ae9 | 1226 | |
fenoth | 0:9efeb5787ae9 | 1227 | //Shift the remaining digits |
fenoth | 0:9efeb5787ae9 | 1228 | for (j = ncRSCodeWord; j < ncDataCodeWord + ncRSCodeWord - 1; ++j) |
fenoth | 0:9efeb5787ae9 | 1229 | lpbyRSWork[j] = lpbyRSWork[j + 1]; |
fenoth | 0:9efeb5787ae9 | 1230 | } |
fenoth | 0:9efeb5787ae9 | 1231 | else |
fenoth | 0:9efeb5787ae9 | 1232 | { |
fenoth | 0:9efeb5787ae9 | 1233 | |
fenoth | 0:9efeb5787ae9 | 1234 | //Shift the remaining digits |
fenoth | 0:9efeb5787ae9 | 1235 | for (j = 0; j < ncDataCodeWord + ncRSCodeWord - 1; ++j) |
fenoth | 0:9efeb5787ae9 | 1236 | lpbyRSWork[j] = lpbyRSWork[j + 1]; |
fenoth | 0:9efeb5787ae9 | 1237 | } |
fenoth | 0:9efeb5787ae9 | 1238 | } |
fenoth | 0:9efeb5787ae9 | 1239 | } |
fenoth | 0:9efeb5787ae9 | 1240 | |
fenoth | 0:9efeb5787ae9 | 1241 | void SetFinderPattern(int x, int y,BYTE m_byModuleData[177][177]) |
fenoth | 0:9efeb5787ae9 | 1242 | { |
fenoth | 0:9efeb5787ae9 | 1243 | static BYTE byPattern[] = {0x7f, // 1111111b |
fenoth | 0:9efeb5787ae9 | 1244 | 0x41, // 1000001b |
fenoth | 0:9efeb5787ae9 | 1245 | 0x5d, // 1011101b |
fenoth | 0:9efeb5787ae9 | 1246 | 0x5d, // 1011101b |
fenoth | 0:9efeb5787ae9 | 1247 | 0x5d, // 1011101b |
fenoth | 0:9efeb5787ae9 | 1248 | 0x41, // 1000001b |
fenoth | 0:9efeb5787ae9 | 1249 | 0x7f}; // 1111111b |
fenoth | 0:9efeb5787ae9 | 1250 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1251 | |
fenoth | 0:9efeb5787ae9 | 1252 | for (i = 0; i < 7; ++i) |
fenoth | 0:9efeb5787ae9 | 1253 | { |
fenoth | 0:9efeb5787ae9 | 1254 | for (j = 0; j < 7; ++j) |
fenoth | 0:9efeb5787ae9 | 1255 | { |
fenoth | 0:9efeb5787ae9 | 1256 | m_byModuleData[x + j][y + i] = (byPattern[i] & (1 << (6 - j))) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1257 | } |
fenoth | 0:9efeb5787ae9 | 1258 | } |
fenoth | 0:9efeb5787ae9 | 1259 | } |
fenoth | 0:9efeb5787ae9 | 1260 | |
fenoth | 0:9efeb5787ae9 | 1261 | void SetVersionPattern(BYTE m_byModuleData[177][177]) |
fenoth | 0:9efeb5787ae9 | 1262 | { |
fenoth | 0:9efeb5787ae9 | 1263 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1264 | |
fenoth | 0:9efeb5787ae9 | 1265 | if (QR_m_nVersion <= 6) |
fenoth | 0:9efeb5787ae9 | 1266 | return; |
fenoth | 0:9efeb5787ae9 | 1267 | |
fenoth | 0:9efeb5787ae9 | 1268 | int nVerData = QR_m_nVersion << 12; |
fenoth | 0:9efeb5787ae9 | 1269 | |
fenoth | 0:9efeb5787ae9 | 1270 | //Calculated bit remainder |
fenoth | 0:9efeb5787ae9 | 1271 | |
fenoth | 0:9efeb5787ae9 | 1272 | for (i = 0; i < 6; ++i) |
fenoth | 0:9efeb5787ae9 | 1273 | { |
fenoth | 0:9efeb5787ae9 | 1274 | if (nVerData & (1 << (17 - i))) |
fenoth | 0:9efeb5787ae9 | 1275 | { |
fenoth | 0:9efeb5787ae9 | 1276 | nVerData ^= (0x1f25 << (5 - i)); |
fenoth | 0:9efeb5787ae9 | 1277 | } |
fenoth | 0:9efeb5787ae9 | 1278 | } |
fenoth | 0:9efeb5787ae9 | 1279 | |
fenoth | 0:9efeb5787ae9 | 1280 | nVerData += QR_m_nVersion << 12; |
fenoth | 0:9efeb5787ae9 | 1281 | |
fenoth | 0:9efeb5787ae9 | 1282 | for (i = 0; i < 6; ++i) |
fenoth | 0:9efeb5787ae9 | 1283 | { |
fenoth | 0:9efeb5787ae9 | 1284 | for (j = 0; j < 3; ++j) |
fenoth | 0:9efeb5787ae9 | 1285 | { |
fenoth | 0:9efeb5787ae9 | 1286 | m_byModuleData[m_nSymbolSize - 11 + j][i] = m_byModuleData[i][m_nSymbolSize - 11 + j] = |
fenoth | 0:9efeb5787ae9 | 1287 | (nVerData & (1 << (i * 3 + j))) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1288 | } |
fenoth | 0:9efeb5787ae9 | 1289 | } |
fenoth | 0:9efeb5787ae9 | 1290 | } |
fenoth | 0:9efeb5787ae9 | 1291 | |
fenoth | 0:9efeb5787ae9 | 1292 | void SetAlignmentPattern(int x, int y,BYTE m_byModuleData[177][177]) |
fenoth | 0:9efeb5787ae9 | 1293 | { |
fenoth | 0:9efeb5787ae9 | 1294 | static BYTE byPattern[] = {0x1f, // 11111b |
fenoth | 0:9efeb5787ae9 | 1295 | 0x11, // 10001b |
fenoth | 0:9efeb5787ae9 | 1296 | 0x15, // 10101b |
fenoth | 0:9efeb5787ae9 | 1297 | 0x11, // 10001b |
fenoth | 0:9efeb5787ae9 | 1298 | 0x1f}; // 11111b |
fenoth | 0:9efeb5787ae9 | 1299 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1300 | |
fenoth | 0:9efeb5787ae9 | 1301 | if (m_byModuleData[x][y] & 0x20) |
fenoth | 0:9efeb5787ae9 | 1302 | return; //Excluded due to overlap with the functional module |
fenoth | 0:9efeb5787ae9 | 1303 | |
fenoth | 0:9efeb5787ae9 | 1304 | x -= 2; y -= 2; //Convert the coordinates to the upper left corner |
fenoth | 0:9efeb5787ae9 | 1305 | |
fenoth | 0:9efeb5787ae9 | 1306 | for (i = 0; i < 5; ++i) |
fenoth | 0:9efeb5787ae9 | 1307 | { |
fenoth | 0:9efeb5787ae9 | 1308 | for (j = 0; j < 5; ++j) |
fenoth | 0:9efeb5787ae9 | 1309 | { |
fenoth | 0:9efeb5787ae9 | 1310 | m_byModuleData[x + j][y + i] = (byPattern[i] & (1 << (4 - j))) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1311 | } |
fenoth | 0:9efeb5787ae9 | 1312 | } |
fenoth | 0:9efeb5787ae9 | 1313 | } |
fenoth | 0:9efeb5787ae9 | 1314 | |
fenoth | 0:9efeb5787ae9 | 1315 | |
fenoth | 0:9efeb5787ae9 | 1316 | |
fenoth | 0:9efeb5787ae9 | 1317 | void SetFunctionModule(BYTE m_byModuleData[177][177]) |
fenoth | 0:9efeb5787ae9 | 1318 | { |
fenoth | 0:9efeb5787ae9 | 1319 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1320 | |
fenoth | 0:9efeb5787ae9 | 1321 | |
fenoth | 0:9efeb5787ae9 | 1322 | //Position detection pattern |
fenoth | 0:9efeb5787ae9 | 1323 | SetFinderPattern(0, 0,m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1324 | SetFinderPattern(m_nSymbolSize - 7, 0,m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1325 | SetFinderPattern(0, m_nSymbolSize - 7,m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1326 | |
fenoth | 0:9efeb5787ae9 | 1327 | //Separator pattern position detection |
fenoth | 0:9efeb5787ae9 | 1328 | for (i = 0; i < 8; ++i) |
fenoth | 0:9efeb5787ae9 | 1329 | { |
fenoth | 0:9efeb5787ae9 | 1330 | m_byModuleData[i][7] = m_byModuleData[7][i] = '\x20'; |
fenoth | 0:9efeb5787ae9 | 1331 | m_byModuleData[m_nSymbolSize - 8][i] = m_byModuleData[m_nSymbolSize - 8 + i][7] = '\x20'; |
fenoth | 0:9efeb5787ae9 | 1332 | m_byModuleData[i][m_nSymbolSize - 8] = m_byModuleData[7][m_nSymbolSize - 8 + i] = '\x20'; |
fenoth | 0:9efeb5787ae9 | 1333 | } |
fenoth | 0:9efeb5787ae9 | 1334 | |
fenoth | 0:9efeb5787ae9 | 1335 | |
fenoth | 0:9efeb5787ae9 | 1336 | //Registration as part of a functional module position description format information |
fenoth | 0:9efeb5787ae9 | 1337 | for (i = 0; i < 9; ++i) |
fenoth | 0:9efeb5787ae9 | 1338 | { |
fenoth | 0:9efeb5787ae9 | 1339 | m_byModuleData[i][8] = m_byModuleData[8][i] = '\x20'; |
fenoth | 0:9efeb5787ae9 | 1340 | } |
fenoth | 0:9efeb5787ae9 | 1341 | |
fenoth | 0:9efeb5787ae9 | 1342 | for (i = 0; i < 8; ++i) |
fenoth | 0:9efeb5787ae9 | 1343 | { |
fenoth | 0:9efeb5787ae9 | 1344 | m_byModuleData[m_nSymbolSize - 8 + i][8] = m_byModuleData[8][m_nSymbolSize - 8 + i] = '\x20'; |
fenoth | 0:9efeb5787ae9 | 1345 | } |
fenoth | 0:9efeb5787ae9 | 1346 | |
fenoth | 0:9efeb5787ae9 | 1347 | |
fenoth | 0:9efeb5787ae9 | 1348 | //Version information pattern |
fenoth | 0:9efeb5787ae9 | 1349 | SetVersionPattern(m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1350 | |
fenoth | 0:9efeb5787ae9 | 1351 | |
fenoth | 0:9efeb5787ae9 | 1352 | //Pattern alignment |
fenoth | 0:9efeb5787ae9 | 1353 | for (i = 0; i < QR_VersionInfo[QR_m_nVersion].ncAlignPoint; ++i) |
fenoth | 0:9efeb5787ae9 | 1354 | { |
fenoth | 0:9efeb5787ae9 | 1355 | SetAlignmentPattern(QR_VersionInfo[QR_m_nVersion].nAlignPoint[i], 6,m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1356 | SetAlignmentPattern(6, QR_VersionInfo[QR_m_nVersion].nAlignPoint[i],m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1357 | |
fenoth | 0:9efeb5787ae9 | 1358 | for (j = 0; j < QR_VersionInfo[QR_m_nVersion].ncAlignPoint; ++j) |
fenoth | 0:9efeb5787ae9 | 1359 | { |
fenoth | 0:9efeb5787ae9 | 1360 | SetAlignmentPattern(QR_VersionInfo[QR_m_nVersion].nAlignPoint[i], QR_VersionInfo[QR_m_nVersion].nAlignPoint[j],m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1361 | } |
fenoth | 0:9efeb5787ae9 | 1362 | } |
fenoth | 0:9efeb5787ae9 | 1363 | |
fenoth | 0:9efeb5787ae9 | 1364 | //Timing pattern |
fenoth | 0:9efeb5787ae9 | 1365 | for (i = 8; i <= m_nSymbolSize - 9; ++i) |
fenoth | 0:9efeb5787ae9 | 1366 | { |
fenoth | 0:9efeb5787ae9 | 1367 | m_byModuleData[i][6] = (i % 2) == 0 ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1368 | m_byModuleData[6][i] = (i % 2) == 0 ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1369 | } |
fenoth | 0:9efeb5787ae9 | 1370 | } |
fenoth | 0:9efeb5787ae9 | 1371 | |
fenoth | 0:9efeb5787ae9 | 1372 | void SetCodeWordPattern(BYTE m_byModuleData[177][177],BYTE m_byAllCodeWord[MAX_ALLCODEWORD]) |
fenoth | 0:9efeb5787ae9 | 1373 | { |
fenoth | 0:9efeb5787ae9 | 1374 | int x = m_nSymbolSize; |
fenoth | 0:9efeb5787ae9 | 1375 | int y = m_nSymbolSize - 1; |
fenoth | 0:9efeb5787ae9 | 1376 | |
fenoth | 0:9efeb5787ae9 | 1377 | int nCoef_x = 1; //placement orientation axis x |
fenoth | 0:9efeb5787ae9 | 1378 | int nCoef_y = 1; //placement orientation axis y |
fenoth | 0:9efeb5787ae9 | 1379 | |
fenoth | 0:9efeb5787ae9 | 1380 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1381 | |
fenoth | 0:9efeb5787ae9 | 1382 | for (i = 0; i < m_ncAllCodeWord; ++i) |
fenoth | 0:9efeb5787ae9 | 1383 | { |
fenoth | 0:9efeb5787ae9 | 1384 | for (j = 0; j < 8; ++j) |
fenoth | 0:9efeb5787ae9 | 1385 | { |
fenoth | 0:9efeb5787ae9 | 1386 | do |
fenoth | 0:9efeb5787ae9 | 1387 | { |
fenoth | 0:9efeb5787ae9 | 1388 | x += nCoef_x; |
fenoth | 0:9efeb5787ae9 | 1389 | nCoef_x *= -1; |
fenoth | 0:9efeb5787ae9 | 1390 | |
fenoth | 0:9efeb5787ae9 | 1391 | if (nCoef_x < 0) |
fenoth | 0:9efeb5787ae9 | 1392 | { |
fenoth | 0:9efeb5787ae9 | 1393 | y += nCoef_y; |
fenoth | 0:9efeb5787ae9 | 1394 | |
fenoth | 0:9efeb5787ae9 | 1395 | if (y < 0 || y == m_nSymbolSize) |
fenoth | 0:9efeb5787ae9 | 1396 | { |
fenoth | 0:9efeb5787ae9 | 1397 | y = (y < 0) ? 0 : m_nSymbolSize - 1; |
fenoth | 0:9efeb5787ae9 | 1398 | nCoef_y *= -1; |
fenoth | 0:9efeb5787ae9 | 1399 | |
fenoth | 0:9efeb5787ae9 | 1400 | x -= 2; |
fenoth | 0:9efeb5787ae9 | 1401 | |
fenoth | 0:9efeb5787ae9 | 1402 | if (x == 6) //Timing pattern |
fenoth | 0:9efeb5787ae9 | 1403 | --x; |
fenoth | 0:9efeb5787ae9 | 1404 | } |
fenoth | 0:9efeb5787ae9 | 1405 | } |
fenoth | 0:9efeb5787ae9 | 1406 | } |
fenoth | 0:9efeb5787ae9 | 1407 | while (m_byModuleData[x][y] & 0x20); //Exclude a functional module |
fenoth | 0:9efeb5787ae9 | 1408 | |
fenoth | 0:9efeb5787ae9 | 1409 | |
fenoth | 0:9efeb5787ae9 | 1410 | m_byModuleData[x][y] = (m_byAllCodeWord[i] & (1 << (7 - j))) ? '\x02' : '\x00'; |
fenoth | 0:9efeb5787ae9 | 1411 | |
fenoth | 0:9efeb5787ae9 | 1412 | } |
fenoth | 0:9efeb5787ae9 | 1413 | } |
fenoth | 0:9efeb5787ae9 | 1414 | } |
fenoth | 0:9efeb5787ae9 | 1415 | |
fenoth | 0:9efeb5787ae9 | 1416 | |
fenoth | 0:9efeb5787ae9 | 1417 | void SetMaskingPattern(int nPatternNo,BYTE m_byModuleData[177][177]) |
fenoth | 0:9efeb5787ae9 | 1418 | { |
fenoth | 0:9efeb5787ae9 | 1419 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1420 | |
fenoth | 0:9efeb5787ae9 | 1421 | for (i = 0; i < m_nSymbolSize; ++i) |
fenoth | 0:9efeb5787ae9 | 1422 | { |
fenoth | 0:9efeb5787ae9 | 1423 | for (j = 0; j < m_nSymbolSize; ++j) |
fenoth | 0:9efeb5787ae9 | 1424 | { |
fenoth | 0:9efeb5787ae9 | 1425 | if (! (m_byModuleData[j][i] & 0x20)) //Exclude a functional module |
fenoth | 0:9efeb5787ae9 | 1426 | { |
fenoth | 0:9efeb5787ae9 | 1427 | int bMask; |
fenoth | 0:9efeb5787ae9 | 1428 | |
fenoth | 0:9efeb5787ae9 | 1429 | switch (nPatternNo) |
fenoth | 0:9efeb5787ae9 | 1430 | { |
fenoth | 0:9efeb5787ae9 | 1431 | case 0: |
fenoth | 0:9efeb5787ae9 | 1432 | bMask = ((i + j) % 2 == 0); |
fenoth | 0:9efeb5787ae9 | 1433 | break; |
fenoth | 0:9efeb5787ae9 | 1434 | |
fenoth | 0:9efeb5787ae9 | 1435 | case 1: |
fenoth | 0:9efeb5787ae9 | 1436 | bMask = (i % 2 == 0); |
fenoth | 0:9efeb5787ae9 | 1437 | break; |
fenoth | 0:9efeb5787ae9 | 1438 | |
fenoth | 0:9efeb5787ae9 | 1439 | case 2: |
fenoth | 0:9efeb5787ae9 | 1440 | bMask = (j % 3 == 0); |
fenoth | 0:9efeb5787ae9 | 1441 | break; |
fenoth | 0:9efeb5787ae9 | 1442 | |
fenoth | 0:9efeb5787ae9 | 1443 | case 3: |
fenoth | 0:9efeb5787ae9 | 1444 | bMask = ((i + j) % 3 == 0); |
fenoth | 0:9efeb5787ae9 | 1445 | break; |
fenoth | 0:9efeb5787ae9 | 1446 | |
fenoth | 0:9efeb5787ae9 | 1447 | case 4: |
fenoth | 0:9efeb5787ae9 | 1448 | bMask = (((i / 2) + (j / 3)) % 2 == 0); |
fenoth | 0:9efeb5787ae9 | 1449 | break; |
fenoth | 0:9efeb5787ae9 | 1450 | |
fenoth | 0:9efeb5787ae9 | 1451 | case 5: |
fenoth | 0:9efeb5787ae9 | 1452 | bMask = (((i * j) % 2) + ((i * j) % 3) == 0); |
fenoth | 0:9efeb5787ae9 | 1453 | break; |
fenoth | 0:9efeb5787ae9 | 1454 | |
fenoth | 0:9efeb5787ae9 | 1455 | case 6: |
fenoth | 0:9efeb5787ae9 | 1456 | bMask = ((((i * j) % 2) + ((i * j) % 3)) % 2 == 0); |
fenoth | 0:9efeb5787ae9 | 1457 | break; |
fenoth | 0:9efeb5787ae9 | 1458 | |
fenoth | 0:9efeb5787ae9 | 1459 | default: // case 7: |
fenoth | 0:9efeb5787ae9 | 1460 | bMask = ((((i * j) % 3) + ((i + j) % 2)) % 2 == 0); |
fenoth | 0:9efeb5787ae9 | 1461 | break; |
fenoth | 0:9efeb5787ae9 | 1462 | } |
fenoth | 0:9efeb5787ae9 | 1463 | |
fenoth | 0:9efeb5787ae9 | 1464 | m_byModuleData[j][i] = (BYTE)((m_byModuleData[j][i] & 0xfe) | (((m_byModuleData[j][i] & 0x02) > 1) ^ bMask)); |
fenoth | 0:9efeb5787ae9 | 1465 | } |
fenoth | 0:9efeb5787ae9 | 1466 | } |
fenoth | 0:9efeb5787ae9 | 1467 | } |
fenoth | 0:9efeb5787ae9 | 1468 | } |
fenoth | 0:9efeb5787ae9 | 1469 | |
fenoth | 0:9efeb5787ae9 | 1470 | void SetFormatInfoPattern(int nPatternNo,BYTE m_byModuleData[177][177]) |
fenoth | 0:9efeb5787ae9 | 1471 | { |
fenoth | 0:9efeb5787ae9 | 1472 | int nFormatInfo; |
fenoth | 0:9efeb5787ae9 | 1473 | int i; |
fenoth | 0:9efeb5787ae9 | 1474 | |
fenoth | 0:9efeb5787ae9 | 1475 | switch (m_nLevel) |
fenoth | 0:9efeb5787ae9 | 1476 | { |
fenoth | 0:9efeb5787ae9 | 1477 | case QR_LEVEL_M: |
fenoth | 0:9efeb5787ae9 | 1478 | nFormatInfo = 0x00; // 00nnnb |
fenoth | 0:9efeb5787ae9 | 1479 | break; |
fenoth | 0:9efeb5787ae9 | 1480 | |
fenoth | 0:9efeb5787ae9 | 1481 | case QR_LEVEL_L: |
fenoth | 0:9efeb5787ae9 | 1482 | nFormatInfo = 0x08; // 01nnnb |
fenoth | 0:9efeb5787ae9 | 1483 | break; |
fenoth | 0:9efeb5787ae9 | 1484 | |
fenoth | 0:9efeb5787ae9 | 1485 | case QR_LEVEL_Q: |
fenoth | 0:9efeb5787ae9 | 1486 | nFormatInfo = 0x18; // 11nnnb |
fenoth | 0:9efeb5787ae9 | 1487 | break; |
fenoth | 0:9efeb5787ae9 | 1488 | |
fenoth | 0:9efeb5787ae9 | 1489 | default: // case QR_LEVEL_H: |
fenoth | 0:9efeb5787ae9 | 1490 | nFormatInfo = 0x10; // 10nnnb |
fenoth | 0:9efeb5787ae9 | 1491 | break; |
fenoth | 0:9efeb5787ae9 | 1492 | } |
fenoth | 0:9efeb5787ae9 | 1493 | |
fenoth | 0:9efeb5787ae9 | 1494 | nFormatInfo += nPatternNo; |
fenoth | 0:9efeb5787ae9 | 1495 | |
fenoth | 0:9efeb5787ae9 | 1496 | int nFormatData = nFormatInfo << 10; |
fenoth | 0:9efeb5787ae9 | 1497 | |
fenoth | 0:9efeb5787ae9 | 1498 | |
fenoth | 0:9efeb5787ae9 | 1499 | //Calculated bit remainder |
fenoth | 0:9efeb5787ae9 | 1500 | |
fenoth | 0:9efeb5787ae9 | 1501 | for (i = 0; i < 5; ++i) |
fenoth | 0:9efeb5787ae9 | 1502 | { |
fenoth | 0:9efeb5787ae9 | 1503 | if (nFormatData & (1 << (14 - i))) |
fenoth | 0:9efeb5787ae9 | 1504 | { |
fenoth | 0:9efeb5787ae9 | 1505 | nFormatData ^= (0x0537 << (4 - i)); // 10100110111b |
fenoth | 0:9efeb5787ae9 | 1506 | } |
fenoth | 0:9efeb5787ae9 | 1507 | } |
fenoth | 0:9efeb5787ae9 | 1508 | |
fenoth | 0:9efeb5787ae9 | 1509 | nFormatData += nFormatInfo << 10; |
fenoth | 0:9efeb5787ae9 | 1510 | |
fenoth | 0:9efeb5787ae9 | 1511 | |
fenoth | 0:9efeb5787ae9 | 1512 | //Masking |
fenoth | 0:9efeb5787ae9 | 1513 | nFormatData ^= 0x5412; // 101010000010010b |
fenoth | 0:9efeb5787ae9 | 1514 | |
fenoth | 0:9efeb5787ae9 | 1515 | |
fenoth | 0:9efeb5787ae9 | 1516 | // Position detection patterns located around the upper left |
fenoth | 0:9efeb5787ae9 | 1517 | for (i = 0; i <= 5; ++i) |
fenoth | 0:9efeb5787ae9 | 1518 | m_byModuleData[8][i] = (nFormatData & (1 << i)) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1519 | |
fenoth | 0:9efeb5787ae9 | 1520 | m_byModuleData[8][7] = (nFormatData & (1 << 6)) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1521 | m_byModuleData[8][8] = (nFormatData & (1 << 7)) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1522 | m_byModuleData[7][8] = (nFormatData & (1 << 8)) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1523 | |
fenoth | 0:9efeb5787ae9 | 1524 | for (i = 9; i <= 14; ++i) |
fenoth | 0:9efeb5787ae9 | 1525 | m_byModuleData[14 - i][8] = (nFormatData & (1 << i)) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1526 | |
fenoth | 0:9efeb5787ae9 | 1527 | |
fenoth | 0:9efeb5787ae9 | 1528 | //Position detection patterns located under the upper right corner |
fenoth | 0:9efeb5787ae9 | 1529 | for (i = 0; i <= 7; ++i) |
fenoth | 0:9efeb5787ae9 | 1530 | m_byModuleData[m_nSymbolSize - 1 - i][8] = (nFormatData & (1 << i)) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1531 | |
fenoth | 0:9efeb5787ae9 | 1532 | |
fenoth | 0:9efeb5787ae9 | 1533 | //Right lower left position detection patterns located |
fenoth | 0:9efeb5787ae9 | 1534 | m_byModuleData[8][m_nSymbolSize - 8] = '\x30'; //Module fixed dark |
fenoth | 0:9efeb5787ae9 | 1535 | |
fenoth | 0:9efeb5787ae9 | 1536 | for (i = 8; i <= 14; ++i) |
fenoth | 0:9efeb5787ae9 | 1537 | m_byModuleData[8][m_nSymbolSize - 15 + i] = (nFormatData & (1 << i)) ? '\x30' : '\x20'; |
fenoth | 0:9efeb5787ae9 | 1538 | } |
fenoth | 0:9efeb5787ae9 | 1539 | int CountPenalty(BYTE m_byModuleData[177][177]) |
fenoth | 0:9efeb5787ae9 | 1540 | { |
fenoth | 0:9efeb5787ae9 | 1541 | int nPenalty = 0; |
fenoth | 0:9efeb5787ae9 | 1542 | int i, j, k; |
fenoth | 0:9efeb5787ae9 | 1543 | |
fenoth | 0:9efeb5787ae9 | 1544 | |
fenoth | 0:9efeb5787ae9 | 1545 | //Column of the same color adjacent module |
fenoth | 0:9efeb5787ae9 | 1546 | for (i = 0; i < m_nSymbolSize; ++i) |
fenoth | 0:9efeb5787ae9 | 1547 | { |
fenoth | 0:9efeb5787ae9 | 1548 | for (j = 0; j < m_nSymbolSize - 4; ++j) |
fenoth | 0:9efeb5787ae9 | 1549 | { |
fenoth | 0:9efeb5787ae9 | 1550 | int nCount = 1; |
fenoth | 0:9efeb5787ae9 | 1551 | |
fenoth | 0:9efeb5787ae9 | 1552 | for (k = j + 1; k < m_nSymbolSize; k++) |
fenoth | 0:9efeb5787ae9 | 1553 | { |
fenoth | 0:9efeb5787ae9 | 1554 | if (((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i][k] & 0x11) == 0)) |
fenoth | 0:9efeb5787ae9 | 1555 | ++nCount; |
fenoth | 0:9efeb5787ae9 | 1556 | else |
fenoth | 0:9efeb5787ae9 | 1557 | break; |
fenoth | 0:9efeb5787ae9 | 1558 | } |
fenoth | 0:9efeb5787ae9 | 1559 | |
fenoth | 0:9efeb5787ae9 | 1560 | if (nCount >= 5) |
fenoth | 0:9efeb5787ae9 | 1561 | { |
fenoth | 0:9efeb5787ae9 | 1562 | nPenalty += 3 + (nCount - 5); |
fenoth | 0:9efeb5787ae9 | 1563 | } |
fenoth | 0:9efeb5787ae9 | 1564 | |
fenoth | 0:9efeb5787ae9 | 1565 | j = k - 1; |
fenoth | 0:9efeb5787ae9 | 1566 | } |
fenoth | 0:9efeb5787ae9 | 1567 | } |
fenoth | 0:9efeb5787ae9 | 1568 | |
fenoth | 0:9efeb5787ae9 | 1569 | |
fenoth | 0:9efeb5787ae9 | 1570 | //Adjacent module line of the same color |
fenoth | 0:9efeb5787ae9 | 1571 | for (i = 0; i < m_nSymbolSize; ++i) |
fenoth | 0:9efeb5787ae9 | 1572 | { |
fenoth | 0:9efeb5787ae9 | 1573 | for (j = 0; j < m_nSymbolSize - 4; ++j) |
fenoth | 0:9efeb5787ae9 | 1574 | { |
fenoth | 0:9efeb5787ae9 | 1575 | int nCount = 1; |
fenoth | 0:9efeb5787ae9 | 1576 | |
fenoth | 0:9efeb5787ae9 | 1577 | for (k = j + 1; k < m_nSymbolSize; k++) |
fenoth | 0:9efeb5787ae9 | 1578 | { |
fenoth | 0:9efeb5787ae9 | 1579 | if (((m_byModuleData[j][i] & 0x11) == 0) == ((m_byModuleData[k][i] & 0x11) == 0)) |
fenoth | 0:9efeb5787ae9 | 1580 | ++nCount; |
fenoth | 0:9efeb5787ae9 | 1581 | else |
fenoth | 0:9efeb5787ae9 | 1582 | break; |
fenoth | 0:9efeb5787ae9 | 1583 | } |
fenoth | 0:9efeb5787ae9 | 1584 | |
fenoth | 0:9efeb5787ae9 | 1585 | if (nCount >= 5) |
fenoth | 0:9efeb5787ae9 | 1586 | { |
fenoth | 0:9efeb5787ae9 | 1587 | nPenalty += 3 + (nCount - 5); |
fenoth | 0:9efeb5787ae9 | 1588 | } |
fenoth | 0:9efeb5787ae9 | 1589 | |
fenoth | 0:9efeb5787ae9 | 1590 | j = k - 1; |
fenoth | 0:9efeb5787ae9 | 1591 | } |
fenoth | 0:9efeb5787ae9 | 1592 | } |
fenoth | 0:9efeb5787ae9 | 1593 | |
fenoth | 0:9efeb5787ae9 | 1594 | |
fenoth | 0:9efeb5787ae9 | 1595 | //Modules of the same color block (2 ~ 2) |
fenoth | 0:9efeb5787ae9 | 1596 | for (i = 0; i < m_nSymbolSize - 1; ++i) |
fenoth | 0:9efeb5787ae9 | 1597 | { |
fenoth | 0:9efeb5787ae9 | 1598 | for (j = 0; j < m_nSymbolSize - 1; ++j) |
fenoth | 0:9efeb5787ae9 | 1599 | { |
fenoth | 0:9efeb5787ae9 | 1600 | if ((((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i + 1][j] & 0x11) == 0)) && |
fenoth | 0:9efeb5787ae9 | 1601 | (((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i] [j + 1] & 0x11) == 0)) && |
fenoth | 0:9efeb5787ae9 | 1602 | (((m_byModuleData[i][j] & 0x11) == 0) == ((m_byModuleData[i + 1][j + 1] & 0x11) == 0))) |
fenoth | 0:9efeb5787ae9 | 1603 | { |
fenoth | 0:9efeb5787ae9 | 1604 | nPenalty += 3; |
fenoth | 0:9efeb5787ae9 | 1605 | } |
fenoth | 0:9efeb5787ae9 | 1606 | } |
fenoth | 0:9efeb5787ae9 | 1607 | } |
fenoth | 0:9efeb5787ae9 | 1608 | |
fenoth | 0:9efeb5787ae9 | 1609 | |
fenoth | 0:9efeb5787ae9 | 1610 | //Pattern (dark dark: light: dark: light) ratio 1:1:3:1:1 in the same column |
fenoth | 0:9efeb5787ae9 | 1611 | for (i = 0; i < m_nSymbolSize; ++i) |
fenoth | 0:9efeb5787ae9 | 1612 | { |
fenoth | 0:9efeb5787ae9 | 1613 | for (j = 0; j < m_nSymbolSize - 6; ++j) |
fenoth | 0:9efeb5787ae9 | 1614 | { |
fenoth | 0:9efeb5787ae9 | 1615 | if (((j == 0) || (! (m_byModuleData[i][j - 1] & 0x11))) && |
fenoth | 0:9efeb5787ae9 | 1616 | ( m_byModuleData[i][j] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1617 | (! (m_byModuleData[i][j + 1] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1618 | ( m_byModuleData[i][j + 2] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1619 | ( m_byModuleData[i][j + 3] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1620 | ( m_byModuleData[i][j + 4] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1621 | (! (m_byModuleData[i][j + 5] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1622 | ( m_byModuleData[i][j + 6] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1623 | ((j == m_nSymbolSize - 7) || (! (m_byModuleData[i][j + 7] & 0x11)))) |
fenoth | 0:9efeb5787ae9 | 1624 | { |
fenoth | 0:9efeb5787ae9 | 1625 | |
fenoth | 0:9efeb5787ae9 | 1626 | //Clear pattern of four or more before or after |
fenoth | 0:9efeb5787ae9 | 1627 | if (((j < 2 || ! (m_byModuleData[i][j - 2] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1628 | (j < 3 || ! (m_byModuleData[i][j - 3] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1629 | (j < 4 || ! (m_byModuleData[i][j - 4] & 0x11))) || |
fenoth | 0:9efeb5787ae9 | 1630 | ((j >= m_nSymbolSize - 8 || ! (m_byModuleData[i][j + 8] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1631 | (j >= m_nSymbolSize - 9 || ! (m_byModuleData[i][j + 9] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1632 | (j >= m_nSymbolSize - 10 || ! (m_byModuleData[i][j + 10] & 0x11)))) |
fenoth | 0:9efeb5787ae9 | 1633 | { |
fenoth | 0:9efeb5787ae9 | 1634 | nPenalty += 40; |
fenoth | 0:9efeb5787ae9 | 1635 | } |
fenoth | 0:9efeb5787ae9 | 1636 | } |
fenoth | 0:9efeb5787ae9 | 1637 | } |
fenoth | 0:9efeb5787ae9 | 1638 | } |
fenoth | 0:9efeb5787ae9 | 1639 | |
fenoth | 0:9efeb5787ae9 | 1640 | |
fenoth | 0:9efeb5787ae9 | 1641 | //Pattern (dark dark: light: dark: light) in the same line ratio 1:1:3:1:1 |
fenoth | 0:9efeb5787ae9 | 1642 | for (i = 0; i < m_nSymbolSize; ++i) |
fenoth | 0:9efeb5787ae9 | 1643 | { |
fenoth | 0:9efeb5787ae9 | 1644 | for (j = 0; j < m_nSymbolSize - 6; ++j) |
fenoth | 0:9efeb5787ae9 | 1645 | { |
fenoth | 0:9efeb5787ae9 | 1646 | if (((j == 0) || (! (m_byModuleData[j - 1][i] & 0x11))) && |
fenoth | 0:9efeb5787ae9 | 1647 | ( m_byModuleData[j] [i] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1648 | (! (m_byModuleData[j + 1][i] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1649 | ( m_byModuleData[j + 2][i] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1650 | ( m_byModuleData[j + 3][i] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1651 | ( m_byModuleData[j + 4][i] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1652 | (! (m_byModuleData[j + 5][i] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1653 | ( m_byModuleData[j + 6][i] & 0x11) && |
fenoth | 0:9efeb5787ae9 | 1654 | ((j == m_nSymbolSize - 7) || (! (m_byModuleData[j + 7][i] & 0x11)))) |
fenoth | 0:9efeb5787ae9 | 1655 | { |
fenoth | 0:9efeb5787ae9 | 1656 | |
fenoth | 0:9efeb5787ae9 | 1657 | //Clear pattern of four or more before or after |
fenoth | 0:9efeb5787ae9 | 1658 | if (((j < 2 || ! (m_byModuleData[j - 2][i] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1659 | (j < 3 || ! (m_byModuleData[j - 3][i] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1660 | (j < 4 || ! (m_byModuleData[j - 4][i] & 0x11))) || |
fenoth | 0:9efeb5787ae9 | 1661 | ((j >= m_nSymbolSize - 8 || ! (m_byModuleData[j + 8][i] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1662 | (j >= m_nSymbolSize - 9 || ! (m_byModuleData[j + 9][i] & 0x11)) && |
fenoth | 0:9efeb5787ae9 | 1663 | (j >= m_nSymbolSize - 10 || ! (m_byModuleData[j + 10][i] & 0x11)))) |
fenoth | 0:9efeb5787ae9 | 1664 | { |
fenoth | 0:9efeb5787ae9 | 1665 | nPenalty += 40; |
fenoth | 0:9efeb5787ae9 | 1666 | } |
fenoth | 0:9efeb5787ae9 | 1667 | } |
fenoth | 0:9efeb5787ae9 | 1668 | } |
fenoth | 0:9efeb5787ae9 | 1669 | } |
fenoth | 0:9efeb5787ae9 | 1670 | |
fenoth | 0:9efeb5787ae9 | 1671 | |
fenoth | 0:9efeb5787ae9 | 1672 | //The proportion of modules for the entire dark |
fenoth | 0:9efeb5787ae9 | 1673 | int nCount = 0; |
fenoth | 0:9efeb5787ae9 | 1674 | |
fenoth | 0:9efeb5787ae9 | 1675 | for (i = 0; i < m_nSymbolSize; ++i) |
fenoth | 0:9efeb5787ae9 | 1676 | { |
fenoth | 0:9efeb5787ae9 | 1677 | for (j = 0; j < m_nSymbolSize; ++j) |
fenoth | 0:9efeb5787ae9 | 1678 | { |
fenoth | 0:9efeb5787ae9 | 1679 | if (! (m_byModuleData[i][j] & 0x11)) |
fenoth | 0:9efeb5787ae9 | 1680 | { |
fenoth | 0:9efeb5787ae9 | 1681 | ++nCount; |
fenoth | 0:9efeb5787ae9 | 1682 | } |
fenoth | 0:9efeb5787ae9 | 1683 | } |
fenoth | 0:9efeb5787ae9 | 1684 | } |
fenoth | 0:9efeb5787ae9 | 1685 | |
fenoth | 0:9efeb5787ae9 | 1686 | nPenalty += (abs(50 - ((nCount * 100) / (m_nSymbolSize * m_nSymbolSize))) / 5) * 10; |
fenoth | 0:9efeb5787ae9 | 1687 | |
fenoth | 0:9efeb5787ae9 | 1688 | return nPenalty; |
fenoth | 0:9efeb5787ae9 | 1689 | } |
fenoth | 0:9efeb5787ae9 | 1690 | |
fenoth | 0:9efeb5787ae9 | 1691 | |
fenoth | 0:9efeb5787ae9 | 1692 | void FormatModule(BYTE m_byModuleData[177][177],BYTE m_byAllCodeWord[MAX_ALLCODEWORD]) |
fenoth | 0:9efeb5787ae9 | 1693 | { |
fenoth | 0:9efeb5787ae9 | 1694 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1695 | |
fenoth | 0:9efeb5787ae9 | 1696 | ZeroMemory(m_byModuleData, sizeof(m_byModuleData)); |
fenoth | 0:9efeb5787ae9 | 1697 | |
fenoth | 0:9efeb5787ae9 | 1698 | |
fenoth | 0:9efeb5787ae9 | 1699 | //Function module placement |
fenoth | 0:9efeb5787ae9 | 1700 | SetFunctionModule(m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1701 | |
fenoth | 0:9efeb5787ae9 | 1702 | |
fenoth | 0:9efeb5787ae9 | 1703 | //Data placement |
fenoth | 0:9efeb5787ae9 | 1704 | SetCodeWordPattern(m_byModuleData,m_byAllCodeWord); |
fenoth | 0:9efeb5787ae9 | 1705 | |
fenoth | 0:9efeb5787ae9 | 1706 | if (m_nMaskingNo == -1) |
fenoth | 0:9efeb5787ae9 | 1707 | { |
fenoth | 0:9efeb5787ae9 | 1708 | |
fenoth | 0:9efeb5787ae9 | 1709 | //Select the best pattern masking |
fenoth | 0:9efeb5787ae9 | 1710 | m_nMaskingNo = 0; |
fenoth | 0:9efeb5787ae9 | 1711 | |
fenoth | 0:9efeb5787ae9 | 1712 | SetMaskingPattern(m_nMaskingNo,m_byModuleData); //Masking |
fenoth | 0:9efeb5787ae9 | 1713 | SetFormatInfoPattern(m_nMaskingNo,m_byModuleData); //Placement pattern format information |
fenoth | 0:9efeb5787ae9 | 1714 | |
fenoth | 0:9efeb5787ae9 | 1715 | int nMinPenalty = CountPenalty(m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1716 | |
fenoth | 0:9efeb5787ae9 | 1717 | for (i = 1; i <= 7; ++i) |
fenoth | 0:9efeb5787ae9 | 1718 | { |
fenoth | 0:9efeb5787ae9 | 1719 | SetMaskingPattern(i,m_byModuleData); //Masking |
fenoth | 0:9efeb5787ae9 | 1720 | SetFormatInfoPattern(i,m_byModuleData); //Placement pattern format information |
fenoth | 0:9efeb5787ae9 | 1721 | |
fenoth | 0:9efeb5787ae9 | 1722 | int nPenalty = CountPenalty(m_byModuleData); |
fenoth | 0:9efeb5787ae9 | 1723 | |
fenoth | 0:9efeb5787ae9 | 1724 | if (nPenalty < nMinPenalty) |
fenoth | 0:9efeb5787ae9 | 1725 | { |
fenoth | 0:9efeb5787ae9 | 1726 | nMinPenalty = nPenalty; |
fenoth | 0:9efeb5787ae9 | 1727 | m_nMaskingNo = i; |
fenoth | 0:9efeb5787ae9 | 1728 | } |
fenoth | 0:9efeb5787ae9 | 1729 | } |
fenoth | 0:9efeb5787ae9 | 1730 | } |
fenoth | 0:9efeb5787ae9 | 1731 | |
fenoth | 0:9efeb5787ae9 | 1732 | SetMaskingPattern(m_nMaskingNo,m_byModuleData); //Masking |
fenoth | 0:9efeb5787ae9 | 1733 | SetFormatInfoPattern(m_nMaskingNo,m_byModuleData); //Placement pattern format information |
fenoth | 0:9efeb5787ae9 | 1734 | |
fenoth | 0:9efeb5787ae9 | 1735 | // The module pattern converted to a Boolean value |
fenoth | 0:9efeb5787ae9 | 1736 | |
fenoth | 0:9efeb5787ae9 | 1737 | for (i = 0; i < m_nSymbolSize; ++i) |
fenoth | 0:9efeb5787ae9 | 1738 | { |
fenoth | 0:9efeb5787ae9 | 1739 | for (j = 0; j < m_nSymbolSize; ++j) |
fenoth | 0:9efeb5787ae9 | 1740 | { |
fenoth | 0:9efeb5787ae9 | 1741 | m_byModuleData[i][j] = (BYTE)((m_byModuleData[i][j] & 0x11) != 0); |
fenoth | 0:9efeb5787ae9 | 1742 | } |
fenoth | 0:9efeb5787ae9 | 1743 | } |
fenoth | 0:9efeb5787ae9 | 1744 | |
fenoth | 0:9efeb5787ae9 | 1745 | } |
fenoth | 0:9efeb5787ae9 | 1746 | |
fenoth | 0:9efeb5787ae9 | 1747 | void putBitToPos(unsigned int pos,int bw,unsigned char *bits) |
fenoth | 0:9efeb5787ae9 | 1748 | { |
fenoth | 0:9efeb5787ae9 | 1749 | if(bw==0) return; |
fenoth | 0:9efeb5787ae9 | 1750 | unsigned int tmp; |
fenoth | 0:9efeb5787ae9 | 1751 | unsigned int bitpos[8]={128,64,32,16,8,4,2,1}; |
fenoth | 0:9efeb5787ae9 | 1752 | if (pos%8==0) |
fenoth | 0:9efeb5787ae9 | 1753 | { |
fenoth | 0:9efeb5787ae9 | 1754 | tmp=(pos/8)-1; |
fenoth | 0:9efeb5787ae9 | 1755 | bits[tmp]=bits[tmp]^bitpos[7]; |
fenoth | 0:9efeb5787ae9 | 1756 | } |
fenoth | 0:9efeb5787ae9 | 1757 | else |
fenoth | 0:9efeb5787ae9 | 1758 | { |
fenoth | 0:9efeb5787ae9 | 1759 | tmp=pos/8; |
fenoth | 0:9efeb5787ae9 | 1760 | bits[tmp]=bits[tmp]^bitpos[pos%8-1]; |
fenoth | 0:9efeb5787ae9 | 1761 | } |
fenoth | 0:9efeb5787ae9 | 1762 | } |
fenoth | 0:9efeb5787ae9 | 1763 | |
fenoth | 0:9efeb5787ae9 | 1764 | int EncodeData(int nLevel, int nVersion , LPCSTR lpsSource, int sourcelen, unsigned char QR_m_data[]) |
fenoth | 0:9efeb5787ae9 | 1765 | { |
fenoth | 0:9efeb5787ae9 | 1766 | |
fenoth | 0:9efeb5787ae9 | 1767 | |
fenoth | 0:9efeb5787ae9 | 1768 | int i, j; |
fenoth | 0:9efeb5787ae9 | 1769 | |
fenoth | 0:9efeb5787ae9 | 1770 | int bAutoExtent=0; |
fenoth | 0:9efeb5787ae9 | 1771 | BYTE m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE]; // [x][y] |
fenoth | 0:9efeb5787ae9 | 1772 | BYTE m_byAllCodeWord[MAX_ALLCODEWORD]; |
fenoth | 0:9efeb5787ae9 | 1773 | int m_nBlockLength[MAX_DATACODEWORD]; |
fenoth | 0:9efeb5787ae9 | 1774 | BYTE m_byBlockMode[MAX_DATACODEWORD]; |
fenoth | 0:9efeb5787ae9 | 1775 | BYTE m_byDataCodeWord[MAX_DATACODEWORD]; |
fenoth | 0:9efeb5787ae9 | 1776 | BYTE m_byRSWork[MAX_CODEBLOCK]; |
fenoth | 0:9efeb5787ae9 | 1777 | m_nLevel = nLevel; |
fenoth | 0:9efeb5787ae9 | 1778 | m_nMaskingNo = -1; |
fenoth | 0:9efeb5787ae9 | 1779 | |
fenoth | 0:9efeb5787ae9 | 1780 | ZeroMemory(QR_m_data,MAX_BITDATA); |
fenoth | 0:9efeb5787ae9 | 1781 | // If the data length is not specified, acquired by lstrlen |
fenoth | 0:9efeb5787ae9 | 1782 | int ncLength = sourcelen > 0 ? sourcelen : strlen(lpsSource); |
fenoth | 0:9efeb5787ae9 | 1783 | |
fenoth | 0:9efeb5787ae9 | 1784 | if (ncLength == 0) |
fenoth | 0:9efeb5787ae9 | 1785 | return -1; // No data |
fenoth | 0:9efeb5787ae9 | 1786 | |
fenoth | 0:9efeb5787ae9 | 1787 | |
fenoth | 0:9efeb5787ae9 | 1788 | // Check version (model number) |
fenoth | 0:9efeb5787ae9 | 1789 | |
fenoth | 0:9efeb5787ae9 | 1790 | nEncodeVersion = GetEncodeVersion(nVersion, lpsSource, ncLength, m_nBlockLength, m_byBlockMode,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1791 | |
fenoth | 0:9efeb5787ae9 | 1792 | if (nEncodeVersion == 0) |
fenoth | 0:9efeb5787ae9 | 1793 | return -1; |
fenoth | 0:9efeb5787ae9 | 1794 | // Over-capacity |
fenoth | 0:9efeb5787ae9 | 1795 | if (nVersion == 0) |
fenoth | 0:9efeb5787ae9 | 1796 | { |
fenoth | 0:9efeb5787ae9 | 1797 | |
fenoth | 0:9efeb5787ae9 | 1798 | // Auto Part |
fenoth | 0:9efeb5787ae9 | 1799 | QR_m_nVersion = nEncodeVersion; |
fenoth | 0:9efeb5787ae9 | 1800 | } |
fenoth | 0:9efeb5787ae9 | 1801 | else |
fenoth | 0:9efeb5787ae9 | 1802 | { |
fenoth | 0:9efeb5787ae9 | 1803 | if (nEncodeVersion <= nVersion) |
fenoth | 0:9efeb5787ae9 | 1804 | { |
fenoth | 0:9efeb5787ae9 | 1805 | QR_m_nVersion = nVersion; |
fenoth | 0:9efeb5787ae9 | 1806 | } |
fenoth | 0:9efeb5787ae9 | 1807 | else |
fenoth | 0:9efeb5787ae9 | 1808 | { |
fenoth | 0:9efeb5787ae9 | 1809 | if (bAutoExtent) |
fenoth | 0:9efeb5787ae9 | 1810 | QR_m_nVersion = nEncodeVersion; // Automatic extended version (model number) |
fenoth | 0:9efeb5787ae9 | 1811 | else |
fenoth | 0:9efeb5787ae9 | 1812 | return -1; // Over-capacity |
fenoth | 0:9efeb5787ae9 | 1813 | } |
fenoth | 0:9efeb5787ae9 | 1814 | } |
fenoth | 0:9efeb5787ae9 | 1815 | |
fenoth | 0:9efeb5787ae9 | 1816 | |
fenoth | 0:9efeb5787ae9 | 1817 | // Terminator addition code "0000" |
fenoth | 0:9efeb5787ae9 | 1818 | int ncDataCodeWord = QR_VersionInfo[QR_m_nVersion].ncDataCodeWord[nLevel]; |
fenoth | 0:9efeb5787ae9 | 1819 | |
fenoth | 0:9efeb5787ae9 | 1820 | int ncTerminater = min(4, (ncDataCodeWord * 8) - m_ncDataCodeWordBit); |
fenoth | 0:9efeb5787ae9 | 1821 | |
fenoth | 0:9efeb5787ae9 | 1822 | if (ncTerminater > 0) |
fenoth | 0:9efeb5787ae9 | 1823 | m_ncDataCodeWordBit = SetBitStream(m_ncDataCodeWordBit, 0, ncTerminater,m_byDataCodeWord); |
fenoth | 0:9efeb5787ae9 | 1824 | |
fenoth | 0:9efeb5787ae9 | 1825 | |
fenoth | 0:9efeb5787ae9 | 1826 | // Additional padding code "11101100, 00010001" |
fenoth | 0:9efeb5787ae9 | 1827 | BYTE byPaddingCode = 0xec; |
fenoth | 0:9efeb5787ae9 | 1828 | |
fenoth | 0:9efeb5787ae9 | 1829 | for (i = (m_ncDataCodeWordBit + 7) / 8; i < ncDataCodeWord; ++i) |
fenoth | 0:9efeb5787ae9 | 1830 | { |
fenoth | 0:9efeb5787ae9 | 1831 | m_byDataCodeWord[i] = byPaddingCode; |
fenoth | 0:9efeb5787ae9 | 1832 | |
fenoth | 0:9efeb5787ae9 | 1833 | byPaddingCode = (BYTE)(byPaddingCode == 0xec ? 0x11 : 0xec); |
fenoth | 0:9efeb5787ae9 | 1834 | } |
fenoth | 0:9efeb5787ae9 | 1835 | |
fenoth | 0:9efeb5787ae9 | 1836 | |
fenoth | 0:9efeb5787ae9 | 1837 | // Calculated the total clear area code word |
fenoth | 0:9efeb5787ae9 | 1838 | m_ncAllCodeWord = QR_VersionInfo[QR_m_nVersion].ncAllCodeWord; |
fenoth | 0:9efeb5787ae9 | 1839 | |
fenoth | 0:9efeb5787ae9 | 1840 | ZeroMemory(m_byAllCodeWord, m_ncAllCodeWord); |
fenoth | 0:9efeb5787ae9 | 1841 | |
fenoth | 0:9efeb5787ae9 | 1842 | int nDataCwIndex = 0; // Position data processing code word |
fenoth | 0:9efeb5787ae9 | 1843 | |
fenoth | 0:9efeb5787ae9 | 1844 | |
fenoth | 0:9efeb5787ae9 | 1845 | // Division number data block |
fenoth | 0:9efeb5787ae9 | 1846 | int ncBlock1 = QR_VersionInfo[QR_m_nVersion].RS_BlockInfo1[nLevel].ncRSBlock; |
fenoth | 0:9efeb5787ae9 | 1847 | |
fenoth | 0:9efeb5787ae9 | 1848 | int ncBlock2 = QR_VersionInfo[QR_m_nVersion].RS_BlockInfo2[nLevel].ncRSBlock; |
fenoth | 0:9efeb5787ae9 | 1849 | |
fenoth | 0:9efeb5787ae9 | 1850 | int ncBlockSum = ncBlock1 + ncBlock2; |
fenoth | 0:9efeb5787ae9 | 1851 | |
fenoth | 0:9efeb5787ae9 | 1852 | |
fenoth | 0:9efeb5787ae9 | 1853 | int nBlockNo = 0; // Block number in the process |
fenoth | 0:9efeb5787ae9 | 1854 | |
fenoth | 0:9efeb5787ae9 | 1855 | |
fenoth | 0:9efeb5787ae9 | 1856 | // The number of data code words by block |
fenoth | 0:9efeb5787ae9 | 1857 | int ncDataCw1 = QR_VersionInfo[QR_m_nVersion].RS_BlockInfo1[nLevel].ncDataCodeWord; |
fenoth | 0:9efeb5787ae9 | 1858 | |
fenoth | 0:9efeb5787ae9 | 1859 | int ncDataCw2 = QR_VersionInfo[QR_m_nVersion].RS_BlockInfo2[nLevel].ncDataCodeWord; |
fenoth | 0:9efeb5787ae9 | 1860 | |
fenoth | 0:9efeb5787ae9 | 1861 | |
fenoth | 0:9efeb5787ae9 | 1862 | // Code word interleaving data placement |
fenoth | 0:9efeb5787ae9 | 1863 | for (i = 0; i < ncBlock1; ++i) |
fenoth | 0:9efeb5787ae9 | 1864 | { |
fenoth | 0:9efeb5787ae9 | 1865 | for (j = 0; j < ncDataCw1; ++j) |
fenoth | 0:9efeb5787ae9 | 1866 | { |
fenoth | 0:9efeb5787ae9 | 1867 | m_byAllCodeWord[(ncBlockSum * j) + nBlockNo] = m_byDataCodeWord[nDataCwIndex++]; |
fenoth | 0:9efeb5787ae9 | 1868 | |
fenoth | 0:9efeb5787ae9 | 1869 | } |
fenoth | 0:9efeb5787ae9 | 1870 | |
fenoth | 0:9efeb5787ae9 | 1871 | ++nBlockNo; |
fenoth | 0:9efeb5787ae9 | 1872 | } |
fenoth | 0:9efeb5787ae9 | 1873 | |
fenoth | 0:9efeb5787ae9 | 1874 | |
fenoth | 0:9efeb5787ae9 | 1875 | for (i = 0; i < ncBlock2; ++i) |
fenoth | 0:9efeb5787ae9 | 1876 | { |
fenoth | 0:9efeb5787ae9 | 1877 | for (j = 0; j < ncDataCw2; ++j) |
fenoth | 0:9efeb5787ae9 | 1878 | { |
fenoth | 0:9efeb5787ae9 | 1879 | if (j < ncDataCw1) |
fenoth | 0:9efeb5787ae9 | 1880 | { |
fenoth | 0:9efeb5787ae9 | 1881 | m_byAllCodeWord[(ncBlockSum * j) + nBlockNo] = m_byDataCodeWord[nDataCwIndex++]; |
fenoth | 0:9efeb5787ae9 | 1882 | } |
fenoth | 0:9efeb5787ae9 | 1883 | else |
fenoth | 0:9efeb5787ae9 | 1884 | { |
fenoth | 0:9efeb5787ae9 | 1885 | // 2 minute fraction block placement event |
fenoth | 0:9efeb5787ae9 | 1886 | m_byAllCodeWord[(ncBlockSum * ncDataCw1) + i] = m_byDataCodeWord[nDataCwIndex++]; |
fenoth | 0:9efeb5787ae9 | 1887 | } |
fenoth | 0:9efeb5787ae9 | 1888 | } |
fenoth | 0:9efeb5787ae9 | 1889 | |
fenoth | 0:9efeb5787ae9 | 1890 | ++nBlockNo; |
fenoth | 0:9efeb5787ae9 | 1891 | } |
fenoth | 0:9efeb5787ae9 | 1892 | |
fenoth | 0:9efeb5787ae9 | 1893 | |
fenoth | 0:9efeb5787ae9 | 1894 | |
fenoth | 0:9efeb5787ae9 | 1895 | // RS code words by block number (currently пїЅпїЅ The same number) |
fenoth | 0:9efeb5787ae9 | 1896 | int ncRSCw1 = QR_VersionInfo[QR_m_nVersion].RS_BlockInfo1[nLevel].ncAllCodeWord - ncDataCw1; |
fenoth | 0:9efeb5787ae9 | 1897 | |
fenoth | 0:9efeb5787ae9 | 1898 | |
fenoth | 0:9efeb5787ae9 | 1899 | int ncRSCw2 = QR_VersionInfo[QR_m_nVersion].RS_BlockInfo2[nLevel].ncAllCodeWord - ncDataCw2; |
fenoth | 0:9efeb5787ae9 | 1900 | |
fenoth | 0:9efeb5787ae9 | 1901 | |
fenoth | 0:9efeb5787ae9 | 1902 | // RS code word is calculated |
fenoth | 0:9efeb5787ae9 | 1903 | |
fenoth | 0:9efeb5787ae9 | 1904 | nDataCwIndex = 0; |
fenoth | 0:9efeb5787ae9 | 1905 | nBlockNo = 0; |
fenoth | 0:9efeb5787ae9 | 1906 | |
fenoth | 0:9efeb5787ae9 | 1907 | for (i = 0; i < ncBlock1; ++i) |
fenoth | 0:9efeb5787ae9 | 1908 | { |
fenoth | 0:9efeb5787ae9 | 1909 | ZeroMemory(m_byRSWork, sizeof(m_byRSWork)); |
fenoth | 0:9efeb5787ae9 | 1910 | |
fenoth | 0:9efeb5787ae9 | 1911 | |
fenoth | 0:9efeb5787ae9 | 1912 | memmove(m_byRSWork, m_byDataCodeWord + nDataCwIndex, ncDataCw1); |
fenoth | 0:9efeb5787ae9 | 1913 | |
fenoth | 0:9efeb5787ae9 | 1914 | |
fenoth | 0:9efeb5787ae9 | 1915 | GetRSCodeWord(m_byRSWork, ncDataCw1, ncRSCw1); |
fenoth | 0:9efeb5787ae9 | 1916 | |
fenoth | 0:9efeb5787ae9 | 1917 | |
fenoth | 0:9efeb5787ae9 | 1918 | // RS code word placement |
fenoth | 0:9efeb5787ae9 | 1919 | for (j = 0; j < ncRSCw1; ++j) |
fenoth | 0:9efeb5787ae9 | 1920 | { |
fenoth | 0:9efeb5787ae9 | 1921 | m_byAllCodeWord[ncDataCodeWord + (ncBlockSum * j) + nBlockNo] = m_byRSWork[j]; |
fenoth | 0:9efeb5787ae9 | 1922 | } |
fenoth | 0:9efeb5787ae9 | 1923 | |
fenoth | 0:9efeb5787ae9 | 1924 | nDataCwIndex += ncDataCw1; |
fenoth | 0:9efeb5787ae9 | 1925 | ++nBlockNo; |
fenoth | 0:9efeb5787ae9 | 1926 | } |
fenoth | 0:9efeb5787ae9 | 1927 | |
fenoth | 0:9efeb5787ae9 | 1928 | for (i = 0; i < ncBlock2; ++i) |
fenoth | 0:9efeb5787ae9 | 1929 | { |
fenoth | 0:9efeb5787ae9 | 1930 | ZeroMemory(m_byRSWork, sizeof(m_byRSWork)); |
fenoth | 0:9efeb5787ae9 | 1931 | |
fenoth | 0:9efeb5787ae9 | 1932 | memmove(m_byRSWork, m_byDataCodeWord + nDataCwIndex, ncDataCw2); |
fenoth | 0:9efeb5787ae9 | 1933 | |
fenoth | 0:9efeb5787ae9 | 1934 | GetRSCodeWord(m_byRSWork, ncDataCw2, ncRSCw2); |
fenoth | 0:9efeb5787ae9 | 1935 | |
fenoth | 0:9efeb5787ae9 | 1936 | |
fenoth | 0:9efeb5787ae9 | 1937 | // RS code word placement |
fenoth | 0:9efeb5787ae9 | 1938 | for (j = 0; j < ncRSCw2; ++j) |
fenoth | 0:9efeb5787ae9 | 1939 | { |
fenoth | 0:9efeb5787ae9 | 1940 | m_byAllCodeWord[ncDataCodeWord + (ncBlockSum * j) + nBlockNo] = m_byRSWork[j]; |
fenoth | 0:9efeb5787ae9 | 1941 | } |
fenoth | 0:9efeb5787ae9 | 1942 | |
fenoth | 0:9efeb5787ae9 | 1943 | nDataCwIndex += ncDataCw2; |
fenoth | 0:9efeb5787ae9 | 1944 | ++nBlockNo; |
fenoth | 0:9efeb5787ae9 | 1945 | } |
fenoth | 0:9efeb5787ae9 | 1946 | |
fenoth | 0:9efeb5787ae9 | 1947 | m_nSymbolSize = QR_m_nVersion * 4 + 17; |
fenoth | 0:9efeb5787ae9 | 1948 | |
fenoth | 0:9efeb5787ae9 | 1949 | |
fenoth | 0:9efeb5787ae9 | 1950 | // Module placement |
fenoth | 0:9efeb5787ae9 | 1951 | FormatModule(m_byModuleData, m_byAllCodeWord); |
fenoth | 0:9efeb5787ae9 | 1952 | |
fenoth | 0:9efeb5787ae9 | 1953 | |
fenoth | 0:9efeb5787ae9 | 1954 | |
fenoth | 0:9efeb5787ae9 | 1955 | for(i=0;i<m_nSymbolSize;i++){ |
fenoth | 0:9efeb5787ae9 | 1956 | for (j=0;j<m_nSymbolSize;j++){ |
fenoth | 0:9efeb5787ae9 | 1957 | if (!m_byModuleData[i][j]){ |
fenoth | 0:9efeb5787ae9 | 1958 | putBitToPos((j*m_nSymbolSize)+i+1,0,QR_m_data); |
fenoth | 0:9efeb5787ae9 | 1959 | }else |
fenoth | 0:9efeb5787ae9 | 1960 | putBitToPos((j*m_nSymbolSize)+i+1,1,QR_m_data);} |
fenoth | 0:9efeb5787ae9 | 1961 | |
fenoth | 0:9efeb5787ae9 | 1962 | } |
fenoth | 0:9efeb5787ae9 | 1963 | |
fenoth | 0:9efeb5787ae9 | 1964 | |
fenoth | 0:9efeb5787ae9 | 1965 | return m_nSymbolSize; |
fenoth | 0:9efeb5787ae9 | 1966 | |
fenoth | 0:9efeb5787ae9 | 1967 | } |
fenoth | 0:9efeb5787ae9 | 1968 | |
fenoth | 0:9efeb5787ae9 | 1969 | |
fenoth | 0:9efeb5787ae9 | 1970 |