mirror of
https://git.code.sf.net/p/zint/code
synced 2026-07-31 10:29:52 +00:00
GRIDMATRIX: fix byte latch 6 -> 7, & allowing more than one
non-digit in numeral (both caused misencodation); replace `gm_macro_matrix[]` array with calculation (marginally slower but saves ~1.4k); replace `gm_shift_set[]` use with simple compares (performance); change GM_CHINESE/etc defines to numbers so can index into new `gm_shift_set[]` array (simplifies mode switching code); GM_NUMBER -> GM_NUMERAL, modules -> macromodules_per_dim, various other renamings to hopefully more explanatory names; various other changes (mostly performance) test suite: make use of new zxing-cpp diagnostics2 branch Grid Matrix decoder manual: slight clarification of `--gs1nocheck` BWIPP: latest
This commit is contained in:
+40
-50
@@ -33,36 +33,31 @@
|
||||
#ifndef Z_GRIDMTX_H
|
||||
#define Z_GRIDMTX_H
|
||||
|
||||
/* From Table 7 - Encoding of control characters */
|
||||
static const char gm_shift_set[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* NULL -> SI */
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, /* DLE -> US */
|
||||
'!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':',
|
||||
';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
|
||||
};
|
||||
|
||||
/* Following 2 tables based on Table 11 - Recommended error correction levels */
|
||||
static const short gm_recommend_cws[13] = {
|
||||
9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021
|
||||
};
|
||||
|
||||
static const short gm_max_cws[13] = {
|
||||
11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313
|
||||
11, 40, 89, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313
|
||||
};
|
||||
|
||||
/* Maximum data codewords per ECL - ECL 1 not permitted for Version 1 */
|
||||
static const short gm_data_cws[13][5] = {
|
||||
{ 0, 15, 13, 11, 9 }, /* 1 */
|
||||
{ 45, 40, 35, 30, 25 }, /* 2 */
|
||||
{ 89, 79, 69, 59, 49 }, /* 3 */
|
||||
{ 146, 130, 114, 98, 81 }, /* 4 */
|
||||
{ 218, 194, 170, 146, 121 }, /* 5 */
|
||||
{ 305, 271, 237, 203, 169 }, /* 6 */
|
||||
{ 405, 360, 315, 270, 225 }, /* 7 */
|
||||
{ 521, 463, 405, 347, 289 }, /* 8 */
|
||||
{ 650, 578, 506, 434, 361 }, /* 9 */
|
||||
{ 794, 706, 618, 530, 441 }, /* 10 */
|
||||
{ 953, 847, 741, 635, 529 }, /* 11 */
|
||||
{ 1125, 1000, 875, 750, 625 }, /* 12 */
|
||||
{ 1313, 1167, 1021, 875, 729 }, /* 13 */
|
||||
/* 90% 80% 70% 60% 50% Total available codewords (Table 1) */
|
||||
{ 0, 15, 13, 11, 9 }, /*1 18 */
|
||||
{ 45, 40, 35, 30, 25 }, /*2 50 */
|
||||
{ 89, 79, 69, 59, 49 }, /*3 98 */
|
||||
{ 146, 130, 114, 98, 81 }, /*4 162 */
|
||||
{ 218, 194, 170, 146, 121 }, /*5 242 */
|
||||
{ 305, 271, 237, 203, 169 }, /*6 338 */
|
||||
{ 405, 360, 315, 270, 225 }, /*7 450 */
|
||||
{ 521, 463, 405, 347, 289 }, /*8 578 */
|
||||
{ 650, 578, 506, 434, 361 }, /*9 722 */
|
||||
{ 794, 706, 618, 530, 441 }, /*10 882 */
|
||||
{ 953, 847, 741, 635, 529 }, /*11 1058 */
|
||||
{ 1125, 1000, 875, 750, 625 }, /*12 1250 */
|
||||
{ 1313, 1167, 1021, 875, 729 }, /*13 1458 */
|
||||
};
|
||||
|
||||
/* Table A.1 N1 */
|
||||
@@ -98,34 +93,29 @@ static const char gm_e1b3e2[13][5][3] = {
|
||||
{ { 13, 1, 12 }, { 25, 3, 24 }, { 37, 5, 36 }, { 49, 7, 48 }, { 61, 9, 60 } } /* 13 */
|
||||
};
|
||||
|
||||
static const short gm_macro_matrix[27][27] = {
|
||||
{ 728, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650 },
|
||||
{ 727, 624, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 651 },
|
||||
{ 726, 623, 528, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 553, 652 },
|
||||
{ 725, 622, 527, 440, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 463, 554, 653 },
|
||||
{ 724, 621, 526, 439, 360, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 381, 464, 555, 654 },
|
||||
{ 723, 620, 525, 438, 359, 288, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 307, 382, 465, 556, 655 },
|
||||
{ 722, 619, 524, 437, 358, 287, 224, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 241, 308, 383, 466, 557, 656 },
|
||||
{ 721, 618, 523, 436, 357, 286, 223, 168, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 183, 242, 309, 384, 467, 558, 657 },
|
||||
{ 720, 617, 522, 435, 356, 285, 222, 167, 120, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 133, 184, 243, 310, 385, 468, 559, 658 },
|
||||
{ 719, 616, 521, 434, 355, 284, 221, 166, 119, 80, 49, 50, 51, 52, 53, 54, 55, 56, 91, 134, 185, 244, 311, 386, 469, 560, 659 },
|
||||
{ 718, 615, 520, 433, 354, 283, 220, 165, 118, 79, 48, 25, 26, 27, 28, 29, 30, 57, 92, 135, 186, 245, 312, 387, 470, 561, 660 },
|
||||
{ 717, 614, 519, 432, 353, 282, 219, 164, 117, 78, 47, 24, 9, 10, 11, 12, 31, 58, 93, 136, 187, 246, 313, 388, 471, 562, 661 },
|
||||
{ 716, 613, 518, 431, 352, 281, 218, 163, 116, 77, 46, 23, 8, 1, 2, 13, 32, 59, 94, 137, 188, 247, 314, 389, 472, 563, 662 },
|
||||
{ 715, 612, 517, 430, 351, 280, 217, 162, 115, 76, 45, 22, 7, 0, 3, 14, 33, 60, 95, 138, 189, 248, 315, 390, 473, 564, 663 },
|
||||
{ 714, 611, 516, 429, 350, 279, 216, 161, 114, 75, 44, 21, 6, 5, 4, 15, 34, 61, 96, 139, 190, 249, 316, 391, 474, 565, 664 },
|
||||
{ 713, 610, 515, 428, 349, 278, 215, 160, 113, 74, 43, 20, 19, 18, 17, 16, 35, 62, 97, 140, 191, 250, 317, 392, 475, 566, 665 },
|
||||
{ 712, 609, 514, 427, 348, 277, 214, 159, 112, 73, 42, 41, 40, 39, 38, 37, 36, 63, 98, 141, 192, 251, 318, 393, 476, 567, 666 },
|
||||
{ 711, 608, 513, 426, 347, 276, 213, 158, 111, 72, 71, 70, 69, 68, 67, 66, 65, 64, 99, 142, 193, 252, 319, 394, 477, 568, 667 },
|
||||
{ 710, 607, 512, 425, 346, 275, 212, 157, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 143, 194, 253, 320, 395, 478, 569, 668 },
|
||||
{ 709, 606, 511, 424, 345, 274, 211, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 195, 254, 321, 396, 479, 570, 669 },
|
||||
{ 708, 605, 510, 423, 344, 273, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 199, 198, 197, 196, 255, 322, 397, 480, 571, 670 },
|
||||
{ 707, 604, 509, 422, 343, 272, 271, 270, 269, 268, 267, 266, 265, 264, 263, 262, 261, 260, 259, 258, 257, 256, 323, 398, 481, 572, 671 },
|
||||
{ 706, 603, 508, 421, 342, 341, 340, 339, 338, 337, 336, 335, 334, 333, 332, 331, 330, 329, 328, 327, 326, 325, 324, 399, 482, 573, 672 },
|
||||
{ 705, 602, 507, 420, 419, 418, 417, 416, 415, 414, 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, 402, 401, 400, 483, 574, 673 },
|
||||
{ 704, 601, 506, 505, 504, 503, 502, 501, 500, 499, 498, 497, 496, 495, 494, 493, 492, 491, 490, 489, 488, 487, 486, 485, 484, 575, 674 },
|
||||
{ 703, 600, 599, 598, 597, 596, 595, 594, 593, 592, 591, 590, 589, 588, 587, 586, 585, 584, 583, 582, 581, 580, 579, 578, 577, 576, 675 },
|
||||
{ 702, 701, 700, 699, 698, 697, 696, 695, 694, 693, 692, 691, 690, 689, 688, 687, 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, 676 }
|
||||
/* Codewords to switch from `row` mode to `col` mode (Table 9 – Type conversion codes) */
|
||||
static const short gm_mode_switch[8][6] = {
|
||||
/* CHN NUM LWR UPR MXD BYT */
|
||||
{ 1, 2, 3, 4, 5, 7 }, /* 0 */
|
||||
{ 0, 8161, 8162, 8163, 8164, 8165 }, /* GM_CHINESE */
|
||||
{ 1019, 0, 1020, 1021, 1022, 1023 }, /* GM_NUMERAL */
|
||||
{ 28, 29, 0, 30, 124, 126 }, /* GM_LOWER */
|
||||
{ 28, 29, 30, 0, 124, 126 }, /* GM_UPPER */
|
||||
{ 1009, 1010, 1011, 1012, 0, 1015 }, /* GM_MIXED */
|
||||
{ 1, 2, 3, 4, 5, 0 }, /* GM_BYTE */
|
||||
{ 8160, 1018, 27, 27, 1008, 0 }, /* GM_EOD (end of data) */
|
||||
};
|
||||
|
||||
/* Bit-lengths of above */
|
||||
static const char gm_mode_len[8][6] = {
|
||||
{ 4, 4, 4, 4, 4, 4 }, /* 0 */
|
||||
{ 0, 13, 13, 13, 13, 13 }, /* GM_CHINESE */
|
||||
{ 10, 0, 10, 10, 10, 10 }, /* GM_NUMERAL */
|
||||
{ 5, 5, 0, 5, 7, 7 }, /* GM_LOWER */
|
||||
{ 5, 5, 5, 0, 7, 7 }, /* GM_UPPER */
|
||||
{ 10, 10, 10, 10, 0, 10 }, /* GM_MIXED */
|
||||
{ 4, 4, 4, 4, 4, 0 }, /* GM_BYTE */
|
||||
{ 13, 10, 5, 5, 10, 4 }, /* GM_EOD (end of data) */
|
||||
};
|
||||
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
Reference in New Issue
Block a user