diff --git a/backend/aztec.c b/backend/aztec.c index a1d9168c..9b173753 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -1570,7 +1570,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], const size_t lengt /* Encodes Aztec runes as specified in ISO/IEC 24778:2008 Annex A */ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length) { - int input_value, error_number, i, p, y, x; + int input_value, error_number, i, y, x; char binary_string[28]; unsigned char data_codewords[3], ecc_codewords[6]; @@ -1603,13 +1603,7 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length) } strcpy(binary_string, ""); - for (p = 0; p < 8; p++) { - if (input_value & (0x80 >> p)) { - strcat(binary_string, "1"); - } else { - strcat(binary_string, "0"); - } - } + bin_append(input_value, 8, binary_string); data_codewords[0] = 0; data_codewords[1] = 0; diff --git a/backend/common.c b/backend/common.c index d0fc8b87..708c4172 100644 --- a/backend/common.c +++ b/backend/common.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008-2016 Robin Stuart + Copyright (C) 2008-2017 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -126,7 +126,7 @@ int posn(const char set_string[], const char data) { return i; } } - return 0; + return -1; } /* Return true (1) if a module is dark/black, otherwise false (0) */ diff --git a/backend/composite.c b/backend/composite.c index f868e30b..842901ce 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -960,8 +960,8 @@ int calc_padding_ccc(int binary_length, int *cc_width, int lin_width, int *ecc) } static int cc_binary_string(struct zint_symbol *symbol, const char source[], char binary_string[], int cc_mode, int *cc_width, int *ecc, int lin_width) { /* Handles all data encodation from section 5 of ISO/IEC 24723 */ - int encoding_method, read_posn, d1, d2, value, alpha_pad; - int i, j, mask, ai_crop, fnc1_latch; + int encoding_method, read_posn, d1, d2, alpha_pad; + int i, j, ai_crop, fnc1_latch; long int group_val; int ai90_mode, latch, remainder, binary_length; char date_str[4]; @@ -980,7 +980,6 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha alpha_pad = 0; ai90_mode = 0; *ecc = 0; - value = 0; target_bitsize = 0; if ((source[0] == '1') && ((source[1] == '0') || (source[1] == '1') || (source[1] == '7')) && (strlen(source) > 8)) { @@ -1021,15 +1020,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha date_str[1] = source[7]; group_val += atoi(date_str); - mask = 0x8000; - for (j = 0; j < 16; j++) { - if ((group_val & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(group_val, 16, binary_string); if (source[1] == '1') { /* Production Date AI 11 */ @@ -1059,7 +1050,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha #endif char numeric_part[4]; int alpha, alphanum, numeric, test1, test2, test3, next_ai_posn; - int numeric_value, table3_letter, mask; + int numeric_value, table3_letter; /* "This encodation method may be used if an element string with an AI 90 occurs at the start of the data message, and if the data field @@ -1193,89 +1184,24 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha table3_letter = -1; if (numeric_value < 31) { - switch (ninety[test1]) { - case 'B': table3_letter = 0; - break; - case 'D': table3_letter = 1; - break; - case 'H': table3_letter = 2; - break; - case 'I': table3_letter = 3; - break; - case 'J': table3_letter = 4; - break; - case 'K': table3_letter = 5; - break; - case 'L': table3_letter = 6; - break; - case 'N': table3_letter = 7; - break; - case 'P': table3_letter = 8; - break; - case 'Q': table3_letter = 9; - break; - case 'R': table3_letter = 10; - break; - case 'S': table3_letter = 11; - break; - case 'T': table3_letter = 12; - break; - case 'V': table3_letter = 13; - break; - case 'W': table3_letter = 14; - break; - case 'Z': table3_letter = 15; - break; - } + table3_letter = posn("BDHIJKLNPQRSTVWZ", ninety[test1]); } if (table3_letter != -1) { /* Encoding can be done according to 5.2.2 c) 2) */ /* five bit binary string representing value before letter */ - mask = 0x10; - for (j = 0; j < 5; j++) { - if ((numeric_value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } - + bin_append(numeric_value, 5, binary_string); + /* followed by four bit representation of letter from Table 3 */ - mask = 0x08; - for (j = 0; j < 4; j++) { - if ((table3_letter & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(table3_letter, 4, binary_string); } else { /* Encoding is done according to 5.2.2 c) 3) */ - strcat(binary_string, "11111"); + bin_append(31, 5, binary_string); /* ten bit representation of number */ - mask = 0x200; - for (j = 0; j < 10; j++) { - if ((numeric_value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(numeric_value, 10, binary_string); /* five bit representation of ASCII character */ - mask = 0x10; - for (j = 0; j < 5; j++) { - if (((ninety[test1] - 65) & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(ninety[test1] - 65, 5, binary_string); } read_posn = test1 + 3; @@ -1291,31 +1217,15 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha /* Alpha encodation (section 5.2.3) */ do { if ((source[read_posn] >= '0') && (source[read_posn] <= '9')) { - mask = 0x10; - for (j = 0; j < 5; j++) { - if (((source[read_posn] + 4) & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(source[read_posn] + 4, 5, binary_string); } if ((source[read_posn] >= 'A') && (source[read_posn] <= 'Z')) { - mask = 0x20; - for (j = 0; j < 6; j++) { - if (((source[read_posn] - 65) & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(source[read_posn] - 65, 6, binary_string); } if (source[read_posn] == '[') { - strcat(binary_string, "11111"); + bin_append(31, 5, binary_string); } read_posn++; @@ -1327,41 +1237,31 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha /* Alphanumeric mode */ do { if ((source[read_posn] >= '0') && (source[read_posn] <= '9')) { - mask = 0x10; - for (j = 0; j < 5; j++) { - if (((source[read_posn] - 43) & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(source[read_posn] - 43, 5, binary_string); } if ((source[read_posn] >= 'A') && (source[read_posn] <= 'Z')) { - mask = 0x20; - for (j = 0; j < 6; j++) { - if (((source[read_posn] - 33) & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(source[read_posn] - 33, 6, binary_string); } switch (source[read_posn]) { - case '[': strcat(binary_string, "01111"); + case '[': + bin_append(15, 5, binary_string); break; - case '*': strcat(binary_string, "111010"); + case '*': + bin_append(58, 6, binary_string); break; - case ',': strcat(binary_string, "111011"); + case ',': + bin_append(59, 6, binary_string); break; - case '-': strcat(binary_string, "111100"); + case '-': + bin_append(60, 6, binary_string); break; - case '.': strcat(binary_string, "111101"); + case '.': + bin_append(61, 6, binary_string); break; - case '/': strcat(binary_string, "111110"); + case '/': + bin_append(62, 6, binary_string); break; } @@ -1487,7 +1387,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha if (i != 0) { if ((general_field_type[i - 1] != NUMERIC) && (general_field[i - 1] != '[')) { - strcat(binary_string, "000"); /* Numeric latch */ + bin_append(0, 3, binary_string); /* Numeric latch */ } } @@ -1503,17 +1403,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha d2 = 10; } - value = (11 * d1) + d2 + 8; - - mask = 0x40; - for (j = 0; j < 7; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append((11 * d1) + d2 + 8, 7, binary_string); i += 2; break; @@ -1522,49 +1412,41 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha if (i != 0) { if ((general_field_type[i - 1] == NUMERIC) || (general_field[i - 1] == '[')) { - strcat(binary_string, "0000"); /* Alphanumeric latch */ + bin_append(0, 4, binary_string); /* Alphanumeric latch */ } if (general_field_type[i - 1] == ISOIEC) { - strcat(binary_string, "00100"); /* ISO/IEC 646 latch */ + bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */ } } if ((general_field[i] >= '0') && (general_field[i] <= '9')) { - - value = general_field[i] - 43; - - mask = 0x10; - for (j = 0; j < 5; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(general_field[i] - 43, 5, binary_string); } if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) { - - value = general_field[i] - 33; - - mask = 0x20; - for (j = 0; j < 6; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(general_field[i] - 33, 6, binary_string); } - if (general_field[i] == '[') strcat(binary_string, "01111"); /* FNC1/Numeric latch */ - if (general_field[i] == '*') strcat(binary_string, "111010"); /* asterisk */ - if (general_field[i] == ',') strcat(binary_string, "111011"); /* comma */ - if (general_field[i] == '-') strcat(binary_string, "111100"); /* minus or hyphen */ - if (general_field[i] == '.') strcat(binary_string, "111101"); /* period or full stop */ - if (general_field[i] == '/') strcat(binary_string, "111110"); /* slash or solidus */ + switch (general_field[i]) { + case '[': + bin_append(15, 5, binary_string); + break; + case '*': + bin_append(58, 6, binary_string); + break; + case ',': + bin_append(59, 6, binary_string); + break; + case '-': + bin_append(60, 6, binary_string); + break; + case '.': + bin_append(61, 6, binary_string); + break; + case '/': + bin_append(62, 6, binary_string); + break; + } i++; break; @@ -1573,57 +1455,24 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha if (i != 0) { if ((general_field_type[i - 1] == NUMERIC) || (general_field[i - 1] == '[')) { - strcat(binary_string, "0000"); /* Alphanumeric latch */ - strcat(binary_string, "00100"); /* ISO/IEC 646 latch */ + bin_append(0, 4, binary_string); /* Alphanumeric latch */ + bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */ } if (general_field_type[i - 1] == ALPHA) { - strcat(binary_string, "00100"); /* ISO/IEC 646 latch */ + bin_append(4, 5, binary_string);; /* ISO/IEC 646 latch */ } } if ((general_field[i] >= '0') && (general_field[i] <= '9')) { - - value = general_field[i] - 43; - - mask = 0x10; - for (j = 0; j < 5; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(general_field[i] - 43, 5, binary_string); } if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) { - - value = general_field[i] - 1; - - mask = 0x40; - for (j = 0; j < 7; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(general_field[i] - 1, 7, binary_string); } if ((general_field[i] >= 'a') && (general_field[i] <= 'z')) { - - value = general_field[i] - 7; - - mask = 0x40; - for (j = 0; j < 7; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(general_field[i] - 7, 7, binary_string); } if (general_field[i] == '[') strcat(binary_string, "01111"); /* FNC1/Numeric latch */ @@ -1679,33 +1528,9 @@ static int cc_binary_string(struct zint_symbol *symbol, const char source[], cha /* There is still one more numeric digit to encode */ if ((remainder >= 4) && (remainder <= 6)) { - d1 = ctoi(general_field[i]); - d1++; - - mask = 0x08; - for (j = 0; j < 4; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append(ctoi(general_field[i]) + 1, 4, binary_string); } else { - d1 = ctoi(general_field[i]); - d2 = 10; - - value = (11 * d1) + d2 + 8; - - mask = 0x40; - for (j = 0; j < 7; j++) { - if ((value & mask) == 0x00) { - strcat(binary_string, "0"); - } else { - strcat(binary_string, "1"); - } - mask = mask >> 1; - } + bin_append((11 * ctoi(general_field[i])) + 18, 7, binary_string); /* This may push the symbol up to the next size */ } } diff --git a/backend/dmatrix.c b/backend/dmatrix.c index dcd696d4..0fc281de 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -223,18 +223,15 @@ static void ecc200(unsigned char *binary, const int bytes, const int datablock, /* Return true (1) if a character is valid in X12 set */ static int isX12(const int source) { - if (source == 13) { - return 1; - } - if (source == 42) { - return 1; - } - if (source == 62) { - return 1; - } - if (source == 32) { - return 1; + + switch(source) { + case 13: // CR + case 42: // * + case 62: // > + case 32: // space + return 1; } + if ((source >= '0') && (source <= '9')) { return 1; } diff --git a/backend/hanxin.c b/backend/hanxin.c index d54dc1ff..303c04d4 100644 --- a/backend/hanxin.c +++ b/backend/hanxin.c @@ -658,20 +658,11 @@ static void calculate_binary(char binary[], char mode[], int source[], const siz void hx_place_finder_top_left(unsigned char* grid, int size) { int xp, yp; int x = 0, y = 0; - - int finder[] = { - 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 0, 0, - 1, 0, 1, 1, 1, 1, 1, - 1, 0, 1, 0, 0, 0, 0, - 1, 0, 1, 0, 1, 1, 1, - 1, 0, 1, 0, 1, 1, 1, - 1, 0, 1, 0, 1, 1, 1 - }; - + char finder[] = {0x7F, 0x40, 0x5F, 0x50, 0x57, 0x57, 0x57}; + for (xp = 0; xp < 7; xp++) { for (yp = 0; yp < 7; yp++) { - if (finder[xp + (7 * yp)] == 1) { + if (finder[yp] & 0x40 >> xp) { grid[((yp + y) * size) + (xp + x)] = 0x11; } else { grid[((yp + y) * size) + (xp + x)] = 0x10; @@ -683,20 +674,11 @@ void hx_place_finder_top_left(unsigned char* grid, int size) { /* Finder pattern for top right and bottom left of symbol */ void hx_place_finder(unsigned char* grid, int size, int x, int y) { int xp, yp; - - int finder[] = { - 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 1, 0, 1, - 0, 0, 0, 0, 1, 0, 1, - 1, 1, 1, 0, 1, 0, 1, - 1, 1, 1, 0, 1, 0, 1, - 1, 1, 1, 0, 1, 0, 1 - }; + char finder[] = {0x7F, 0x01, 0x7D, 0x05, 0x75, 0x75, 0x75}; for (xp = 0; xp < 7; xp++) { for (yp = 0; yp < 7; yp++) { - if (finder[xp + (7 * yp)] == 1) { + if (finder[yp] & 0x40 >> xp) { grid[((yp + y) * size) + (xp + x)] = 0x11; } else { grid[((yp + y) * size) + (xp + x)] = 0x10; @@ -709,20 +691,11 @@ void hx_place_finder(unsigned char* grid, int size, int x, int y) { void hx_place_finder_bottom_right(unsigned char* grid, int size) { int xp, yp; int x = size - 7, y = size - 7; - - int finder[] = { - 1, 1, 1, 0, 1, 0, 1, - 1, 1, 1, 0, 1, 0, 1, - 1, 1, 1, 0, 1, 0, 1, - 0, 0, 0, 0, 1, 0, 1, - 1, 1, 1, 1, 1, 0, 1, - 0, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 1, 1, 1 - }; + char finder[] = {0x75, 0x75, 0x75, 0x05, 0x7D, 0x01, 0x7F}; for (xp = 0; xp < 7; xp++) { for (yp = 0; yp < 7; yp++) { - if (finder[xp + (7 * yp)] == 1) { + if (finder[yp] & 0x40 >> xp) { grid[((yp + y) * size) + (xp + x)] = 0x11; } else { grid[((yp + y) * size) + (xp + x)] = 0x10; diff --git a/backend/imail.c b/backend/imail.c index e4f33886..c4e2c10b 100644 --- a/backend/imail.c +++ b/backend/imail.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008-2016 Robin Stuart + Copyright (C) 2008-2017 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -33,19 +33,6 @@ /* The function "USPS_MSB_Math_CRC11GenerateFrameCheckSequence" is Copyright (C) 2006 United States Postal Service */ -static const short int BCD[40] = { - 0, 0, 0, 0, - 1, 0, 0, 0, - 0, 1, 0, 0, - 1, 1, 0, 0, - 0, 0, 1, 0, - 1, 0, 1, 0, - 0, 1, 1, 0, - 1, 1, 1, 0, - 0, 0, 0, 1, - 1, 0, 0, 1 -}; - #include #include #include @@ -337,13 +324,13 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) { binary_add(accum, x_reg); } - x_reg[0] = BCD[ctoi(zip[read]) * 4]; - x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1]; - x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2]; - x_reg[3] = BCD[(ctoi(zip[read]) * 4) + 3]; - for (i = 4; i < 112; i++) { + for (i = 0; i < 112; i++) { x_reg[i] = 0; } + + for (i = 0; i < 4; i++) { + if (ctoi(zip[read]) & (0x01 << i)) x_reg[i] = 1; + } binary_add(accum, x_reg); } @@ -381,14 +368,14 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) { for (i = 0; i < 9; i++) { binary_add(accum, y_reg); } - - y_reg[0] = BCD[ctoi(zip_adder[read]) * 4]; - y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(zip_adder[read]) * 4) + 3]; - for (i = 4; i < 112; i++) { + + for (i = 0; i < 112; i++) { y_reg[i] = 0; } + + for (i = 0; i < 4; i++) { + if (ctoi(zip_adder[read]) & (0x01 << i)) y_reg[i] = 1; + } binary_add(accum, y_reg); } @@ -405,15 +392,15 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) { for (i = 0; i < 9; i++) { binary_add(accum, y_reg); } - - /* add first digit of tracker */ - y_reg[0] = BCD[ctoi(tracker[0]) * 4]; - y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(tracker[0]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(tracker[0]) * 4) + 3]; - for (i = 4; i < 112; i++) { + + for (i = 0; i < 112; i++) { y_reg[i] = 0; } + + /* add first digit of tracker */ + for (i = 0; i < 4; i++) { + if (ctoi(tracker[0]) & (0x01 << i)) y_reg[i] = 1; + } binary_add(accum, y_reg); @@ -425,14 +412,14 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) { for (i = 0; i < 4; i++) { binary_add(accum, y_reg); } + + for (i = 0; i < 112; i++) { + y_reg[i] = 0; + } /* add second digit */ - y_reg[0] = BCD[ctoi(tracker[1]) * 4]; - y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(tracker[1]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(tracker[1]) * 4) + 3]; - for (i = 4; i < 112; i++) { - y_reg[i] = 0; + for (i = 0; i < 4; i++) { + if (ctoi(tracker[1]) & (0x01 << i)) y_reg[i] = 1; } binary_add(accum, y_reg); @@ -448,15 +435,15 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) { for (i = 0; i < 9; i++) { binary_add(accum, y_reg); } - - y_reg[0] = BCD[ctoi(tracker[read]) * 4]; - y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1]; - y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2]; - y_reg[3] = BCD[(ctoi(tracker[read]) * 4) + 3]; - for (i = 4; i < 112; i++) { + + for (i = 0; i < 112; i++) { y_reg[i] = 0; } - + + for (i = 0; i < 4; i++) { + if (ctoi(tracker[read]) & (0x01 << i)) y_reg[i] = 1; + } + binary_add(accum, y_reg); } diff --git a/backend/large.c b/backend/large.c index a0bdc5c2..dda4d5f1 100644 --- a/backend/large.c +++ b/backend/large.c @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008-2016 Robin Stuart + Copyright (C) 2008-2017 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -35,19 +35,6 @@ #include "common.h" #include "large.h" -static const short int BCD[40] = { - 0, 0, 0, 0, - 1, 0, 0, 0, - 0, 1, 0, 0, - 1, 1, 0, 0, - 0, 0, 1, 0, - 1, 0, 1, 0, - 0, 1, 1, 0, - 1, 1, 1, 0, - 0, 0, 0, 1, - 1, 0, 0, 1 -}; - void binary_add(short int accumulator[], short int input_buffer[]) { /* Binary addition */ int i, carry, done; carry = 0; @@ -190,13 +177,13 @@ void binary_load(short int reg[], char data[], const size_t src_len) { binary_add(reg, temp); } - temp[0] = BCD[ctoi(data[read]) * 4]; - temp[1] = BCD[(ctoi(data[read]) * 4) + 1]; - temp[2] = BCD[(ctoi(data[read]) * 4) + 2]; - temp[3] = BCD[(ctoi(data[read]) * 4) + 3]; - for (i = 4; i < 112; i++) { + for (i = 0; i < 112; i++) { temp[i] = 0; } + + for (i = 0; i < 4; i++) { + if (ctoi(data[read]) & (0x01 << i)) temp[i] = 1; + } binary_add(reg, temp); } diff --git a/backend/qr.c b/backend/qr.c index 296051c2..b6aabc4a 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -546,20 +546,11 @@ static void add_ecc(int fullstream[],const int datastream[],const int version,co static void place_finder(unsigned char grid[],const int size,const int x,const int y) { int xp, yp; - - static const int finder[] = { - 1, 1, 1, 1, 1, 1, 1, - 1, 0, 0, 0, 0, 0, 1, - 1, 0, 1, 1, 1, 0, 1, - 1, 0, 1, 1, 1, 0, 1, - 1, 0, 1, 1, 1, 0, 1, - 1, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 1, 1, 1 - }; - + char finder[] = {0x7F, 0x41, 0x5D, 0x5D, 0x5D, 0x41, 0x7F}; + for (xp = 0; xp < 7; xp++) { for (yp = 0; yp < 7; yp++) { - if (finder[xp + (7 * yp)] == 1) { + if (finder[yp] & 0x40 >> xp) { grid[((yp + y) * size) + (xp + x)] = 0x11; } else { grid[((yp + y) * size) + (xp + x)] = 0x10; @@ -570,21 +561,14 @@ static void place_finder(unsigned char grid[],const int size,const int x,const i static void place_align(unsigned char grid[],const int size,int x,int y) { int xp, yp; - - static const int alignment[] = { - 1, 1, 1, 1, 1, - 1, 0, 0, 0, 1, - 1, 0, 1, 0, 1, - 1, 0, 0, 0, 1, - 1, 1, 1, 1, 1 - }; + char alignment[] = {0x1F, 0x11, 0x15, 0x11, 0x1F}; x -= 2; y -= 2; /* Input values represent centre of pattern */ for (xp = 0; xp < 5; xp++) { for (yp = 0; yp < 5; yp++) { - if (alignment[xp + (5 * yp)] == 1) { + if (alignment[yp] & 0x10 >> xp) { grid[((yp + y) * size) + (xp + x)] = 0x11; } else { grid[((yp + y) * size) + (xp + x)] = 0x10;