From 5a8bbb28f086a9988872f204a0ba68230b1d2ebd Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 4 Oct 2020 10:32:57 +0100 Subject: [PATCH] Ultracode: Fix miscalculation of number of codewords when using reader initialisation --- README | 1 + backend/ultra.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README b/README index fafa3243..e1278fbe 100644 --- a/README +++ b/README @@ -289,6 +289,7 @@ Bugs: - Code16k selects GS1 mode by default in GUI - Ultracode: use white pixels instead background for white modules. - EMF: fix Ultracode colours. +- Ultracode: fix count of codewords when using reader init mode CONTACT US ---------- diff --git a/backend/ultra.c b/backend/ultra.c index 8f58181f..e3e9c3fb 100644 --- a/backend/ultra.c +++ b/backend/ultra.c @@ -660,6 +660,7 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c if (symbol->output_options & READER_INIT) { /* Reader Initialisation mode */ + codeword_count = 2; if (symbol_mode == ASCII_MODE) { codewords[0] = 272; // 7-bit ASCII mode codewords[1] = 271; // FNC3 @@ -667,9 +668,9 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c codewords[0] = 257; // 8859-1 codewords[1] = 269; // FNC3 } - codeword_count = 2; } else { /* Calculate start character codeword */ + codeword_count = 1; if (symbol_mode == ASCII_MODE) { if (gs1) { codewords[0] = 273; @@ -688,7 +689,7 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c // ECI indicates use of character set outside ISO/IEC 8859 codewords[0] = 275 + (symbol->eci / 256); codewords[1] = symbol->eci % 256; - codeword_count++; + codeword_count = 2; } else if (symbol->eci == 899) { // Non-language byte data codewords[0] = 280; @@ -699,7 +700,7 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c codewords[1] = 274; // Encode ECI as 3 codewords codewords[2] = (symbol->eci / 100) + 128; codewords[3] = (symbol->eci % 100) + 128; - codeword_count += 3; + codeword_count = 4; } else if (symbol->eci >= 10000) { // Encode as 4 codewords codewords[0] = 257; // ISO/IEC 8859-1 used to enter 8-bit mode @@ -707,7 +708,7 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c codewords[2] = (symbol->eci / 10000) + 128; codewords[3] = ((symbol->eci % 10000) / 100) + 128; codewords[4] = (symbol->eci % 100) + 128; - codeword_count += 4; + codeword_count = 5; } else { codewords[0] = 257; // Default is assumed to be ISO/IEC 8859-1 (ECI 3) } @@ -733,8 +734,6 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c } } - codeword_count++; - /* Check for 06 Macro Sequence and crop accordingly */ if (in_length >= 9 && source[0] == '[' && source[1] == ')' && source[2] == '>' && source[3] == '\x1e' @@ -969,6 +968,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, const unsigned char source[], locn = 0; /* Calculate error correction codewords (RSEC) */ + ultra_gf283((short) data_cw_count, (short) qcc, data_codewords); /* Rearrange to make final codeword sequence */