mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-27 21:44:13 -04:00
HANXIN/QRCODE: fix incorrect numeric costings (out-by-1) in
`qr_in_numeric()`/`hx_in_numeric()` (restrict to 3, not 4), ticket #300 (#16), props Andre Maute manual: "Maxicode" -> "MaxiCode"; add max capacities for matrix barcodes
This commit is contained in:
parent
4a340ab614
commit
0a6280dd80
9 changed files with 380 additions and 359 deletions
|
@ -308,7 +308,7 @@ static int hx_in_numeric(const unsigned int ddata[], const int length, const int
|
|||
}
|
||||
|
||||
/* Attempt to calculate the average 'cost' of using numeric mode in number of bits (times HX_MULT) */
|
||||
for (i = in_posn; i < length && i < in_posn + 4 && z_isdigit(ddata[i]); i++);
|
||||
for (i = in_posn; i < length && i < in_posn + 3 && z_isdigit(ddata[i]); i++);
|
||||
|
||||
digit_cnt = i - in_posn;
|
||||
|
||||
|
@ -548,7 +548,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
bp = bin_append_posn(1, 4, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
fputs("Numeric\n", stdout);
|
||||
printf("Numeric (N%d): ", block_length);
|
||||
}
|
||||
|
||||
count = 0; /* Suppress gcc -Wmaybe-uninitialized */
|
||||
|
@ -574,7 +574,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
bp = bin_append_posn(encoding_value, 10, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
printf("0x%3x (%d)", encoding_value, encoding_value);
|
||||
printf(" 0x%3x(%d)", encoding_value, encoding_value);
|
||||
}
|
||||
|
||||
i += count;
|
||||
|
@ -604,7 +604,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
bp = bin_append_posn(2, 4, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
fputs("Text\n", stdout);
|
||||
printf("Text (T%d):", block_length);
|
||||
}
|
||||
|
||||
submode = 1;
|
||||
|
@ -618,7 +618,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
bp = bin_append_posn(62, 6, binary, bp);
|
||||
submode = hx_getsubmode(ddata[i + position]);
|
||||
if (debug_print) {
|
||||
fputs("SWITCH ", stdout);
|
||||
fputs(" SWITCH", stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -631,7 +631,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
bp = bin_append_posn(encoding_value, 6, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
printf("%.2x [ASC %.2x] ", encoding_value, ddata[i + position]);
|
||||
printf(" %.2x[ASC %.2x]", encoding_value, ddata[i + position]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
bp = bin_append_posn(block_length + double_byte, 13, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
printf("Binary Mode (%d):", block_length + double_byte);
|
||||
printf("Binary Mode (B%d):", block_length + double_byte);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
@ -681,7 +681,8 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
}
|
||||
|
||||
if (debug_print) {
|
||||
printf("Region One%s\n", position == 0 || mode[position - 1] != '2' ? "" : " (NO indicator)" );
|
||||
printf("Region One%s H(1)%d:",
|
||||
position == 0 || mode[position - 1] != '2' ? "" : " (NO indicator)", block_length);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
@ -706,7 +707,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
}
|
||||
|
||||
if (debug_print) {
|
||||
printf("%.3x [GB %.4x] ", glyph, ddata[i + position]);
|
||||
printf(" %.3x[GB %.4x]", glyph, ddata[i + position]);
|
||||
}
|
||||
|
||||
bp = bin_append_posn(glyph, 12, binary, bp);
|
||||
|
@ -718,7 +719,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
? 4095 : 4094, 12, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
printf("(TERM %x)\n", position + block_length == length || mode[position + block_length] != '2'
|
||||
printf(" (TERM %x)\n", position + block_length == length || mode[position + block_length] != '2'
|
||||
? 4095 : 4094);
|
||||
}
|
||||
|
||||
|
@ -731,7 +732,8 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
}
|
||||
|
||||
if (debug_print) {
|
||||
printf("Region Two%s\n", position == 0 || mode[position - 1] != '1' ? "" : " (NO indicator)" );
|
||||
printf("Region Two%s H(2)%d:",
|
||||
position == 0 || mode[position - 1] != '1' ? "" : " (NO indicator)", block_length);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
@ -743,7 +745,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
glyph = (0x5e * (first_byte - 0xd8)) + (second_byte - 0xa1);
|
||||
|
||||
if (debug_print) {
|
||||
printf("%.3x [GB %.4x] ", glyph, ddata[i + position]);
|
||||
printf(" %.3x[GB %.4x]", glyph, ddata[i + position]);
|
||||
}
|
||||
|
||||
bp = bin_append_posn(glyph, 12, binary, bp);
|
||||
|
@ -755,7 +757,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
? 4095 : 4094, 12, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
printf("(TERM %x)\n", position + block_length == length || mode[position + block_length] != '1'
|
||||
printf(" (TERM %x)\n", position + block_length == length || mode[position + block_length] != '1'
|
||||
? 4095 : 4094);
|
||||
}
|
||||
|
||||
|
@ -766,7 +768,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
bp = bin_append_posn(6, 4, binary, bp);
|
||||
|
||||
if (debug_print) {
|
||||
fputs("Double byte\n", stdout);
|
||||
printf("Double byte (H(d)%d):", block_length);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
@ -801,7 +803,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
case 'f':
|
||||
/* Four-byte encoding */
|
||||
if (debug_print) {
|
||||
fputs("Four byte\n", stdout);
|
||||
printf("Four byte (H(f)%d):", block_length);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
@ -820,7 +822,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
|
|||
(0x0a * (third_byte - 0x81)) + (fourth_byte - 0x30);
|
||||
|
||||
if (debug_print) {
|
||||
printf("%d ", glyph);
|
||||
printf(" %d", glyph);
|
||||
}
|
||||
|
||||
bp = bin_append_posn(glyph, 21, binary, bp);
|
||||
|
@ -1554,7 +1556,7 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in
|
|||
codewords++;
|
||||
}
|
||||
if (debug_print) {
|
||||
printf("Num. of codewords: %d\n", codewords);
|
||||
printf("Num. of codewords: %d (%d padbits)\n", codewords, bin_len & 0x07);
|
||||
}
|
||||
|
||||
version = 85;
|
||||
|
|
18
backend/qr.c
18
backend/qr.c
|
@ -77,7 +77,7 @@ static int qr_in_numeric(const unsigned int ddata[], const int length, const int
|
|||
}
|
||||
|
||||
/* Attempt to calculate the average 'cost' of using numeric mode in number of bits (times QR_MULT) */
|
||||
for (i = in_posn; i < length && i < in_posn + 4 && z_isdigit(ddata[i]); i++);
|
||||
for (i = in_posn; i < length && i < in_posn + 3 && z_isdigit(ddata[i]); i++);
|
||||
|
||||
digit_cnt = i - in_posn;
|
||||
|
||||
|
@ -302,11 +302,15 @@ static void qr_define_mode(char mode[], const unsigned int ddata[], const int le
|
|||
}
|
||||
|
||||
#ifdef QR_DEBUG_DEFINE_MODE
|
||||
printf(" % 4d: curr", i);
|
||||
for (j = 0; j < QR_NUM_MODES; j++) {
|
||||
printf(" %c(%c)=%d", qr_mode_types[j], char_modes[cm_i + j], cur_costs[j]);
|
||||
{
|
||||
int min_j = 0;
|
||||
printf(" % 4d: curr", i);
|
||||
for (j = 0; j < QR_NUM_MODES; j++) {
|
||||
printf(" %c(%c)=%d", qr_mode_types[j], char_modes[cm_i + j], cur_costs[j]);
|
||||
if (cur_costs[j] < cur_costs[min_j]) min_j = j;
|
||||
}
|
||||
printf(" min %c(%c)=%d\n", qr_mode_types[min_j], char_modes[cm_i + min_j], cur_costs[min_j]);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
memcpy(prev_costs, cur_costs, QR_NUM_MODES * sizeof(unsigned int));
|
||||
}
|
||||
|
@ -762,7 +766,7 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i
|
|||
}
|
||||
|
||||
if (debug_print) {
|
||||
fputs("Resulting codewords:\n\t", stdout);
|
||||
printf("Resulting codewords (%d):\n\t", target_codewords);
|
||||
for (i = 0; i < target_codewords; i++) {
|
||||
printf("0x%02X ", datastream[i]);
|
||||
}
|
||||
|
@ -867,7 +871,7 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
|
|||
}
|
||||
|
||||
if (debug_print) {
|
||||
fputs("\nData Stream: \n", stdout);
|
||||
printf("\nData Stream (%d): \n", data_cw + ecc_cw);
|
||||
for (j = 0; j < (data_cw + ecc_cw); j++) {
|
||||
printf("%2X ", fullstream[j]);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8884,6 +8884,7 @@ static void test_fuzz(const testCtx *const p_ctx) {
|
|||
struct item {
|
||||
int symbology;
|
||||
int input_mode;
|
||||
int eci;
|
||||
int option_1;
|
||||
int option_2;
|
||||
int option_3;
|
||||
|
@ -8895,8 +8896,9 @@ static void test_fuzz(const testCtx *const p_ctx) {
|
|||
};
|
||||
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
||||
struct item data[] = {
|
||||
/* 0*/ { BARCODE_QRCODE, GS1_MODE | GS1NOCHECK_MODE, -1, -1, -1, "[]CCCCCLLLLLLLLLLLLLLLLLLLLLCCCCCCCC@CCCCCCCCCCCCCCCCCCCCCCC%%C%C%%%%%%%%%%%%%%LLLCCCCCCCC%%C%C%%%%%%%%%%%%%%LLLLLLLLLLLLLLLLLLL000000032861710*383556LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL155816162LLLLLCC%%C%C%%%%%%%%%%%%%%LLLCCCCCCCC%%C%C%%%%%%%%%%%%%%LLLLLLLLLL)!1661055777[723]T5", -1, 0, 1, "" }, /* #300 (#14), Andre Maute */
|
||||
/* 1*/ { BARCODE_QRCODE, DATA_MODE, -1, -1, ZINT_FULL_MULTIBYTE, "\215\215\350\2156750\215\215\215\215\215\215\000\000\000\025\215\215\215\215\215\232\215\232\232\001\361\215\215\215\215\215\221\215\215\215\215JJJJJJNJJJJJJ\215\215\215\2159999\215\215\215\215\215\215\215\215\215\235\215\215\215\215\215\035\004\000\000@\000\000\000\000\375\000\000\000\000\000\000\000\000\000\000\000\000\000\241\000\000\000\000\000\000\000\241\247^^^\377\377\377\000 \000\000\000\000\000\000\377\377u\000\000\000\000\000\000\000^\377\377^^\000:\000\177\377\377\377?\377\377\377\377\377\377\377\377\377\377\377\377\377\377\241\241\232\232\232\232\232\232\232\232\000\377\377\377\242\003\000\000\377\377/\000AA\000\000\000\000\000\000\000\000\000\000\000\000T\000\000\000\000\000\000\000\000WWW\237\250WWWWWW\377\377R30 \377\377\000\000\000", 231, 0, 1, "" }, /* #300 (#15), Andre Maute */
|
||||
/* 0*/ { BARCODE_QRCODE, GS1_MODE | GS1NOCHECK_MODE, -1, -1, -1, -1, "[]CCCCCLLLLLLLLLLLLLLLLLLLLLCCCCCCCC@CCCCCCCCCCCCCCCCCCCCCCC%%C%C%%%%%%%%%%%%%%LLLCCCCCCCC%%C%C%%%%%%%%%%%%%%LLLLLLLLLLLLLLLLLLL000000032861710*383556LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL155816162LLLLLCC%%C%C%%%%%%%%%%%%%%LLLCCCCCCCC%%C%C%%%%%%%%%%%%%%LLLLLLLLLL)!1661055777[723]T5", -1, 0, 1, "" }, /* #300 (#14), Andre Maute */
|
||||
/* 1*/ { BARCODE_QRCODE, DATA_MODE, -1, -1, -1, ZINT_FULL_MULTIBYTE, "\215\215\350\2156750\215\215\215\215\215\215\000\000\000\025\215\215\215\215\215\232\215\232\232\001\361\215\215\215\215\215\221\215\215\215\215JJJJJJNJJJJJJ\215\215\215\2159999\215\215\215\215\215\215\215\215\215\235\215\215\215\215\215\035\004\000\000@\000\000\000\000\375\000\000\000\000\000\000\000\000\000\000\000\000\000\241\000\000\000\000\000\000\000\241\247^^^\377\377\377\000 \000\000\000\000\000\000\377\377u\000\000\000\000\000\000\000^\377\377^^\000:\000\177\377\377\377?\377\377\377\377\377\377\377\377\377\377\377\377\377\377\241\241\232\232\232\232\232\232\232\232\000\377\377\377\242\003\000\000\377\377/\000AA\000\000\000\000\000\000\000\000\000\000\000\000T\000\000\000\000\000\000\000\000WWW\237\250WWWWWW\377\377R30 \377\377\000\000\000", 231, 0, 1, "" }, /* #300 (#15), Andre Maute */
|
||||
/* 2*/ { BARCODE_QRCODE, DATA_MODE, 35, -1, -1, ZINT_FULL_MULTIBYTE, "\215\215\215\215\215\350\215\215999\215\21500000\215\215\215\215\215\215\377O\000\000\036\000\000\000\000\357\376\026\377\377\377\377\241\241\232\232\232\232\232\232\235\032@\374:JGB \000\000@d\000\000\000\241\241\000\000\027\002\241\241\000\000\014\000\000\000\000\357\327\004\000\000\000\000\000\000\000\375\000\000\000\000\000\000\000\000\000\000\000\000\0000253]9R4R44,44,4404[255\350999\215\21599999\215\215\215\2150000\215\215\215\215\215\215\215\215\215]9444442<4444,4044%44vA\000\000\002\000'\000\000\215\377@\215\215\350\215\215\215\215\215\215\215\307\306\306n\215\215\000\000\001\000\000\203\000\000\000\000\000\000@\215\215\215[\2154315@]R0", 229, 0, 1, "" }, /* #300 (#16), Andre Maute */
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
int i, length, ret;
|
||||
|
@ -8911,7 +8913,7 @@ static void test_fuzz(const testCtx *const p_ctx) {
|
|||
symbol = ZBarcode_Create();
|
||||
assert_nonnull(symbol, "Symbol not created\n");
|
||||
|
||||
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug);
|
||||
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, data[i].option_1, data[i].option_2, data[i].option_3, -1 /*output_options*/, data[i].data, data[i].length, debug);
|
||||
|
||||
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
|
||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
|
||||
|
|
|
@ -32,9 +32,7 @@ run_zxingcpp_test "test_dmatrix" "encode_segs"
|
|||
run_zxingcpp_test "test_dotcode" "input"
|
||||
run_zxingcpp_test "test_dotcode" "encode"
|
||||
run_zxingcpp_test "test_dotcode" "encode_segs"
|
||||
run_zxingcpp_test "test_hanxin" "input"
|
||||
run_zxingcpp_test "test_hanxin" "encode"
|
||||
run_zxingcpp_test "test_hanxin" "encode_segs"
|
||||
run_zxingcpp_test "test_hanxin"
|
||||
run_zxingcpp_test "test_mailmark" "2d_encode"
|
||||
run_zxingcpp_test "test_maxicode" "input"
|
||||
run_zxingcpp_test "test_maxicode" "encode"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue