From 7da2041cfda85b15f00498406a72496709cb9061 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Tue, 14 Sep 2010 11:36:00 +0100 Subject: [PATCH] More code cleanup Patch 7 of 7 from "Ismael Luceno" --- backend/2of5.c | 14 ++-- backend/code128.c | 18 ++-- backend/code16k.c | 6 +- backend/common.c | 35 ++------ backend/composite.c | 2 +- backend/gridmtx.c | 4 +- backend/gs1.c | 106 ++++++++++++++--------- backend/maxicode.c | 4 +- backend/medical.c | 2 +- backend/pdf417.c | 2 +- backend/plessey.c | 16 ++-- backend/png.c | 8 +- backend/ps.c | 8 +- backend/qr.c | 65 ++++++++------- backend/render.c | 6 +- backend/rss.c | 199 +++++++++++--------------------------------- backend/svg.c | 2 +- backend/telepen.c | 2 +- backend/upcean.c | 12 +-- 19 files changed, 198 insertions(+), 313 deletions(-) diff --git a/backend/2of5.c b/backend/2of5.c index 38700cde..03b78e1b 100644 --- a/backend/2of5.c +++ b/backend/2of5.c @@ -194,7 +194,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], ustrcpy(temp, (unsigned char *) ""); /* Input must be an even number of characters for Interlaced 2 of 5 to work: if an odd number of characters has been entered then add a leading zero */ - if ((length % 2) != 0) + if (length & 1) { ustrcpy(temp, (unsigned char *) "0"); length++; @@ -262,12 +262,10 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length) /* Calculate the check digit - the same method used for EAN-13 */ - for (i = 12; i >= 0; i--) - { + for (i = 12; i >= 0; i--) { count += ctoi(localstr[i]); - if ((i%2) == 0) - { + if (!(i & 1)) { count += 2 * ctoi(localstr[i]); } } @@ -308,8 +306,7 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { count += 4 * ctoi(localstr[i]); - if (!((i%2) == 0)) - { + if (i & 1) { count += 5 * ctoi(localstr[i]); } } @@ -348,8 +345,7 @@ int dpident(struct zint_symbol *symbol, unsigned char source[], int length) { count += 4 * ctoi(localstr[i]); - if (!((i%2) == 0)) - { + if (i & 1) { count += 5 * ctoi(localstr[i]); } } diff --git a/backend/code128.c b/backend/code128.c index ed8043a2..ae3ad3ff 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -290,7 +290,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) dxsmooth(&indexliste); /* Resolve odd length LATCHC blocks */ - if((list[1][0] == LATCHC) && ((list[0][0] % 2) == 1)) { + if((list[1][0] == LATCHC) && (list[0][0] & 1)) { /* Rule 2 */ list[0][1]++; list[0][0]--; @@ -302,7 +302,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) } if(indexliste > 1) { for(i = 1; i < indexliste; i++) { - if((list[1][i] == LATCHC) && ((list[0][i] % 2) == 1)) { + if((list[1][i] == LATCHC) && (list[0][i] & 1)) { /* Rule 3b */ list[0][i - 1]++; list[0][i]--; @@ -688,7 +688,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 0; i < read; i++) { if(set[i] == 'C') { if(reduced[i] == '[') { - if(c_count % 2) { + if(c_count & 1) { if((i - c_count) != 0) { set[i - c_count] = 'B'; } else { @@ -700,7 +700,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) c_count++; } } else { - if(c_count % 2) { + if(c_count & 1) { if((i - c_count) != 0) { set[i - c_count] = 'B'; } else { @@ -710,7 +710,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) c_count = 0; } } - if(c_count % 2) { + if(c_count & 1) { if((i - c_count) != 0) { set[i - c_count] = 'B'; } else { @@ -941,7 +941,7 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length) { total_sum += ctoi(source[i]); - if(!((i%2) == 1)) { + if(!(i & 1)) { total_sum += 2 * ctoi(source[i]); } } @@ -979,12 +979,10 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[], int length) ustrcpy(ean128_equiv + 4 + zeroes, source); count = 0; - for (i = length - 1; i >= 0; i--) - { + for (i = length - 1; i >= 0; i--) { count += ctoi(source[i]); - if (!((i % 2) == 1)) - { + if (!(i & 1)) { count += 2 * ctoi(source[i]); } } diff --git a/backend/code16k.c b/backend/code16k.c index 8697601d..638d786a 100644 --- a/backend/code16k.c +++ b/backend/code16k.c @@ -294,7 +294,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 0; i < read; i++) { if(set[i] == 'C') { if(source[i] == '[') { - if(c_count % 2) { + if(c_count & 1) { if((i - c_count) != 0) { set[i - c_count] = 'B'; } else { @@ -306,7 +306,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) c_count++; } } else { - if(c_count % 2) { + if(c_count & 1) { if((i - c_count) != 0) { set[i - c_count] = 'B'; } else { @@ -316,7 +316,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) c_count = 0; } } - if(c_count % 2) { + if(c_count & 1) { if((i - c_count) != 0) { set[i - c_count] = 'B'; } else { diff --git a/backend/common.c b/backend/common.c index 34b8c0d7..17e668ad 100644 --- a/backend/common.c +++ b/backend/common.c @@ -201,11 +201,8 @@ void expand(struct zint_symbol *symbol, char data[]) if(latch == '1') { set_module(symbol, symbol->rows, writer); } writer++; } - if(latch == '1') { - latch = '0'; - } else { - latch = '1'; - } + + latch = (latch == '1' ? '0' : '1'); } if(symbol->symbology != BARCODE_PHARMA) { @@ -325,7 +322,7 @@ int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) { - int bpos, jpos, error_number, done; + int bpos, jpos, error_number; int next; bpos = 0; @@ -334,51 +331,33 @@ int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], next = 0; do { - done = 0; - if(source[bpos] <= 0x7f) { /* 1 byte mode (7-bit ASCII) */ vals[jpos] = source[bpos]; next = bpos + 1; jpos++; - done = 1; - } - - if(done == 0) { + } else { if((source[bpos] >= 0x80) && (source[bpos] <= 0xbf)) { strcpy(symbol->errtxt, "Corrupt Unicode data"); return ERROR_INVALID_DATA; } - } - - if(done == 0) { if((source[bpos] >= 0xc0) && (source[bpos] <= 0xc1)) { strcpy(symbol->errtxt, "Overlong encoding not supported"); return ERROR_INVALID_DATA; } - } - - if(done == 0) { + if((source[bpos] >= 0xc2) && (source[bpos] <= 0xdf)) { /* 2 byte mode */ vals[jpos] = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f); next = bpos + 2; jpos++; - done = 1; - } - } - - if(done == 0) { + } else if((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) { /* 3 byte mode */ vals[jpos] = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f); next = bpos + 3; jpos ++; - done = 1; - } - } - - if(done == 0) { + } else if(source[bpos] >= 0xf0) { strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported"); return ERROR_INVALID_DATA; diff --git a/backend/composite.c b/backend/composite.c index 82f3360e..424aaa3a 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -71,7 +71,7 @@ int _min(int first, int second) { /* gets bit in bitString at bitPos */ int getBit(UINT *bitStr, int bitPos) { - return(((bitStr[bitPos/16] & (0x8000>>(bitPos%16))) == 0) ? 0 : 1); + return !!(bitStr[bitPos >> 4] & (0x8000 >> (bitPos & 15))); } /* initialize pwr928 encoding table */ diff --git a/backend/gridmtx.c b/backend/gridmtx.c index f05cd109..2a21606a 100644 --- a/backend/gridmtx.c +++ b/backend/gridmtx.c @@ -758,7 +758,7 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor /* Add padding codewords */ data[data_posn] = 0x00; for(i = (data_posn + 1); i < data_cw; i++) { - if(i % 2) { + if(i & 1) { data[i] = 0x7e; toggle = 1; } else { @@ -1055,7 +1055,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) /* Add macromodule frames */ for(x = 0; x < modules; x++) { - dark = 1 - (x % 2); + dark = 1 - (x & 1); for(y = 0; y < modules; y++) { if(dark == 1) { for(i = 0; i < 5; i++) { diff --git a/backend/gs1.c b/backend/gs1.c index e567b5f1..e8b6240e 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -170,48 +170,68 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne for(i = 0; i < ai_count; i++) { switch (ai_value[i]) { case 0: if(data_length[i] != 18) { error_latch = 1; } break; - case 1: if(data_length[i] != 14) { error_latch = 1; } break; - case 2: if(data_length[i] != 14) { error_latch = 1; } break; + case 1: + case 2: case 3: if(data_length[i] != 14) { error_latch = 1; } break; case 4: if(data_length[i] != 16) { error_latch = 1; } break; - case 11: if(data_length[i] != 6) { error_latch = 1; } break; - case 12: if(data_length[i] != 6) { error_latch = 1; } break; - case 13: if(data_length[i] != 6) { error_latch = 1; } break; - case 14: if(data_length[i] != 6) { error_latch = 1; } break; - case 15: if(data_length[i] != 6) { error_latch = 1; } break; - case 16: if(data_length[i] != 6) { error_latch = 1; } break; - case 17: if(data_length[i] != 6) { error_latch = 1; } break; - case 18: if(data_length[i] != 6) { error_latch = 1; } break; + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: case 19: if(data_length[i] != 6) { error_latch = 1; } break; case 20: if(data_length[i] != 2) { error_latch = 1; } break; - case 23: error_latch = 2; break; - case 24: error_latch = 2; break; - case 25: error_latch = 2; break; - case 39: error_latch = 2; break; - case 40: error_latch = 2; break; - case 41: error_latch = 2; break; - case 42: error_latch = 2; break; - case 70: error_latch = 2; break; - case 80: error_latch = 2; break; + case 23: + case 24: + case 25: + case 39: + case 40: + case 41: + case 42: + case 70: + case 80: case 81: error_latch = 2; break; } - if((ai_value[i] >= 100) && (ai_value[i] <= 179)) { error_latch = 2; } - if((ai_value[i] >= 1000) && (ai_value[i] <= 1799)) { error_latch = 2; } - if((ai_value[i] >= 200) && (ai_value[i] <= 229)) { error_latch = 2; } - if((ai_value[i] >= 2000) && (ai_value[i] <= 2299)) { error_latch = 2; } - if((ai_value[i] >= 300) && (ai_value[i] <= 309)) { error_latch = 2; } - if((ai_value[i] >= 3000) && (ai_value[i] <= 3099)) { error_latch = 2; } - if((ai_value[i] >= 31) && (ai_value[i] <= 36)) { error_latch = 2; } - if((ai_value[i] >= 310) && (ai_value[i] <= 369)) { error_latch = 2; } - if((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) { if(data_length[i] != 6) { error_latch = 1; } } - if((ai_value[i] >= 370) && (ai_value[i] <= 379)) { error_latch = 2; } - if((ai_value[i] >= 3700) && (ai_value[i] <= 3799)) { error_latch = 2; } - if((ai_value[i] >= 410) && (ai_value[i] <= 415)) { if(data_length[i] != 13) { error_latch = 1; } } - if((ai_value[i] >= 4100) && (ai_value[i] <= 4199)) { error_latch = 2; } - if((ai_value[i] >= 700) && (ai_value[i] <= 703)) { error_latch = 2; } - if((ai_value[i] >= 800) && (ai_value[i] <= 810)) { error_latch = 2; } - if((ai_value[i] >= 900) && (ai_value[i] <= 999)) { error_latch = 2; } - if((ai_value[i] >= 9000) && (ai_value[i] <= 9999)) { error_latch = 2; } + if( + ((ai_value[i] >= 100) && (ai_value[i] <= 179)) + || ((ai_value[i] >= 1000) && (ai_value[i] <= 1799)) + || ((ai_value[i] >= 200) && (ai_value[i] <= 229)) + || ((ai_value[i] >= 2000) && (ai_value[i] <= 2299)) + || ((ai_value[i] >= 300) && (ai_value[i] <= 309)) + || ((ai_value[i] >= 3000) && (ai_value[i] <= 3099)) + || ((ai_value[i] >= 31) && (ai_value[i] <= 36)) + || ((ai_value[i] >= 310) && (ai_value[i] <= 369)) + ) { + error_latch = 2; + } + if((ai_value[i] >= 3100) && (ai_value[i] <= 3699)) { + if(data_length[i] != 6) { + error_latch = 1; + } + } + if( + ((ai_value[i] >= 370) && (ai_value[i] <= 379)) + || ((ai_value[i] >= 3700) && (ai_value[i] <= 3799)) + ) { + error_latch = 2; + } + if((ai_value[i] >= 410) && (ai_value[i] <= 415)) { + if(data_length[i] != 13) { + error_latch = 1; + } + } + if( + ((ai_value[i] >= 4100) && (ai_value[i] <= 4199)) + || ((ai_value[i] >= 700) && (ai_value[i] <= 703)) + || ((ai_value[i] >= 800) && (ai_value[i] <= 810)) + || ((ai_value[i] >= 900) && (ai_value[i] <= 999)) + || ((ai_value[i] >= 9000) && (ai_value[i] <= 9999)) + ) { + error_latch = 2; + } if((error_latch < 4) && (error_latch > 0)) { /* error has just been detected: capture AI */ itostr(ai_string, ai_value[i]); @@ -251,11 +271,15 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne ai_latch = 0; /* The following values from "GS-1 General Specification version 8.0 issue 2, May 2008" figure 5.4.8.2.1 - 1 "Element Strings with Pre-Defined Length Using Application Identifiers" */ - if((last_ai >= 0) && (last_ai <= 4)) { ai_latch = 1; } - if((last_ai >= 11) && (last_ai <= 20)) { ai_latch = 1; } - if(last_ai == 23) { ai_latch = 1; } /* legacy support - see 5.3.8.2.2 */ - if((last_ai >= 31) && (last_ai <= 36)) { ai_latch = 1; } - if(last_ai == 41) { ai_latch = 1; } + if( + ((last_ai >= 0) && (last_ai <= 4)) + || ((last_ai >= 11) && (last_ai <= 20)) + || (last_ai == 23) /* legacy support - see 5.3.8.2.2 */ + || ((last_ai >= 31) && (last_ai <= 36)) + || (last_ai == 41) + ) { + ai_latch = 1; + } } /* The ']' character is simply dropped from the input */ } diff --git a/backend/maxicode.c b/backend/maxicode.c index 2a882d6e..7f59afc0 100644 --- a/backend/maxicode.c +++ b/backend/maxicode.c @@ -71,7 +71,7 @@ void maxi_do_secondary_chk_odd( int ecclen ) datalen = 84; for(j = 0; j < datalen; j += 1) - if ((j % 2) == 1) // odd + if (j & 1) // odd data[(j-1)/2] = maxi_codeword[j + 20]; rs_encode(datalen/2, data, results); @@ -96,7 +96,7 @@ void maxi_do_secondary_chk_even(int ecclen ) rs_init_code(ecclen, 1); for(j = 0; j < datalen + 1; j += 1) - if ((j % 2) == 0) // even + if (!(j & 1)) // even data[j/2] = maxi_codeword[j + 20]; rs_encode(datalen/2, data, results); diff --git a/backend/medical.c b/backend/medical.c index ab1a6331..73d31ba2 100644 --- a/backend/medical.c +++ b/backend/medical.c @@ -73,7 +73,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) do { - if(tester % 2 == 0) { + if(!(tester & 1)) { concat(inter, "W"); tester = (tester - 2) / 2; } else { diff --git a/backend/pdf417.c b/backend/pdf417.c index 99c7996c..a97906ab 100644 --- a/backend/pdf417.c +++ b/backend/pdf417.c @@ -289,7 +289,7 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len } /* 663 */ - if ((wnet % 2) > 0) { + if (wnet & 1) { chainet[wnet] = 29; wnet++; } diff --git a/backend/plessey.c b/backend/plessey.c index baaf9700..c87ec20d 100644 --- a/backend/plessey.c +++ b/backend/plessey.c @@ -151,7 +151,7 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le /* caluculate check digit */ wright = 0; - n = ((length % 2) == 0) ? 1 : 0; + n = !(length & 1); for(i = n; i < length; i += 2) { un[wright++] = source[i]; @@ -170,7 +170,7 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le pedwar += ctoi(tri[i]); } - n = length % 2; + n = length & 1; for(i = n; i < length; i+=2) { pedwar += ctoi(source[i]); @@ -223,7 +223,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons /* calculate first check digit */ wright = 0; - n = ((src_len %2) == 0) ? 1 : 0; + n = !(src_len & 1); for(i = n; i < src_len; i += 2) { un[wright++] = source[i]; @@ -242,7 +242,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons pedwar += ctoi(tri[i]); } - n = src_len % 2; + n = src_len & 1; for(i = n; i < src_len; i += 2) { pedwar += ctoi(source[i]); @@ -256,7 +256,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons /* calculate second check digit */ wright = 0; - n = src_len % 2; + n = src_len & 1; for(i = n; i < src_len; i += 2) { un[wright++] = source[i]; @@ -277,7 +277,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons } - i = ((src_len % 2) == 0) ? 1 : 0; + i = !(src_len & 1); for(; i < src_len; i += 2) { pedwar += ctoi(source[i]); @@ -424,7 +424,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons /* caluculate second (mod 10) check digit */ wright = 0; - i = ((temp_len % 2) == 0) ? 1 : 0; + i = !(temp_len & 1); for(; i < temp_len; i += 2) { un[wright++] = temp[i]; @@ -443,7 +443,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons pedwar += ctoi(tri[i]); } - i = temp_len % 2; + i = temp_len & 1; for(; i < temp_len; i+=2) { pedwar += ctoi(temp[i]); diff --git a/backend/png.c b/backend/png.c index 00a76da6..71a5ce2b 100644 --- a/backend/png.c +++ b/backend/png.c @@ -635,13 +635,13 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) for(column = 0; column < symbol->width; column++) { xposn = column * 10; if(module_is_set(symbol, row, column)) { - if((row % 2) == 0) { - /* Even (full) row */ - draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset)); - } else { + if(row & 1) { /* Odd (reduced) row */ xposn += 5; draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset)); + } else { + /* Even (full) row */ + draw_hexagon(pixelbuf, image_width, xposn + (2 * xoffset), yposn + (2 * yoffset)); } } } diff --git a/backend/ps.c b/backend/ps.c index c7d6d93a..ad67aadb 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -256,11 +256,9 @@ int ps_plot(struct zint_symbol *symbol) dy = my - 1.0 + yoffset; ey = my - 0.5 + yoffset; fy = my + 0.5 + yoffset; - if(r % 2 == 1) { - mx = (2.46 * i) + 1.23 + 1.23; - } else { - mx = (2.46 * i) + 1.23; - } + + mx = 2.46 * i + 1.23 + (r & 1 ? 1.23 : 0); + ax = mx + xoffset; bx = mx + 0.86 + xoffset; cx = mx + 0.86 + xoffset; diff --git a/backend/qr.c b/backend/qr.c index 643b2d45..3384c588 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -133,7 +133,7 @@ int estimate_binary_length(char mode[], int length, int gs1) case 'B': count += 8; break; case 'A': a_count++; - if((a_count % 2) == 0) { + if((a_count & 1) == 0) { count += 5; // 11 in total a_count = 0; } @@ -146,10 +146,10 @@ int estimate_binary_length(char mode[], int length, int gs1) count += 3; // 10 in total n_count = 0; } - else if ((n_count % 2) == 0) - count += 3; // 7 in total - else - count += 4; + else if ((n_count & 1) == 0) + count += 3; // 7 in total + else + count += 4; break; } } @@ -186,11 +186,9 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in if(version <= 9) { scheme = 1; - } - if((version >= 10) && (version <= 26)) { + } else if((version >= 10) && (version <= 26)) { scheme = 2; - } - if(version >= 27) { + } else if(version >= 27) { scheme = 3; } @@ -879,14 +877,14 @@ int apply_bitmask(unsigned char *grid, int size) mask[(y * size) + x] = 0x00; if (!(grid[(y * size) + x] & 0xf0)) { - if(((y + x) % 2) == 0) { mask[(y * size) + x] += 0x01; } - if((y % 2) == 0) { mask[(y * size) + x] += 0x02; } + if(((y + x) & 1) == 0) { mask[(y * size) + x] += 0x01; } + if((y & 1) == 0) { mask[(y * size) + x] += 0x02; } if((x % 3) == 0) { mask[(y * size) + x] += 0x04; } if(((y + x) % 3) == 0) { mask[(y * size) + x] += 0x08; } - if((((y / 2) + (x / 3)) % 2) == 0) { mask[(y * size) + x] += 0x10; } - if((((y * x) % 2) + ((y * x) % 3)) == 0) { mask[(y * size) + x] += 0x20; } - if(((((y * x) % 2) + ((y * x) % 3)) % 2) == 0) { mask[(y * size) + x] += 0x40; } - if(((((y + x) % 2) + ((y * x) % 3)) % 2) == 0) { mask[(y * size) + x] += 0x80; } + if((((y / 2) + (x / 3)) & 1) == 0) { mask[(y * size) + x] += 0x10; } + if((((y * x) & 1) + ((y * x) % 3)) == 0) { mask[(y * size) + x] += 0x20; } + if(((((y * x) & 1) + ((y * x) % 3)) & 1) == 0) { mask[(y * size) + x] += 0x40; } + if(((((y + x) & 1) + ((y * x) % 3)) & 1) == 0) { mask[(y * size) + x] += 0x80; } } } } @@ -1010,11 +1008,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) char* mode = (char *)_alloca(length + 1); #endif - if(symbol->input_mode == GS1_MODE) { - gs1 = 1; - } else { - gs1 = 0; - } + gs1 = (symbol->input_mode == GS1_MODE); switch(symbol->input_mode) { case DATA_MODE: @@ -1520,8 +1514,7 @@ void micro_qr_m1(char binary_data[]) if(bits_left > 4) { remainder = (bits_left - 4) / 8; for(i = 0; i < remainder; i++) { - if((i % 2) == 0) { concat(binary_data, "11101100"); } - if((i % 2) == 1) { concat(binary_data, "00010001"); } + concat(binary_data, i & 1 ? "00010001" : "11101100"); } } concat(binary_data, "0000"); @@ -1595,8 +1588,7 @@ void micro_qr_m2(char binary_data[], int ecc_mode) bits_left = bits_total - strlen(binary_data); remainder = bits_left / 8; for(i = 0; i < remainder; i++) { - if((i % 2) == 0) { concat(binary_data, "11101100"); } - if((i % 2) == 1) { concat(binary_data, "00010001"); } + concat(binary_data, i & 1 ? "00010001" : "11101100"); } } @@ -1677,8 +1669,7 @@ void micro_qr_m3(char binary_data[], int ecc_mode) if(bits_left > 4) { remainder = (bits_left - 4) / 8; for(i = 0; i < remainder; i++) { - if((i % 2) == 0) { concat(binary_data, "11101100"); } - if((i % 2) == 1) { concat(binary_data, "00010001"); } + concat(binary_data, i & 1 ? "00010001" : "11101100"); } } concat(binary_data, "0000"); @@ -1766,8 +1757,7 @@ void micro_qr_m4(char binary_data[], int ecc_mode) bits_left = bits_total - strlen(binary_data); remainder = bits_left / 8; for(i = 0; i < remainder; i++) { - if((i % 2) == 0) { concat(binary_data, "11101100"); } - if((i % 2) == 1) { concat(binary_data, "00010001"); } + concat(binary_data, i & 1 ? "00010001" : "11101100"); } } @@ -1930,10 +1920,21 @@ int micro_apply_bitmask(unsigned char *grid, int size) mask[(y * size) + x] = 0x00; if (!(grid[(y * size) + x] & 0xf0)) { - if((y % 2) == 0) { mask[(y * size) + x] += 0x01; } - if((((y / 2) + (x / 3)) % 2) == 0) { mask[(y * size) + x] += 0x02; } - if(((((y * x) % 2) + ((y * x) % 3)) % 2) == 0) { mask[(y * size) + x] += 0x04; } - if(((((y + x) % 2) + ((y * x) % 3)) % 2) == 0) { mask[(y * size) + x] += 0x08; } + if((y & 1) == 0) { + mask[(y * size) + x] += 0x01; + } + + if((((y / 2) + (x / 3)) & 1) == 0) { + mask[(y * size) + x] += 0x02; + } + + if(((((y * x) & 1) + ((y * x) % 3)) & 1) == 0) { + mask[(y * size) + x] += 0x04; + } + + if(((((y + x) & 1) + ((y * x) % 3)) & 1) == 0) { + mask[(y * size) + x] += 0x08; + } } } } diff --git a/backend/render.c b/backend/render.c index e2a9494d..cbe4bb10 100644 --- a/backend/render.c +++ b/backend/render.c @@ -334,11 +334,7 @@ int render_plot(struct zint_symbol *symbol, float width, float height) for(r = 0; r < symbol->rows; r++) { for(i = 0; i < symbol->width; i++) { if(module_is_set(symbol, r, i)) { - if(r % 2 == 1) { - hexagon = render_plot_create_hexagon(((i * 0.88) + 1.76) * scaler, ((r * 0.76) + 0.76) * scaler); - } else { - hexagon = render_plot_create_hexagon(((i * 0.88) + 1.32) * scaler, ((r * 0.76) + 0.76) * scaler); - } + hexagon = render_plot_create_hexagon(((i * 0.88) + (r & 1 ? 1.76 : 1.32)) * scaler, ((r * 0.76) + 0.76) * scaler); render_plot_add_hexagon(symbol, hexagon, &last_hexagon); } } diff --git a/backend/rss.c b/backend/rss.c index dd7bb4da..f0c6a52b 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -112,7 +112,7 @@ void getRSSwidths(int val, int n, int elements, int maxWidth, int noNarrow) /* get all combinations */ subVal = combins(n-elmWidth-1, elements-bar-2); /* less combinations with no single-module element */ - if ((!noNarrow) && (narrowMask == 0) && + if ((!noNarrow) && (!narrowMask) && (n-elmWidth-(elements-bar-1) >= elements-bar-1)) { subVal -= combins(n-elmWidth-(elements-bar), elements-bar-2); @@ -440,12 +440,10 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int src_len) } hrt[14] = '\0'; - for (i = 0; i < 13; i++) - { + for (i = 0; i < 13; i++) { count += ctoi(hrt[i]); - if ((i%2) == 0) - { + if (!(i & 1)) { count += 2 * (ctoi(hrt[i])); } } @@ -550,11 +548,7 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int src_len) if(latch == '1') { set_module(symbol, symbol->rows, writer); } else { unset_module(symbol, symbol->rows, writer); } writer++; } - if(latch == '1') { - latch = '0'; - } else { - latch = '1'; - } + latch = (latch == '1' ? '0' : '1'); } set_module(symbol, symbol->rows, writer); unset_module(symbol, symbol->rows, writer + 1); @@ -901,11 +895,7 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int src_len) if(latch == '1') { set_module(symbol, symbol->rows, writer); } else { unset_module(symbol, symbol->rows, writer); } writer++; } - if(latch == '1') { - latch = '0'; - } else { - latch = '1'; - } + latch = (latch == '1' ? '0' : '1'); } if(symbol->width < writer) { symbol->width = writer; } symbol->rows = symbol->rows + 1; @@ -932,12 +922,10 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int src_len) hrt[12 - i] = source[src_len - i - 1]; } - for (i = 0; i < 13; i++) - { + for (i = 0; i < 13; i++) { count += ctoi(hrt[i]); - if ((i%2) == 0) - { + if (!(i & 1)) { count += 2 * (ctoi(hrt[i])); } } @@ -1045,7 +1033,7 @@ int general_rules(char field[], char type[]) } for(i = 0; i < block_count - 1; i++) { - if((block[1][i] == NUMERIC) && (block[0][i] % 2 == 1)) { + if((block[1][i] == NUMERIC) && (block[0][i] & 1)) { /* Odd size numeric block */ block[0][i] = block[0][i] - 1; block[0][i + 1] = block[0][i + 1] + 1; @@ -1060,7 +1048,7 @@ int general_rules(char field[], char type[]) } } - if((block[1][block_count - 1] == NUMERIC) && (block[0][block_count - 1] % 2 == 1)) { + if((block[1][block_count - 1] == NUMERIC) && (block[0][block_count - 1] & 1)) { /* If the last block is numeric and an odd size, further processing needs to be done outside this procedure */ return 1; @@ -1274,11 +1262,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x08; for(j = 0; j < 4; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } @@ -1291,11 +1275,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x200; for(j = 0; j < 10; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1320,11 +1300,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x200; for(j = 0; j < 10; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1337,11 +1313,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x4000; for(j = 0; j < 15; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } @@ -1364,11 +1336,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x200; for(j = 0; j < 10; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1385,11 +1353,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x4000; for(j = 0; j < 15; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } @@ -1413,11 +1377,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x200; for(j = 0; j < 10; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1432,11 +1392,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x80000; for(j = 0; j < 20; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } @@ -1460,11 +1416,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x8000; for(j = 0; j < 16; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } @@ -1484,11 +1436,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x200; for(j = 0; j < 10; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1518,11 +1466,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x200; for(j = 0; j < 10; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1542,11 +1486,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x200; for(j = 0; j < 10; j++) { - if((group_val & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (group_val & mask) ? "1" : "0"); mask = mask >> 1; } @@ -1689,12 +1629,9 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x40; for(j = 0; j < 7; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - if(debug) printf("0"); - } else { - concat(binary_string, "1"); - if(debug) printf("1"); + concat(binary_string, (value & mask) ? "1" : "0"); + if (debug) { + printf("%d", !!(value & mask)); } mask = mask >> 1; } @@ -1721,11 +1658,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x10; for(j = 0; j < 5; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1736,11 +1669,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x20; for(j = 0; j < 6; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1774,11 +1703,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x10; for(j = 0; j < 5; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1789,11 +1714,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x40; for(j = 0; j < 7; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1804,11 +1725,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x40; for(j = 0; j < 7; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1859,11 +1776,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x08; for(j = 0; j < 4; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } else { @@ -1874,11 +1787,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x40; for(j = 0; j < 7; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1887,11 +1796,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str mask = 0x10; for(j = 0; j < 5; j++) { - if((value & mask) == 0x00) { - concat(binary_string, "0"); - } else { - concat(binary_string, "1"); - } + concat(binary_string, (value & mask) ? "1" : "0"); mask = mask >> 1; } } @@ -1924,20 +1829,20 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str concat(binary_string, padstring); /* Patch variable length symbol bit field */ - d1 = ((strlen(binary_string) / 12) + 1) % 2; + d1 = ((strlen(binary_string) / 12) + 1) & 1; if(strlen(binary_string) <= 156) { d2 = 0; } else { d2 = 1; } if(encoding_method == 1) { - if(d1 == 0) { binary_string[2] = '0'; } else { binary_string[2] = '1'; } - if(d2 == 0) { binary_string[3] = '0'; } else { binary_string[3] = '1'; } + binary_string[2] = d1 ? '1' : '0'; + binary_string[3] = d2 ? '1' : '0'; } if(encoding_method == 2) { - if(d1 == 0) { binary_string[3] = '0'; } else { binary_string[3] = '1'; } - if(d2 == 0) { binary_string[4] = '0'; } else { binary_string[4] = '1'; } + binary_string[3] = d1 ? '1' : '0'; + binary_string[4] = d2 ? '1' : '0'; } if((encoding_method == 5) || (encoding_method == 6)) { - if(d1 == 0) { binary_string[6] = '0'; } else { binary_string[6] = '1'; } - if(d2 == 0) { binary_string[7] = '0'; } else { binary_string[7] = '1'; } + binary_string[6] = d1 ? '1' : '0'; + binary_string[7] = d2 ? '1' : '0'; } if(debug) printf("Resultant binary = %s\n", binary_string); if(debug) printf("\tLength: %d\n", (int)strlen(binary_string)); @@ -2070,7 +1975,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) check_widths[7] = widths[3]; /* Initialise element array */ - pattern_width = ((((data_chars + 1) / 2) + ((data_chars + 1) % 2)) * 5) + ((data_chars + 1) * 8) + 4; + pattern_width = ((((data_chars + 1) / 2) + ((data_chars + 1) & 1)) * 5) + ((data_chars + 1) * 8) + 4; for(i = 0; i < pattern_width; i++) { elements[i] = 0; } @@ -2081,8 +1986,8 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) elements[pattern_width - 1] = 1; /* Put finder patterns in element array */ - for(i = 0; i < (((data_chars + 1) / 2) + ((data_chars + 1) % 2)); i++) { - k = ((((((data_chars + 1) - 2) / 2) + ((data_chars + 1) % 2)) - 1) * 11) + i; + for(i = 0; i < (((data_chars + 1) / 2) + ((data_chars + 1) & 1)); i++) { + k = ((((((data_chars + 1) - 2) / 2) + ((data_chars + 1) & 1)) - 1) * 11) + i; for(j = 0; j < 5; j++) { elements[(21 * i) + j + 10] = finder_pattern_exp[((finder_sequence[k] - 1) * 5) + j]; } @@ -2194,9 +2099,9 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) /* Row Data */ reader = 0; do { - if(((symbol->option_2 % 2 == 1) || (current_row % 2 == 1)) || + if(((symbol->option_2 & 1) || (current_row & 1)) || ((current_row == stack_rows) && (codeblocks != (current_row * symbol->option_2)) && - ((((current_row * symbol->option_2) - codeblocks) % 2) == 1) )) { + (((current_row * symbol->option_2) - codeblocks) & 1))) { /* left to right */ left_to_right = 1; i = 2 + (current_block * 21); @@ -2233,15 +2138,11 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) sub_elements[elements_in_sub] = 1; sub_elements[elements_in_sub + 1] = 1; elements_in_sub += 2; - - if(current_row % 2 == 1) { - latch = '0'; - } else { - latch = '1'; - } + + latch = current_row & 1 ? '0' : '1'; if ((current_row == stack_rows) && (codeblocks != (current_row * symbol->option_2)) && - ((((current_row * symbol->option_2) - codeblocks) % 2) == 1) ) { + (((current_row * symbol->option_2) - codeblocks) & 1) ) { /* Special case bottom row */ special_case_row = 1; sub_elements[0] = 2; @@ -2279,11 +2180,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len) symbol->row_height[symbol->rows - 1] = 1; /* finder bar adjustment */ for(j = 0; j < reader; j++) { - if(special_case_row == 0) { - k = (49 * j) + 18; - } else { - k = (49 * j) + 19; - } + k = (49 * j) + (special_case_row ? 19 : 18); if(left_to_right) { for(i = 0; i < 15; i++) { if((!(module_is_set(symbol, symbol->rows, i + k - 1))) && diff --git a/backend/svg.c b/backend/svg.c index b6cac3ac..3d294d57 100644 --- a/backend/svg.c +++ b/backend/svg.c @@ -240,7 +240,7 @@ int svg_plot(struct zint_symbol *symbol) dy = my - 1.0 + yoffset; ey = my - 0.5 + yoffset; fy = my + 0.5 + yoffset; - if(r % 2 == 1) { + if(r & 1) { mx = (2.46 * i) + 1.23 + 1.23; } else { mx = (2.46 * i) + 1.23; diff --git a/backend/telepen.c b/backend/telepen.c index 5d1ccd95..6316e69f 100644 --- a/backend/telepen.c +++ b/backend/telepen.c @@ -114,7 +114,7 @@ int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len) } /* Add a leading zero if required */ - if ((temp_length % 2) != 0) + if (temp_length & 1) { memmove(temp + 1, temp, temp_length); temp[0] = '0'; diff --git a/backend/upcean.c b/backend/upcean.c index 67301a1a..da12c8f2 100644 --- a/backend/upcean.c +++ b/backend/upcean.c @@ -49,12 +49,10 @@ char upc_check(char source[]) count = 0; - for (i = 0; i < strlen(source); i++) - { + for (i = 0; i < strlen(source); i++) { count += ctoi(source[i]); - if ((i%2) == 0) - { + if (!(i & 1)) { count += 2 * (ctoi(source[i])); } } @@ -290,12 +288,10 @@ char ean_check(char source[]) count = 0; h = strlen(source); - for (i = h - 1; i >= 0; i--) - { + for (i = h - 1; i >= 0; i--) { count += ctoi(source[i]); - if (!((i%2) == 0)) - { + if (i & 1) { count += 2 * ctoi(source[i]); } }