diff --git a/backend/common.c b/backend/common.c index e7ed58a6..34b8c0d7 100644 --- a/backend/common.c +++ b/backend/common.c @@ -127,7 +127,7 @@ void lookup(char set_string[], char *table[], char data, char dest[]) int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) { - return (symbol->encoded_data[y_coord][x_coord / 7] & (1 << (x_coord % 7))) ? 1 : 0; + return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1; #if 0 switch(x_sub) { case 0: if((symbol->encoded_data[y_coord][x_char] & 0x01) != 0) { result = 1; } break; @@ -145,8 +145,7 @@ int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) void set_module(struct zint_symbol *symbol, int y_coord, int x_coord) { - if(module_is_set(symbol, y_coord, x_coord)) { return; } - symbol->encoded_data[y_coord][x_coord / 7] += 1 << (x_coord % 7); + symbol->encoded_data[y_coord][x_coord / 7] |= 1 << (x_coord % 7); #if 0 int x_char, x_sub; @@ -168,8 +167,7 @@ void set_module(struct zint_symbol *symbol, int y_coord, int x_coord) void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) { - if(!(module_is_set(symbol, y_coord, x_coord))) { return; } - symbol->encoded_data[y_coord][x_coord / 7] -= 1 << (x_coord % 7); + symbol->encoded_data[y_coord][x_coord / 7] &= ~(1 << (x_coord % 7)); #if 0 int x_char, x_sub; diff --git a/backend/library.c b/backend/library.c index 9f2c413a..edec5210 100644 --- a/backend/library.c +++ b/backend/library.c @@ -200,6 +200,36 @@ void error_tag(char error_string[], int error_number) } } +int dump_plot(struct zint_symbol *symbol) +{ + FILE *f; + int i, r; + + if(symbol->output_options & BARCODE_STDOUT) { + f = stdout; + } else { + f = fopen(symbol->outfile, "w"); + if(!f) { + strcpy(symbol->errtxt, "Could not open output file"); + return ERROR_FILE_ACCESS; + } + } + + fputs("[\n", f); + for (r = 0; r < symbol->rows; r++) { + fputs(" [ ", f); + for (i = 0; i < symbol->width; i++) { + fputs(module_is_set(symbol, r, i) ? "1 " : "0 ", f); + } + fputs("]\n", f); + } + fputs("]\n", f); + + fclose(f); + + return 0; +} + int hibc(struct zint_symbol *symbol, unsigned char source[], int length) { int counter, error_number, i; @@ -692,22 +722,22 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) if(!(strcmp(output, "PNG"))) { if(symbol->scale < 1.0) { symbol->text[0] = '\0'; } error_number = png_handle(symbol, rotate_angle); - } else { + } else #endif - if(!(strcmp(output, "EPS"))) { - error_number = ps_plot(symbol); - } else { - if(!(strcmp(output, "SVG"))) { - error_number = svg_plot(symbol); - } else { - strcpy(symbol->errtxt, "Unknown output format"); - error_tag(symbol->errtxt, ERROR_INVALID_OPTION); - return ERROR_INVALID_OPTION; - } - } -#ifndef NO_PNG + if(!(strcmp(output, "TXT"))) { + error_number = dump_plot(symbol); + } else + if(!(strcmp(output, "EPS"))) { + error_number = ps_plot(symbol); + } else + if(!(strcmp(output, "SVG"))) { + error_number = svg_plot(symbol); + } else + { + strcpy(symbol->errtxt, "Unknown output format"); + error_tag(symbol->errtxt, ERROR_INVALID_OPTION); + return ERROR_INVALID_OPTION; } -#endif } else { strcpy(symbol->errtxt, "Unknown output format"); error_tag(symbol->errtxt, ERROR_INVALID_OPTION); @@ -777,22 +807,27 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) unsigned int nRead = 0, n = 0; int ret; - file = fopen(filename, "rb"); - if (!file) { - strcpy(symbol->errtxt, "Unable to read input file"); - return ERROR_INVALID_DATA; - } + if (!strcmp(filename, "-")) { + file = stdin; + fileLen = 7100; + } else { + file = fopen(filename, "rb"); + if (!file) { + strcpy(symbol->errtxt, "Unable to read input file"); + return ERROR_INVALID_DATA; + } - /* Get file length */ - fseek(file, 0, SEEK_END); - fileLen = ftell(file); - fseek(file, 0, SEEK_SET); + /* Get file length */ + fseek(file, 0, SEEK_END); + fileLen = ftell(file); + fseek(file, 0, SEEK_SET); - if(fileLen > 7100) { - /* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */ - strcpy(symbol->errtxt, "Input file too long"); - fclose(file); - return ERROR_INVALID_DATA; + if(fileLen > 7100) { + /* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */ + strcpy(symbol->errtxt, "Input file too long"); + fclose(file); + return ERROR_INVALID_DATA; + } } /* Allocate memory */ diff --git a/backend/qr.c b/backend/qr.c index 2d1833ad..643b2d45 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -157,6 +157,13 @@ int estimate_binary_length(char mode[], int length, int gs1) return count; } +static inline void qr_bscan(char *binary, int data, int h) +{ + for (; h; h>>=1) { + concat(binary, data & h ? "1" : "0"); + } +} + void qr_binary(int datastream[], int version, int target_binlen, char mode[], int jisdata[], int length, int gs1, int est_binlen) { /* Convert input data to a binary stream and add padding */ @@ -210,24 +217,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in concat(binary, "1000"); /* Character count indicator */ - switch(scheme) { - case 3: - if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - case 2: - if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + qr_bscan(binary, short_data_block_length, 0x20 << (scheme*2)); /* scheme = 1..3 */ if(debug) { printf("Kanji block (length %d)\n\t", short_data_block_length); } @@ -240,20 +230,8 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in msb = (jis & 0xff00) >> 4; lsb = (jis & 0xff); prod = (msb * 0xc0) + lsb; - - if(prod & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } + + qr_bscan(binary, prod, 0x1000); if(debug) { printf("0x%4X ", prod); } } @@ -267,28 +245,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in concat(binary, "0100"); /* Character count indicator */ - switch (scheme) { - case 3: - case 2: - if(short_data_block_length & 0x8000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x4000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x2000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + qr_bscan(binary, short_data_block_length, scheme > 1 ? 0x8000 : 0x80); /* scheme = 1..3 */ if(debug) { printf("Byte block (length %d)\n\t", short_data_block_length); } @@ -300,14 +257,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in byte = 0x1d; /* FNC1 */ } - if(byte & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } + qr_bscan(binary, byte, 0x80); if(debug) { printf("0x%4X ", byte); } } @@ -321,25 +271,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in concat(binary, "0010"); /* Character count indicator */ - switch (scheme) { - case 3: - if(short_data_block_length & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); } - case 2: - if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + qr_bscan(binary, short_data_block_length, 0x40 << (2 * scheme)); /* scheme = 1..3 */ if(debug) { printf("Alpha block (length %d)\n\t", short_data_block_length); } @@ -410,22 +342,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in } } - switch(count) { - case 2: - if(prod & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + qr_bscan(binary, prod, count == 2 ? 0x400 : 0x20); /* count = 1..2 */ if(debug) { printf("0x%4X ", prod); } }; @@ -439,26 +356,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in concat(binary, "0001"); /* Character count indicator */ - switch (scheme) { - case 3: - if(short_data_block_length & 0x2000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); } - case 2: - if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + qr_bscan(binary, short_data_block_length, 0x80 << (2 * scheme)); /* scheme = 1..3 */ if(debug) { printf("Number block (length %d)\n\t", short_data_block_length); } @@ -484,22 +382,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in prod = (prod * 10) + third; } - switch(count) { - case 3: - if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - case 2: - if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + qr_bscan(binary, prod, 1 << (3 * count)); /* count = 1..3 */ if(debug) { printf("0x%4X (%d)", prod, prod); } @@ -1334,20 +1217,8 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, msb = (jis & 0xff00) >> 4; lsb = (jis & 0xff); prod = (msb * 0xc0) + lsb; - - if(prod & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } + + qr_bscan(binary, prod, 0x1000); if(debug) { printf("0x%4X ", prod); } @@ -1376,14 +1247,7 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, for(i = 0; i < short_data_block_length; i++) { int byte = jisdata[position + i]; - if(byte & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(byte & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } + qr_bscan(binary, byte, 0x80); if(debug) { printf("0x%4X ", byte); } @@ -1423,23 +1287,8 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, count = 2; prod = (first * 45) + second; } - - switch(count) { - case 2: - if(prod & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + + qr_bscan(binary, prod, 1 << (5 * count)); /* count = 1..2 */ if(debug) { printf("0x%4X ", prod); } @@ -1486,23 +1335,8 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, count = 3; prod = (prod * 10) + third; } - - switch(count) { - case 3: - if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } - case 2: - if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } - case 1: - if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } - if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } - break; - } + + qr_bscan(binary, prod, 1 << (3 * count)); /* count = 1..3 */ if(debug) { printf("0x%4X (%d)", prod, prod); } @@ -1592,18 +1426,7 @@ void microqr_expand_binary(char binary_stream[], char full_stream[], int version } /* Character count indicator */ - switch(version) { - case 3: - if(binary_stream[i + 1] & 0x20) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - case 2: - if(binary_stream[i + 1] & 0x10) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - case 1: - if(binary_stream[i + 1] & 0x08) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - case 0: - if(binary_stream[i + 1] & 0x04) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x02) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x01) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - } + qr_bscan(full_stream, binary_stream[i + 1], 4 << version); /* version = 0..3 */ i += 2; break; @@ -1617,16 +1440,7 @@ void microqr_expand_binary(char binary_stream[], char full_stream[], int version } /* Character count indicator */ - switch(version) { - case 3: - if(binary_stream[i + 1] & 0x10) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - case 2: - if(binary_stream[i + 1] & 0x08) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - case 1: - if(binary_stream[i + 1] & 0x04) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x02) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x01) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - } + qr_bscan(full_stream, binary_stream[i + 1], 2 << version); /* version = 1..3 */ i += 2; break; @@ -1639,15 +1453,7 @@ void microqr_expand_binary(char binary_stream[], char full_stream[], int version } /* Character count indicator */ - switch(version) { - case 3: - if(binary_stream[i + 1] & 0x10) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - case 2: - if(binary_stream[i + 1] & 0x08) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x04) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x02) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x01) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - } + qr_bscan(full_stream, binary_stream[i + 1], 2 << version); /* version = 2..3 */ i += 2; break; @@ -1660,14 +1466,7 @@ void microqr_expand_binary(char binary_stream[], char full_stream[], int version } /* Character count indicator */ - switch(version) { - case 3: - if(binary_stream[i + 1] & 0x08) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - case 2: - if(binary_stream[i + 1] & 0x04) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x02) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - if(binary_stream[i + 1] & 0x01) { concat(full_stream, "1"); } else { concat(full_stream, "0"); } - } + qr_bscan(full_stream, binary_stream[i + 1], 1 << version); /* version = 2..3 */ i += 2; break; @@ -1757,14 +1556,7 @@ void micro_qr_m1(char binary_data[]) /* Add Reed-Solomon codewords to binary data */ for(i = 0; i < ecc_codewords; i++) { - if(ecc_blocks[ecc_codewords - i - 1] & 0x80) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x40) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x20) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + qr_bscan(binary_data, ecc_blocks[ecc_codewords - i - 1], 0x80); } } @@ -1832,14 +1624,7 @@ void micro_qr_m2(char binary_data[], int ecc_mode) /* Add Reed-Solomon codewords to binary data */ for(i = 0; i < ecc_codewords; i++) { - if(ecc_blocks[ecc_codewords - i - 1] & 0x80) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x40) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x20) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + qr_bscan(binary_data, ecc_blocks[ecc_codewords - i - 1], 0x80); } return; @@ -1939,14 +1724,7 @@ void micro_qr_m3(char binary_data[], int ecc_mode) /* Add Reed-Solomon codewords to binary data */ for(i = 0; i < ecc_codewords; i++) { - if(ecc_blocks[ecc_codewords - i - 1] & 0x80) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x40) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x20) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + qr_bscan(binary_data, ecc_blocks[ecc_codewords - i - 1], 0x80); } return; @@ -2018,14 +1796,7 @@ void micro_qr_m4(char binary_data[], int ecc_mode) /* Add Reed-Solomon codewords to binary data */ for(i = 0; i < ecc_codewords; i++) { - if(ecc_blocks[ecc_codewords - i - 1] & 0x80) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x40) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x20) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(ecc_blocks[ecc_codewords - i - 1] & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + qr_bscan(binary_data, ecc_blocks[ecc_codewords - i - 1], 0x80); } } diff --git a/frontend/main.c b/frontend/main.c index 979337b6..022e8890 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -91,6 +91,7 @@ void usage(void) " --directpng Send PNG output to stdout\n" " --directeps Send EPS output to stdout\n" " --directsvg Send SVG output to stdout\n" + " --dump Dump binary data to stdout\n" " --rotate=NUMBER Rotate symbol (PNG output only).\n" " --cols=NUMBER (PDF417) Number of columns.\n" " --vers=NUMBER (QR Code) Version\n" @@ -193,6 +194,7 @@ int main(int argc, char **argv) {"directeps", 0, 0, 0}, {"directpng", 0, 0, 0}, {"directsvg", 0, 0, 0}, + {"dump", 0, 0, 0}, {"barcode", 1, 0, 'b'}, {"height", 1, 0, 0}, {"whitesp", 1, 0, 'w'}, @@ -241,6 +243,10 @@ int main(int argc, char **argv) my_symbol->output_options += BARCODE_STDOUT; strncpy(my_symbol->outfile, "dummy.svg", 10); } + if(!strcmp(long_options[option_index].name, "dump")) { + my_symbol->output_options += BARCODE_STDOUT; + strncpy(my_symbol->outfile, "dummy.txt", 10); + } if(!strcmp(long_options[option_index].name, "gs1")) { my_symbol->input_mode = GS1_MODE; }