Add new symbology UPNQR

This commit is contained in:
Robin Stuart 2017-05-20 23:37:50 +01:00
parent 847fa6f332
commit b426877a4f
4 changed files with 107 additions and 2 deletions

View File

@ -205,6 +205,7 @@ extern int grid_matrix(struct zint_symbol *symbol, const unsigned char source[],
extern int han_xin(struct zint_symbol * symbol, const unsigned char source[], int length); /* Han Xin */ extern int han_xin(struct zint_symbol * symbol, const unsigned char source[], int length); /* Han Xin */
extern int dotcode(struct zint_symbol * symbol, const unsigned char source[], int length); /* DotCode */ extern int dotcode(struct zint_symbol * symbol, const unsigned char source[], int length); /* DotCode */
extern int codablock(struct zint_symbol * symbol, unsigned char source[], int length); /* Codablock */ extern int codablock(struct zint_symbol * symbol, unsigned char source[], int length); /* Codablock */
extern int upnqr(struct zint_symbol *symbol, const unsigned char source[], int length); /* UPNQR */
extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */ extern int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to PNG/BMP/PCX */
extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels */ extern int render_plot(struct zint_symbol *symbol, float width, float height); /* Plot to gLabels */
@ -459,6 +460,7 @@ static int is_matrix(const int symbology) {
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_DOTCODE: case BARCODE_DOTCODE:
case BARCODE_UPNQR:
result = 1; result = 1;
break; break;
} }
@ -482,6 +484,7 @@ static int supports_eci(const int symbology) {
case BARCODE_DOTCODE: case BARCODE_DOTCODE:
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_UPNQR:
result = 1; result = 1;
break; break;
} }
@ -584,6 +587,7 @@ int ZBarcode_ValidID(int symbol_id) {
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_DOTCODE: case BARCODE_DOTCODE:
case BARCODE_CODABLOCKF: case BARCODE_CODABLOCKF:
case BARCODE_UPNQR:
result = 1; result = 1;
break; break;
} }
@ -604,6 +608,8 @@ static int extended_charset(struct zint_symbol *symbol, const unsigned char *sou
break; break;
case BARCODE_HANXIN: error_number = han_xin(symbol, source, length); case BARCODE_HANXIN: error_number = han_xin(symbol, source, length);
break; break;
case BARCODE_UPNQR: error_number = upnqr(symbol, source, length);
break;
} }
return error_number; return error_number;
@ -958,7 +964,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
error_number = ZINT_WARN_INVALID_OPTION; error_number = ZINT_WARN_INVALID_OPTION;
} }
/* Everything from 128 up is Zint-specific */ /* Everything from 128 up is Zint-specific */
if (symbol->symbology >= 143) { if (symbol->symbology >= 144) {
strcpy(symbol->errtxt, "Symbology out of range, using Code 128 (B16)"); strcpy(symbol->errtxt, "Symbology out of range, using Code 128 (B16)");
symbol->symbology = BARCODE_CODE128; symbol->symbology = BARCODE_CODE128;
error_number = ZINT_WARN_INVALID_OPTION; error_number = ZINT_WARN_INVALID_OPTION;
@ -1017,6 +1023,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
case BARCODE_MICROQR: case BARCODE_MICROQR:
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_UPNQR:
error_number = extended_charset(symbol, local_source, length); error_number = extended_charset(symbol, local_source, length);
break; break;
default: default:

View File

@ -2947,3 +2947,100 @@ int microqr(struct zint_symbol *symbol, const unsigned char source[], int length
return 0; return 0;
} }
/* For UPNQR the symbol size and error correction capacity is fixed */
int upnqr(struct zint_symbol *symbol, const unsigned char source[], int length) {
int i, j, est_binlen;
int ecc_level, version, max_cw, target_binlen, blocks, size;
int bitmask;
#ifndef _MSC_VER
int jisdata[length + 1];
char mode[length + 1];
#else
int* datastream;
int* fullstream;
unsigned char* grid;
int* jisdata = (int *) _alloca((length + 1) * sizeof (int));
char* mode = (char *) _alloca(length + 1);
#endif
switch(symbol->eci) {
case 3:
/* Convert input to ISO-8859-2 */
strcpy(symbol->errtxt, "Not implemented yet!");
return ZINT_ERROR_INVALID_DATA;
break;
case 4:
/* Input is already in ISO-8859-2 format */
for (i = 0; i < length; i++) {
jisdata[i] = (int) source[i];
mode[i] = 'B';
}
break;
default:
strcpy(symbol->errtxt, "Input data should be in Unicode or ISO-8859-2 format");
return ZINT_ERROR_INVALID_DATA;
break;
}
symbol->eci = 4;
est_binlen = estimate_binary_length(mode, length, 0, symbol->eci);
ecc_level = LEVEL_M;
max_cw = 2334;
if (est_binlen > (8 * max_cw)) {
strcpy(symbol->errtxt, "Input too long for selected error correction level (E61)");
return ZINT_ERROR_TOO_LONG;
}
version = 15; // 77 x 77
target_binlen = qr_data_codewords_M[version - 1];
blocks = qr_blocks_M[version - 1];
#ifndef _MSC_VER
int datastream[target_binlen + 1];
int fullstream[qr_total_codewords[version - 1] + 1];
#else
datastream = (int *) _alloca((target_binlen + 1) * sizeof (int));
fullstream = (int *) _alloca((qr_total_codewords[version - 1] + 1) * sizeof (int));
#endif
qr_binary(datastream, version, target_binlen, mode, jisdata, length, 0, symbol->eci, est_binlen, symbol->debug);
add_ecc(fullstream, datastream, version, target_binlen, blocks);
size = qr_sizes[version - 1];
#ifndef _MSC_VER
unsigned char grid[size * size];
#else
grid = (unsigned char *) _alloca((size * size) * sizeof (unsigned char));
#endif
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
grid[(i * size) + j] = 0;
}
}
setup_grid(grid, size, version);
populate_grid(grid, size, fullstream, qr_total_codewords[version - 1]);
bitmask = apply_bitmask(grid, size, ecc_level);
add_format_info(grid, size, ecc_level, bitmask);
symbol->width = size;
symbol->rows = size;
for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
if (grid[(i * size) + j] & 0x01) {
set_module(symbol, i, j);
}
}
symbol->row_height[i] = 1;
}
return 0;
}

View File

@ -201,6 +201,7 @@ extern "C" {
#define BARCODE_CHANNEL 140 #define BARCODE_CHANNEL 140
#define BARCODE_CODEONE 141 #define BARCODE_CODEONE 141
#define BARCODE_GRIDMATRIX 142 #define BARCODE_GRIDMATRIX 142
#define BARCODE_UPNQR 143
// Output options // Output options
#define BARCODE_NO_ASCII 1 #define BARCODE_NO_ASCII 1

View File

@ -66,7 +66,7 @@ void types(void) {
"38: UPC-E + Check 85: USPS OneCode 140: Channel Code\n" "38: UPC-E + Check 85: USPS OneCode 140: Channel Code\n"
"40: Postnet 86: UK Plessey 141: Code One\n" "40: Postnet 86: UK Plessey 141: Code One\n"
"47: MSI Plessey 87: Telepen Numeric 142: Grid Matrix\n" "47: MSI Plessey 87: Telepen Numeric 142: Grid Matrix\n"
"49: FIM 89: ITF-14\n" "49: FIM 89: ITF-14 143: UPNQR\n"
); );
} }