From 8afa0a24c6cd5cd15170d90fd1d62338b9783b32 Mon Sep 17 00:00:00 2001 From: Robin Stuart Date: Sun, 24 Oct 2010 16:19:29 +0100 Subject: [PATCH] Bugfix for 144x144 size Data Matrix Conform with non-standard convention which now allows proper decoding of 144x144 size symbols. Thanks to Terry Burton from Barcode Writer in Pure Postscript for the tip-off. Ref: http://groups.google.com/group/postscriptbarcode/msg/5ae8fda7757477da --- backend/dmatrix.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 90021f7f..d370d6c9 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -163,20 +163,32 @@ static void ecc200placement(int *array, int NR, int NC) } // calculate and append ecc code, and if necessary interleave -static void ecc200(unsigned char *binary, int bytes, int datablock, int rsblock) +static void ecc200(unsigned char *binary, int bytes, int datablock, int rsblock, int skew) { int blocks = (bytes + 2) / datablock, b; + int n, p; rs_init_gf(0x12d); rs_init_code(rsblock, 1); for (b = 0; b < blocks; b++) { unsigned char buf[256], ecc[256]; - int n, p = 0; + p = 0; for (n = b; n < bytes; n += blocks) buf[p++] = binary[n]; rs_encode(p, buf, ecc); p = rsblock - 1; // comes back reversed - for (n = b; n < rsblock * blocks; n += blocks) - binary[bytes + n] = ecc[p--]; + for (n = b; n < rsblock * blocks; n += blocks) { + if (skew) { + /* Rotate ecc data to make 144x144 size symbols acceptable */ + /* See http://groups.google.com/group/postscriptbarcode/msg/5ae8fda7757477da */ + if(b < 8) { + binary[bytes + n + 2] = ecc[p--]; + } else { + binary[bytes + n - 8] = ecc[p--]; + } + } else { + binary[bytes + n] = ecc[p--]; + } + } } rs_free(); } @@ -219,6 +231,8 @@ int look_ahead_test(unsigned char source[], int sourcelen, int position, int cur /* A custom version of the 'look ahead test' from Annex P */ /* This version is deliberately very reluctant to end a data stream with EDIFACT encoding */ + return DM_ASCII; + float ascii_count, c40_count, text_count, x12_count, edf_count, b256_count, best_count; int sp, done, best_scheme; char reduced_char; @@ -763,7 +777,7 @@ void add_tail(unsigned char target[], int tp, int tail_length, int last_mode) int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length) { - int inputlen, i; + int inputlen, i, skew = 0; unsigned char binary[2200]; int binlen; int symbolsize, optionsize, calcsize; @@ -831,7 +845,8 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng } // ecc code - ecc200(binary, bytes, datablock, rsblock); + if(symbolsize == 29) { skew = 1; } + ecc200(binary, bytes, datablock, rsblock, skew); { // placement int x, y, NC, NR, *places; NC = W - 2 * (W / FW);