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
This commit is contained in:
Robin Stuart 2010-10-24 16:19:29 +01:00
parent 6792246fe9
commit 8afa0a24c6

View File

@ -163,21 +163,33 @@ static void ecc200placement(int *array, int NR, int NC)
} }
// calculate and append ecc code, and if necessary interleave // 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 blocks = (bytes + 2) / datablock, b;
int n, p;
rs_init_gf(0x12d); rs_init_gf(0x12d);
rs_init_code(rsblock, 1); rs_init_code(rsblock, 1);
for (b = 0; b < blocks; b++) { for (b = 0; b < blocks; b++) {
unsigned char buf[256], ecc[256]; unsigned char buf[256], ecc[256];
int n, p = 0; p = 0;
for (n = b; n < bytes; n += blocks) for (n = b; n < bytes; n += blocks)
buf[p++] = binary[n]; buf[p++] = binary[n];
rs_encode(p, buf, ecc); rs_encode(p, buf, ecc);
p = rsblock - 1; // comes back reversed p = rsblock - 1; // comes back reversed
for (n = b; n < rsblock * blocks; n += blocks) 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--]; binary[bytes + n] = ecc[p--];
} }
}
}
rs_free(); 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 */ /* 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 */ /* 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; float ascii_count, c40_count, text_count, x12_count, edf_count, b256_count, best_count;
int sp, done, best_scheme; int sp, done, best_scheme;
char reduced_char; 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 data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length)
{ {
int inputlen, i; int inputlen, i, skew = 0;
unsigned char binary[2200]; unsigned char binary[2200];
int binlen; int binlen;
int symbolsize, optionsize, calcsize; int symbolsize, optionsize, calcsize;
@ -831,7 +845,8 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
} }
// ecc code // ecc code
ecc200(binary, bytes, datablock, rsblock); if(symbolsize == 29) { skew = 1; }
ecc200(binary, bytes, datablock, rsblock, skew);
{ // placement { // placement
int x, y, NC, NR, *places; int x, y, NC, NR, *places;
NC = W - 2 * (W / FW); NC = W - 2 * (W / FW);