diff --git a/backend/code1.c b/backend/code1.c index f590a4b1..c5dcd043 100644 --- a/backend/code1.c +++ b/backend/code1.c @@ -152,6 +152,7 @@ static int c1_look_ahead_test(const unsigned char source[], const int sourcelen, const int current_mode, const int gs1) { float ascii_count, c40_count, text_count, edi_count, byte_count; int ascii_rnded, c40_rnded, text_rnded, edi_rnded, byte_rnded; + float cnt_1; int sp; /* Step J1 */ @@ -181,12 +182,14 @@ static int c1_look_ahead_test(const unsigned char source[], const int sourcelen, } for (sp = position; sp < sourcelen; sp++) { + unsigned char c = source[sp]; + int is_extended = c & 0x80; /* Step L */ - if ((source[sp] >= '0') && (source[sp] <= '9')) { + if ((c >= '0') && (c <= '9')) { ascii_count += 0.5f; /* Step L1 */ } else { - if (source[sp] > 127) { + if (is_extended) { ascii_count = ceilf(ascii_count) + 2.0f; /* Step L2 */ } else { ascii_count = ceilf(ascii_count) + 1.0f; /* Step L3 */ @@ -194,34 +197,34 @@ static int c1_look_ahead_test(const unsigned char source[], const int sourcelen, } /* Step M */ - if (isc40(source[sp])) { + if (isc40(c)) { c40_count += (2.0f / 3.0f); /* Step M1 */ - } else if (source[sp] > 127) { + } else if (is_extended) { c40_count += (8.0f / 3.0f); /* Step M2 */ } else { c40_count += (4.0f / 3.0f); /* Step M3 */ } /* Step N */ - if (istext(source[sp])) { + if (istext(c)) { text_count += (2.0f / 3.0f); /* Step N1 */ - } else if (source[sp] > 127) { + } else if (is_extended) { text_count += (8.0f / 3.0f); /* Step N2 */ } else { text_count += (4.0f / 3.0f); /* Step N3 */ } /* Step O */ - if (isedi(source[sp])) { + if (isedi(c)) { edi_count += (2.0f / 3.0f); /* Step O1 */ - } else if (source[sp] > 127) { + } else if (is_extended) { edi_count += (13.0f / 3.0f); /* Step O2 */ } else { edi_count += (10.0f / 3.0f); /* Step O3 */ } /* Step P */ - if (gs1 && (source[sp] == '[')) { + if (gs1 && (c == '[')) { byte_count += 3.0f; /* Step P1 */ } else { byte_count += 1.0f; /* Step P2 */ @@ -232,27 +235,26 @@ static int c1_look_ahead_test(const unsigned char source[], const int sourcelen, BWIPP also uses 4 (cf very similar Data Matrix ISO/IEC 16022:2006 Annex P algorithm) */ if (sp >= position + 3) { /* Step Q */ - float cnt; ascii_rnded = (int) ceilf(stripf(ascii_count)); c40_rnded = (int) ceilf(stripf(c40_count)); text_rnded = (int) ceilf(stripf(text_count)); edi_rnded = (int) ceilf(stripf(edi_count)); byte_rnded = (int) ceilf(stripf(byte_count)); - cnt = byte_count + 1.0f; - if (cnt <= ascii_rnded && cnt <= c40_rnded && cnt <= text_rnded && cnt <= edi_rnded) { + cnt_1 = byte_count + 1.0f; + if (cnt_1 <= ascii_rnded && cnt_1 <= c40_rnded && cnt_1 <= text_rnded && cnt_1 <= edi_rnded) { return C1_BYTE; /* Step Q1 */ } - cnt = ascii_count + 1.0f; - if (cnt <= c40_rnded && cnt <= text_rnded && cnt <= edi_rnded && cnt <= byte_rnded) { + cnt_1 = ascii_count + 1.0f; + if (cnt_1 <= c40_rnded && cnt_1 <= text_rnded && cnt_1 <= edi_rnded && cnt_1 <= byte_rnded) { return C1_ASCII; /* Step Q2 */ } - cnt = text_rnded + 1.0f; - if (cnt <= ascii_rnded && cnt <= c40_rnded && cnt <= edi_rnded && cnt <= byte_rnded) { + cnt_1 = text_rnded + 1.0f; + if (cnt_1 <= ascii_rnded && cnt_1 <= c40_rnded && cnt_1 <= edi_rnded && cnt_1 <= byte_rnded) { return C1_TEXT; /* Step Q3 */ } - cnt = c40_rnded + 1.0f; - if (cnt <= ascii_rnded && cnt <= text_rnded) { + cnt_1 = c40_rnded + 1.0f; + if (cnt_1 <= ascii_rnded && cnt_1 <= text_rnded) { /* Step Q4 */ if (c40_rnded < edi_rnded) { return C1_C40; /* Step Q4a */ @@ -265,8 +267,8 @@ static int c1_look_ahead_test(const unsigned char source[], const int sourcelen, return C1_C40; /* Step Q4bii */ } } - cnt = edi_rnded + 1.0f; - if (cnt <= ascii_rnded && cnt <= c40_rnded && cnt <= text_rnded && cnt <= byte_rnded) { + cnt_1 = edi_rnded + 1.0f; + if (cnt_1 <= ascii_rnded && cnt_1 <= c40_rnded && cnt_1 <= text_rnded && cnt_1 <= byte_rnded) { return C1_EDI; /* Step Q5 */ } } @@ -433,7 +435,7 @@ static int c40text_cnt(const int current_mode, const int gs1, unsigned char inpu return 2; } cnt = 1; - if (input > 127) { + if (input & 0x80) { cnt += 2; input = input - 128; } @@ -577,7 +579,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigne if (next_mode == C1_ASCII) { if (debug_print) printf("ASCII "); - if (source[sp] > 127) { + if (source[sp] & 0x80) { /* Step B7 */ target[tp++] = 235; /* FNC4 (Upper Shift) */ target[tp++] = (source[sp] - 128) + 1; @@ -627,7 +629,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigne } if (debug_print) printf(current_mode == C1_C40 ? "C40 " : "TEXT "); - if (source[sp] > 127) { + if (source[sp] & 0x80) { cte_buffer[cte_p++] = 1; /* Shift 2 */ cte_buffer[cte_p++] = 30; /* FNC4 (Upper Shift) */ if (ct_shift[source[sp] - 128]) { @@ -824,7 +826,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigne if (istwodigits(source, length, sp)) { target[tp++] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; sp++; - } else if (source[sp] > 127) { + } else if (source[sp] & 0x80) { target[tp++] = 235; /* FNC4 (Upper Shift) */ target[tp++] = (source[sp] - 128) + 1; } else if ((gs1) && (source[sp] == '[')) { diff --git a/backend/dmatrix.c b/backend/dmatrix.c index c2f5880f..42d9cbe0 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -306,11 +306,14 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, } for (sp = position; sp < sourcelen; sp++) { + unsigned char c = inputData[sp]; + int is_extended = c & 0x80; + /* ascii ... step (l) */ - if ((inputData[sp] >= '0') && (inputData[sp] <= '9')) { + if ((c >= '0') && (c <= '9')) { ascii_count += 0.5F; // (l)(1) } else { - if (inputData[sp] > 127) { + if (is_extended) { ascii_count = ceilf(ascii_count) + 2.0F; // (l)(2) } else { ascii_count = ceilf(ascii_count) + 1.0F; // (l)(3) @@ -318,10 +321,10 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, } /* c40 ... step (m) */ - if (isc40(inputData[sp])) { + if (isc40(c)) { c40_count += (2.0F / 3.0F); // (m)(1) } else { - if (inputData[sp] > 127) { + if (is_extended) { c40_count += (8.0F / 3.0F); // (m)(2) } else { c40_count += (4.0F / 3.0F); // (m)(3) @@ -329,10 +332,10 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, } /* text ... step (n) */ - if (istext(inputData[sp])) { + if (istext(c)) { text_count += (2.0F / 3.0F); // (n)(1) } else { - if (inputData[sp] > 127) { + if (is_extended) { text_count += (8.0F / 3.0F); // (n)(2) } else { text_count += (4.0F / 3.0F); // (n)(3) @@ -340,10 +343,10 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, } /* x12 ... step (o) */ - if (isX12(inputData[sp])) { + if (isX12(c)) { x12_count += (2.0F / 3.0F); // (o)(1) } else { - if (inputData[sp] > 127) { + if (is_extended) { x12_count += (13.0F / 3.0F); // (o)(2) } else { x12_count += (10.0F / 3.0F); // (o)(3) @@ -351,10 +354,10 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, } /* edifact ... step (p) */ - if ((inputData[sp] >= ' ') && (inputData[sp] <= '^')) { + if ((c >= ' ') && (c <= '^')) { edf_count += (3.0F / 4.0F); // (p)(1) } else { - if (inputData[sp] > 127) { + if (is_extended) { edf_count += 17.0F / 4.0f; // (p)(2) } else { edf_count += 13.0F / 4.0f; // (p)(3) @@ -362,7 +365,7 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, } /* base 256 ... step (q) */ - if ((gs1 == 1) && (inputData[sp] == '[')) { + if ((gs1 == 1) && (c == '[')) { /* FNC1 separator */ b256_count += 4.0F; // (q)(1) } else { @@ -381,7 +384,7 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, c40_count = stripf(c40_count); if (debug) { printf("\n(%d, %d, %d): ascii_count %.8g, b256_count %.8g, edf_count %.8g, text_count %.8g" - ", x12_count %.8g, c40_count %.8g", + ", x12_count %.8g, c40_count %.8g ", current_mode, position, sp, ascii_count, b256_count, edf_count, text_count, x12_count, c40_count); } @@ -436,7 +439,7 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, c40_rnded = (int) ceilf(stripf(c40_count)); if (debug) { printf("\nEOD(%d, %d): ascii_rnded %d, b256_rnded %d, edf_rnded %d, text_rnded %d, x12_rnded %d (%g)" - ", c40_rnded %d (%g)\n", + ", c40_rnded %d (%g) ", current_mode, position, ascii_rnded, b256_rnded, edf_rnded, text_rnded, x12_rnded, x12_count, c40_rnded, c40_count); } @@ -569,7 +572,7 @@ static int c40text_cnt(const int current_mode, const int gs1, unsigned char inpu return 2; } cnt = 1; - if (input > 127) { + if (input & 0x80) { cnt += 2; input = input - 128; } @@ -735,7 +738,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], break; } } else { - if (source[sp] > 127) { + if (source[sp] & 0x80) { target[tp] = 235; /* FNC4 */ tp++; target[tp] = (source[sp] - 128) + 1; @@ -785,7 +788,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], ct_value = text_value; } - if (source[sp] > 127) { + if (source[sp] & 0x80) { process_buffer[process_p++] = 1; process_buffer[process_p++] = 30; /* Upper Shift */ shift_set = ct_shift[source[sp] - 128]; @@ -955,7 +958,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], target[tp++] = (unsigned char) ((10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130); if (debug) printf("N%02d ", target[tp - 1] - 130); sp++; - } else if (source[sp] > 127) { + } else if (source[sp] & 0x80) { target[tp++] = 235; /* FNC4 */ target[tp++] = (source[sp] - 128) + 1; if (debug) printf("FN4 A%02X ", target[tp - 1] - 1); diff --git a/backend/rss.c b/backend/rss.c index 8ea2cb4a..b9c1686f 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -754,6 +754,9 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i checksum = 0; /* Calculate the checksum */ for (i = 0; i < 14; i++) { +#if _MSC_VER == 1900 && defined(_WIN64) /* MSVC 2015 x64 */ + checksum %= 89; /* Hack to get around optimizer bug */ +#endif checksum += checksum_weight_ltd[i] * left_widths[i]; checksum += checksum_weight_ltd[i + 14] * right_widths[i]; }