Code format and audit, part 1

Update copyright info, remove unused code, etc.
This commit is contained in:
Robin Stuart 2016-02-20 09:38:03 +00:00
parent ae335b104a
commit 77cdf77690
23 changed files with 21568 additions and 20025 deletions

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -39,22 +39,27 @@
#define inline _inline #define inline _inline
#endif #endif
static const char *C25MatrixTable[10] = {"113311", "311131", "131131", "331111", "113131", "313111", static const char *C25MatrixTable[10] = {
"133111", "111331", "311311", "131311"}; "113311", "311131", "131131", "331111", "113131", "313111",
"133111", "111331", "311311", "131311"
};
static const char *C25IndustTable[10] = {"1111313111", "3111111131", "1131111131", "3131111111", "1111311131", static const char *C25IndustTable[10] = {
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"}; "1111313111", "3111111131", "1131111131", "3131111111", "1111311131",
"3111311111", "1131311111", "1111113131", "3111113111", "1131113111"
};
static const char *C25InterTable[10] = {"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133", static const char *C25InterTable[10] = {
"31131", "13131"}; "11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133",
"31131", "13131"
};
static inline char check_digit(unsigned int count) static inline char check_digit(unsigned int count) {
{
return itoc((10 - (count % 10)) % 10); return itoc((10 - (count % 10)) % 10);
} }
int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
{ /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/ char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
@ -86,8 +91,8 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l
return error_number; return error_number;
} }
int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Industrial */
{ /* Code 2 of 5 Industrial */ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
char dest[512]; /* 6 + 40 * 10 + 6 + 1 */ char dest[512]; /* 6 + 40 * 10 + 6 + 1 */
@ -119,8 +124,8 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i
return error_number; return error_number;
} }
int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 IATA */
{ /* Code 2 of 5 IATA */ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
char dest[512]; /* 4 + 45 * 10 + 3 + 1 */ char dest[512]; /* 4 + 45 * 10 + 3 + 1 */
@ -151,8 +156,8 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int len
return error_number; return error_number;
} }
int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Data Logic */
{ /* Code 2 of 5 Data Logic */ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */ char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
@ -184,8 +189,8 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int le
return error_number; return error_number;
} }
int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 2 of 5 Interleaved */
{ /* Code 2 of 5 Interleaved */ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, k, error_number; int i, j, k, error_number;
char bars[7], spaces[7], mixed[14], dest[1000]; char bars[7], spaces[7], mixed[14], dest[1000];
@ -210,8 +215,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
ustrcpy(temp, (unsigned char *) ""); ustrcpy(temp, (unsigned char *) "");
/* Input must be an even number of characters for Interlaced 2 of 5 to work: /* Input must be an even number of characters for Interlaced 2 of 5 to work:
if an odd number of characters has been entered then add a leading zero */ if an odd number of characters has been entered then add a leading zero */
if (length & 1) if (length & 1) {
{
ustrcpy(temp, (unsigned char *) "0"); ustrcpy(temp, (unsigned char *) "0");
length++; length++;
} }
@ -220,8 +224,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
/* start character */ /* start character */
strcpy(dest, "1111"); strcpy(dest, "1111");
for(i = 0; i < length; i+=2 ) for (i = 0; i < length; i += 2) {
{
/* look up the bars and the spaces and put them in two strings */ /* look up the bars and the spaces and put them in two strings */
strcpy(bars, ""); strcpy(bars, "");
lookup(NEON, C25InterTable, temp[i], bars); lookup(NEON, C25InterTable, temp[i], bars);
@ -230,10 +233,11 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
/* then merge (interlace) the strings together */ /* then merge (interlace) the strings together */
k = 0; k = 0;
for(j = 0; j <= 4; j++) for (j = 0; j <= 4; j++) {
{ mixed[k] = bars[j];
mixed[k] = bars[j]; k++; k++;
mixed[k] = spaces[j]; k++; mixed[k] = spaces[j];
k++;
} }
mixed[k] = '\0'; mixed[k] = '\0';
concat(dest, mixed); concat(dest, mixed);
@ -248,8 +252,8 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
} }
int itf14(struct zint_symbol *symbol, unsigned char source[], int length) /* Interleaved 2-of-5 (ITF) */
{ int itf14(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count; unsigned int count;
char localstr[16]; char localstr[16];
@ -277,7 +281,6 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(localstr + zeroes, (char *) source); strcpy(localstr + zeroes, (char *) source);
/* Calculate the check digit - the same method used for EAN-13 */ /* Calculate the check digit - the same method used for EAN-13 */
for (i = 12; i >= 0; i--) { for (i = 12; i >= 0; i--) {
count += ctoi(localstr[i]); count += ctoi(localstr[i]);
@ -292,8 +295,8 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) /* Deutshe Post Leitcode */
{ /* Deutshe Post Leitcode */ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number; int i, error_number;
unsigned int count; unsigned int count;
char localstr[16]; char localstr[16];
@ -316,8 +319,7 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
localstr[i] = '0'; localstr[i] = '0';
strcpy(localstr + zeroes, (char *) source); strcpy(localstr + zeroes, (char *) source);
for (i = 12; i >= 0; i--) for (i = 12; i >= 0; i--) {
{
count += 4 * ctoi(localstr[i]); count += 4 * ctoi(localstr[i]);
if (i & 1) { if (i & 1) {
@ -331,8 +333,8 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int dpident(struct zint_symbol *symbol, unsigned char source[], int length) /* Deutsche Post Identcode */
{ /* Deutsche Post Identcode */ int dpident(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count; unsigned int count;
char localstr[16]; char localstr[16];
@ -353,8 +355,7 @@ int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
localstr[i] = '0'; localstr[i] = '0';
strcpy(localstr + zeroes, (char *) source); strcpy(localstr + zeroes, (char *) source);
for (i = 10; i >= 0; i--) for (i = 10; i >= 0; i--) {
{
count += 4 * ctoi(localstr[i]); count += 4 * ctoi(localstr[i]);
if (i & 1) { if (i & 1) {

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -32,21 +32,27 @@
#define GDSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #" #define GDSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
static const char *AusNTable[10] = {"00", "01", "02", "10", "11", "12", "20", "21", "22", "30"}; static const char *AusNTable[10] = {
"00", "01", "02", "10", "11", "12", "20", "21", "22", "30"
};
static const char *AusCTable[64] = {"222", "300", "301", "302", "310", "311", "312", "320", "321", "322", static const char *AusCTable[64] = {
"222", "300", "301", "302", "310", "311", "312", "320", "321", "322",
"000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110", "000", "001", "002", "010", "011", "012", "020", "021", "022", "100", "101", "102", "110",
"111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221", "111", "112", "120", "121", "122", "200", "201", "202", "210", "211", "212", "220", "221",
"023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203", "023", "030", "031", "032", "033", "103", "113", "123", "130", "131", "132", "133", "203",
"213", "223", "230", "231", "232", "233", "303", "313", "323", "330", "331", "332", "333", "213", "223", "230", "231", "232", "233", "303", "313", "323", "330", "331", "332", "333",
"003", "013"}; "003", "013"
};
static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011", "012", "013", "020", "021", static const char *AusBarTable[64] = {
"000", "001", "002", "003", "010", "011", "012", "013", "020", "021",
"022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112", "022", "023", "030", "031", "032", "033", "100", "101", "102", "103", "110", "111", "112",
"113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203", "113", "120", "121", "122", "123", "130", "131", "132", "133", "200", "201", "202", "203",
"210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300", "210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300",
"301", "302", "303", "310", "311", "312", "313", "320", "321", "322", "323", "330", "331", "301", "302", "303", "310", "311", "312", "313", "320", "321", "322", "323", "330", "331",
"332", "333"}; "332", "333"
};
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -57,28 +63,23 @@ static const char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011",
#define inline _inline #define inline _inline
#endif #endif
static inline char convert_pattern(char data, int shift) static inline char convert_pattern(char data, int shift) {
{
return (data - '0') << shift; return (data - '0') << shift;
} }
void rs_error(char data_pattern[])
{
/* Adds Reed-Solomon error correction to auspost */ /* Adds Reed-Solomon error correction to auspost */
void rs_error(char data_pattern[]) {
int reader, triple_writer = 0; int reader, triple_writer = 0;
char triple[31], inv_triple[31]; char triple[31], inv_triple[31];
unsigned char result[5]; unsigned char result[5];
for(reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++) for (reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++) {
{
triple[triple_writer] = convert_pattern(data_pattern[reader], 4) triple[triple_writer] = convert_pattern(data_pattern[reader], 4)
+ convert_pattern(data_pattern[reader + 1], 2) + convert_pattern(data_pattern[reader + 1], 2)
+ convert_pattern(data_pattern[reader + 2], 0); + convert_pattern(data_pattern[reader + 2], 0);
} }
for(reader = 0; reader < triple_writer; reader++) for (reader = 0; reader < triple_writer; reader++) {
{
inv_triple[reader] = triple[(triple_writer - 1) - reader]; inv_triple[reader] = triple[(triple_writer - 1) - reader];
} }
@ -86,16 +87,14 @@ void rs_error(char data_pattern[])
rs_init_code(4, 1); rs_init_code(4, 1);
rs_encode(triple_writer, (unsigned char*) inv_triple, result); rs_encode(triple_writer, (unsigned char*) inv_triple, result);
for(reader = 4; reader > 0; reader--) for (reader = 4; reader > 0; reader--) {
{
concat(data_pattern, AusBarTable[(int) result[reader - 1]]); concat(data_pattern, AusBarTable[(int) result[reader - 1]]);
} }
rs_free(); rs_free();
} }
int australia_post(struct zint_symbol *symbol, unsigned char source[], int length)
{
/* Handles Australia Posts's 4 State Codes */ /* Handles Australia Posts's 4 State Codes */
int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically /* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically
(i.e. the FCC doesn't need to be specified by the user) dependent (i.e. the FCC doesn't need to be specified by the user) dependent
on the length of the input string */ on the length of the input string */
@ -119,8 +118,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Do all of the length checking first to avoid stack smashing */ /* Do all of the length checking first to avoid stack smashing */
if (symbol->symbology == BARCODE_AUSPOST) { if (symbol->symbology == BARCODE_AUSPOST) {
/* Format control code (FCC) */ /* Format control code (FCC) */
switch(length) switch (length) {
{
case 8: case 8:
strcpy(fcc, "11"); strcpy(fcc, "11");
break; break;
@ -152,9 +150,12 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
switch (symbol->symbology) { switch (symbol->symbology) {
case BARCODE_AUSREPLY: strcpy(fcc, "45"); break; case BARCODE_AUSREPLY: strcpy(fcc, "45");
case BARCODE_AUSROUTE: strcpy(fcc, "87"); break; break;
case BARCODE_AUSREDIRECT: strcpy(fcc, "92"); break; case BARCODE_AUSROUTE: strcpy(fcc, "87");
break;
case BARCODE_AUSREDIRECT: strcpy(fcc, "92");
break;
} }
/* Add leading zeros as required */ /* Add leading zeros as required */
@ -184,28 +185,24 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
strcpy(data_pattern, "13"); strcpy(data_pattern, "13");
/* Encode the FCC */ /* Encode the FCC */
for(reader = 0; reader < 2; reader++) for (reader = 0; reader < 2; reader++) {
{
lookup(NEON, AusNTable, fcc[reader], data_pattern); lookup(NEON, AusNTable, fcc[reader], data_pattern);
} }
/* printf("AUSPOST FCC: %s ", fcc); */ /* printf("AUSPOST FCC: %s ", fcc); */
/* Delivery Point Identifier (DPID) */ /* Delivery Point Identifier (DPID) */
for(reader = 0; reader < 8; reader++) for (reader = 0; reader < 8; reader++) {
{
lookup(NEON, AusNTable, dpid[reader], data_pattern); lookup(NEON, AusNTable, dpid[reader], data_pattern);
} }
/* Customer Information */ /* Customer Information */
if(h > 8) if (h > 8) {
{
if ((h == 13) || (h == 18)) { if ((h == 13) || (h == 18)) {
for (reader = 8; reader < h; reader++) { for (reader = 8; reader < h; reader++) {
lookup(GDSET, AusCTable, localstr[reader], data_pattern); lookup(GDSET, AusCTable, localstr[reader], data_pattern);
} }
} } else if ((h == 16) || (h == 23)) {
else if((h == 16) || (h == 23)) {
for (reader = 8; reader < h; reader++) { for (reader = 8; reader < h; reader++) {
lookup(NEON, AusNTable, localstr[reader], data_pattern); lookup(NEON, AusNTable, localstr[reader], data_pattern);
} }
@ -214,8 +211,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Filler bar */ /* Filler bar */
h = strlen(data_pattern); h = strlen(data_pattern);
switch (h) switch (h) {
{
case 22: case 22:
case 37: case 37:
case 52: case 52:
@ -234,15 +230,12 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Turn the symbol into a bar pattern ready for plotting */ /* Turn the symbol into a bar pattern ready for plotting */
writer = 0; writer = 0;
h = strlen(data_pattern); h = strlen(data_pattern);
for(loopey = 0; loopey < h; loopey++) for (loopey = 0; loopey < h; loopey++) {
{ if ((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0')) {
if((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0'))
{
set_module(symbol, 0, writer); set_module(symbol, 0, writer);
} }
set_module(symbol, 1, writer); set_module(symbol, 1, writer);
if((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) if ((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) {
{
set_module(symbol, 2, writer); set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -43,8 +43,7 @@
/** /**
* Shorten the string by one character * Shorten the string by one character
*/ */
void mapshorten(int *charmap, int *typemap, int start, int length) void mapshorten(int *charmap, int *typemap, int start, int length) {
{
memmove(charmap + start + 1, charmap + start + 2, (length - 1) * sizeof (int)); memmove(charmap + start + 1, charmap + start + 2, (length - 1) * sizeof (int));
memmove(typemap + start + 1, typemap + start + 2, (length - 1) * sizeof (int)); memmove(typemap + start + 1, typemap + start + 2, (length - 1) * sizeof (int));
} }
@ -52,8 +51,7 @@ void mapshorten(int *charmap, int *typemap, int start, int length)
/** /**
* Insert a character into the middle of a string at position posn * Insert a character into the middle of a string at position posn
*/ */
void insert(char binary_string[], int posn, char newbit) void insert(char binary_string[], int posn, char newbit) {
{
int i, end; int i, end;
end = strlen(binary_string); end = strlen(binary_string);
@ -66,8 +64,7 @@ void insert(char binary_string[], int posn, char newbit)
/** /**
* Encode input data into a binary string * Encode input data into a binary string
*/ */
int aztec_text_process(unsigned char source[], const unsigned int src_len, char binary_string[], int gs1) int aztec_text_process(unsigned char source[], const unsigned int src_len, char binary_string[], int gs1) {
{
int i, j, k, bytes; int i, j, k, bytes;
int curtable, newtable, lasttable, chartype, maplength, blocks, debug; int curtable, newtable, lasttable, chartype, maplength, blocks, debug;
#ifndef _MSC_VER #ifndef _MSC_VER
@ -112,7 +109,8 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
/* Look for double character encoding possibilities */ /* Look for double character encoding possibilities */
i = 0; i = 0;
do { do {
if(((charmap[i] == 300) && (charmap[i + 1] == 11)) && ((typemap[i] == PUNC) && (typemap[i + 1] == PUNC))) { if (((charmap[i] == 300) && (charmap[i + 1] == 11))
&& ((typemap[i] == PUNC) && (typemap[i + 1] == PUNC))) {
/* CR LF combination */ /* CR LF combination */
charmap[i] = 2; charmap[i] = 2;
typemap[i] = PUNC; typemap[i] = PUNC;
@ -120,7 +118,8 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
maplength--; maplength--;
} }
if(((charmap[i] == 302) && (charmap[i + 1] == 1)) && ((typemap[i] == 24) && (typemap[i + 1] == 23))) { if (((charmap[i] == 302) && (charmap[i + 1] == 1))
&& ((typemap[i] == 24) && (typemap[i + 1] == 23))) {
/* . SP combination */ /* . SP combination */
charmap[i] = 3; charmap[i] = 3;
typemap[i] = PUNC; typemap[i] = PUNC;
@ -128,7 +127,8 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
maplength--; maplength--;
} }
if(((charmap[i] == 301) && (charmap[i + 1] == 1)) && ((typemap[i] == 24) && (typemap[i + 1] == 23))) { if (((charmap[i] == 301) && (charmap[i + 1] == 1))
&& ((typemap[i] == 24) && (typemap[i + 1] == 23))) {
/* , SP combination */ /* , SP combination */
charmap[i] = 4; charmap[i] = 4;
typemap[i] = PUNC; typemap[i] = PUNC;
@ -136,7 +136,8 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
maplength--; maplength--;
} }
if(((charmap[i] == 21) && (charmap[i + 1] == 1)) && ((typemap[i] == PUNC) && (typemap[i + 1] == 23))) { if (((charmap[i] == 21) && (charmap[i + 1] == 1))
&& ((typemap[i] == PUNC) && (typemap[i + 1] == 23))) {
/* : SP combination */ /* : SP combination */
charmap[i] = 5; charmap[i] = 5;
typemap[i] = PUNC; typemap[i] = PUNC;
@ -161,10 +162,18 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
} }
} }
if(blockmap[0][0] & 1) { blockmap[0][0] = 1; } if (blockmap[0][0] & 1) {
if(blockmap[0][0] & 2) { blockmap[0][0] = 2; } blockmap[0][0] = 1;
if(blockmap[0][0] & 4) { blockmap[0][0] = 4; } }
if(blockmap[0][0] & 8) { blockmap[0][0] = 8; } if (blockmap[0][0] & 2) {
blockmap[0][0] = 2;
}
if (blockmap[0][0] & 4) {
blockmap[0][0] = 4;
}
if (blockmap[0][0] & 8) {
blockmap[0][0] = 8;
}
if (blocks > 1) { if (blocks > 1) {
/* look for adjacent blocks which can use the same table (left to right search) */ /* look for adjacent blocks which can use the same table (left to right search) */
@ -174,10 +183,18 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
} }
} }
if(blockmap[0][blocks - 1] & 1) { blockmap[0][blocks - 1] = 1; } if (blockmap[0][blocks - 1] & 1) {
if(blockmap[0][blocks - 1] & 2) { blockmap[0][blocks - 1] = 2; } blockmap[0][blocks - 1] = 1;
if(blockmap[0][blocks - 1] & 4) { blockmap[0][blocks - 1] = 4; } }
if(blockmap[0][blocks - 1] & 8) { blockmap[0][blocks - 1] = 8; } if (blockmap[0][blocks - 1] & 2) {
blockmap[0][blocks - 1] = 2;
}
if (blockmap[0][blocks - 1] & 4) {
blockmap[0][blocks - 1] = 4;
}
if (blockmap[0][blocks - 1] & 8) {
blockmap[0][blocks - 1] = 8;
}
/* look for adjacent blocks which can use the same table (right to left search) */ /* look for adjacent blocks which can use the same table (right to left search) */
for (i = blocks - 1; i > 0; i--) { for (i = blocks - 1; i > 0; i--) {
@ -188,10 +205,18 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
/* determine the encoding table for characters which do not fit with adjacent blocks */ /* determine the encoding table for characters which do not fit with adjacent blocks */
for (i = 1; i < blocks; i++) { for (i = 1; i < blocks; i++) {
if(blockmap[0][i] & 8) { blockmap[0][i] = 8; } if (blockmap[0][i] & 8) {
if(blockmap[0][i] & 4) { blockmap[0][i] = 4; } blockmap[0][i] = 8;
if(blockmap[0][i] & 2) { blockmap[0][i] = 2; } }
if(blockmap[0][i] & 1) { blockmap[0][i] = 1; } if (blockmap[0][i] & 4) {
blockmap[0][i] = 4;
}
if (blockmap[0][i] & 2) {
blockmap[0][i] = 2;
}
if (blockmap[0][i] & 1) {
blockmap[0][i] = 1;
}
} }
/* Combine blocks of the same type */ /* Combine blocks of the same type */
@ -213,7 +238,8 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
/* Put the adjusted block data back into typemap */ /* Put the adjusted block data back into typemap */
j = 0; j = 0;
for (i = 0; i < blocks; i++) { for (i = 0; i < blocks; i++) {
if((blockmap[1][i] < 3) && (blockmap[0][i] != 32)) { /* Shift character(s) needed */ if ((blockmap[1][i] < 3) && (blockmap[0][i] != 32)) {
/* Shift character(s) needed */
for (k = 0; k < blockmap[1][i]; k++) { for (k = 0; k < blockmap[1][i]; k++) {
typemap[j + k] = blockmap[0][i] + 64; typemap[j + k] = blockmap[0][i] + 64;
} }
@ -226,9 +252,12 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
} }
/* Don't shift an initial capital letter */ /* Don't shift an initial capital letter */
if(typemap[0] == 65) { typemap[0] = 1; }; if (typemap[0] == 65) {
typemap[0] = 1;
};
/* Problem characters (those that appear in different tables with different values) can now be resolved into their tables */ /* Problem characters (those that appear in different tables with
* different values) can now be resolved into their tables */
for (i = 0; i < maplength; i++) { for (i = 0; i < maplength; i++) {
if ((charmap[i] >= 300) && (charmap[i] < 400)) { if ((charmap[i] >= 300) && (charmap[i] < 400)) {
curtable = typemap[i]; curtable = typemap[i];
@ -238,20 +267,26 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
switch (charmap[i]) { switch (charmap[i]) {
case 300: /* Carriage Return */ case 300: /* Carriage Return */
switch (curtable) { switch (curtable) {
case PUNC: charmap[i] = 1; break; case PUNC: charmap[i] = 1;
case MIXED: charmap[i] = 14; break; break;
case MIXED: charmap[i] = 14;
break;
} }
break; break;
case 301: /* Comma */ case 301: /* Comma */
switch (curtable) { switch (curtable) {
case PUNC: charmap[i] = 17; break; case PUNC: charmap[i] = 17;
case DIGIT: charmap[i] = 12; break; break;
case DIGIT: charmap[i] = 12;
break;
} }
break; break;
case 302: /* Full Stop */ case 302: /* Full Stop */
switch (curtable) { switch (curtable) {
case PUNC: charmap[i] = 19; break; case PUNC: charmap[i] = 19;
case DIGIT: charmap[i] = 13; break; break;
case DIGIT: charmap[i] = 13;
break;
} }
break; break;
} }
@ -591,28 +626,26 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
if(bytes > 31) { /* Put 00000 followed by 11-bit number of bytes less 31 */ if (bytes > 31) {
int adjusted; /* Put 00000 followed by 11-bit number of bytes less 31 */
adjusted = bytes - 31;
concat(binary_string, "00000"); concat(binary_string, "00000");
if(adjusted & 0x400) { concat(binary_string, "1"); } else { concat(binary_string, "0"); }
if(adjusted & 0x200) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } for (int p = 0; p < 11; p++) {
if(adjusted & 0x100) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } if ((bytes - 31) & (0x400 >> p)) {
if(adjusted & 0x80) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "1");
if(adjusted & 0x40) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } } else {
if(adjusted & 0x20) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "0");
if(adjusted & 0x10) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
if(adjusted & 0x08) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
if(adjusted & 0x04) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } } else {
if(adjusted & 0x02) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } /* Put 5-bit number of bytes */
if(adjusted & 0x01) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } for (int p = 0; p < 5; p++) {
} else { /* Put 5-bit number of bytes */ if (bytes & (0x10 >> p)) {
if(bytes & 0x10) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "1");
if(bytes & 0x08) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } } else {
if(bytes & 0x04) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "0");
if(bytes & 0x02) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
if(bytes & 0x01) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
} }
if (debug) printf("(%d bytes) ", bytes); if (debug) printf("(%d bytes) ", bytes);
@ -623,7 +656,9 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
/* Add data to the binary string */ /* Add data to the binary string */
curtable = newtable; curtable = newtable;
chartype = typemap[i]; chartype = typemap[i];
if(chartype > 64) { chartype -= 64; } if (chartype > 64) {
chartype -= 64;
}
switch (chartype) { switch (chartype) {
case UPPER: case UPPER:
case LOWER: case LOWER:
@ -643,14 +678,13 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
if (debug) printf("%d ", charmap[i]); if (debug) printf("%d ", charmap[i]);
break; break;
case BINARY: case BINARY:
if(charmap[i] & 0x80) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } for (int p = 0; p < 8; p++) {
if(charmap[i] & 0x40) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } if (charmap[i] & (0x80 >> p)) {
if(charmap[i] & 0x20) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "1");
if(charmap[i] & 0x10) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } } else {
if(charmap[i] & 0x08) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "0");
if(charmap[i] & 0x04) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
if(charmap[i] & 0x02) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
if(charmap[i] & 0x01) { concat(binary_string, "1"); } else { concat(binary_string, "0"); }
if (debug) printf("%d ", charmap[i]); if (debug) printf("%d ", charmap[i]);
break; break;
} }
@ -666,6 +700,7 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char
return 0; return 0;
} }
/* Prevent data from obscuring reference grid */
int avoidReferenceGrid(int input) { int avoidReferenceGrid(int input) {
int output; int output;
@ -701,9 +736,8 @@ int avoidReferenceGrid(int input) {
return output; return output;
} }
void popilate_map()
{
/* Calculate the position of the bits in the grid */ /* Calculate the position of the bits in the grid */
void popilate_map() {
int layer, start, length, n, i; int layer, start, length, n, i;
int x, y; int x, y;
@ -795,20 +829,20 @@ void popilate_map()
} }
/* Descriptor */ /* Descriptor */
for (i = 0; i < 10; i++) { /* Top */ for (i = 0; i < 10; i++) {
/* Top */
AztecMap[(avoidReferenceGrid(66 + i) * 151) + avoidReferenceGrid(64)] = 20000 + i; AztecMap[(avoidReferenceGrid(66 + i) * 151) + avoidReferenceGrid(64)] = 20000 + i;
} }
for (i = 0; i < 10; i++) { /* Right */ for (i = 0; i < 10; i++) {
/* Right */
AztecMap[(avoidReferenceGrid(77) * 151) + avoidReferenceGrid(66 + i)] = 20010 + i; AztecMap[(avoidReferenceGrid(77) * 151) + avoidReferenceGrid(66 + i)] = 20010 + i;
} }
for (i = 0; i < 10; i++) { /* Bottom */ for (i = 0; i < 10; i++) {
/* Bottom */
AztecMap[(avoidReferenceGrid(75 - i) * 151) + avoidReferenceGrid(77)] = 20020 + i; AztecMap[(avoidReferenceGrid(75 - i) * 151) + avoidReferenceGrid(77)] = 20020 + i;
} }
for (i = 0; i < 10; i++) { /* Left */ for (i = 0; i < 10; i++) {
/* Left */
AztecMap[(avoidReferenceGrid(64) * 151) + avoidReferenceGrid(75 - i)] = 20030 + i; AztecMap[(avoidReferenceGrid(64) * 151) + avoidReferenceGrid(75 - i)] = 20030 + i;
} }
@ -821,8 +855,7 @@ void popilate_map()
AztecMap[(avoidReferenceGrid(77) * 151) + avoidReferenceGrid(76)] = 1; AztecMap[(avoidReferenceGrid(77) * 151) + avoidReferenceGrid(76)] = 1;
} }
int aztec(struct zint_symbol *symbol, unsigned char source[], int length) int aztec(struct zint_symbol *symbol, unsigned char source[], int length) {
{
int x, y, i, j, data_blocks, ecc_blocks, layers, total_bits; int x, y, i, j, data_blocks, ecc_blocks, layers, total_bits;
char binary_string[20000], bit_pattern[20045], descriptor[42]; char binary_string[20000], bit_pattern[20045], descriptor[42];
char adjusted_string[20000]; char adjusted_string[20000];
@ -843,8 +876,15 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
memset(binary_string, 0, 20000); memset(binary_string, 0, 20000);
memset(adjusted_string, 0, 20000); memset(adjusted_string, 0, 20000);
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } if (symbol->input_mode == GS1_MODE) {
if(symbol->output_options & READER_INIT) { reader = 1; comp_loop = 1; } gs1 = 1;
} else {
gs1 = 0;
}
if (symbol->output_options & READER_INIT) {
reader = 1;
comp_loop = 1;
}
if ((gs1 == 1) && (reader == 1)) { if ((gs1 == 1) && (reader == 1)) {
strcpy(symbol->errtxt, "Cannot encode in GS1 and Reader Initialisation mode at the same time"); strcpy(symbol->errtxt, "Cannot encode in GS1 and Reader Initialisation mode at the same time");
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
@ -858,7 +898,9 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
break; break;
case UNICODE_MODE: case UNICODE_MODE:
err_code = latin1_process(symbol, source, local_source, &length); err_code = latin1_process(symbol, source, local_source, &length);
if(err_code != 0) { return err_code; } if (err_code != 0) {
return err_code;
}
break; break;
} }
@ -958,18 +1000,26 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
break; break;
} }
if(layers == 0) { /* Couldn't find a symbol which fits the data */ if (layers == 0) {
/* Couldn't find a symbol which fits the data */
strcpy(symbol->errtxt, "Input too long (too many bits for selected ECC)"); strcpy(symbol->errtxt, "Input too long (too many bits for selected ECC)");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
/* Determine codeword bitlength - Table 3 */ /* Determine codeword bitlength - Table 3 */
codeword_size = 6; /* if (layers <= 2) */ codeword_size = 6; /* if (layers <= 2) */
if((layers >= 3) && (layers <= 8)) { codeword_size = 8; } if ((layers >= 3) && (layers <= 8)) {
if((layers >= 9) && (layers <= 22)) { codeword_size = 10; } codeword_size = 8;
if(layers >= 23) { codeword_size = 12; } }
if ((layers >= 9) && (layers <= 22)) {
codeword_size = 10;
}
if (layers >= 23) {
codeword_size = 12;
}
j = 0; i = 0; j = 0;
i = 0;
do { do {
if ((j + 1) % codeword_size == 0) { if ((j + 1) % codeword_size == 0) {
/* Last bit of codeword */ /* Last bit of codeword */
@ -1011,7 +1061,9 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
remainder = adjusted_length % codeword_size; remainder = adjusted_length % codeword_size;
padbits = codeword_size - remainder; padbits = codeword_size - remainder;
if(padbits == codeword_size) { padbits = 0; } if (padbits == codeword_size) {
padbits = 0;
}
for (i = 0; i < padbits; i++) { for (i = 0; i < padbits; i++) {
concat(adjusted_string, "1"); concat(adjusted_string, "1");
@ -1020,9 +1072,13 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
count = 0; count = 0;
for (i = (adjusted_length - codeword_size); i < adjusted_length; i++) { for (i = (adjusted_length - codeword_size); i < adjusted_length; i++) {
if(adjusted_string[i] == '1') { count++; } if (adjusted_string[i] == '1') {
count++;
}
}
if (count == codeword_size) {
adjusted_string[adjusted_length - 1] = '0';
} }
if(count == codeword_size) { adjusted_string[adjusted_length - 1] = '0'; }
if (debug) { if (debug) {
printf("Codewords:\n"); printf("Codewords:\n");
@ -1057,12 +1113,21 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
} }
/* Determine codeword bitlength - Table 3 */ /* Determine codeword bitlength - Table 3 */
if((layers >= 0) && (layers <= 2)) { codeword_size = 6; } if ((layers >= 0) && (layers <= 2)) {
if((layers >= 3) && (layers <= 8)) { codeword_size = 8; } codeword_size = 6;
if((layers >= 9) && (layers <= 22)) { codeword_size = 10; } }
if(layers >= 23) { codeword_size = 12; } if ((layers >= 3) && (layers <= 8)) {
codeword_size = 8;
}
if ((layers >= 9) && (layers <= 22)) {
codeword_size = 10;
}
if (layers >= 23) {
codeword_size = 12;
}
j = 0; i = 0; j = 0;
i = 0;
do { do {
if ((j + 1) % codeword_size == 0) { if ((j + 1) % codeword_size == 0) {
/* Last bit of codeword */ /* Last bit of codeword */
@ -1102,7 +1167,9 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
remainder = adjusted_length % codeword_size; remainder = adjusted_length % codeword_size;
padbits = codeword_size - remainder; padbits = codeword_size - remainder;
if(padbits == codeword_size) { padbits = 0; } if (padbits == codeword_size) {
padbits = 0;
}
for (i = 0; i < padbits; i++) { for (i = 0; i < padbits; i++) {
concat(adjusted_string, "1"); concat(adjusted_string, "1");
@ -1111,9 +1178,13 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
count = 0; count = 0;
for (i = (adjusted_length - codeword_size); i < adjusted_length; i++) { for (i = (adjusted_length - codeword_size); i < adjusted_length; i++) {
if(adjusted_string[i] == '1') { count++; } if (adjusted_string[i] == '1') {
count++;
}
}
if (count == codeword_size) {
adjusted_string[adjusted_length - 1] = '0';
} }
if(count == codeword_size) { adjusted_string[adjusted_length - 1] = '0'; }
/* Check if the data actually fits into the selected symbol size */ /* Check if the data actually fits into the selected symbol size */
if (compact) { if (compact) {
@ -1154,10 +1225,18 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
if (debug) { if (debug) {
printf("Generating a "); printf("Generating a ");
if(compact) { printf("compact"); } else { printf("full-size"); } if (compact) {
printf("compact");
} else {
printf("full-size");
}
printf(" symbol with %d layers\n", layers); printf(" symbol with %d layers\n", layers);
printf("Requires "); printf("Requires ");
if(compact) { printf("%d", AztecCompactSizes[layers - 1]); } else { printf("%d", AztecSizes[layers - 1]); } if (compact) {
printf("%d", AztecCompactSizes[layers - 1]);
} else {
printf("%d", AztecSizes[layers - 1]);
}
printf(" codewords of %d-bits\n", codeword_size); printf(" codewords of %d-bits\n", codeword_size);
printf(" (%d data words, %d ecc words)\n", data_blocks, ecc_blocks); printf(" (%d data words, %d ecc words)\n", data_blocks, ecc_blocks);
} }
@ -1176,113 +1255,89 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
switch (codeword_size) { switch (codeword_size) {
case 6: case 6:
for (i = 0; i < data_blocks; i++) { for (i = 0; i < data_blocks; i++) {
if(adjusted_string[i * codeword_size] == '1') { data_part[i] += 32; } for (int p = 0; p < 6; p++) {
if(adjusted_string[(i * codeword_size) + 1] == '1') { data_part[i] += 16; } if (adjusted_string[i * codeword_size + p] == '1') {
if(adjusted_string[(i * codeword_size) + 2] == '1') { data_part[i] += 8; } data_part[i] += (0x20 >> p);
if(adjusted_string[(i * codeword_size) + 3] == '1') { data_part[i] += 4; } }
if(adjusted_string[(i * codeword_size) + 4] == '1') { data_part[i] += 2; } }
if(adjusted_string[(i * codeword_size) + 5] == '1') { data_part[i] += 1; }
} }
rs_init_gf(0x43); rs_init_gf(0x43);
rs_init_code(ecc_blocks, 1); rs_init_code(ecc_blocks, 1);
rs_encode_long(data_blocks, data_part, ecc_part); rs_encode_long(data_blocks, data_part, ecc_part);
for (i = (ecc_blocks - 1); i >= 0; i--) { for (i = (ecc_blocks - 1); i >= 0; i--) {
if(ecc_part[i] & 0x20) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } for (int p = 0; p < 6; p++) {
if(ecc_part[i] & 0x10) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } if (ecc_part[i] & (0x20 >> p)) {
if(ecc_part[i] & 0x08) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "1");
if(ecc_part[i] & 0x04) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } } else {
if(ecc_part[i] & 0x02) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "0");
if(ecc_part[i] & 0x01) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } }
}
} }
rs_free(); rs_free();
break; break;
case 8: case 8:
for (i = 0; i < data_blocks; i++) { for (i = 0; i < data_blocks; i++) {
if(adjusted_string[i * codeword_size] == '1') { data_part[i] += 128; } for (int p = 0; p < 8; p++) {
if(adjusted_string[(i * codeword_size) + 1] == '1') { data_part[i] += 64; } if (adjusted_string[i * codeword_size + p] == '1') {
if(adjusted_string[(i * codeword_size) + 2] == '1') { data_part[i] += 32; } data_part[i] += (0x80 >> p);
if(adjusted_string[(i * codeword_size) + 3] == '1') { data_part[i] += 16; } }
if(adjusted_string[(i * codeword_size) + 4] == '1') { data_part[i] += 8; } }
if(adjusted_string[(i * codeword_size) + 5] == '1') { data_part[i] += 4; }
if(adjusted_string[(i * codeword_size) + 6] == '1') { data_part[i] += 2; }
if(adjusted_string[(i * codeword_size) + 7] == '1') { data_part[i] += 1; }
} }
rs_init_gf(0x12d); rs_init_gf(0x12d);
rs_init_code(ecc_blocks, 1); rs_init_code(ecc_blocks, 1);
rs_encode_long(data_blocks, data_part, ecc_part); rs_encode_long(data_blocks, data_part, ecc_part);
for (i = (ecc_blocks - 1); i >= 0; i--) { for (i = (ecc_blocks - 1); i >= 0; i--) {
if(ecc_part[i] & 0x80) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } for (int p = 0; p < 8; p++) {
if(ecc_part[i] & 0x40) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } if (ecc_part[i] & (0x80 >> p)) {
if(ecc_part[i] & 0x20) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "1");
if(ecc_part[i] & 0x10) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } } else {
if(ecc_part[i] & 0x08) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "0");
if(ecc_part[i] & 0x04) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } }
if(ecc_part[i] & 0x02) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } }
if(ecc_part[i] & 0x01) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
} }
rs_free(); rs_free();
break; break;
case 10: case 10:
for (i = 0; i < data_blocks; i++) { for (i = 0; i < data_blocks; i++) {
if(adjusted_string[i * codeword_size] == '1') { data_part[i] += 512; } for(int p = 0; p < 10; p++) {
if(adjusted_string[(i * codeword_size) + 1] == '1') { data_part[i] += 256; } if (adjusted_string[i * codeword_size + p] == '1') {
if(adjusted_string[(i * codeword_size) + 2] == '1') { data_part[i] += 128; } data_part[i] += (0x200 >> p);
if(adjusted_string[(i * codeword_size) + 3] == '1') { data_part[i] += 64; } }
if(adjusted_string[(i * codeword_size) + 4] == '1') { data_part[i] += 32; } }
if(adjusted_string[(i * codeword_size) + 5] == '1') { data_part[i] += 16; }
if(adjusted_string[(i * codeword_size) + 6] == '1') { data_part[i] += 8; }
if(adjusted_string[(i * codeword_size) + 7] == '1') { data_part[i] += 4; }
if(adjusted_string[(i * codeword_size) + 8] == '1') { data_part[i] += 2; }
if(adjusted_string[(i * codeword_size) + 9] == '1') { data_part[i] += 1; }
} }
rs_init_gf(0x409); rs_init_gf(0x409);
rs_init_code(ecc_blocks, 1); rs_init_code(ecc_blocks, 1);
rs_encode_long(data_blocks, data_part, ecc_part); rs_encode_long(data_blocks, data_part, ecc_part);
for (i = (ecc_blocks - 1); i >= 0; i--) { for (i = (ecc_blocks - 1); i >= 0; i--) {
if(ecc_part[i] & 0x200) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } for (int p = 0; p < 10; p++) {
if(ecc_part[i] & 0x100) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } if (ecc_part[i] & (0x200 >> p)) {
if(ecc_part[i] & 0x80) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "1");
if(ecc_part[i] & 0x40) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } } else {
if(ecc_part[i] & 0x20) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "0");
if(ecc_part[i] & 0x10) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } }
if(ecc_part[i] & 0x08) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } }
if(ecc_part[i] & 0x04) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
if(ecc_part[i] & 0x02) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
if(ecc_part[i] & 0x01) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
} }
rs_free(); rs_free();
break; break;
case 12: case 12:
for (i = 0; i < data_blocks; i++) { for (i = 0; i < data_blocks; i++) {
if(adjusted_string[i * codeword_size] == '1') { data_part[i] += 2048; } for (int p = 0; p < 12; p++) {
if(adjusted_string[(i * codeword_size) + 1] == '1') { data_part[i] += 1024; } if (adjusted_string[i * codeword_size + p] == '1') {
if(adjusted_string[(i * codeword_size) + 2] == '1') { data_part[i] += 512; } data_part[i] += (0x800 >> p);
if(adjusted_string[(i * codeword_size) + 3] == '1') { data_part[i] += 256; } }
if(adjusted_string[(i * codeword_size) + 4] == '1') { data_part[i] += 128; } }
if(adjusted_string[(i * codeword_size) + 5] == '1') { data_part[i] += 64; }
if(adjusted_string[(i * codeword_size) + 6] == '1') { data_part[i] += 32; }
if(adjusted_string[(i * codeword_size) + 7] == '1') { data_part[i] += 16; }
if(adjusted_string[(i * codeword_size) + 8] == '1') { data_part[i] += 8; }
if(adjusted_string[(i * codeword_size) + 9] == '1') { data_part[i] += 4; }
if(adjusted_string[(i * codeword_size) + 10] == '1') { data_part[i] += 2; }
if(adjusted_string[(i * codeword_size) + 11] == '1') { data_part[i] += 1; }
} }
rs_init_gf(0x1069); rs_init_gf(0x1069);
rs_init_code(ecc_blocks, 1); rs_init_code(ecc_blocks, 1);
rs_encode_long(data_blocks, data_part, ecc_part); rs_encode_long(data_blocks, data_part, ecc_part);
for (i = (ecc_blocks - 1); i >= 0; i--) { for (i = (ecc_blocks - 1); i >= 0; i--) {
if(ecc_part[i] & 0x800) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } for (int p = 0; p < 12; p++) {
if(ecc_part[i] & 0x400) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } if (ecc_part[i] & (0x800 >> p)) {
if(ecc_part[i] & 0x200) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "1");
if(ecc_part[i] & 0x100) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } } else {
if(ecc_part[i] & 0x80) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } concat(adjusted_string, "0");
if(ecc_part[i] & 0x40) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } }
if(ecc_part[i] & 0x20) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); } }
if(ecc_part[i] & 0x10) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
if(ecc_part[i] & 0x08) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
if(ecc_part[i] & 0x04) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
if(ecc_part[i] & 0x02) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
if(ecc_part[i] & 0x01) { concat(adjusted_string, "1"); } else { concat(adjusted_string, "0"); }
} }
rs_free(); rs_free();
break; break;
@ -1303,54 +1358,158 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
if (compact) { if (compact) {
/* The first 2 bits represent the number of layers minus 1 */ /* The first 2 bits represent the number of layers minus 1 */
if((layers - 1) & 0x02) { descriptor[0] = '1'; } else { descriptor[0] = '0'; } if ((layers - 1) & 0x02) {
if((layers - 1) & 0x01) { descriptor[1] = '1'; } else { descriptor[1] = '0'; } descriptor[0] = '1';
} else {
descriptor[0] = '0';
}
if ((layers - 1) & 0x01) {
descriptor[1] = '1';
} else {
descriptor[1] = '0';
}
/* The next 6 bits represent the number of data blocks minus 1 */ /* The next 6 bits represent the number of data blocks minus 1 */
if (reader) { if (reader) {
descriptor[2] = '1'; descriptor[2] = '1';
} else { } else {
if((data_blocks - 1) & 0x20) { descriptor[2] = '1'; } else { descriptor[2] = '0'; } if ((data_blocks - 1) & 0x20) {
descriptor[2] = '1';
} else {
descriptor[2] = '0';
}
}
if ((data_blocks - 1) & 0x10) {
descriptor[3] = '1';
} else {
descriptor[3] = '0';
}
if ((data_blocks - 1) & 0x08) {
descriptor[4] = '1';
} else {
descriptor[4] = '0';
}
if ((data_blocks - 1) & 0x04) {
descriptor[5] = '1';
} else {
descriptor[5] = '0';
}
if ((data_blocks - 1) & 0x02) {
descriptor[6] = '1';
} else {
descriptor[6] = '0';
}
if ((data_blocks - 1) & 0x01) {
descriptor[7] = '1';
} else {
descriptor[7] = '0';
} }
if((data_blocks - 1) & 0x10) { descriptor[3] = '1'; } else { descriptor[3] = '0'; }
if((data_blocks - 1) & 0x08) { descriptor[4] = '1'; } else { descriptor[4] = '0'; }
if((data_blocks - 1) & 0x04) { descriptor[5] = '1'; } else { descriptor[5] = '0'; }
if((data_blocks - 1) & 0x02) { descriptor[6] = '1'; } else { descriptor[6] = '0'; }
if((data_blocks - 1) & 0x01) { descriptor[7] = '1'; } else { descriptor[7] = '0'; }
descriptor[8] = '\0'; descriptor[8] = '\0';
if (debug) printf("Mode Message = %s\n", descriptor); if (debug) printf("Mode Message = %s\n", descriptor);
} else { } else {
/* The first 5 bits represent the number of layers minus 1 */ /* The first 5 bits represent the number of layers minus 1 */
if((layers - 1) & 0x10) { descriptor[0] = '1'; } else { descriptor[0] = '0'; } if ((layers - 1) & 0x10) {
if((layers - 1) & 0x08) { descriptor[1] = '1'; } else { descriptor[1] = '0'; } descriptor[0] = '1';
if((layers - 1) & 0x04) { descriptor[2] = '1'; } else { descriptor[2] = '0'; } } else {
if((layers - 1) & 0x02) { descriptor[3] = '1'; } else { descriptor[3] = '0'; } descriptor[0] = '0';
if((layers - 1) & 0x01) { descriptor[4] = '1'; } else { descriptor[4] = '0'; } }
if ((layers - 1) & 0x08) {
descriptor[1] = '1';
} else {
descriptor[1] = '0';
}
if ((layers - 1) & 0x04) {
descriptor[2] = '1';
} else {
descriptor[2] = '0';
}
if ((layers - 1) & 0x02) {
descriptor[3] = '1';
} else {
descriptor[3] = '0';
}
if ((layers - 1) & 0x01) {
descriptor[4] = '1';
} else {
descriptor[4] = '0';
}
/* The next 11 bits represent the number of data blocks minus 1 */ /* The next 11 bits represent the number of data blocks minus 1 */
if (reader) { if (reader) {
descriptor[5] = '1'; descriptor[5] = '1';
} else { } else {
if((data_blocks - 1) & 0x400) { descriptor[5] = '1'; } else { descriptor[5] = '0'; } if ((data_blocks - 1) & 0x400) {
descriptor[5] = '1';
} else {
descriptor[5] = '0';
}
}
if ((data_blocks - 1) & 0x200) {
descriptor[6] = '1';
} else {
descriptor[6] = '0';
}
if ((data_blocks - 1) & 0x100) {
descriptor[7] = '1';
} else {
descriptor[7] = '0';
}
if ((data_blocks - 1) & 0x80) {
descriptor[8] = '1';
} else {
descriptor[8] = '0';
}
if ((data_blocks - 1) & 0x40) {
descriptor[9] = '1';
} else {
descriptor[9] = '0';
}
if ((data_blocks - 1) & 0x20) {
descriptor[10] = '1';
} else {
descriptor[10] = '0';
}
if ((data_blocks - 1) & 0x10) {
descriptor[11] = '1';
} else {
descriptor[11] = '0';
}
if ((data_blocks - 1) & 0x08) {
descriptor[12] = '1';
} else {
descriptor[12] = '0';
}
if ((data_blocks - 1) & 0x04) {
descriptor[13] = '1';
} else {
descriptor[13] = '0';
}
if ((data_blocks - 1) & 0x02) {
descriptor[14] = '1';
} else {
descriptor[14] = '0';
}
if ((data_blocks - 1) & 0x01) {
descriptor[15] = '1';
} else {
descriptor[15] = '0';
} }
if((data_blocks - 1) & 0x200) { descriptor[6] = '1'; } else { descriptor[6] = '0'; }
if((data_blocks - 1) & 0x100) { descriptor[7] = '1'; } else { descriptor[7] = '0'; }
if((data_blocks - 1) & 0x80) { descriptor[8] = '1'; } else { descriptor[8] = '0'; }
if((data_blocks - 1) & 0x40) { descriptor[9] = '1'; } else { descriptor[9] = '0'; }
if((data_blocks - 1) & 0x20) { descriptor[10] = '1'; } else { descriptor[10] = '0'; }
if((data_blocks - 1) & 0x10) { descriptor[11] = '1'; } else { descriptor[11] = '0'; }
if((data_blocks - 1) & 0x08) { descriptor[12] = '1'; } else { descriptor[12] = '0'; }
if((data_blocks - 1) & 0x04) { descriptor[13] = '1'; } else { descriptor[13] = '0'; }
if((data_blocks - 1) & 0x02) { descriptor[14] = '1'; } else { descriptor[14] = '0'; }
if((data_blocks - 1) & 0x01) { descriptor[15] = '1'; } else { descriptor[15] = '0'; }
descriptor[16] = '\0'; descriptor[16] = '\0';
if (debug) printf("Mode Message = %s\n", descriptor); if (debug) printf("Mode Message = %s\n", descriptor);
} }
/* Split into 4-bit codewords */ /* Split into 4-bit codewords */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if(descriptor[i * 4] == '1') { desc_data[i] += 8; } if (descriptor[i * 4] == '1') {
if(descriptor[(i * 4) + 1] == '1') { desc_data[i] += 4; } desc_data[i] += 8;
if(descriptor[(i * 4) + 2] == '1') { desc_data[i] += 2; } }
if(descriptor[(i * 4) + 3] == '1') { desc_data[i] += 1; } if (descriptor[(i * 4) + 1] == '1') {
desc_data[i] += 4;
}
if (descriptor[(i * 4) + 2] == '1') {
desc_data[i] += 2;
}
if (descriptor[(i * 4) + 3] == '1') {
desc_data[i] += 1;
}
} }
/* Add reed-solomon error correction with Galois field GF(16) and prime modulus /* Add reed-solomon error correction with Galois field GF(16) and prime modulus
@ -1361,19 +1520,51 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
rs_init_code(5, 1); rs_init_code(5, 1);
rs_encode(2, desc_data, desc_ecc); rs_encode(2, desc_data, desc_ecc);
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
if(desc_ecc[4 - i] & 0x08) { descriptor[(i * 4) + 8] = '1'; } else { descriptor[(i * 4) + 8] = '0'; } if (desc_ecc[4 - i] & 0x08) {
if(desc_ecc[4 - i] & 0x04) { descriptor[(i * 4) + 9] = '1'; } else { descriptor[(i * 4) + 9] = '0'; } descriptor[(i * 4) + 8] = '1';
if(desc_ecc[4 - i] & 0x02) { descriptor[(i * 4) + 10] = '1'; } else { descriptor[(i * 4) + 10] = '0'; } } else {
if(desc_ecc[4 - i] & 0x01) { descriptor[(i * 4) + 11] = '1'; } else { descriptor[(i * 4) + 11] = '0'; } descriptor[(i * 4) + 8] = '0';
}
if (desc_ecc[4 - i] & 0x04) {
descriptor[(i * 4) + 9] = '1';
} else {
descriptor[(i * 4) + 9] = '0';
}
if (desc_ecc[4 - i] & 0x02) {
descriptor[(i * 4) + 10] = '1';
} else {
descriptor[(i * 4) + 10] = '0';
}
if (desc_ecc[4 - i] & 0x01) {
descriptor[(i * 4) + 11] = '1';
} else {
descriptor[(i * 4) + 11] = '0';
}
} }
} else { } else {
rs_init_code(6, 1); rs_init_code(6, 1);
rs_encode(4, desc_data, desc_ecc); rs_encode(4, desc_data, desc_ecc);
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
if(desc_ecc[5 - i] & 0x08) { descriptor[(i * 4) + 16] = '1'; } else { descriptor[(i * 4) + 16] = '0'; } if (desc_ecc[5 - i] & 0x08) {
if(desc_ecc[5 - i] & 0x04) { descriptor[(i * 4) + 17] = '1'; } else { descriptor[(i * 4) + 17] = '0'; } descriptor[(i * 4) + 16] = '1';
if(desc_ecc[5 - i] & 0x02) { descriptor[(i * 4) + 18] = '1'; } else { descriptor[(i * 4) + 18] = '0'; } } else {
if(desc_ecc[5 - i] & 0x01) { descriptor[(i * 4) + 19] = '1'; } else { descriptor[(i * 4) + 19] = '0'; } descriptor[(i * 4) + 16] = '0';
}
if (desc_ecc[5 - i] & 0x04) {
descriptor[(i * 4) + 17] = '1';
} else {
descriptor[(i * 4) + 17] = '0';
}
if (desc_ecc[5 - i] & 0x02) {
descriptor[(i * 4) + 18] = '1';
} else {
descriptor[(i * 4) + 18] = '0';
}
if (desc_ecc[5 - i] & 0x01) {
descriptor[(i * 4) + 19] = '1';
} else {
descriptor[(i * 4) + 19] = '0';
}
} }
} }
rs_free(); rs_free();
@ -1427,8 +1618,8 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
return err_code; return err_code;
} }
int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length) /* Encodes Aztec runes as specified in ISO/IEC 24778:2008 Annex A */
{ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length) {
int input_value, error_number, i, y, x; int input_value, error_number, i, y, x;
char binary_string[28]; char binary_string[28];
unsigned char data_codewords[3], ecc_codewords[6]; unsigned char data_codewords[3], ecc_codewords[6];
@ -1462,23 +1653,30 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length)
} }
strcpy(binary_string, ""); strcpy(binary_string, "");
if(input_value & 0x80) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } for (int p = 0; p < 8; p++) {
if(input_value & 0x40) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } if (input_value & (0x80 >> p)) {
if(input_value & 0x20) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "1");
if(input_value & 0x10) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } } else {
if(input_value & 0x08) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } concat(binary_string, "0");
if(input_value & 0x04) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
if(input_value & 0x02) { concat(binary_string, "1"); } else { concat(binary_string, "0"); } }
if(input_value & 0x01) { concat(binary_string, "1"); } else { concat(binary_string, "0"); }
data_codewords[0] = 0; data_codewords[0] = 0;
data_codewords[1] = 0; data_codewords[1] = 0;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if(binary_string[i * 4] == '1') { data_codewords[i] += 8; } if (binary_string[i * 4] == '1') {
if(binary_string[(i * 4) + 1] == '1') { data_codewords[i] += 4; } data_codewords[i] += 8;
if(binary_string[(i * 4) + 2] == '1') { data_codewords[i] += 2; } }
if(binary_string[(i * 4) + 3] == '1') { data_codewords[i] += 1; } if (binary_string[(i * 4) + 1] == '1') {
data_codewords[i] += 4;
}
if (binary_string[(i * 4) + 2] == '1') {
data_codewords[i] += 2;
}
if (binary_string[(i * 4) + 3] == '1') {
data_codewords[i] += 1;
}
} }
rs_init_gf(0x13); rs_init_gf(0x13);
@ -1489,14 +1687,34 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(binary_string, ""); strcpy(binary_string, "");
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
if(ecc_codewords[4 - i] & 0x08) { binary_string[(i * 4) + 8] = '1'; } else { binary_string[(i * 4) + 8] = '0'; } if (ecc_codewords[4 - i] & 0x08) {
if(ecc_codewords[4 - i] & 0x04) { binary_string[(i * 4) + 9] = '1'; } else { binary_string[(i * 4) + 9] = '0'; } binary_string[(i * 4) + 8] = '1';
if(ecc_codewords[4 - i] & 0x02) { binary_string[(i * 4) + 10] = '1'; } else { binary_string[(i * 4) + 10] = '0'; } } else {
if(ecc_codewords[4 - i] & 0x01) { binary_string[(i * 4) + 11] = '1'; } else { binary_string[(i * 4) + 11] = '0'; } binary_string[(i * 4) + 8] = '0';
}
if (ecc_codewords[4 - i] & 0x04) {
binary_string[(i * 4) + 9] = '1';
} else {
binary_string[(i * 4) + 9] = '0';
}
if (ecc_codewords[4 - i] & 0x02) {
binary_string[(i * 4) + 10] = '1';
} else {
binary_string[(i * 4) + 10] = '0';
}
if (ecc_codewords[4 - i] & 0x01) {
binary_string[(i * 4) + 11] = '1';
} else {
binary_string[(i * 4) + 11] = '0';
}
} }
for (i = 0; i < 28; i += 2) { for (i = 0; i < 28; i += 2) {
if(binary_string[i] == '1') { binary_string[i] = '0'; } else { binary_string[i] = '1'; } if (binary_string[i] == '1') {
binary_string[i] = '0';
} else {
binary_string[i] = '1';
}
} }
for (y = 8; y < 19; y++) { for (y = 8; y < 19; y++) {

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -39,7 +39,8 @@
static int AztecMap[22801]; static int AztecMap[22801];
static const int CompactAztecMap[] = { /* 27 x 27 data grid */ static const int CompactAztecMap[] = {
/* 27 x 27 data grid */
609, 608, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 609, 608, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459,
607, 606, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 607, 606, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458,
605, 604, 409, 408, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 460, 461, 605, 604, 409, 408, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 460, 461,
@ -69,7 +70,8 @@ static const int CompactAztecMap[] = { /* 27 x 27 data grid */
559, 557, 555, 553, 551, 549, 547, 545, 543, 541, 539, 537, 535, 533, 531, 529, 527, 525, 523, 521, 519, 517, 515, 513, 511, 508, 509 559, 557, 555, 553, 551, 549, 547, 545, 543, 541, 539, 537, 535, 533, 531, 529, 527, 525, 523, 521, 519, 517, 515, 513, 511, 508, 509
}; };
const int AztecCodeSet[128] = { /* From Table 2 */ const int AztecCodeSet[128] = {
/* From Table 2 */
32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 12, 32, 32, 32, 32, 32, 32,
32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8, 32, 32, 32, 32, 32, 32, 32, 4, 4, 4, 4, 4, 23, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 24, 8, 24, 8, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8,
@ -79,7 +81,8 @@ const int AztecCodeSet[128] = { /* From Table 2 */
2, 2, 2, 8, 4, 8, 4, 4 2, 2, 2, 8, 4, 8, 4, 4
}; };
const int AztecSymbolChar[128] = { /* From Table 2 */ const int AztecSymbolChar[128] = {
/* From Table 2 */
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 300, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 1, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22, 13, 14, 15, 16, 301, 18, 302, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 21, 22,
@ -95,56 +98,80 @@ const int AztecSymbolChar[128] = { /* From Table 2 */
302: Full Stop (ASCII 46) 302: Full Stop (ASCII 46)
*/ */
static const char *hexbit[32] = {"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", static const char *hexbit[32] = {
"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
"01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101",
"10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111" "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
}; };
static const char *pentbit[16] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", static const char *pentbit[16] = {
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001",
"1010", "1011", "1100", "1101", "1110", "1111" "1010", "1011", "1100", "1101", "1110", "1111"
}; };
static const char *tribit[8] = {"000", "001", "010", "011", "100", "101", "110", "111"}; static const char *tribit[8] = {
"000", "001", "010", "011", "100", "101", "110", "111"
};
static const int AztecSizes[32] = { /* Codewords per symbol */ static const int AztecSizes[32] = {
/* Codewords per symbol */
21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,
864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664 864, 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
}; };
static const int AztecCompactSizes[4] = { 17, 40, 51, 76 }; static const int AztecCompactSizes[4] = {
17, 40, 51, 76
};
static const int Aztec10DataSizes[32] = { /* Data bits per symbol maximum with 10% error correction */ static const int Aztec10DataSizes[32] = {
/* Data bits per symbol maximum with 10% error correction */
96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730, 96, 246, 408, 616, 840, 1104, 1392, 1704, 2040, 2420, 2820, 3250, 3720, 4200, 4730,
5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076, 5270, 5840, 6450, 7080, 7750, 8430, 9150, 9900, 10680, 11484, 12324, 13188, 14076,
15000, 15948, 16920, 17940 15000, 15948, 16920, 17940
}; };
static const int Aztec23DataSizes[32] = { /* Data bits per symbol maximum with 23% error correction */ static const int Aztec23DataSizes[32] = {
/* Data bits per symbol maximum with 23% error correction */
84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040, 84, 204, 352, 520, 720, 944, 1184, 1456, 1750, 2070, 2410, 2780, 3180, 3590, 4040,
4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036, 4500, 5000, 5520, 6060, 6630, 7210, 7830, 8472, 9132, 9816, 10536, 11280, 12036,
12828, 13644, 14472, 15348 12828, 13644, 14472, 15348
}; };
static const int Aztec36DataSizes[32] = { /* Data bits per symbol maximum with 36% error correction */ static const int Aztec36DataSizes[32] = {
/* Data bits per symbol maximum with 36% error correction */
66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350, 66, 168, 288, 432, 592, 776, 984, 1208, 1450, 1720, 2000, 2300, 2640, 2980, 3350,
3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656, 3740, 4150, 4580, 5030, 5500, 5990, 6500, 7032, 7584, 8160, 8760, 9372, 9996, 10656,
11340, 12024, 12744 11340, 12024, 12744
}; };
static const int Aztec50DataSizes[32] = { /* Data bits per symbol maximum with 50% error correction */ static const int Aztec50DataSizes[32] = {
/* Data bits per symbol maximum with 50% error correction */
48, 126, 216, 328, 456, 600, 760, 936, 1120, 1330, 1550, 1790, 2050, 2320, 2610, 48, 126, 216, 328, 456, 600, 760, 936, 1120, 1330, 1550, 1790, 2050, 2320, 2610,
2910, 3230, 3570, 3920, 4290, 4670, 5070, 5484, 5916, 6360, 6828, 7308, 7800, 8316, 2910, 3230, 3570, 3920, 4290, 4670, 5070, 5484, 5916, 6360, 6828, 7308, 7800, 8316,
8844, 9384, 9948 8844, 9384, 9948
}; };
static const int AztecCompact10DataSizes [4] = { 78, 198, 336, 520 }; static const int AztecCompact10DataSizes [4] = {
static const int AztecCompact23DataSizes [4] = { 66, 168, 288, 440 }; 78, 198, 336, 520
static const int AztecCompact36DataSizes [4] = { 48, 138, 232, 360 }; };
static const int AztecCompact50DataSizes [4] = { 36, 102, 176, 280 };
static const int AztecCompact23DataSizes [4] = {
66, 168, 288, 440
};
static const int AztecCompact36DataSizes [4] = {
48, 138, 232, 360
};
static const int AztecCompact50DataSizes [4] = {
36, 102, 176, 280
};
static const int AztecOffset[32] = { static const int AztecOffset[32] = {
66, 64, 62, 60, 57, 55, 53, 51, 49, 47, 45, 42, 40, 38, 36, 34, 32, 30, 28, 25, 23, 21, 66, 64, 62, 60, 57, 55, 53, 51, 49, 47, 45, 42, 40, 38, 36, 34, 32, 30, 28, 25, 23, 21,
19, 17, 15, 13, 10, 8, 6, 4, 2, 0 19, 17, 15, 13, 10, 8, 6, 4, 2, 0
}; };
static const int AztecCompactOffset[4] = { 6, 4, 2, 0 }; static const int AztecCompactOffset[4] = {
6, 4, 2, 0
};

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -40,49 +40,58 @@
#define SODIUM "0123456789-" #define SODIUM "0123456789-"
#define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd" #define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"
static const char *C11Table[11] = {"111121", "211121", "121121", "221111", "112121", "212111", "122111", static const char *C11Table[11] = {
"111221", "211211", "211111", "112111"}; "111121", "211121", "121121", "221111", "112121", "212111", "122111",
"111221", "211211", "211111", "112111"
};
/* Code 39 tables checked against ISO/IEC 16388:2007 */ /* Code 39 tables checked against ISO/IEC 16388:2007 */
/* Incorporates Table A1 */ /* Incorporates Table A1 */
static const char *C39Table[43] = { "1112212111", "2112111121", "1122111121", "2122111111", "1112211121", static const char *C39Table[43] = {
/* Code 39 character assignments (Table 1) */
"1112212111", "2112111121", "1122111121", "2122111111", "1112211121",
"2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121", "2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121",
"1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121", "1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121",
"2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211", "2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211",
"1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211", "1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211",
"1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111", "1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111",
"1221211111", "1211112121", "2211112111", "1221112111", "1212121111", "1212111211", "1221211111", "1211112121", "2211112111", "1221112111", "1212121111", "1212111211",
"1211121211", "1112121211"}; "1211121211", "1112121211"
/* Code 39 character assignments (Table 1) */ };
static const char *EC39Ctrl[128] = {"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K", static const char *EC39Ctrl[128] = {
/* Encoding the full ASCII character set in Code 39 (Table A2) */
"%U", "$A", "$B", "$C", "$D", "$E", "$F", "$G", "$H", "$I", "$J", "$K",
"$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z", "$L", "$M", "$N", "$O", "$P", "$Q", "$R", "$S", "$T", "$U", "$V", "$W", "$X", "$Y", "$Z",
"%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J", "%A", "%B", "%C", "%D", "%E", " ", "/A", "/B", "/C", "/D", "/E", "/F", "/G", "/H", "/I", "/J",
"/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F", "/K", "/L", "-", ".", "/O", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "/Z", "%F",
"%G", "%H", "%I", "%J", "%V", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "%G", "%H", "%I", "%J", "%V", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "%K", "%L", "%M", "%N", "%O", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "%K", "%L", "%M", "%N", "%O",
"%W", "+A", "+B", "+C", "+D", "+E", "+F", "+G", "+H", "+I", "+J", "+K", "+L", "+M", "+N", "+O", "%W", "+A", "+B", "+C", "+D", "+E", "+F", "+G", "+H", "+I", "+J", "+K", "+L", "+M", "+N", "+O",
"+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"}; "+P", "+Q", "+R", "+S", "+T", "+U", "+V", "+W", "+X", "+Y", "+Z", "%P", "%Q", "%R", "%S", "%T"
/* Encoding the full ASCII character set in Code 39 (Table A2) */ };
static const char *C93Ctrl[128] = {"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK", static const char *C93Ctrl[128] = {
"bU", "aA", "aB", "aC", "aD", "aE", "aF", "aG", "aH", "aI", "aJ", "aK",
"aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ", "aL", "aM", "aN", "aO", "aP", "aQ", "aR", "aS", "aT", "aU", "aV", "aW", "aX", "aY", "aZ",
"bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "$", "%", "cF", "cG", "cH", "cI", "cJ", "bA", "bB", "bC", "bD", "bE", " ", "cA", "cB", "cC", "$", "%", "cF", "cG", "cH", "cI", "cJ",
"+", "cL", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF", "+", "cL", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cZ", "bF",
"bG", "bH", "bI", "bJ", "bV", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "bG", "bH", "bI", "bJ", "bV", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bK", "bL", "bM", "bN", "bO", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bK", "bL", "bM", "bN", "bO",
"bW", "dA", "dB", "dC", "dD", "dE", "dF", "dG", "dH", "dI", "dJ", "dK", "dL", "dM", "dN", "dO", "bW", "dA", "dB", "dC", "dD", "dE", "dF", "dG", "dH", "dI", "dJ", "dK", "dL", "dM", "dN", "dO",
"dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"}; "dP", "dQ", "dR", "dS", "dT", "dU", "dV", "dW", "dX", "dY", "dZ", "bP", "bQ", "bR", "bS", "bT"
};
static const char *C93Table[47] = {"131112", "111213", "111312", "111411", "121113", "121212", "121311", static const char *C93Table[47] = {
"131112", "111213", "111312", "111411", "121113", "121212", "121311",
"111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111", "111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111",
"112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122", "112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122",
"131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221", "131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221",
"122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131", "122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131",
"121221", "312111", "311121", "122211"}; "121221", "312111", "311121", "122211"
};
/* Global Variables for Channel Code */ /* Global Variables for Channel Code */
int S[11], B[11]; int S[11], B[11];
@ -95,9 +104,7 @@ void NextS(int Chan, int i, int MaxS, int MaxB);
void NextB(int Chan, int i, int MaxB, int MaxS); void NextB(int Chan, int i, int MaxB, int MaxS);
/* *********************** CODE 11 ******************** */ /* *********************** CODE 11 ******************** */
int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 11 */
int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 11 */
unsigned int i; unsigned int i;
int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count; int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
@ -159,8 +166,12 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
checkstr[0] = itoc(c_digit); checkstr[0] = itoc(c_digit);
checkstr[1] = itoc(k_digit); checkstr[1] = itoc(k_digit);
if(checkstr[0] == 'A') { checkstr[0] = '-'; } if (checkstr[0] == 'A') {
if(checkstr[1] == 'A') { checkstr[1] = '-'; } checkstr[0] = '-';
}
if (checkstr[1] == 'A') {
checkstr[1] = '-';
}
checkstr[2] = '\0'; checkstr[2] = '\0';
lookup(SODIUM, C11Table, checkstr[0], dest); lookup(SODIUM, C11Table, checkstr[0], dest);
lookup(SODIUM, C11Table, checkstr[1], dest); lookup(SODIUM, C11Table, checkstr[1], dest);
@ -175,8 +186,8 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int c39(struct zint_symbol *symbol, unsigned char source[], int length) /* Code 39 */
{ /* Code 39 */ int c39(struct zint_symbol *symbol, unsigned char source[], int length) {
unsigned int i; unsigned int i;
unsigned int counter; unsigned int counter;
char check_digit; char check_digit;
@ -223,14 +234,22 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
check_digit = (counter - 10) + 'A'; check_digit = (counter - 10) + 'A';
} else { } else {
switch (counter) { switch (counter) {
case 36: check_digit = '-'; break; case 36: check_digit = '-';
case 37: check_digit = '.'; break; break;
case 38: check_digit = ' '; break; case 37: check_digit = '.';
case 39: check_digit = '$'; break; break;
case 40: check_digit = '/'; break; case 38: check_digit = ' ';
case 41: check_digit = '+'; break; break;
case 42: check_digit = 37; break; case 39: check_digit = '$';
default: check_digit = ' '; break; /* Keep compiler happy */ break;
case 40: check_digit = '/';
break;
case 41: check_digit = '+';
break;
case 42: check_digit = 37;
break;
default: check_digit = ' ';
break; /* Keep compiler happy */
} }
} }
} }
@ -272,8 +291,8 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) /* Pharmazentral Nummer (PZN) */
{ /* Pharmazentral Nummer (PZN) */ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, error_number, zeroes; int i, error_number, zeroes;
unsigned int count, check_digit; unsigned int count, check_digit;
@ -303,7 +322,9 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length
} }
check_digit = count % 11; check_digit = count % 11;
if (check_digit == 11) { check_digit = 0; } if (check_digit == 11) {
check_digit = 0;
}
localstr[7] = itoc(check_digit); localstr[7] = itoc(check_digit);
localstr[8] = '\0'; localstr[8] = '\0';
if (localstr[7] == 'A') { if (localstr[7] == 'A') {
@ -316,11 +337,8 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length
return error_number; return error_number;
} }
/* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
/* ************** EXTENDED CODE 39 *************** */ int ec39(struct zint_symbol *symbol, unsigned char source[], int length) {
int ec39(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Extended Code 39 - ISO/IEC 16388:2007 Annex A */
unsigned char buffer[150] = {0}; unsigned char buffer[150] = {0};
unsigned int i; unsigned int i;
@ -353,10 +371,8 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
/* ******************** CODE 93 ******************* */ /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */
int c93(struct zint_symbol *symbol, unsigned char source[], int length) {
int c93(struct zint_symbol *symbol, unsigned char source[], int length)
{ /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */
/* SILVER includes the extra characters a, b, c and d to represent Code 93 specific /* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
shift characters 1, 2, 3 and 4 respectively. These characters are never used by shift characters 1, 2, 3 and 4 respectively. These characters are never used by
@ -445,6 +461,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length)
} }
/* NextS() and NextB() are from ANSI/AIM BC12-1998 and are Copyright (c) AIM 1997 */ /* NextS() and NextB() are from ANSI/AIM BC12-1998 and are Copyright (c) AIM 1997 */
/* Their are used here on the understanding that they form part of the specification /* Their are used here on the understanding that they form part of the specification
for Channel Code and therefore their use is permitted under the following terms for Channel Code and therefore their use is permitted under the following terms
set out in that document: set out in that document:
@ -495,9 +512,8 @@ void NextS(int Chan, int i, int MaxS, int MaxB) {
} }
} }
int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
/* Channel Code - According to ANSI/AIM BC12-1998 */ /* Channel Code - According to ANSI/AIM BC12-1998 */
int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) {
int channels, i; int channels, i;
int error_number = 0, range = 0, zeroes; int error_number = 0, range = 0, zeroes;
char hrt[9]; char hrt[9];
@ -514,9 +530,17 @@ int channel_code(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; } if ((symbol->option_2 < 3) || (symbol->option_2 > 8)) {
if(channels == 0) { channels = length + 1; } channels = 0;
if(channels == 2) { channels = 3; } } else {
channels = symbol->option_2;
}
if (channels == 0) {
channels = length + 1;
}
if (channels == 2) {
channels = 3;
}
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
target_value *= 10; target_value *= 10;
@ -524,19 +548,40 @@ int channel_code(struct zint_symbol *symbol, unsigned char source[], int length)
} }
switch (channels) { switch (channels) {
case 3: if(target_value > 26) { range = 1; } break; case 3: if (target_value > 26) {
case 4: if(target_value > 292) { range = 1; } break; range = 1;
case 5: if(target_value > 3493) { range = 1; } break; }
case 6: if(target_value > 44072) { range = 1; } break; break;
case 7: if(target_value > 576688) { range = 1; } break; case 4: if (target_value > 292) {
case 8: if(target_value > 7742862) { range = 1; } break; range = 1;
}
break;
case 5: if (target_value > 3493) {
range = 1;
}
break;
case 6: if (target_value > 44072) {
range = 1;
}
break;
case 7: if (target_value > 576688) {
range = 1;
}
break;
case 8: if (target_value > 7742862) {
range = 1;
}
break;
} }
if (range) { if (range) {
strcpy(symbol->errtxt, "Value out of range"); strcpy(symbol->errtxt, "Value out of range");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
for(i = 0; i < 11; i++) { B[i] = 0; S[i] = 0; } for (i = 0; i < 11; i++) {
B[i] = 0;
S[i] = 0;
}
B[0] = S[1] = B[1] = S[2] = B[2] = 1; B[0] = S[1] = B[1] = S[2] = B[2] = 1;
value = 0; value = 0;

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -34,35 +34,65 @@ static const int c40_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
static const int c40_value[] = { static const int c40_value[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15, 16, 17, 18, 19, 20, 21, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 15, 16, 17, 18, 19, 20, 21, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
};
static const int text_shift[] = { static const int text_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3
};
static const int text_value[] = { static const int text_value[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15, 16, 17, 18, 19, 20, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 20, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27, 28, 29, 30, 31
};
static const int c1_height[] = { 16, 22, 28, 40, 52, 70, 104, 148 }; static const int c1_height[] = {
static const int c1_width[] = { 18, 22, 32, 42, 54, 76, 98, 134 }; 16, 22, 28, 40, 52, 70, 104, 148
static const int c1_data_length[] = { 10, 19, 44, 91, 182, 370, 732, 1480 }; };
static const int c1_ecc_length[] = { 10, 16, 26, 44, 70, 140, 280, 560 };
static const int c1_blocks[] = { 1, 1, 1, 1, 1, 2, 4, 8 }; static const int c1_width[] = {
static const int c1_data_blocks[] = { 10, 19, 44, 91, 182, 185, 183, 185 }; 18, 22, 32, 42, 54, 76, 98, 134
static const int c1_ecc_blocks[] = { 10, 16, 26, 44, 70, 70, 70, 70 }; };
static const int c1_grid_width[] = { 4, 5, 7, 9, 12, 17, 22, 30 };
static const int c1_grid_height[] = { 5, 7, 10, 15, 21, 30, 46, 68 }; static const int c1_data_length[] = {
10, 19, 44, 91, 182, 370, 732, 1480
};
static const int c1_ecc_length[] = {
10, 16, 26, 44, 70, 140, 280, 560
};
static const int c1_blocks[] = {
1, 1, 1, 1, 1, 2, 4, 8
};
static const int c1_data_blocks[] = {
10, 19, 44, 91, 182, 185, 183, 185
};
static const int c1_ecc_blocks[] = {
10, 16, 26, 44, 70, 70, 70, 70
};
static const int c1_grid_width[] = {
4, 5, 7, 9, 12, 17, 22, 30
};
static const int c1_grid_height[] = {
5, 7, 10, 15, 21, 30, 46, 68
};
#define C1_ASCII 1 #define C1_ASCII 1
#define C1_C40 2 #define C1_C40 2

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Bugfixes thanks to Christian Sakowski and BogDan Vatra Bugfixes thanks to Christian Sakowski and BogDan Vatra
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -57,7 +57,9 @@ static int list[2][170];
/* Code 128 tables checked against ISO/IEC 15417:2007 */ /* Code 128 tables checked against ISO/IEC 15417:2007 */
static const char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322", "131222", "122213", static const char *C128Table[107] = {
/* Code 128 character encodation - Table 1 */
"212222", "222122", "222221", "121223", "121322", "131222", "122213",
"122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222", "122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222",
"123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222", "123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222",
"321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323", "321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323",
@ -69,21 +71,29 @@ static const char *C128Table[107] = {"212222", "222122", "222221", "121223", "12
"134111", "111242", "121142", "121241", "114212", "124112", "124211", "411212", "421112", "134111", "111242", "121142", "121241", "114212", "124112", "124211", "411212", "421112",
"421211", "212141", "214121", "412121", "111143", "111341", "131141", "114113", "114311", "421211", "212141", "214121", "412121", "111143", "111341", "131141", "114113", "114311",
"411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232", "411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232",
"2331112"}; "2331112"
/* Code 128 character encodation - Table 1 */ };
int parunmodd(unsigned char llyth) /* Determine appropriate mode for a given character */
{ int parunmodd(unsigned char llyth) {
int modd; int modd;
modd = 0; modd = 0;
if(llyth <= 31) { modd = SHIFTA; } if (llyth <= 31) {
else if((llyth >= 48) && (llyth <= 57)) { modd = ABORC; } modd = SHIFTA;
else if(llyth <= 95) { modd = AORB; } } else if ((llyth >= 48) && (llyth <= 57)) {
else if(llyth <= 127) { modd = SHIFTB; } modd = ABORC;
else if(llyth <= 159) { modd = SHIFTA; } } else if (llyth <= 95) {
else if(llyth <= 223) { modd = AORB; } modd = AORB;
else { modd = SHIFTB; } } else if (llyth <= 127) {
modd = SHIFTB;
} else if (llyth <= 159) {
modd = SHIFTA;
} else if (llyth <= 223) {
modd = AORB;
} else {
modd = SHIFTB;
}
return modd; return modd;
} }
@ -91,8 +101,7 @@ int parunmodd(unsigned char llyth)
/** /**
* bring together same type blocks * bring together same type blocks
*/ */
void grwp(int *indexliste) void grwp(int *indexliste) {
{
int i, j; int i, j;
/* bring together same type blocks */ /* bring together same type blocks */
@ -121,38 +130,106 @@ void grwp(int *indexliste)
/** /**
* Implements rules from ISO 15417 Annex E * Implements rules from ISO 15417 Annex E
*/ */
void dxsmooth(int *indexliste) void dxsmooth(int *indexliste) {
{ /* Implements rules from ISO 15417 Annex E */
int i, current, last, next, length; int i, current, last, next, length;
for (i = 0; i < *(indexliste); i++) { for (i = 0; i < *(indexliste); i++) {
current = list[1][i]; current = list[1][i];
length = list[0][i]; length = list[0][i];
if(i != 0) { last = list[1][i - 1]; } else { last = FALSE; } if (i != 0) {
if(i != *(indexliste) - 1) { next = list[1][i + 1]; } else { next = FALSE; } last = list[1][i - 1];
} else {
last = FALSE;
}
if (i != *(indexliste) - 1) {
next = list[1][i + 1];
} else {
next = FALSE;
}
if (i == 0) { /* first block */ if (i == 0) { /* first block */
if((*(indexliste) == 1) && ((length == 2) && (current == ABORC))) { /* Rule 1a */ list[1][i] = LATCHC; } if ((*(indexliste) == 1) && ((length == 2) && (current == ABORC))) {
if(current == ABORC) { /* Rule 1a */
if(length >= 4) {/* Rule 1b */ list[1][i] = LATCHC; } else { list[1][i] = AORB; current = AORB; } list[1][i] = LATCHC;
} }
if(current == SHIFTA) { /* Rule 1c */ list[1][i] = LATCHA; } if (current == ABORC) {
if((current == AORB) && (next == SHIFTA)) { /* Rule 1c */ list[1][i] = LATCHA; current = LATCHA; } if (length >= 4) {
if(current == AORB) { /* Rule 1d */ list[1][i] = LATCHB; } /* Rule 1b */
list[1][i] = LATCHC;
} else { } else {
if((current == ABORC) && (length >= 4)) { /* Rule 3 */ list[1][i] = LATCHC; current = LATCHC; } list[1][i] = AORB;
if(current == ABORC) { list[1][i] = AORB; current = AORB; } current = AORB;
if((current == AORB) && (last == LATCHA)) { list[1][i] = LATCHA; current = LATCHA; } }
if((current == AORB) && (last == LATCHB)) { list[1][i] = LATCHB; current = LATCHB; } }
if((current == AORB) && (next == SHIFTA)) { list[1][i] = LATCHA; current = LATCHA; } if (current == SHIFTA) {
if((current == AORB) && (next == SHIFTB)) { list[1][i] = LATCHB; current = LATCHB; } /* Rule 1c */
if(current == AORB) { list[1][i] = LATCHB; current = LATCHB; } list[1][i] = LATCHA;
if((current == SHIFTA) && (length > 1)) { /* Rule 4 */ list[1][i] = LATCHA; current = LATCHA; } }
if((current == SHIFTB) && (length > 1)) { /* Rule 5 */ list[1][i] = LATCHB; current = LATCHB; } if ((current == AORB) && (next == SHIFTA)) {
if((current == SHIFTA) && (last == LATCHA)) { list[1][i] = LATCHA; current = LATCHA; } /* Rule 1c */
if((current == SHIFTB) && (last == LATCHB)) { list[1][i] = LATCHB; current = LATCHB; } list[1][i] = LATCHA;
if((current == SHIFTA) && (last == LATCHC)) { list[1][i] = LATCHA; current = LATCHA; } current = LATCHA;
if((current == SHIFTB) && (last == LATCHC)) { list[1][i] = LATCHB; current = LATCHB; } }
if (current == AORB) {
/* Rule 1d */
list[1][i] = LATCHB;
}
} else {
if ((current == ABORC) && (length >= 4)) {
/* Rule 3 */
list[1][i] = LATCHC;
current = LATCHC;
}
if (current == ABORC) {
list[1][i] = AORB;
current = AORB;
}
if ((current == AORB) && (last == LATCHA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == AORB) && (last == LATCHB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == AORB) && (next == SHIFTA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == AORB) && (next == SHIFTB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if (current == AORB) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (length > 1)) {
/* Rule 4 */
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (length > 1)) {
/* Rule 5 */
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (last == LATCHA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (last == LATCHB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (last == LATCHC)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (last == LATCHC)) {
list[1][i] = LATCHB;
current = LATCHB;
}
} /* Rule 2 is implimented elsewhere, Rule 6 is implied */ } /* Rule 2 is implimented elsewhere, Rule 6 is implied */
} }
grwp(indexliste); grwp(indexliste);
@ -163,9 +240,7 @@ void dxsmooth(int *indexliste)
* Translate Code 128 Set A characters into barcodes. * Translate Code 128 Set A characters into barcodes.
* This set handles all control characters NULL to US. * This set handles all control characters NULL to US.
*/ */
void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars) void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars) {
{ /* Translate Code 128 Set A characters into barcodes */
/* This set handles all control characters NULL to US */
if (source > 127) { if (source > 127) {
if (source < 160) { if (source < 160) {
@ -192,8 +267,7 @@ void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars)
* This set handles all characters which are not part of long numbers and not * This set handles all characters which are not part of long numbers and not
* control characters. * control characters.
*/ */
void c128_set_b(unsigned char source, char dest[], int values[], int *bar_chars) void c128_set_b(unsigned char source, char dest[], int values[], int *bar_chars) {
{
if (source > 127) { if (source > 127) {
concat(dest, C128Table[source - 32 - 128]); concat(dest, C128Table[source - 32 - 128]);
values[(*bar_chars)] = source - 32 - 128; values[(*bar_chars)] = source - 32 - 128;
@ -204,9 +278,10 @@ void c128_set_b(unsigned char source, char dest[], int values[], int *bar_chars)
(*bar_chars)++; (*bar_chars)++;
} }
void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int values[], int *bar_chars) /* Translate Code 128 Set C characters into barcodes
{ /* Translate Code 128 Set C characters into barcodes */ * This set handles numbers in a compressed form
/* This set handles numbers in a compressed form */ */
void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int values[], int *bar_chars) {
int weight; int weight;
weight = (10 * ctoi(source_a)) + ctoi(source_b); weight = (10 * ctoi(source_a)) + ctoi(source_b);
@ -215,8 +290,8 @@ void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int
(*bar_chars)++; (*bar_chars)++;
} }
int code_128(struct zint_symbol *symbol, unsigned char source[], int length) /* Handle Code 128 and NVE-18 */
{ /* Handle Code 128 and NVE-18 */ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, k, values[170] = {0}, bar_characters, read, total_sum; int i, j, k, values[170] = {0}, bar_characters, read, total_sum;
int error_number, indexchaine, indexliste, sourcelen, f_state; int error_number, indexchaine, indexliste, sourcelen, f_state;
char set[170] = {' '}, fset[170] = {' '}, mode, last_set, current_set = ' '; char set[170] = {' '}, fset[170] = {' '}, mode, last_set, current_set = ' ';
@ -338,11 +413,16 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {
for (j = 0; j < list[0][i]; j++) { for (j = 0; j < list[0][i]; j++) {
switch (list[1][i]) { switch (list[1][i]) {
case SHIFTA: set[read] = 'a'; break; case SHIFTA: set[read] = 'a';
case LATCHA: set[read] = 'A'; break; break;
case SHIFTB: set[read] = 'b'; break; case LATCHA: set[read] = 'A';
case LATCHB: set[read] = 'B'; break; break;
case LATCHC: set[read] = 'C'; break; case SHIFTB: set[read] = 'b';
break;
case LATCHB: set[read] = 'B';
break;
case LATCHC: set[read] = 'C';
break;
} }
read++; read++;
} }
@ -483,10 +563,9 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
read = 0; read = 0;
do { do {
if((read != 0) && (set[read] != current_set)) if ((read != 0) && (set[read] != current_set)) {
{ /* Latch different code set */ /* Latch different code set */
switch(set[read]) switch (set[read]) {
{
case 'A': concat(dest, C128Table[101]); case 'A': concat(dest, C128Table[101]);
values[bar_characters] = 101; values[bar_characters] = 101;
bar_characters++; bar_characters++;
@ -568,8 +647,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
bar_characters++; bar_characters++;
} }
switch(set[read]) switch (set[read]) { /* Encode data characters */
{ /* Encode data characters */
case 'a': case 'a':
case 'A': c128_set_a(source[read], dest, values, &bar_characters); case 'A': c128_set_a(source[read], dest, values, &bar_characters);
read++; read++;
@ -587,14 +665,9 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
/* check digit calculation */ /* check digit calculation */
total_sum = 0; total_sum = 0;
/*for(i = 0; i < bar_characters; i++) {
printf("%d\n", values[i]);
}*/
for(i = 0; i < bar_characters; i++) for (i = 0; i < bar_characters; i++) {
{ if (i > 0) {
if(i > 0)
{
values[i] *= i; values[i] *= i;
} }
total_sum += values[i]; total_sum += values[i];
@ -607,8 +680,8 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) /* Handle EAN-128 (Now known as GS1-128) */
{ /* Handle EAN-128 (Now known as GS1-128) */ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, j, values[170], bar_characters, read, total_sum; int i, j, values[170], bar_characters, read, total_sum;
int error_number, indexchaine, indexliste; int error_number, indexchaine, indexliste;
char set[170], mode, last_set; char set[170], mode, last_set;
@ -655,7 +728,9 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
if (symbol->input_mode != GS1_MODE) { if (symbol->input_mode != GS1_MODE) {
/* GS1 data has not been checked yet */ /* GS1 data has not been checked yet */
error_number = gs1_verify(symbol, source, length, reduced); error_number = gs1_verify(symbol, source, length, reduced);
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
} }
/* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */ /* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */
@ -677,7 +752,9 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
list[0][indexliste]++; list[0][indexliste]++;
indexchaine++; indexchaine++;
mode = parunmodd(reduced[indexchaine]); mode = parunmodd(reduced[indexchaine]);
if(reduced[indexchaine] == '[') { mode = ABORC; } if (reduced[indexchaine] == '[') {
mode = ABORC;
}
} }
indexliste++; indexliste++;
} while (indexchaine < strlen(reduced)); } while (indexchaine < strlen(reduced));
@ -689,11 +766,16 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {
for (j = 0; j < list[0][i]; j++) { for (j = 0; j < list[0][i]; j++) {
switch (list[1][i]) { switch (list[1][i]) {
case SHIFTA: set[read] = 'a'; break; case SHIFTA: set[read] = 'a';
case LATCHA: set[read] = 'A'; break; break;
case SHIFTB: set[read] = 'b'; break; case LATCHA: set[read] = 'A';
case LATCHB: set[read] = 'B'; break; break;
case LATCHC: set[read] = 'C'; break; case SHIFTB: set[read] = 'b';
break;
case LATCHB: set[read] = 'B';
break;
case LATCHC: set[read] = 'C';
break;
} }
read++; read++;
} }
@ -739,10 +821,6 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
/* for(i = 0; i < read; i++) {
printf("char %c mode %c\n", reduced[i], set[i]);
} */
/* Now we can calculate how long the barcode is going to be - and stop it from /* Now we can calculate how long the barcode is going to be - and stop it from
being too long */ being too long */
last_set = ' '; last_set = ' ';
@ -770,8 +848,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
} }
/* So now we know what start character to use - we can get on with it! */ /* So now we know what start character to use - we can get on with it! */
switch(set[0]) switch (set[0]) {
{
case 'A': /* Start A */ case 'A': /* Start A */
concat(dest, C128Table[103]); concat(dest, C128Table[103]);
values[0] = 103; values[0] = 103;
@ -795,10 +872,8 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
read = 0; read = 0;
do { do {
if((read != 0) && (set[read] != set[read - 1])) if ((read != 0) && (set[read] != set[read - 1])) { /* Latch different code set */
{ /* Latch different code set */ switch (set[read]) {
switch(set[read])
{
case 'A': concat(dest, C128Table[101]); case 'A': concat(dest, C128Table[101]);
values[bar_characters] = 101; values[bar_characters] = 101;
bar_characters++; bar_characters++;
@ -822,8 +897,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
} }
if (reduced[read] != '[') { if (reduced[read] != '[') {
switch(set[read]) switch (set[read]) { /* Encode data characters */
{ /* Encode data characters */
case 'A': case 'A':
case 'a': case 'a':
c128_set_a(reduced[read], dest, values, &bar_characters); c128_set_a(reduced[read], dest, values, &bar_characters);
@ -857,17 +931,23 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
case 2: case 2:
/* CC-A or CC-B 2D component */ /* CC-A or CC-B 2D component */
switch (set[strlen(reduced) - 1]) { switch (set[strlen(reduced) - 1]) {
case 'A': linkage_flag = 100; break; case 'A': linkage_flag = 100;
case 'B': linkage_flag = 99; break; break;
case 'C': linkage_flag = 101; break; case 'B': linkage_flag = 99;
break;
case 'C': linkage_flag = 101;
break;
} }
break; break;
case 3: case 3:
/* CC-C 2D component */ /* CC-C 2D component */
switch (set[strlen(reduced) - 1]) { switch (set[strlen(reduced) - 1]) {
case 'A': linkage_flag = 99; break; case 'A': linkage_flag = 99;
case 'B': linkage_flag = 101; break; break;
case 'C': linkage_flag = 100; break; case 'B': linkage_flag = 101;
break;
case 'C': linkage_flag = 100;
break;
} }
break; break;
} }
@ -878,17 +958,10 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
bar_characters++; bar_characters++;
} }
/*for(i = 0; i < bar_characters; i++) {
printf("[%d] ", values[i]);
}
printf("\n");*/
/* check digit calculation */ /* check digit calculation */
total_sum = 0; total_sum = 0;
for(i = 0; i < bar_characters; i++) for (i = 0; i < bar_characters; i++) {
{ if (i > 0) {
if(i > 0)
{
values[i] *= i; values[i] *= i;
} }
@ -928,9 +1001,8 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
{
/* Add check digit if encoding an NVE18 symbol */ /* Add check digit if encoding an NVE18 symbol */
int nve_18(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number, zeroes, i, nve_check, total_sum, sourcelen; int error_number, zeroes, i, nve_check, total_sum, sourcelen;
unsigned char ean128_equiv[25]; unsigned char ean128_equiv[25];
@ -953,8 +1025,7 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy((char*) ean128_equiv + 4 + zeroes, (char*) source); strcpy((char*) ean128_equiv + 4 + zeroes, (char*) source);
total_sum = 0; total_sum = 0;
for(i = sourcelen - 1; i >= 0; i--) for (i = sourcelen - 1; i >= 0; i--) {
{
total_sum += ctoi(source[i]); total_sum += ctoi(source[i]);
if (!(i & 1)) { if (!(i & 1)) {
@ -962,7 +1033,9 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
nve_check = 10 - total_sum % 10; nve_check = 10 - total_sum % 10;
if(nve_check == 10) { nve_check = 0; } if (nve_check == 10) {
nve_check = 0;
}
ean128_equiv[21] = itoc(nve_check); ean128_equiv[21] = itoc(nve_check);
ean128_equiv[22] = '\0'; ean128_equiv[22] = '\0';
@ -971,9 +1044,8 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
return error_number; return error_number;
} }
int ean_14(struct zint_symbol *symbol, unsigned char source[], int length)
{
/* EAN-14 - A version of EAN-128 */ /* EAN-14 - A version of EAN-128 */
int ean_14(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, count, check_digit; int i, count, check_digit;
int error_number, zeroes; int error_number, zeroes;
unsigned char ean128_equiv[20]; unsigned char ean128_equiv[20];
@ -1003,7 +1075,9 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} }
check_digit = 10 - (count % 10); check_digit = 10 - (count % 10);
if (check_digit == 10) { check_digit = 0; } if (check_digit == 10) {
check_digit = 0;
}
ean128_equiv[17] = itoc(check_digit); ean128_equiv[17] = itoc(check_digit);
ean128_equiv[18] = '\0'; ean128_equiv[18] = '\0';

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -32,7 +32,7 @@
/* Updated to comply with BS EN 12323:2005 */ /* Updated to comply with BS EN 12323:2005 */
/* up to 77 characters or 154 numbers */ /* Code 16k can hold up to 77 characters or 154 numbers */
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -54,8 +54,9 @@
static int list[2][170]; static int list[2][170];
static const char *C16KTable[107] = {
/* EN 12323 Table 1 - "Code 16K" character encodations */ /* EN 12323 Table 1 - "Code 16K" character encodations */
static const char *C16KTable[107] = {"212222", "222122", "222221", "121223", "121322", "131222", "122213", "212222", "222122", "222221", "121223", "121322", "131222", "122213",
"122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222", "122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222",
"123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222", "123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222",
"321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323", "321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323",
@ -67,17 +68,25 @@ static const char *C16KTable[107] = {"212222", "222122", "222221", "121223", "12
"134111", "111242", "121142", "121241", "114212", "124112", "124211", "411212", "421112", "134111", "111242", "121142", "121241", "114212", "124112", "124211", "411212", "421112",
"421211", "212141", "214121", "412121", "111143", "111341", "131141", "114113", "114311", "421211", "212141", "214121", "412121", "111143", "111341", "131141", "114113", "114311",
"411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232", "411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232",
"211133"}; "211133"
};
static const char *C16KStartStop[8] = {
/* EN 12323 Table 3 and Table 4 - Start patterns and stop patterns */ /* EN 12323 Table 3 and Table 4 - Start patterns and stop patterns */
static const char *C16KStartStop[8] = {"3211", "2221", "2122", "1411", "1132", "1231", "1114", "3112"}; "3211", "2221", "2122", "1411", "1132", "1231", "1114", "3112"
};
/* EN 12323 Table 5 - Start and stop values defining row numbers */ /* EN 12323 Table 5 - Start and stop values defining row numbers */
static const int C16KStartValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}; static const int C16KStartValues[16] = {
static const int C16KStopValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3}; 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7
};
void grwp16(int *indexliste) static const int C16KStopValues[16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3
};
void grwp16(int *indexliste) {
int i, j; int i, j;
/* bring together same type blocks */ /* bring together same type blocks */
@ -103,46 +112,115 @@ void grwp16(int *indexliste)
} }
} }
void dxsmooth16(int *indexliste) /* Implements rules from ISO 15417 Annex E */
{ /* Implements rules from ISO 15417 Annex E */ void dxsmooth16(int *indexliste) {
int i, current, last, next, length; int i, current, last, next, length;
for (i = 0; i < *(indexliste); i++) { for (i = 0; i < *(indexliste); i++) {
current = list[1][i]; current = list[1][i];
length = list[0][i]; length = list[0][i];
if(i != 0) { last = list[1][i - 1]; } else { last = FALSE; } if (i != 0) {
if(i != *(indexliste) - 1) { next = list[1][i + 1]; } else { next = FALSE; } last = list[1][i - 1];
if(i == 0) { /* first block */
if((*(indexliste) == 1) && ((length == 2) && (current == ABORC))) { /* Rule 1a */ list[1][i] = LATCHC; }
if(current == ABORC) {
if(length >= 4) {/* Rule 1b */ list[1][i] = LATCHC; } else { list[1][i] = AORB; current = AORB; }
}
if(current == SHIFTA) { /* Rule 1c */ list[1][i] = LATCHA; }
if((current == AORB) && (next == SHIFTA)) { /* Rule 1c */ list[1][i] = LATCHA; current = LATCHA; }
if(current == AORB) { /* Rule 1d */ list[1][i] = LATCHB; }
} else { } else {
if((current == ABORC) && (length >= 4)) { /* Rule 3 */ list[1][i] = LATCHC; current = LATCHC; } last = FALSE;
if(current == ABORC) { list[1][i] = AORB; current = AORB; } }
if((current == AORB) && (last == LATCHA)) { list[1][i] = LATCHA; current = LATCHA; } if (i != *(indexliste) - 1) {
if((current == AORB) && (last == LATCHB)) { list[1][i] = LATCHB; current = LATCHB; } next = list[1][i + 1];
if((current == AORB) && (next == SHIFTA)) { list[1][i] = LATCHA; current = LATCHA; } } else {
if((current == AORB) && (next == SHIFTB)) { list[1][i] = LATCHB; current = LATCHB; } next = FALSE;
if(current == AORB) { list[1][i] = LATCHB; current = LATCHB; } }
if((current == SHIFTA) && (length > 1)) { /* Rule 4 */ list[1][i] = LATCHA; current = LATCHA; }
if((current == SHIFTB) && (length > 1)) { /* Rule 5 */ list[1][i] = LATCHB; current = LATCHB; } if (i == 0) {
if((current == SHIFTA) && (last == LATCHA)) { list[1][i] = LATCHA; current = LATCHA; } /* first block */
if((current == SHIFTB) && (last == LATCHB)) { list[1][i] = LATCHB; current = LATCHB; } if ((*(indexliste) == 1) && ((length == 2) && (current == ABORC))) {
if((current == SHIFTA) && (last == LATCHC)) { list[1][i] = LATCHA; current = LATCHA; } /* Rule 1a */
if((current == SHIFTB) && (last == LATCHC)) { list[1][i] = LATCHB; current = LATCHB; } list[1][i] = LATCHC;
}
if (current == ABORC) {
if (length >= 4) {
/* Rule 1b */
list[1][i] = LATCHC;
} else {
list[1][i] = AORB;
current = AORB;
}
}
if (current == SHIFTA) {
/* Rule 1c */
list[1][i] = LATCHA;
}
if ((current == AORB) && (next == SHIFTA)) {
/* Rule 1c */
list[1][i] = LATCHA;
current = LATCHA;
}
if (current == AORB) {
/* Rule 1d */
list[1][i] = LATCHB;
}
} else {
if ((current == ABORC) && (length >= 4)) {
/* Rule 3 */
list[1][i] = LATCHC;
current = LATCHC;
}
if (current == ABORC) {
list[1][i] = AORB;
current = AORB;
}
if ((current == AORB) && (last == LATCHA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == AORB) && (last == LATCHB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == AORB) && (next == SHIFTA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == AORB) && (next == SHIFTB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if (current == AORB) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (length > 1)) {
/* Rule 4 */
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (length > 1)) {
/* Rule 5 */
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (last == LATCHA)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (last == LATCHB)) {
list[1][i] = LATCHB;
current = LATCHB;
}
if ((current == SHIFTA) && (last == LATCHC)) {
list[1][i] = LATCHA;
current = LATCHA;
}
if ((current == SHIFTB) && (last == LATCHC)) {
list[1][i] = LATCHB;
current = LATCHB;
}
} /* Rule 2 is implimented elsewhere, Rule 6 is implied */ } /* Rule 2 is implimented elsewhere, Rule 6 is implied */
} }
grwp16(indexliste); grwp16(indexliste);
} }
void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars) void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars) {
{
if (source > 127) { if (source > 127) {
if (source < 160) { if (source < 160) {
values[(*bar_chars)] = source + 64 - 128; values[(*bar_chars)] = source + 64 - 128;
@ -159,8 +237,7 @@ void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_c
(*bar_chars)++; (*bar_chars)++;
} }
void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_chars) void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_chars) {
{
if (source > 127) { if (source > 127) {
values[(*bar_chars)] = source - 32 - 128; values[(*bar_chars)] = source - 32 - 128;
} else { } else {
@ -169,8 +246,7 @@ void c16k_set_b(unsigned char source, unsigned int values[], unsigned int *bar_c
(*bar_chars)++; (*bar_chars)++;
} }
void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int values[], unsigned int *bar_chars) void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int values[], unsigned int *bar_chars) {
{
int weight; int weight;
weight = (10 * ctoi(source_a)) + ctoi(source_b); weight = (10 * ctoi(source_a)) + ctoi(source_b);
@ -178,8 +254,7 @@ void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int val
(*bar_chars)++; (*bar_chars)++;
} }
int code16k(struct zint_symbol *symbol, unsigned char source[], int length) int code16k(struct zint_symbol *symbol, unsigned char source[], int length) {
{
char width_pattern[100]; char width_pattern[100];
int current_row, rows_needed, flip_flop, looper, first_check, second_check; int current_row, rows_needed, flip_flop, looper, first_check, second_check;
int indexliste, indexchaine, pads_needed, f_state; int indexliste, indexchaine, pads_needed, f_state;
@ -196,7 +271,11 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(width_pattern, ""); strcpy(width_pattern, "");
input_length = length; input_length = length;
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } if (symbol->input_mode == GS1_MODE) {
gs1 = 1;
} else {
gs1 = 0;
}
if (input_length > 157) { if (input_length > 157) {
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
@ -248,7 +327,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
indexchaine = 0; indexchaine = 0;
mode = parunmodd(source[indexchaine]); mode = parunmodd(source[indexchaine]);
if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */ if ((gs1) && (source[indexchaine] == '[')) {
mode = ABORC;
} /* FNC1 */
for (i = 0; i < 160; i++) { for (i = 0; i < 160; i++) {
list[0][i] = 0; list[0][i] = 0;
@ -260,7 +341,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
list[0][indexliste]++; list[0][indexliste]++;
indexchaine++; indexchaine++;
mode = parunmodd(source[indexchaine]); mode = parunmodd(source[indexchaine]);
if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */ if ((gs1) && (source[indexchaine] == '[')) {
mode = ABORC;
} /* FNC1 */
} }
indexliste++; indexliste++;
} while (indexchaine < input_length); } while (indexchaine < input_length);
@ -272,11 +355,16 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
for (i = 0; i < indexliste; i++) { for (i = 0; i < indexliste; i++) {
for (j = 0; j < list[0][i]; j++) { for (j = 0; j < list[0][i]; j++) {
switch (list[1][i]) { switch (list[1][i]) {
case SHIFTA: set[read] = 'a'; break; case SHIFTA: set[read] = 'a';
case LATCHA: set[read] = 'A'; break; break;
case SHIFTB: set[read] = 'b'; break; case LATCHA: set[read] = 'A';
case LATCHB: set[read] = 'B'; break; break;
case LATCHC: set[read] = 'C'; break; case SHIFTB: set[read] = 'b';
break;
case LATCHB: set[read] = 'B';
break;
case LATCHC: set[read] = 'C';
break;
} }
read++; read++;
} }
@ -397,7 +485,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
glyph_count = glyph_count + 2.0; glyph_count = glyph_count + 2.0;
i = glyph_count; i = glyph_count;
rows_needed = (i / 5); rows_needed = (i / 5);
if(i%5 > 0) { rows_needed++; } if (i % 5 > 0) {
rows_needed++;
}
if (rows_needed == 1) { if (rows_needed == 1) {
rows_needed = 2; rows_needed = 2;
@ -406,18 +496,25 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
/* start with the mode character - Table 2 */ /* start with the mode character - Table 2 */
m = 0; m = 0;
switch (set[0]) { switch (set[0]) {
case 'A': m = 0; break; case 'A': m = 0;
case 'B': m = 1; break; break;
case 'C': m = 2; break; case 'B': m = 1;
break;
case 'C': m = 2;
break;
} }
if (symbol->output_options & READER_INIT) { if (symbol->output_options & READER_INIT) {
if(m == 2) { m = 5; } if (m == 2) {
m = 5;
}
if (gs1) { if (gs1) {
strcpy(symbol->errtxt, "Cannot use both GS1 mode and Reader Initialisation"); strcpy(symbol->errtxt, "Cannot use both GS1 mode and Reader Initialisation");
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
} else { } else {
if((set[0] == 'B') && (set[1] == 'C')) { m = 6; } if ((set[0] == 'B') && (set[1] == 'C')) {
m = 6;
}
} }
values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */ values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
values[bar_characters + 1] = 96; /* FNC3 */ values[bar_characters + 1] = 96; /* FNC3 */
@ -426,19 +523,26 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
if (gs1) { if (gs1) {
/* Integrate FNC1 */ /* Integrate FNC1 */
switch (set[0]) { switch (set[0]) {
case 'B': m = 3; break; case 'B': m = 3;
case 'C': m = 4; break; break;
case 'C': m = 4;
break;
} }
} else { } else {
if((set[0] == 'B') && (set[1] == 'C')) { m = 5; } if ((set[0] == 'B') && (set[1] == 'C')) {
if(((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) { m = 6; } m = 5;
}
if (((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C')) {
m = 6;
}
} }
values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */ values[bar_characters] = (7 * (rows_needed - 2)) + m; /* see 4.3.4.2 */
bar_characters++; bar_characters++;
} }
current_set = set[0]; current_set = set[0];
f_state = 0; /* f_state remembers if we are in Extended ASCII mode (value 1) or f_state = 0;
/* f_state remembers if we are in Extended ASCII mode (value 1) or
in ISO/IEC 646 mode (value 0) */ in ISO/IEC 646 mode (value 0) */
if (fset[0] == 'F') { if (fset[0] == 'F') {
switch (current_set) { switch (current_set) {
@ -460,10 +564,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
/* Encode the data */ /* Encode the data */
do { do {
if((read != 0) && (set[read] != set[read - 1])) if ((read != 0) && (set[read] != set[read - 1])) {
{ /* Latch different code set */ /* Latch different code set */
switch(set[read]) switch (set[read]) {
{
case 'A': case 'A':
values[bar_characters] = 101; values[bar_characters] = 101;
bar_characters++; bar_characters++;
@ -475,7 +578,8 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
current_set = 'B'; current_set = 'B';
break; break;
case 'C': case 'C':
if(!((read == 1) && (set[0] == 'B'))) { /* Not Mode C/Shift B */ if (!((read == 1) && (set[0] == 'B'))) {
/* Not Mode C/Shift B */
if (!((read == 2) && ((set[0] == 'B') && (set[1] == 'B')))) { if (!((read == 2) && ((set[0] == 'B') && (set[1] == 'B')))) {
/* Not Mode C/Double Shift B */ /* Not Mode C/Double Shift B */
values[bar_characters] = 99; values[bar_characters] = 99;
@ -486,7 +590,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
break; break;
} }
} }
/* printf("tp8\n"); */
if (read != 0) { if (read != 0) {
if ((fset[read] == 'F') && (f_state == 0)) { if ((fset[read] == 'F') && (f_state == 0)) {
/* Latch beginning of extended mode */ /* Latch beginning of extended mode */
@ -540,8 +644,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
} }
if (!((gs1) && (source[read] == '['))) { if (!((gs1) && (source[read] == '['))) {
switch(set[read]) switch (set[read]) { /* Encode data characters */
{ /* Encode data characters */
case 'A': case 'A':
case 'a': case 'a':
c16k_set_a(source[read], values, &bar_characters); c16k_set_a(source[read], values, &bar_characters);
@ -561,7 +664,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
bar_characters++; bar_characters++;
read++; read++;
} }
/* printf("tp9 read=%d surrent set=%c\n", read, set[read]); */
} while (read < ustrlen(source)); } while (read < ustrlen(source));
pads_needed = 5 - ((bar_characters + 2) % 5); pads_needed = 5 - ((bar_characters + 2) % 5);
@ -579,8 +681,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
/* Calculate check digits */ /* Calculate check digits */
first_sum = 0; first_sum = 0;
second_sum = 0; second_sum = 0;
for(i = 0; i < bar_characters; i++) for (i = 0; i < bar_characters; i++) {
{
first_sum += (i + 2) * values[i]; first_sum += (i + 2) * values[i];
second_sum += (i + 1) * values[i]; second_sum += (i + 1) * values[i];
} }
@ -598,11 +699,8 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
concat(width_pattern, "1"); concat(width_pattern, "1");
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
concat(width_pattern, C16KTable[values[(current_row * 5) + i]]); concat(width_pattern, C16KTable[values[(current_row * 5) + i]]);
/* printf("[%d] ", values[(current_row * 5) + i]); */
} }
concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]); concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]);
/* printf("\n"); */
/* Write the information into the symbol */ /* Write the information into the symbol */
writer = 0; writer = 0;
@ -611,11 +709,16 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
for (looper = 0; looper < ctoi(width_pattern[mx_reader]); looper++) { for (looper = 0; looper < ctoi(width_pattern[mx_reader]); looper++) {
if (flip_flop == 1) { if (flip_flop == 1) {
set_module(symbol, current_row, writer); set_module(symbol, current_row, writer);
writer++; } writer++;
else { } else {
writer++; } writer++;
}
}
if (flip_flop == 0) {
flip_flop = 1;
} else {
flip_flop = 0;
} }
if(flip_flop == 0) { flip_flop = 1; } else { flip_flop = 0; }
} }
symbol->row_height[current_row] = 10; symbol->row_height[current_row] = 10;
} }

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -37,10 +37,10 @@
#include "code49.h" #include "code49.h"
#define INSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%!&*" #define INSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%!&*"
/* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */ /* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */
int code_49(struct zint_symbol *symbol, unsigned char source[], int length) int code_49(struct zint_symbol *symbol, unsigned char source[], int length) {
{
int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h; int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h;
char intermediate[170]; char intermediate[170];
int codewords[170], codeword_count; int codewords[170], codeword_count;
@ -54,9 +54,13 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(symbol->errtxt, "Input too long"); strcpy(symbol->errtxt, "Input too long");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } if (symbol->input_mode == GS1_MODE) {
gs1 = 1;
strcpy(intermediate, "*"); /* FNC1 */
} else {
gs1 = 0;
}
strcpy(intermediate, gs1 ? "*" : ""); /* FNC1 */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (source[i] > 127) { if (source[i] > 127) {
strcpy(symbol->errtxt, "Invalid characters in input data"); strcpy(symbol->errtxt, "Invalid characters in input data");
@ -190,11 +194,16 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
} }
} while (i < h); } while (i < h);
switch(codewords[0]) { /* Set starting mode value */ switch (codewords[0]) {
case 48: M = 2; break; /* Set starting mode value */
case 43: M = 4; break; case 48: M = 2;
case 44: M = 5; break; break;
default: M = 0; break; case 43: M = 4;
break;
case 44: M = 5;
break;
default: M = 0;
break;
} }
if (M != 0) { if (M != 0) {

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -34,16 +34,16 @@
#include <stdlib.h> #include <stdlib.h>
#include "common.h" #include "common.h"
int ustrlen(const unsigned char data[]) {
/* Local replacement for strlen() with unsigned char strings */ /* Local replacement for strlen() with unsigned char strings */
int ustrlen(const unsigned char data[]) {
int i; int i;
for (i = 0; data[i]; i++); for (i = 0; data[i]; i++);
return i; return i;
} }
void ustrcpy(unsigned char target[],const unsigned char source[]) {
/* Local replacement for strcpy() with unsigned char strings */ /* Local replacement for strcpy() with unsigned char strings */
void ustrcpy(unsigned char target[], const unsigned char source[]) {
int i, len; int i, len;
len = ustrlen(source); len = ustrlen(source);
@ -53,53 +53,56 @@ void ustrcpy(unsigned char target[],const unsigned char source[]) {
target[i] = '\0'; target[i] = '\0';
} }
void concat(char dest[],const char source[]) /* Concatinates dest[] with the contents of source[], copying /0 as well */
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */ void concat(char dest[], const char source[]) {
unsigned int i, j, n; unsigned int i, j, n;
j = strlen(dest); j = strlen(dest);
n = strlen(source); n = strlen(source);
for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) {
dest[i + j] = source[i]; } dest[i + j] = source[i];
}
} }
void uconcat(unsigned char dest[], const unsigned char source[]) /* Concatinates dest[] with the contents of source[], copying /0 as well */
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */ void uconcat(unsigned char dest[], const unsigned char source[]) {
unsigned int i, j; unsigned int i, j;
j = ustrlen(dest); j = ustrlen(dest);
for (i = 0; i <= ustrlen(source); i++) { for (i = 0; i <= ustrlen(source); i++) {
dest[i + j] = source[i]; } dest[i + j] = source[i];
}
} }
/* Converts a character 0-9 to its equivalent integer value */
int ctoi(char source) int ctoi(char source) {
{ /* Converts a character 0-9 to its equivalent integer value */
if ((source >= '0') && (source <= '9')) if ((source >= '0') && (source <= '9'))
return (source - '0'); return (source - '0');
return (source - 'A' + 10); return (source - 'A' + 10);
} }
char itoc(int source) /* Converts an integer value to its hexadecimal character */
{ /* Converts an integer value to its hexadecimal character */ char itoc(int source) {
if ((source >= 0) && (source <= 9)) { if ((source >= 0) && (source <= 9)) {
return ('0' + source); } return ('0' + source);
else { } else {
return ('A' + (source - 10)); } return ('A' + (source - 10));
}
} }
void to_upper(unsigned char source[]) /* Converts lower case characters to upper case in a string source[] */
{ /* Converts lower case characters to upper case in a string source[] */ void to_upper(unsigned char source[]) {
unsigned int i, src_len = ustrlen(source); unsigned int i, src_len = ustrlen(source);
for (i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
if ((source[i] >= 'a') && (source[i] <= 'z')) { if ((source[i] >= 'a') && (source[i] <= 'z')) {
source [i] = (source[i] - 'a') + 'A'; } source [i] = (source[i] - 'a') + 'A';
}
} }
} }
int is_sane(char test_string[], unsigned char source[], int length) /* Verifies that a string only uses valid characters */
{ /* Verifies that a string only uses valid characters */ int is_sane(char test_string[], unsigned char source[], int length) {
unsigned int i, j, latch; unsigned int i, j, latch;
unsigned int lt = strlen(test_string); unsigned int lt = strlen(test_string);
@ -119,86 +122,46 @@ int is_sane(char test_string[], unsigned char source[], int length)
return 0; return 0;
} }
int posn(char set_string[], char data) /* Returns the position of data in set_string */
{ /* Returns the position of data in set_string */ int posn(char set_string[], char data) {
unsigned int i, n = strlen(set_string); unsigned int i, n = strlen(set_string);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (data == set_string[i]) { return i; } } if (data == set_string[i]) {
return i;
}
}
return 0; return 0;
} }
void lookup(char set_string[],const char *table[], char data, char dest[]) /* Replaces huge switch statements for looking up in tables */
{ /* Replaces huge switch statements for looking up in tables */ void lookup(char set_string[], const char *table[], char data, char dest[]) {
unsigned int i, n = strlen(set_string); unsigned int i, n = strlen(set_string);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (data == set_string[i]) { concat(dest, table[i]); } } if (data == set_string[i]) {
concat(dest, table[i]);
}
}
} }
int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) /* Return true (1) if a module is dark/black, orherwise false (0) */
{ int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord) {
return (symbol->encoded_data[y_coord][x_coord / 7] >> (x_coord % 7)) & 1; 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;
case 1: if((symbol->encoded_data[y_coord][x_char] & 0x02) != 0) { result = 1; } break;
case 2: if((symbol->encoded_data[y_coord][x_char] & 0x04) != 0) { result = 1; } break;
case 3: if((symbol->encoded_data[y_coord][x_char] & 0x08) != 0) { result = 1; } break;
case 4: if((symbol->encoded_data[y_coord][x_char] & 0x10) != 0) { result = 1; } break;
case 5: if((symbol->encoded_data[y_coord][x_char] & 0x20) != 0) { result = 1; } break;
case 6: if((symbol->encoded_data[y_coord][x_char] & 0x40) != 0) { result = 1; } break;
} }
return result; /* Set a module to dark/black */
#endif void set_module(struct zint_symbol *symbol, int y_coord, int x_coord) {
}
void set_module(struct zint_symbol *symbol, int y_coord, int x_coord)
{
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;
x_char = x_coord / 7;
x_sub = x_coord % 7;
switch(x_sub) {
case 0: symbol->encoded_data[y_coord][x_char] += 0x01; break;
case 1: symbol->encoded_data[y_coord][x_char] += 0x02; break;
case 2: symbol->encoded_data[y_coord][x_char] += 0x04; break;
case 3: symbol->encoded_data[y_coord][x_char] += 0x08; break;
case 4: symbol->encoded_data[y_coord][x_char] += 0x10; break;
case 5: symbol->encoded_data[y_coord][x_char] += 0x20; break;
case 6: symbol->encoded_data[y_coord][x_char] += 0x40; break;
} /* The last binary digit is reserved for colour barcodes */
#endif
} }
void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) /* Set (or unset) a module to white */
{ void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) {
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;
x_char = x_coord / 7;
x_sub = x_coord % 7;
switch(x_sub) {
case 0: symbol->encoded_data[y_coord][x_char] -= 0x01; break;
case 1: symbol->encoded_data[y_coord][x_char] -= 0x02; break;
case 2: symbol->encoded_data[y_coord][x_char] -= 0x04; break;
case 3: symbol->encoded_data[y_coord][x_char] -= 0x08; break;
case 4: symbol->encoded_data[y_coord][x_char] -= 0x10; break;
case 5: symbol->encoded_data[y_coord][x_char] -= 0x20; break;
case 6: symbol->encoded_data[y_coord][x_char] -= 0x40; break;
} /* The last binary digit is reserved for colour barcodes */
#endif
} }
void expand(struct zint_symbol *symbol, char data[]) /* Expands from a width pattern to a bit pattern */
{ /* Expands from a width pattern to a bit pattern */ void expand(struct zint_symbol *symbol, char data[]) {
unsigned int reader, n = strlen(data); unsigned int reader, n = strlen(data);
int writer, i; int writer, i;
@ -209,7 +172,9 @@ void expand(struct zint_symbol *symbol, char data[])
for (reader = 0; reader < n; reader++) { for (reader = 0; reader < n; reader++) {
for (i = 0; i < ctoi(data[reader]); i++) { for (i = 0; i < ctoi(data[reader]); i++) {
if(latch == '1') { set_module(symbol, symbol->rows, writer); } if (latch == '1') {
set_module(symbol, symbol->rows, writer);
}
writer++; writer++;
} }
@ -229,37 +194,70 @@ void expand(struct zint_symbol *symbol, char data[])
symbol->rows = symbol->rows + 1; symbol->rows = symbol->rows + 1;
} }
int is_stackable(int symbology) {
/* Indicates which symbologies can have row binding */ /* Indicates which symbologies can have row binding */
if(symbology < BARCODE_PDF417) { return 1; } int is_stackable(int symbology) {
if(symbology == BARCODE_CODE128B) { return 1; } if (symbology < BARCODE_PDF417) {
if(symbology == BARCODE_ISBNX) { return 1; } return 1;
if(symbology == BARCODE_EAN14) { return 1; } }
if(symbology == BARCODE_NVE18) { return 1; } if (symbology == BARCODE_CODE128B) {
if(symbology == BARCODE_KOREAPOST) { return 1; } return 1;
if(symbology == BARCODE_PLESSEY) { return 1; } }
if(symbology == BARCODE_TELEPEN_NUM) { return 1; } if (symbology == BARCODE_ISBNX) {
if(symbology == BARCODE_ITF14) { return 1; } return 1;
if(symbology == BARCODE_CODE32) { return 1; } }
if (symbology == BARCODE_EAN14) {
return 1;
}
if (symbology == BARCODE_NVE18) {
return 1;
}
if (symbology == BARCODE_KOREAPOST) {
return 1;
}
if (symbology == BARCODE_PLESSEY) {
return 1;
}
if (symbology == BARCODE_TELEPEN_NUM) {
return 1;
}
if (symbology == BARCODE_ITF14) {
return 1;
}
if (symbology == BARCODE_CODE32) {
return 1;
}
return 0; return 0;
} }
/* Indicates which symbols can have addon (EAN-2 and EAN-5) */
int is_extendable(int symbology) { int is_extendable(int symbology) {
/* Indicates which symbols can have addon */ if (symbology == BARCODE_EANX) {
if(symbology == BARCODE_EANX) { return 1; } return 1;
if(symbology == BARCODE_UPCA) { return 1; } }
if(symbology == BARCODE_UPCE) { return 1; } if (symbology == BARCODE_UPCA) {
if(symbology == BARCODE_ISBNX) { return 1; } return 1;
if(symbology == BARCODE_UPCA_CC) { return 1; } }
if(symbology == BARCODE_UPCE_CC) { return 1; } if (symbology == BARCODE_UPCE) {
if(symbology == BARCODE_EANX_CC) { return 1; } return 1;
}
if (symbology == BARCODE_ISBNX) {
return 1;
}
if (symbology == BARCODE_UPCA_CC) {
return 1;
}
if (symbology == BARCODE_UPCE_CC) {
return 1;
}
if (symbology == BARCODE_EANX_CC) {
return 1;
}
return 0; return 0;
} }
int roundup(float input) int roundup(float input) {
{
float remainder; float remainder;
int integer_part; int integer_part;
@ -273,8 +271,7 @@ int roundup(float input)
return integer_part; return integer_part;
} }
int istwodigits(unsigned char source[], int position) int istwodigits(unsigned char source[], int position) {
{
if ((source[position] >= '0') && (source[position] <= '9')) { if ((source[position] >= '0') && (source[position] <= '9')) {
if ((source[position + 1] >= '0') && (source[position + 1] <= '9')) { if ((source[position + 1] >= '0') && (source[position + 1] <= '9')) {
return 1; return 1;
@ -284,21 +281,23 @@ int istwodigits(unsigned char source[], int position)
return 0; return 0;
} }
float froundup(float input) float froundup(float input) {
{
float fraction, output = 0.0; float fraction, output = 0.0;
fraction = input - (int) input; fraction = input - (int) input;
if(fraction > 0.01) { output = (input - fraction) + 1.0; } else { output = input; } if (fraction > 0.01) {
output = (input - fraction) + 1.0;
} else {
output = input;
}
return output; return output;
} }
int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length) /* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */
{ int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length) {
int j, i, next; int j, i, next;
/* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */
j = 0; j = 0;
i = 0; i = 0;
do { do {
@ -331,8 +330,7 @@ int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned
return 0; return 0;
} }
int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length) {
{
int bpos, jpos, error_number; int bpos, jpos, error_number;
int next; int next;

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -48,8 +48,7 @@
#include "zint.h" #include "zint.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif /* __cplusplus */ #endif /* __cplusplus */
extern int ustrlen(const unsigned char source[]); extern int ustrlen(const unsigned char source[]);

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
developed from and including some functions from: developed from and including some functions from:
IEC16022 bar code generation IEC16022 bar code generation
@ -52,8 +52,7 @@
#include "dmatrix.h" #include "dmatrix.h"
// Annex M placement alorithm low level // Annex M placement alorithm low level
static void ecc200placementbit(int *array, int NR, int NC, int r, int c, int p, char b) static void ecc200placementbit(int *array, int NR, int NC, int r, int c, int p, char b) {
{
if (r < 0) { if (r < 0) {
r += NR; r += NR;
c += 4 - ((NR + 4) % 8); c += 4 - ((NR + 4) % 8);
@ -87,9 +86,7 @@ static void ecc200placementbit(int *array, int NR, int NC, int r, int c, int p,
array[r * NC + c] = (p << 3) + b; array[r * NC + c] = (p << 3) + b;
} }
static void ecc200placementblock(int *array, int NR, int NC, int r, static void ecc200placementblock(int *array, int NR, int NC, int r, int c, int p) {
int c, int p)
{
ecc200placementbit(array, NR, NC, r - 2, c - 2, p, 7); ecc200placementbit(array, NR, NC, r - 2, c - 2, p, 7);
ecc200placementbit(array, NR, NC, r - 2, c - 1, p, 6); ecc200placementbit(array, NR, NC, r - 2, c - 1, p, 6);
ecc200placementbit(array, NR, NC, r - 1, c - 2, p, 5); ecc200placementbit(array, NR, NC, r - 1, c - 2, p, 5);
@ -100,8 +97,7 @@ static void ecc200placementblock(int *array, int NR, int NC, int r,
ecc200placementbit(array, NR, NC, r - 0, c - 0, p, 0); ecc200placementbit(array, NR, NC, r - 0, c - 0, p, 0);
} }
static void ecc200placementcornerA(int *array, int NR, int NC, int p) static void ecc200placementcornerA(int *array, int NR, int NC, int p) {
{
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 7); ecc200placementbit(array, NR, NC, NR - 1, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 1, 1, p, 6); ecc200placementbit(array, NR, NC, NR - 1, 1, p, 6);
ecc200placementbit(array, NR, NC, NR - 1, 2, p, 5); ecc200placementbit(array, NR, NC, NR - 1, 2, p, 5);
@ -112,8 +108,7 @@ static void ecc200placementcornerA(int *array, int NR, int NC, int p)
ecc200placementbit(array, NR, NC, 3, NC - 1, p, 0); ecc200placementbit(array, NR, NC, 3, NC - 1, p, 0);
} }
static void ecc200placementcornerB(int *array, int NR, int NC, int p) static void ecc200placementcornerB(int *array, int NR, int NC, int p) {
{
ecc200placementbit(array, NR, NC, NR - 3, 0, p, 7); ecc200placementbit(array, NR, NC, NR - 3, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 2, 0, p, 6); ecc200placementbit(array, NR, NC, NR - 2, 0, p, 6);
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 5); ecc200placementbit(array, NR, NC, NR - 1, 0, p, 5);
@ -124,8 +119,7 @@ static void ecc200placementcornerB(int *array, int NR, int NC, int p)
ecc200placementbit(array, NR, NC, 1, NC - 1, p, 0); ecc200placementbit(array, NR, NC, 1, NC - 1, p, 0);
} }
static void ecc200placementcornerC(int *array, int NR, int NC, int p) static void ecc200placementcornerC(int *array, int NR, int NC, int p) {
{
ecc200placementbit(array, NR, NC, NR - 3, 0, p, 7); ecc200placementbit(array, NR, NC, NR - 3, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 2, 0, p, 6); ecc200placementbit(array, NR, NC, NR - 2, 0, p, 6);
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 5); ecc200placementbit(array, NR, NC, NR - 1, 0, p, 5);
@ -136,8 +130,7 @@ static void ecc200placementcornerC(int *array, int NR, int NC, int p)
ecc200placementbit(array, NR, NC, 3, NC - 1, p, 0); ecc200placementbit(array, NR, NC, 3, NC - 1, p, 0);
} }
static void ecc200placementcornerD(int *array, int NR, int NC, int p) static void ecc200placementcornerD(int *array, int NR, int NC, int p) {
{
ecc200placementbit(array, NR, NC, NR - 1, 0, p, 7); ecc200placementbit(array, NR, NC, NR - 1, 0, p, 7);
ecc200placementbit(array, NR, NC, NR - 1, NC - 1, p, 6); ecc200placementbit(array, NR, NC, NR - 1, NC - 1, p, 6);
ecc200placementbit(array, NR, NC, 0, NC - 3, p, 5); ecc200placementbit(array, NR, NC, 0, NC - 3, p, 5);
@ -149,8 +142,7 @@ static void ecc200placementcornerD(int *array, int NR, int NC, int p)
} }
// Annex M placement alorithm main function // Annex M placement alorithm main function
static void ecc200placement(int *array, int NR, int NC) static void ecc200placement(int *array, int NR, int NC) {
{
int r, c, p; int r, c, p;
// invalidate // invalidate
for (r = 0; r < NR; r++) for (r = 0; r < NR; r++)
@ -176,8 +168,7 @@ static void ecc200placement(int *array, int NR, int NC)
ecc200placementblock(array, NR, NC, r, c, p++); ecc200placementblock(array, NR, NC, r, c, p++);
r -= 2; r -= 2;
c += 2; c += 2;
} } while (r >= 0 && c < NC);
while (r >= 0 && c < NC);
r++; r++;
c += 3; c += 3;
// down/left // down/left
@ -186,20 +177,17 @@ static void ecc200placement(int *array, int NR, int NC)
ecc200placementblock(array, NR, NC, r, c, p++); ecc200placementblock(array, NR, NC, r, c, p++);
r += 2; r += 2;
c -= 2; c -= 2;
} } while (r < NR && c >= 0);
while (r < NR && c >= 0);
r += 3; r += 3;
c++; c++;
} } while (r < NR || c < NC);
while (r < NR || c < NC);
// unfilled corner // unfilled corner
if (!array[NR * NC - 1]) if (!array[NR * NC - 1])
array[NR * NC - 1] = array[NR * NC - NC - 2] = 1; array[NR * NC - 1] = array[NR * NC - NC - 2] = 1;
} }
// 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, int skew) 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; int n, p;
rs_init_gf(0x12d); rs_init_gf(0x12d);
@ -228,20 +216,32 @@ static void ecc200(unsigned char *binary, int bytes, int datablock, int rsblock,
rs_free(); rs_free();
} }
int isX12(unsigned char source) /* Return true (1) if a character is valid in X12 set */
{ int isX12(unsigned char source) {
if(source == 13) { return 1; } if (source == 13) {
if(source == 42) { return 1; } return 1;
if(source == 62) { return 1; } }
if(source == 32) { return 1; } if (source == 42) {
if((source >= '0') && (source <= '9')) { return 1; } return 1;
if((source >= 'A') && (source <= 'Z')) { return 1; } }
if (source == 62) {
return 1;
}
if (source == 32) {
return 1;
}
if ((source >= '0') && (source <= '9')) {
return 1;
}
if ((source >= 'A') && (source <= 'Z')) {
return 1;
}
return 0; return 0;
} }
void dminsert(char binary_string[], int posn, char newbit) /* Insert a character into the middle of a string at position posn */
{ /* Insert a character into the middle of a string at position posn */ void dminsert(char binary_string[], int posn, char newbit) {
int i, end; int i, end;
end = strlen(binary_string); end = strlen(binary_string);
@ -251,8 +251,7 @@ void dminsert(char binary_string[], int posn, char newbit)
binary_string[posn] = newbit; binary_string[posn] = newbit;
} }
void insert_value(unsigned char binary_stream[], int posn, int streamlen, char newbit) void insert_value(unsigned char binary_stream[], int posn, int streamlen, char newbit) {
{
int i; int i;
for (i = streamlen; i > posn; i--) { for (i = streamlen; i > posn; i--) {
@ -297,10 +296,8 @@ int p_r_6_2_1(unsigned char inputData[], int position, int sourcelen) {
return retval; return retval;
} }
int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int current_mode, int gs1)
{
/* 'look ahead test' from Annex P */ /* 'look ahead test' from Annex P */
int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int current_mode, int gs1) {
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, best_scheme; int sp, best_scheme;
@ -324,11 +321,16 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
} }
switch (current_mode) { switch (current_mode) {
case DM_C40: c40_count = 0.0; break; case DM_C40: c40_count = 0.0;
case DM_TEXT: text_count = 0.0; break; break;
case DM_X12: x12_count = 0.0; break; case DM_TEXT: text_count = 0.0;
case DM_EDIFACT: edf_count = 0.0; break; break;
case DM_BASE256: b256_count = 0.0; break; case DM_X12: x12_count = 0.0;
break;
case DM_EDIFACT: edf_count = 0.0;
break;
case DM_BASE256: b256_count = 0.0;
break;
} }
sp = position; sp = position;
@ -517,10 +519,10 @@ int look_ahead_test(unsigned char inputData[], int sourcelen, int position, int
return best_scheme; return best_scheme;
} }
int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned char target[], int *last_mode, int *length_p, int process_buffer[], int *process_p) /* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate
{ Supports encoding FNC1 in supporting systems */
/* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate */ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned char target[], int *last_mode, int *length_p, int process_buffer[], int *process_p) {
/* Supports encoding FNC1 in supporting systems */
int sp, tp, i, gs1; int sp, tp, i, gs1;
int current_mode, next_mode; int current_mode, next_mode;
@ -542,10 +544,15 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
current_mode = DM_ASCII; current_mode = DM_ASCII;
next_mode = DM_ASCII; next_mode = DM_ASCII;
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } if (symbol->input_mode == GS1_MODE) {
gs1 = 1;
} else {
gs1 = 0;
}
if (gs1) { if (gs1) {
target[tp] = 232; tp++; target[tp] = 232;
tp++;
concat(binary, " "); concat(binary, " ");
if (debug) printf("FN1 "); if (debug) printf("FN1 ");
} /* FNC1 */ } /* FNC1 */
@ -555,7 +562,8 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
strcpy(symbol->errtxt, "Cannot encode in GS1 mode and Reader Initialisation at the same time"); strcpy(symbol->errtxt, "Cannot encode in GS1 mode and Reader Initialisation at the same time");
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
} else { } else {
target[tp] = 234; tp++; /* Reader Programming */ target[tp] = 234;
tp++; /* Reader Programming */
concat(binary, " "); concat(binary, " ");
if (debug) printf("RP "); if (debug) printf("RP ");
} }
@ -569,8 +577,7 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
&& source[3] == '\x1e' && source[4] == '0' && source[3] == '\x1e' && source[4] == '0'
&& (source[5] == '5' || source[5] == '6') && (source[5] == '5' || source[5] == '6')
&& source[6] == '\x1d' && source[6] == '\x1d'
&& source[inputlen-2] == '\x1e' && source[inputlen-1] == '\x04' ) && source[inputlen - 2] == '\x1e' && source[inputlen - 1] == '\x04') {
{
/* Output macro Codeword */ /* Output macro Codeword */
if (source[5] == '5') { if (source[5] == '5') {
target[tp] = 236; target[tp] = 236;
@ -599,23 +606,39 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
if (istwodigits(source, sp) && ((sp + 1) != inputlen)) { if (istwodigits(source, sp) && ((sp + 1) != inputlen)) {
target[tp] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; target[tp] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130;
if (debug) printf("N%d ", target[tp] - 130); if (debug) printf("N%d ", target[tp] - 130);
tp++; concat(binary, " "); tp++;
concat(binary, " ");
sp += 2; sp += 2;
} else { } else {
next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1);
if (next_mode != DM_ASCII) { if (next_mode != DM_ASCII) {
switch (next_mode) { switch (next_mode) {
case DM_C40: target[tp] = 230; tp++; concat(binary, " "); case DM_C40: target[tp] = 230;
if(debug) printf("C40 "); break; tp++;
case DM_TEXT: target[tp] = 239; tp++; concat(binary, " "); concat(binary, " ");
if(debug) printf("TEX "); break; if (debug) printf("C40 ");
case DM_X12: target[tp] = 238; tp++; concat(binary, " "); break;
if(debug) printf("X12 "); break; case DM_TEXT: target[tp] = 239;
case DM_EDIFACT: target[tp] = 240; tp++; concat(binary, " "); tp++;
if(debug) printf("EDI "); break; concat(binary, " ");
case DM_BASE256: target[tp] = 231; tp++; concat(binary, " "); if (debug) printf("TEX ");
if(debug) printf("BAS "); break; break;
case DM_X12: target[tp] = 238;
tp++;
concat(binary, " ");
if (debug) printf("X12 ");
break;
case DM_EDIFACT: target[tp] = 240;
tp++;
concat(binary, " ");
if (debug) printf("EDI ");
break;
case DM_BASE256: target[tp] = 231;
tp++;
concat(binary, " ");
if (debug) printf("BAS ");
break;
} }
} else { } else {
if (source[sp] > 127) { if (source[sp] > 127) {
@ -624,7 +647,8 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
tp++; tp++;
target[tp] = (source[sp] - 128) + 1; target[tp] = (source[sp] - 128) + 1;
if (debug) printf("A%02X ", target[tp] - 1); if (debug) printf("A%02X ", target[tp] - 1);
tp++; concat(binary, " "); tp++;
concat(binary, " ");
} else { } else {
if (gs1 && (source[sp] == '[')) { if (gs1 && (source[sp] == '[')) {
target[tp] = 232; /* FNC1 */ target[tp] = 232; /* FNC1 */
@ -652,13 +676,17 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
} }
if (next_mode != DM_C40) { if (next_mode != DM_C40) {
target[tp] = 254; tp++; concat(binary, " "); /* Unlatch */ target[tp] = 254;
tp++;
concat(binary, " "); /* Unlatch */
next_mode = DM_ASCII; next_mode = DM_ASCII;
if (debug) printf("ASC "); if (debug) printf("ASC ");
} else { } else {
if (source[sp] > 127) { if (source[sp] > 127) {
process_buffer[*process_p] = 1; (*process_p)++; process_buffer[*process_p] = 1;
process_buffer[*process_p] = 30; (*process_p)++; /* Upper Shift */ (*process_p)++;
process_buffer[*process_p] = 30;
(*process_p)++; /* Upper Shift */
shift_set = c40_shift[source[sp] - 128]; shift_set = c40_shift[source[sp] - 128];
value = c40_value[source[sp] - 128]; value = c40_value[source[sp] - 128];
} else { } else {
@ -672,16 +700,20 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
} }
if (shift_set != 0) { if (shift_set != 0) {
process_buffer[*process_p] = shift_set - 1; (*process_p)++; process_buffer[*process_p] = shift_set - 1;
(*process_p)++;
} }
process_buffer[*process_p] = value; (*process_p)++; process_buffer[*process_p] = value;
(*process_p)++;
if (*process_p >= 3) { if (*process_p >= 3) {
int iv; int iv;
iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1; iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1;
target[tp] = iv / 256; tp++; target[tp] = iv / 256;
target[tp] = iv % 256; tp++; tp++;
target[tp] = iv % 256;
tp++;
concat(binary, " "); concat(binary, " ");
if (debug) printf("[%d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2]); if (debug) printf("[%d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2]);
@ -707,13 +739,17 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
} }
if (next_mode != DM_TEXT) { if (next_mode != DM_TEXT) {
target[tp] = 254; tp++; concat(binary, " ");/* Unlatch */ target[tp] = 254;
tp++;
concat(binary, " "); /* Unlatch */
next_mode = DM_ASCII; next_mode = DM_ASCII;
if (debug) printf("ASC "); if (debug) printf("ASC ");
} else { } else {
if (source[sp] > 127) { if (source[sp] > 127) {
process_buffer[*process_p] = 1; (*process_p)++; process_buffer[*process_p] = 1;
process_buffer[*process_p] = 30; (*process_p)++; /* Upper Shift */ (*process_p)++;
process_buffer[*process_p] = 30;
(*process_p)++; /* Upper Shift */
shift_set = text_shift[source[sp] - 128]; shift_set = text_shift[source[sp] - 128];
value = text_value[source[sp] - 128]; value = text_value[source[sp] - 128];
} else { } else {
@ -727,16 +763,20 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
} }
if (shift_set != 0) { if (shift_set != 0) {
process_buffer[*process_p] = shift_set - 1; (*process_p)++; process_buffer[*process_p] = shift_set - 1;
(*process_p)++;
} }
process_buffer[*process_p] = value; (*process_p)++; process_buffer[*process_p] = value;
(*process_p)++;
if (*process_p >= 3) { if (*process_p >= 3) {
int iv; int iv;
iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1; iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1;
target[tp] = iv / 256; tp++; target[tp] = iv / 256;
target[tp] = iv % 256; tp++; tp++;
target[tp] = iv % 256;
tp++;
concat(binary, " "); concat(binary, " ");
if (debug) printf("[%d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2]); if (debug) printf("[%d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2]);
@ -762,25 +802,42 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
} }
if (next_mode != DM_X12) { if (next_mode != DM_X12) {
target[tp] = 254; tp++; concat(binary, " ");/* Unlatch */ target[tp] = 254;
tp++;
concat(binary, " "); /* Unlatch */
next_mode = DM_ASCII; next_mode = DM_ASCII;
if (debug) printf("ASC "); if (debug) printf("ASC ");
} else { } else {
if(source[sp] == 13) { value = 0; } if (source[sp] == 13) {
if(source[sp] == '*') { value = 1; } value = 0;
if(source[sp] == '>') { value = 2; } }
if(source[sp] == ' ') { value = 3; } if (source[sp] == '*') {
if((source[sp] >= '0') && (source[sp] <= '9')) { value = (source[sp] - '0') + 4; } value = 1;
if((source[sp] >= 'A') && (source[sp] <= 'Z')) { value = (source[sp] - 'A') + 14; } }
if (source[sp] == '>') {
value = 2;
}
if (source[sp] == ' ') {
value = 3;
}
if ((source[sp] >= '0') && (source[sp] <= '9')) {
value = (source[sp] - '0') + 4;
}
if ((source[sp] >= 'A') && (source[sp] <= 'Z')) {
value = (source[sp] - 'A') + 14;
}
process_buffer[*process_p] = value; (*process_p)++; process_buffer[*process_p] = value;
(*process_p)++;
if (*process_p >= 3) { if (*process_p >= 3) {
int iv; int iv;
iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1; iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1;
target[tp] = iv / 256; tp++; target[tp] = iv / 256;
target[tp] = iv % 256; tp++; tp++;
target[tp] = iv % 256;
tp++;
concat(binary, " "); concat(binary, " ");
if (debug) printf("[%d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2]); if (debug) printf("[%d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2]);
@ -806,21 +863,30 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
} }
if (next_mode != DM_EDIFACT) { if (next_mode != DM_EDIFACT) {
process_buffer[*process_p] = 31; (*process_p)++; process_buffer[*process_p] = 31;
(*process_p)++;
next_mode = DM_ASCII; next_mode = DM_ASCII;
} else { } else {
if((source[sp] >= '@') && (source[sp] <= '^')) { value = source[sp] - '@'; } if ((source[sp] >= '@') && (source[sp] <= '^')) {
if((source[sp] >= ' ') && (source[sp] <= '?')) { value = source[sp]; } value = source[sp] - '@';
}
if ((source[sp] >= ' ') && (source[sp] <= '?')) {
value = source[sp];
}
/* possibility put an assertion here for invalid character (none of the ifs trigger) */ /* possibility put an assertion here for invalid character (none of the ifs trigger) */
process_buffer[*process_p] = value; (*process_p)++; process_buffer[*process_p] = value;
(*process_p)++;
sp++; sp++;
} }
if (*process_p >= 4) { if (*process_p >= 4) {
target[tp] = (process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4); tp++; target[tp] = (process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4);
target[tp] = ((process_buffer[1] & 0x0f) << 4) + ((process_buffer[2] & 0x3c) >> 2); tp++; tp++;
target[tp] = ((process_buffer[2] & 0x03) << 6) + process_buffer[3]; tp++; target[tp] = ((process_buffer[1] & 0x0f) << 4) + ((process_buffer[2] & 0x3c) >> 2);
tp++;
target[tp] = ((process_buffer[2] & 0x03) << 6) + process_buffer[3];
tp++;
concat(binary, " "); concat(binary, " ");
if (debug) printf("[%d %d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2], process_buffer[3]); if (debug) printf("[%d %d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2], process_buffer[3]);
@ -870,12 +936,15 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
if (binary_count <= 249) { if (binary_count <= 249) {
dminsert(binary, i, 'b'); dminsert(binary, i, 'b');
insert_value(target, i, tp, binary_count); tp++; insert_value(target, i, tp, binary_count);
tp++;
} else { } else {
dminsert(binary, i, 'b'); dminsert(binary, i, 'b');
dminsert(binary, i + 1, 'b'); dminsert(binary, i + 1, 'b');
insert_value(target, i, tp, (binary_count / 250) + 249); tp++; insert_value(target, i, tp, (binary_count / 250) + 249);
insert_value(target, i + 1, tp, binary_count % 250); tp++; tp++;
insert_value(target, i + 1, tp, binary_count % 250);
tp++;
} }
} }
} }
@ -888,7 +957,11 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
prn = ((149 * (i + 1)) % 255) + 1; prn = ((149 * (i + 1)) % 255) + 1;
temp = target[i] + prn; temp = target[i] + prn;
if (temp <= 255) { target[i] = temp; } else { target[i] = temp - 256; } if (temp <= 255) {
target[i] = temp;
} else {
target[i] = temp - 256;
}
} }
} }
@ -896,42 +969,44 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
return tp; return tp;
} }
int dm200encode_remainder(unsigned char target[], int target_length, unsigned char source[], int inputlen, int last_mode, int process_buffer[], int process_p, int symbols_left) int dm200encode_remainder(unsigned char target[], int target_length, unsigned char source[], int inputlen, int last_mode, int process_buffer[], int process_p, int symbols_left) {
{
int debug = 0; int debug = 0;
switch (last_mode) switch (last_mode) {
{
case DM_C40: case DM_C40:
case DM_TEXT: case DM_TEXT:
if (symbols_left == process_p) // No unlatch required! if (symbols_left == process_p) // No unlatch required!
{ {
if (process_p == 1) // 1 data character left to encode. if (process_p == 1) // 1 data character left to encode.
{ {
target[target_length] = source[inputlen - 1] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
if (process_p == 2) // 2 data characters left to encode. if (process_p == 2) // 2 data characters left to encode.
{ {
// Pad with shift 1 value (0) and encode as double. // Pad with shift 1 value (0) and encode as double.
int intValue = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + 1; // ie (0 + 1). int intValue = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + 1; // ie (0 + 1).
target[target_length] = (unsigned char)(intValue / 256); target_length++; target[target_length] = (unsigned char) (intValue / 256);
target[target_length] = (unsigned char)(intValue % 256); target_length++; target_length++;
target[target_length] = (unsigned char) (intValue % 256);
target_length++;
} }
} }
if (symbols_left > process_p) if (symbols_left > process_p) {
{ target[target_length] = (254);
target[target_length] = (254); target_length++; // Unlatch and encode remaining data in ascii. target_length++; // Unlatch and encode remaining data in ascii.
if (process_p == 1 || (process_p == 2 && process_buffer[0] < 3)) // Check for a shift value. if (process_p == 1 || (process_p == 2 && process_buffer[0] < 3)) // Check for a shift value.
{ {
target[target_length] = source[inputlen - 1] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
else if (process_p == 2) {
else if (process_p == 2) target[target_length] = source[inputlen - 2] + 1;
{ target_length++;
target[target_length] = source[inputlen - 2] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target[target_length] = source[inputlen - 1] + 1; target_length++; target_length++;
} }
} }
break; break;
@ -941,29 +1016,33 @@ int dm200encode_remainder(unsigned char target[], int target_length, unsigned ch
{ {
if (process_p == 1) // 1 data character left to encode. if (process_p == 1) // 1 data character left to encode.
{ {
target[target_length] = source[inputlen - 1] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
if (process_p == 2) if (process_p == 2) {
{
// Encode last 2 bytes as ascii. // Encode last 2 bytes as ascii.
target[target_length] = source[inputlen - 2] + 1; target_length++; target[target_length] = source[inputlen - 2] + 1;
target[target_length] = source[inputlen - 1] + 1; target_length++; target_length++;
target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
} }
if (symbols_left > process_p) // Unlatch and encode remaining data in ascii. if (symbols_left > process_p) // Unlatch and encode remaining data in ascii.
{ {
target[target_length] = (254); target_length++; // Unlatch. target[target_length] = (254);
if (process_p == 1) target_length++; // Unlatch.
{ if (process_p == 1) {
target[target_length] = source[inputlen - 1] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
if (process_p == 2) if (process_p == 2) {
{ target[target_length] = source[inputlen - 2] + 1;
target[target_length] = source[inputlen - 2] + 1; target_length++; target_length++;
target[target_length] = source[inputlen - 1] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
} }
break; break;
@ -971,59 +1050,65 @@ int dm200encode_remainder(unsigned char target[], int target_length, unsigned ch
case DM_EDIFACT: case DM_EDIFACT:
if (symbols_left == process_p) // Unlatch not required! if (symbols_left == process_p) // Unlatch not required!
{ {
if (process_p == 1) if (process_p == 1) {
{ target[target_length] = source[inputlen - 1] + 1;
target[target_length] = source[inputlen - 1] + 1; target_length++; target_length++;
} }
if (process_p == 2) if (process_p == 2) {
{ target[target_length] = source[inputlen - 2] + 1;
target[target_length] = source[inputlen - 2] + 1; target_length++; target_length++;
target[target_length] = source[inputlen - 1] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
if (process_p == 3) // Append edifact unlatch value (31) and encode as triple. if (process_p == 3) // Append edifact unlatch value (31) and encode as triple.
{ {
target[target_length] = (unsigned char)((process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4)); target_length++; target[target_length] = (unsigned char) ((process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4));
target[target_length] = (unsigned char)(((process_buffer[1] & 0x0f) << 4) + ((process_buffer[2] & 0x3c) >> 2)); target_length++; target_length++;
target[target_length] = (unsigned char)(((process_buffer[2] & 0x03) << 6) + 31); target_length++; target[target_length] = (unsigned char) (((process_buffer[1] & 0x0f) << 4) + ((process_buffer[2] & 0x3c) >> 2));
target_length++;
target[target_length] = (unsigned char) (((process_buffer[2] & 0x03) << 6) + 31);
target_length++;
} }
} }
if (symbols_left > process_p) // Unlatch and encode remaining data in ascii. if (symbols_left > process_p) // Unlatch and encode remaining data in ascii.
{ {
// Edifact unlatch. // Edifact unlatch.
if (symbols_left < 3) if (symbols_left < 3) {
{ target[target_length] = 31;
target[target_length] = 31; target_length++; target_length++;
} }
else else
target[target_length] = (31 << 2); target_length++; target[target_length] = (31 << 2);
target_length++;
if (process_p == 1) if (process_p == 1) {
{ target[target_length] = source[inputlen - 1] + 1;
target[target_length] = source[inputlen - 1] + 1; target_length++; target_length++;
} }
if (process_p == 2) if (process_p == 2) {
{ target[target_length] = source[inputlen - 2] + 1;
target[target_length] = source[inputlen - 2] + 1; target_length++; target_length++;
target[target_length] = source[inputlen - 1] + 1; target_length++; target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
if (process_p == 3) if (process_p == 3) {
{ target[target_length] = source[inputlen - 3] + 1;
target[target_length] = source[inputlen - 3] + 1; target_length++; target_length++;
target[target_length] = source[inputlen - 2] + 1; target_length++; target[target_length] = source[inputlen - 2] + 1;
target[target_length] = source[inputlen - 1] + 1; target_length++; target_length++;
target[target_length] = source[inputlen - 1] + 1;
target_length++;
} }
} }
break; break;
} }
if(debug) if (debug) {
{
int i; int i;
printf("\n\n"); printf("\n\n");
for (i = 0; i < target_length; i++) for (i = 0; i < target_length; i++)
@ -1035,28 +1120,29 @@ int dm200encode_remainder(unsigned char target[], int target_length, unsigned ch
return target_length; return target_length;
} }
void add_tail(unsigned char target[], int tp, int tail_length)
{
/* add pad bits */ /* add pad bits */
void add_tail(unsigned char target[], int tp, int tail_length) {
int i, prn, temp; int i, prn, temp;
for (i = tail_length; i > 0; i--) { for (i = tail_length; i > 0; i--) {
if (i == tail_length) { if (i == tail_length) {
target[tp] = 129; tp++; /* Pad */ target[tp] = 129;
tp++; /* Pad */
} else { } else {
prn = ((149 * (tp + 1)) % 253) + 1; prn = ((149 * (tp + 1)) % 253) + 1;
temp = 129 + prn; temp = 129 + prn;
if (temp <= 254) { if (temp <= 254) {
target[tp] = temp; tp++; target[tp] = temp;
tp++;
} else { } else {
target[tp] = temp - 254; tp++; target[tp] = temp - 254;
tp++;
} }
} }
} }
} }
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, skew = 0; int inputlen, i, skew = 0;
unsigned char binary[2200]; unsigned char binary[2200];
int binlen; int binlen;
@ -1086,8 +1172,8 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
calcsize = DMSIZESCOUNT - 1; calcsize = DMSIZESCOUNT - 1;
for (i = DMSIZESCOUNT - 1; i > -1; i--) { for (i = DMSIZESCOUNT - 1; i > -1; i--) {
if(matrixbytes[i] >= (binlen + process_p)) // Allow for the remaining data characters. if (matrixbytes[i] >= (binlen + process_p)) {
{ // Allow for the remaining data characters
calcsize = i; calcsize = i;
} }
} }
@ -1126,7 +1212,9 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
} }
// ecc code // ecc code
if(symbolsize == INTSYMBOL144) { skew = 1; } if (symbolsize == INTSYMBOL144) {
skew = 1;
}
ecc200(binary, bytes, datablock, rsblock, skew); ecc200(binary, bytes, datablock, rsblock, skew);
// Print Codewords // Print Codewords
#ifdef DEBUG #ifdef DEBUG
@ -1202,8 +1290,7 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
return error_number; return error_number;
} }
int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length) int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length) {
{
int error_number; int error_number;
if (symbol->option_1 <= 1) { if (symbol->option_1 <= 1) {

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -41,8 +41,7 @@
#ifndef __IEC16022ECC200_H #ifndef __IEC16022ECC200_H
#define __IEC16022ECC200_H #define __IEC16022ECC200_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
{
#endif /* __cplusplus */ #endif /* __cplusplus */
extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length); extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length);
@ -65,25 +64,29 @@ static const int c40_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
};
static const int c40_value[] = { static const int c40_value[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15, 16, 17, 18, 19, 20, 21, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 15, 16, 17, 18, 19, 20, 21, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
};
static const int text_shift[] = { static const int text_shift[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 }; 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3
};
static const int text_value[] = { static const int text_value[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
15, 16, 17, 18, 19, 20, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 15, 16, 17, 18, 19, 20, 21, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 }; 22, 23, 24, 25, 26, 0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27, 28, 29, 30, 31
};
// Activate DMRE Extensions // Activate DMRE Extensions
//#define DMRE //#define DMRE
@ -105,7 +108,8 @@ static const int intsymbol[] = {
15, /* 33: 12x64 , 43*/ 22, /* 34: 16x64 , 62*/ 18, /* 35: 24x32 , 49*/ 20, /* 36: 24x36 , 55*/ 15, /* 33: 12x64 , 43*/ 22, /* 34: 16x64 , 62*/ 18, /* 35: 24x32 , 49*/ 20, /* 36: 24x36 , 55*/
24, /* 37: 24x48 , 80*/ 27, /* 38: 24x64 ,108*/ 19, /* 39: 26x32 , 52*/ 23, /* 40: 26x40 , 70*/ 24, /* 37: 24x48 , 80*/ 27, /* 38: 24x64 ,108*/ 19, /* 39: 26x32 , 52*/ 23, /* 40: 26x40 , 70*/
26, /* 41: 26x48 , 90*/ 29, /* 42: 26x64 ,118*/ 26, /* 41: 26x48 , 90*/ 29, /* 42: 26x64 ,118*/
0 }; 0
};
// Number of DM Sizes // Number of DM Sizes
#define DMSIZESCOUNT 42 #define DMSIZESCOUNT 42
@ -228,7 +232,8 @@ static const int matrixrsblock[] = {
// No Rectangular extensions // No Rectangular extensions
static const int intsymbol[] = { static const int intsymbol[] = {
0,1,3,5,7,8,10,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,2,4,6,9,11,14 }; 0, 1, 3, 5, 7, 8, 10, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2, 4, 6, 9, 11, 14
};
// Number of DM Sizes // Number of DM Sizes
#define DMSIZESCOUNT 30 #define DMSIZESCOUNT 30
@ -237,32 +242,39 @@ static const int intsymbol[] = {
static const int matrixH[] = { static const int matrixH[] = {
10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 32, 36, 40, 44, 48, 10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 32, 36, 40, 44, 48,
52, 64, 72, 80, 88, 96, 104, 120, 132, 144 }; 52, 64, 72, 80, 88, 96, 104, 120, 132, 144
};
static const int matrixW[] = { static const int matrixW[] = {
10, 12, 18, 14, 32, 16, 26, 18, 20, 36, 22, 36, 24, 26, 48, 32, 36, 40, 44, 10, 12, 18, 14, 32, 16, 26, 18, 20, 36, 22, 36, 24, 26, 48, 32, 36, 40, 44,
48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144 }; 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144
};
static const int matrixFH[] = { static const int matrixFH[] = {
10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 16, 18, 20, 22, 24, 10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 16, 18, 20, 22, 24,
26, 16, 18, 20, 22, 24, 26, 20, 22, 24 }; 26, 16, 18, 20, 22, 24, 26, 20, 22, 24
};
static const int matrixFW[] = { static const int matrixFW[] = {
10, 12, 18, 14, 16, 16, 26, 18, 20, 18, 22, 18, 24, 26, 24, 16, 18, 20, 22, 10, 12, 18, 14, 16, 16, 26, 18, 20, 18, 22, 18, 24, 26, 24, 16, 18, 20, 22,
24, 26, 16, 18, 20, 22, 24, 26, 20, 22, 24 }; 24, 26, 16, 18, 20, 22, 24, 26, 20, 22, 24
};
static const int matrixbytes[] = { static const int matrixbytes[] = {
3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144, 3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144,
174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558 }; 174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558
};
static const int matrixdatablock[] = { static const int matrixdatablock[] = {
3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144, 3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144,
174, 102, 140, 92, 114, 144, 174, 136, 175, 163, 156 }; 174, 102, 140, 92, 114, 144, 174, 136, 175, 163, 156
};
static const int matrixrsblock[] = { static const int matrixrsblock[] = {
5, 7, 7, 10, 11, 12, 14, 14, 18, 18, 20, 24, 24, 28, 28, 36, 42, 48, 56, 68, 5, 7, 7, 10, 11, 12, 14, 14, 18, 18, 20, 24, 24, 28, 28, 36, 42, 48, 56, 68,
42, 56, 36, 48, 56, 68, 56, 68, 62, 62 }; 42, 56, 36, 48, 56, 68, 56, 68, 62, 62
};
#endif #endif
#endif /* __IEC16022ECC200_H */ #endif

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk> Copyright (C) 2008-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions

View File

@ -1,7 +1,7 @@
/* gb2312.h - Unicode to GB 2312-1980 lookup table /* gb2312.h - Unicode to GB 2312-1980 lookup table
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions

View File

@ -1,7 +1,7 @@
/* gridmtx.c - Grid Matrix /* gridmtx.c - Grid Matrix
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -43,8 +43,7 @@
#include "gridmtx.h" #include "gridmtx.h"
#include "gb2312.h" #include "gb2312.h"
int number_lat(int gbdata[], int length, int position) int number_lat(int gbdata[], int length, int position) {
{
/* Attempt to calculate the 'cost' of using numeric mode from a given position in number of bits */ /* Attempt to calculate the 'cost' of using numeric mode from a given position in number of bits */
/* Also ensures that numeric mode is not selected when it cannot be used: for example in /* Also ensures that numeric mode is not selected when it cannot be used: for example in
a string which has "2.2.0" (cannot have more than one non-numeric character for each a string which has "2.2.0" (cannot have more than one non-numeric character for each
@ -58,7 +57,10 @@ int number_lat(int gbdata[], int length, int position)
do { do {
done = 0; done = 0;
if((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) { numb++; done = 1; } if ((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) {
numb++;
done = 1;
}
switch (gbdata[sp]) { switch (gbdata[sp]) {
case ' ': case ' ':
case '+': case '+':
@ -116,8 +118,7 @@ int number_lat(int gbdata[], int length, int position)
return tally; return tally;
} }
int seek_forward(int gbdata[], int length, int position, int current_mode) int seek_forward(int gbdata[], int length, int position, int current_mode) {
{
/* In complete contrast to the method recommended in Annex D of the ANSI standard this /* In complete contrast to the method recommended in Annex D of the ANSI standard this
code uses a look-ahead test in the same manner as Data Matrix. This decision was made code uses a look-ahead test in the same manner as Data Matrix. This decision was made
because the "official" algorithm does not provide clear methods for dealing with all because the "official" algorithm does not provide clear methods for dealing with all
@ -128,7 +129,9 @@ int seek_forward(int gbdata[], int length, int position, int current_mode)
int best_count, last = -1; int best_count, last = -1;
int debug = 0; int debug = 0;
if(gbdata[position] > 0xff) { return GM_CHINESE; } if (gbdata[position] > 0xff) {
return GM_CHINESE;
}
switch (current_mode) { switch (current_mode) {
case GM_CHINESE: case GM_CHINESE:
@ -273,7 +276,9 @@ int seek_forward(int gbdata[], int length, int position, int current_mode)
/* Numeric mode is more complex */ /* Numeric mode is more complex */
number_count += number_lat(gbdata, length, position); number_count += number_lat(gbdata, length, position);
if(debug) { printf("C %d / B %d / M %d / U %d / L %d / N %d\n", chinese_count, byte_count, mixed_count, upper_count, lower_count, number_count); } if (debug) {
printf("C %d / B %d / M %d / U %d / L %d / N %d\n", chinese_count, byte_count, mixed_count, upper_count, lower_count, number_count);
}
best_count = chinese_count; best_count = chinese_count;
best_mode = GM_CHINESE; best_mode = GM_CHINESE;
@ -306,23 +311,19 @@ int seek_forward(int gbdata[], int length, int position, int current_mode)
return best_mode; return best_mode;
} }
void add_byte_count(char binary[], int byte_count_posn, int byte_count)
{
/* Add the length indicator for byte encoded blocks */ /* Add the length indicator for byte encoded blocks */
if(byte_count & 0x100) { binary[byte_count_posn] = '0'; } else { binary[byte_count_posn] = '1'; } void add_byte_count(char binary[], int byte_count_posn, int byte_count) {
if(byte_count & 0x80) { binary[byte_count_posn + 1] = '0'; } else { binary[byte_count_posn + 1] = '1'; } for (int p = 0; p < 8; p++) {
if(byte_count & 0x40) { binary[byte_count_posn + 2] = '0'; } else { binary[byte_count_posn + 2] = '1'; } if (byte_count & (0x100 >> p)) {
if(byte_count & 0x20) { binary[byte_count_posn + 3] = '0'; } else { binary[byte_count_posn + 3] = '1'; } binary[byte_count_posn + p] = '0';
if(byte_count & 0x10) { binary[byte_count_posn + 4] = '0'; } else { binary[byte_count_posn + 4] = '1'; } } else {
if(byte_count & 0x08) { binary[byte_count_posn + 5] = '0'; } else { binary[byte_count_posn + 5] = '1'; } binary[byte_count_posn + p] = '1';
if(byte_count & 0x04) { binary[byte_count_posn + 6] = '0'; } else { binary[byte_count_posn + 6] = '1'; } }
if(byte_count & 0x02) { binary[byte_count_posn + 7] = '0'; } else { binary[byte_count_posn + 7] = '1'; } }
if(byte_count & 0x01) { binary[byte_count_posn + 8] = '0'; } else { binary[byte_count_posn + 8] = '1'; }
} }
void add_shift_char(char binary[], int shifty)
{
/* Add a control character to the data stream */ /* Add a control character to the data stream */
void add_shift_char(char binary[], int shifty) {
int i, debug = 0; int i, debug = 0;
int glyph = 0; int glyph = 0;
@ -332,18 +333,20 @@ void add_shift_char(char binary[], int shifty)
} }
} }
if(debug) { printf("SHIFT [%d] ", glyph); } if (debug) {
printf("SHIFT [%d] ", glyph);
if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
} }
int gm_encode(int gbdata[], int length, char binary[], int reader) for (int p = 0; p < 6; p++) {
{ if (glyph & (0x20 >> p)) {
concat(binary, "1");
} else {
concat(binary, "0");
}
}
}
int gm_encode(int gbdata[], int length, char binary[], int reader) {
/* Create a binary stream representation of the input data. /* Create a binary stream representation of the input data.
7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters, 7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters,
Mixed numerals and latters, Control characters and 8-bit binary data */ Mixed numerals and latters, Control characters and 8-bit binary data */
@ -373,56 +376,88 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
switch (current_mode) { switch (current_mode) {
case 0: case 0:
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: concat(binary, "0001"); break; case GM_CHINESE: concat(binary, "0001");
case GM_NUMBER: concat(binary, "0010"); break; break;
case GM_LOWER: concat(binary, "0011"); break; case GM_NUMBER: concat(binary, "0010");
case GM_UPPER: concat(binary, "0100"); break; break;
case GM_MIXED: concat(binary, "0101"); break; case GM_LOWER: concat(binary, "0011");
case GM_BYTE: concat(binary, "0111"); break; break;
case GM_UPPER: concat(binary, "0100");
break;
case GM_MIXED: concat(binary, "0101");
break;
case GM_BYTE: concat(binary, "0111");
break;
} }
break; break;
case GM_CHINESE: case GM_CHINESE:
switch (next_mode) { switch (next_mode) {
case GM_NUMBER: concat(binary, "1111111100001"); break; // 8161 case GM_NUMBER: concat(binary, "1111111100001");
case GM_LOWER: concat(binary, "1111111100010"); break; // 8162 break; // 8161
case GM_UPPER: concat(binary, "1111111100011"); break; // 8163 case GM_LOWER: concat(binary, "1111111100010");
case GM_MIXED: concat(binary, "1111111100100"); break; // 8164 break; // 8162
case GM_BYTE: concat(binary, "1111111100101"); break; // 8165 case GM_UPPER: concat(binary, "1111111100011");
break; // 8163
case GM_MIXED: concat(binary, "1111111100100");
break; // 8164
case GM_BYTE: concat(binary, "1111111100101");
break; // 8165
} }
break; break;
case GM_NUMBER: case GM_NUMBER:
/* add numeric block padding value */ /* add numeric block padding value */
switch (p) { switch (p) {
case 1: binary[number_pad_posn] = '1'; binary[number_pad_posn + 1] = '0'; break; // 2 pad digits case 1: binary[number_pad_posn] = '1';
case 2: binary[number_pad_posn] = '0'; binary[number_pad_posn + 1] = '1'; break; // 1 pad digit binary[number_pad_posn + 1] = '0';
case 3: binary[number_pad_posn] = '0'; binary[number_pad_posn + 1] = '0'; break; // 0 pad digits break; // 2 pad digits
case 2: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '1';
break; // 1 pad digit
case 3: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '0';
break; // 0 pad digits
} }
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: concat(binary, "1111111011"); break; // 1019 case GM_CHINESE: concat(binary, "1111111011");
case GM_LOWER: concat(binary, "1111111100"); break; // 1020 break; // 1019
case GM_UPPER: concat(binary, "1111111101"); break; // 1021 case GM_LOWER: concat(binary, "1111111100");
case GM_MIXED: concat(binary, "1111111110"); break; // 1022 break; // 1020
case GM_BYTE: concat(binary, "1111111111"); break; // 1023 case GM_UPPER: concat(binary, "1111111101");
break; // 1021
case GM_MIXED: concat(binary, "1111111110");
break; // 1022
case GM_BYTE: concat(binary, "1111111111");
break; // 1023
} }
break; break;
case GM_LOWER: case GM_LOWER:
case GM_UPPER: case GM_UPPER:
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: concat(binary, "11100"); break; // 28 case GM_CHINESE: concat(binary, "11100");
case GM_NUMBER: concat(binary, "11101"); break; // 29 break; // 28
case GM_NUMBER: concat(binary, "11101");
break; // 29
case GM_LOWER: case GM_LOWER:
case GM_UPPER: concat(binary, "11110"); break; // 30 case GM_UPPER: concat(binary, "11110");
case GM_MIXED: concat(binary, "1111100"); break; // 124 break; // 30
case GM_BYTE: concat(binary, "1111110"); break; // 126 case GM_MIXED: concat(binary, "1111100");
break; // 124
case GM_BYTE: concat(binary, "1111110");
break; // 126
} }
break; break;
case GM_MIXED: case GM_MIXED:
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: concat(binary, "1111110001"); break; // 1009 case GM_CHINESE: concat(binary, "1111110001");
case GM_NUMBER: concat(binary, "1111110010"); break; // 1010 break; // 1009
case GM_LOWER: concat(binary, "1111110011"); break; // 1011 case GM_NUMBER: concat(binary, "1111110010");
case GM_UPPER: concat(binary, "1111110100"); break; // 1012 break; // 1010
case GM_BYTE: concat(binary, "1111110111"); break; // 1015 case GM_LOWER: concat(binary, "1111110011");
break; // 1011
case GM_UPPER: concat(binary, "1111110100");
break; // 1012
case GM_BYTE: concat(binary, "1111110111");
break; // 1015
} }
break; break;
case GM_BYTE: case GM_BYTE:
@ -430,22 +465,33 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
add_byte_count(binary, byte_count_posn, byte_count); add_byte_count(binary, byte_count_posn, byte_count);
byte_count = 0; byte_count = 0;
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: concat(binary, "0001"); break; // 1 case GM_CHINESE: concat(binary, "0001");
case GM_NUMBER: concat(binary, "0010"); break; // 2 break; // 1
case GM_LOWER: concat(binary, "0011"); break; // 3 case GM_NUMBER: concat(binary, "0010");
case GM_UPPER: concat(binary, "0100"); break; // 4 break; // 2
case GM_MIXED: concat(binary, "0101"); break; // 5 case GM_LOWER: concat(binary, "0011");
break; // 3
case GM_UPPER: concat(binary, "0100");
break; // 4
case GM_MIXED: concat(binary, "0101");
break; // 5
} }
break; break;
} }
if (debug) { if (debug) {
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: printf("CHIN "); break; case GM_CHINESE: printf("CHIN ");
case GM_NUMBER: printf("NUMB "); break; break;
case GM_LOWER: printf("LOWR "); break; case GM_NUMBER: printf("NUMB ");
case GM_UPPER: printf("UPPR "); break; break;
case GM_MIXED: printf("MIXD "); break; case GM_LOWER: printf("LOWR ");
case GM_BYTE: printf("BYTE "); break; break;
case GM_UPPER: printf("UPPR ");
break;
case GM_MIXED: printf("MIXD ");
break;
case GM_BYTE: printf("BYTE ");
break;
} }
} }
} }
@ -493,21 +539,17 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
glyph = 7777 + gbdata[sp]; glyph = 7777 + gbdata[sp];
} }
if(debug) { printf("[%d] ", glyph); } if (debug) {
printf("[%d] ", glyph);
}
if(glyph & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); } for (int p = 0; p < 13; p++) {
if(glyph & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); } if (glyph & (0x1000 >> p)) {
if(glyph & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "1");
if(glyph & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } } else {
if(glyph & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "0");
if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } }
if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } }
if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
sp++; sp++;
break; break;
@ -555,43 +597,47 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
if (ppos != -1) { if (ppos != -1) {
switch (punt) { switch (punt) {
case ' ': glyph = 0; break; case ' ': glyph = 0;
case '+': glyph = 3; break; break;
case '-': glyph = 6; break; case '+': glyph = 3;
case '.': glyph = 9; break; break;
case ',': glyph = 12; break; case '-': glyph = 6;
case 0x13: glyph = 15; break; break;
case '.': glyph = 9;
break;
case ',': glyph = 12;
break;
case 0x13: glyph = 15;
break;
} }
glyph += ppos; glyph += ppos;
glyph += 1000; glyph += 1000;
if(debug) { printf("[%d] ", glyph); } if (debug) {
printf("[%d] ", glyph);
}
if(glyph & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } for (int p = 0; p < 10; p++) {
if(glyph & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } if (glyph & (0x200 >> p)) {
if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "1");
if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } } else {
if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "0");
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } }
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } }
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
} }
glyph = (100 * (numbuf[0] - '0')) + (10 * (numbuf[1] - '0')) + (numbuf[2] - '0'); glyph = (100 * (numbuf[0] - '0')) + (10 * (numbuf[1] - '0')) + (numbuf[2] - '0');
if(debug) { printf("[%d] ", glyph); } if (debug) {
printf("[%d] ", glyph);
}
if(glyph & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } for (int p = 0; p < 10; p++) {
if(glyph & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); } if (glyph & (0x200 >> p)) {
if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "1");
if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } } else {
if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "0");
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } }
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } }
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
break; break;
case GM_BYTE: case GM_BYTE:
@ -610,37 +656,49 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
} }
glyph = gbdata[sp]; glyph = gbdata[sp];
if(debug) { printf("[%d] ", glyph); } if (debug) {
if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } printf("[%d] ", glyph);
if(glyph & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } }
if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } for (int p = 0; p < 8; p++) {
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } if (glyph & (0x80 >> p)) {
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "1");
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } } else {
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "0");
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } }
}
sp++; sp++;
byte_count++; byte_count++;
break; break;
case GM_MIXED: case GM_MIXED:
shift = 1; shift = 1;
if((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) { shift = 0; } if ((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) {
if((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) { shift = 0; } shift = 0;
if((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) { shift = 0; } }
if(gbdata[sp] == ' ') { shift = 0; } if ((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) {
shift = 0;
}
if ((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) {
shift = 0;
}
if (gbdata[sp] == ' ') {
shift = 0;
}
if (shift == 0) { if (shift == 0) {
/* Mixed Mode character */ /* Mixed Mode character */
glyph = posn(EUROPIUM, gbdata[sp]); glyph = posn(EUROPIUM, gbdata[sp]);
if(debug) { printf("[%d] ", glyph); } if (debug) {
printf("[%d] ", glyph);
}
if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } for (int p = 0; p < 6; p++) {
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } if (glyph & (0x20 >> p)) {
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "1");
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } } else {
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "0");
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } }
}
} else { } else {
/* Shift Mode character */ /* Shift Mode character */
concat(binary, "1111110110"); /* 1014 - shift indicator */ concat(binary, "1111110110"); /* 1014 - shift indicator */
@ -652,19 +710,27 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
case GM_UPPER: case GM_UPPER:
shift = 1; shift = 1;
if((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) { shift = 0; } if ((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) {
if(gbdata[sp] == ' ') { shift = 0; } shift = 0;
}
if (gbdata[sp] == ' ') {
shift = 0;
}
if (shift == 0) { if (shift == 0) {
/* Upper Case character */ /* Upper Case character */
glyph = posn("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", gbdata[sp]); glyph = posn("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", gbdata[sp]);
if(debug) { printf("[%d] ", glyph); } if (debug) {
printf("[%d] ", glyph);
}
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } for (int p = 0; p < 5; p++) {
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } if (glyph & (0x10 >> p)) {
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "1");
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } } else {
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "0");
}
}
} else { } else {
/* Shift Mode character */ /* Shift Mode character */
concat(binary, "1111101"); /* 127 - shift indicator */ concat(binary, "1111101"); /* 127 - shift indicator */
@ -676,19 +742,27 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
case GM_LOWER: case GM_LOWER:
shift = 1; shift = 1;
if((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) { shift = 0; } if ((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) {
if(gbdata[sp] == ' ') { shift = 0; } shift = 0;
}
if (gbdata[sp] == ' ') {
shift = 0;
}
if (shift == 0) { if (shift == 0) {
/* Lower Case character */ /* Lower Case character */
glyph = posn("abcdefghijklmnopqrstuvwxyz ", gbdata[sp]); glyph = posn("abcdefghijklmnopqrstuvwxyz ", gbdata[sp]);
if(debug) { printf("[%d] ", glyph); } if (debug) {
printf("[%d] ", glyph);
}
if(glyph & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); } for (int p = 0; p < 5; p++) {
if(glyph & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); } if (glyph & (0x10 >> p)) {
if(glyph & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "1");
if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } } else {
if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } concat(binary, "0");
}
}
} else { } else {
/* Shift Mode character */ /* Shift Mode character */
concat(binary, "1111101"); /* 127 - shift indicator */ concat(binary, "1111101"); /* 127 - shift indicator */
@ -707,9 +781,15 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
if (current_mode == GM_NUMBER) { if (current_mode == GM_NUMBER) {
/* add numeric block padding value */ /* add numeric block padding value */
switch (p) { switch (p) {
case 1: binary[number_pad_posn] = '1'; binary[number_pad_posn + 1] = '0'; break; // 2 pad digits case 1: binary[number_pad_posn] = '1';
case 2: binary[number_pad_posn] = '0'; binary[number_pad_posn + 1] = '1'; break; // 1 pad digit binary[number_pad_posn + 1] = '0';
case 3: binary[number_pad_posn] = '0'; binary[number_pad_posn + 1] = '0'; break; // 0 pad digits break; // 2 pad digits
case 2: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '1';
break; // 1 pad digit
case 3: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '0';
break; // 0 pad digits
} }
} }
@ -720,17 +800,24 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
/* Add "end of data" character */ /* Add "end of data" character */
switch (current_mode) { switch (current_mode) {
case GM_CHINESE: concat(binary, "1111111100000"); break; // 8160 case GM_CHINESE: concat(binary, "1111111100000");
case GM_NUMBER: concat(binary, "1111111010"); break; // 1018 break; // 8160
case GM_NUMBER: concat(binary, "1111111010");
break; // 1018
case GM_LOWER: case GM_LOWER:
case GM_UPPER: concat(binary, "11011"); break; // 27 case GM_UPPER: concat(binary, "11011");
case GM_MIXED: concat(binary, "1111110000"); break; // 1008 break; // 27
case GM_BYTE: concat(binary, "0000"); break; // 0 case GM_MIXED: concat(binary, "1111110000");
break; // 1008
case GM_BYTE: concat(binary, "0000");
break; // 0
} }
/* Add padding bits if required */ /* Add padding bits if required */
p = 7 - (strlen(binary) % 7); p = 7 - (strlen(binary) % 7);
if(p == 7) { p = 0; } if (p == 7) {
p = 0;
}
for (i = 0; i < p; i++) { for (i = 0; i < p; i++) {
concat(binary, "0"); concat(binary, "0");
} }
@ -741,8 +828,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader)
return 0; return 0;
} }
void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int word[]) void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int word[]) {
{
int data_cw, i, j, wp; int data_cw, i, j, wp;
int n1, b1, n2, b2, e1, b3, e2; int n1, b1, n2, b2, e1, b3, e2;
int block_size, data_size, ecc_size; int block_size, data_size, ecc_size;
@ -757,13 +843,11 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor
/* Convert from binary sream to 7-bit codewords */ /* Convert from binary sream to 7-bit codewords */
for (i = 0; i < data_posn; i++) { for (i = 0; i < data_posn; i++) {
if(binary[i * 7] == '1') { data[i] += 0x40; } for (int p = 0; p < 7; p++) {
if(binary[(i * 7) + 1] == '1') { data[i] += 0x20; } if (binary[i * 7 + p] == '1') {
if(binary[(i * 7) + 2] == '1') { data[i] += 0x10; } data[i] += (0x40 >> p);
if(binary[(i * 7) + 3] == '1') { data[i] += 0x08; } }
if(binary[(i * 7) + 4] == '1') { data[i] += 0x04; } }
if(binary[(i * 7) + 5] == '1') { data[i] += 0x02; }
if(binary[(i * 7) + 6] == '1') { data[i] += 0x01; }
} }
/* Add padding codewords */ /* Add padding codewords */
@ -788,8 +872,16 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor
/* Split the data into blocks */ /* Split the data into blocks */
wp = 0; wp = 0;
for (i = 0; i < (b1 + b2); i++) { for (i = 0; i < (b1 + b2); i++) {
if(i < b1) { block_size = n1; } else { block_size = n2; } if (i < b1) {
if(i < b3) { ecc_size = e1; } else { ecc_size = e2; } block_size = n1;
} else {
block_size = n2;
}
if (i < b3) {
ecc_size = e1;
} else {
ecc_size = e2;
}
data_size = block_size - ecc_size; data_size = block_size - ecc_size;
/* printf("block %d/%d: data %d / ecc %d\n", i + 1, (b1 + b2), data_size, ecc_size);*/ /* printf("block %d/%d: data %d / ecc %d\n", i + 1, (b1 + b2), data_size, ecc_size);*/
@ -822,31 +914,57 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor
} }
} }
void place_macromodule(char grid[], int x, int y, int word1, int word2, int size) void place_macromodule(char grid[], int x, int y, int word1, int word2, int size) {
{
int i, j; int i, j;
i = (x * 6) + 1; i = (x * 6) + 1;
j = (y * 6) + 1; j = (y * 6) + 1;
if(word2 & 0x40) { grid[(j * size) + i + 2] = '1'; } if (word2 & 0x40) {
if(word2 & 0x20) { grid[(j * size) + i + 3] = '1'; } grid[(j * size) + i + 2] = '1';
if(word2 & 0x10) { grid[((j + 1) * size) + i] = '1'; } }
if(word2 & 0x08) { grid[((j + 1) * size) + i + 1] = '1'; } if (word2 & 0x20) {
if(word2 & 0x04) { grid[((j + 1) * size) + i + 2] = '1'; } grid[(j * size) + i + 3] = '1';
if(word2 & 0x02) { grid[((j + 1) * size) + i + 3] = '1'; } }
if(word2 & 0x01) { grid[((j + 2) * size) + i] = '1'; } if (word2 & 0x10) {
if(word1 & 0x40) { grid[((j + 2) * size) + i + 1] = '1'; } grid[((j + 1) * size) + i] = '1';
if(word1 & 0x20) { grid[((j + 2) * size) + i + 2] = '1'; } }
if(word1 & 0x10) { grid[((j + 2) * size) + i + 3] = '1'; } if (word2 & 0x08) {
if(word1 & 0x08) { grid[((j + 3) * size) + i] = '1'; } grid[((j + 1) * size) + i + 1] = '1';
if(word1 & 0x04) { grid[((j + 3) * size) + i + 1] = '1'; } }
if(word1 & 0x02) { grid[((j + 3) * size) + i + 2] = '1'; } if (word2 & 0x04) {
if(word1 & 0x01) { grid[((j + 3) * size) + i + 3] = '1'; } grid[((j + 1) * size) + i + 2] = '1';
}
if (word2 & 0x02) {
grid[((j + 1) * size) + i + 3] = '1';
}
if (word2 & 0x01) {
grid[((j + 2) * size) + i] = '1';
}
if (word1 & 0x40) {
grid[((j + 2) * size) + i + 1] = '1';
}
if (word1 & 0x20) {
grid[((j + 2) * size) + i + 2] = '1';
}
if (word1 & 0x10) {
grid[((j + 2) * size) + i + 3] = '1';
}
if (word1 & 0x08) {
grid[((j + 3) * size) + i] = '1';
}
if (word1 & 0x04) {
grid[((j + 3) * size) + i + 1] = '1';
}
if (word1 & 0x02) {
grid[((j + 3) * size) + i + 2] = '1';
}
if (word1 & 0x01) {
grid[((j + 3) * size) + i + 3] = '1';
}
} }
void place_data_in_grid(int word[], char grid[], int modules, int size) void place_data_in_grid(int word[], char grid[], int modules, int size) {
{
int x, y, macromodule, offset; int x, y, macromodule, offset;
offset = 13 - ((modules - 1) / 2); offset = 13 - ((modules - 1) / 2);
@ -858,10 +976,8 @@ void place_data_in_grid(int word[], char grid[], int modules, int size)
} }
} }
void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level)
{
/* Place the layer ID into each macromodule */ /* Place the layer ID into each macromodule */
void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level) {
int i, j, layer, start, stop; int i, j, layer, start, stop;
#ifndef _MSC_VER #ifndef _MSC_VER
@ -914,8 +1030,7 @@ void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level
} }
} }
int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) {
{
int size, modules, dark, error_number; int size, modules, dark, error_number;
int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level; int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level;
int x, y, i, j, glyph; int x, y, i, j, glyph;
@ -945,7 +1060,9 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
default: default:
/* Convert Unicode input to GB-2312 */ /* Convert Unicode input to GB-2312 */
error_number = utf8toutf16(symbol, source, utfdata, &length); error_number = utf8toutf16(symbol, source, utfdata, &length);
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (utfdata[i] <= 0xff) { if (utfdata[i] <= 0xff) {
@ -982,19 +1099,31 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
auto_layers = 13; auto_layers = 13;
for (i = 12; i > 0; i--) { for (i = 12; i > 0; i--) {
if(gm_recommend_cw[(i - 1)] >= data_cw) { auto_layers = i; } if (gm_recommend_cw[(i - 1)] >= data_cw) {
auto_layers = i;
}
} }
min_layers = 13; min_layers = 13;
for (i = 12; i > 0; i--) { for (i = 12; i > 0; i--) {
if(gm_max_cw[(i - 1)] >= data_cw) { min_layers = i; } if (gm_max_cw[(i - 1)] >= data_cw) {
min_layers = i;
}
} }
layers = auto_layers; layers = auto_layers;
auto_ecc_level = 3; auto_ecc_level = 3;
if(layers == 1) { auto_ecc_level = 5; } if (layers == 1) {
if((layers == 2) || (layers == 3)) { auto_ecc_level = 4; } auto_ecc_level = 5;
}
if ((layers == 2) || (layers == 3)) {
auto_ecc_level = 4;
}
min_ecc_level = 1; min_ecc_level = 1;
if(layers == 1) { min_ecc_level = 4; } if (layers == 1) {
if((layers == 2) || (layers == 3)) { min_ecc_level = 2; } min_ecc_level = 4;
}
if ((layers == 2) || (layers == 3)) {
min_ecc_level = 2;
}
ecc_level = auto_ecc_level; ecc_level = auto_ecc_level;
if ((symbol->option_2 >= 1) && (symbol->option_2 <= 13)) { if ((symbol->option_2 >= 1) && (symbol->option_2 <= 13)) {
@ -1008,8 +1137,12 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
if (input_latch == 1) { if (input_latch == 1) {
auto_ecc_level = 3; auto_ecc_level = 3;
if(layers == 1) { auto_ecc_level = 5; } if (layers == 1) {
if((layers == 2) || (layers == 3)) { auto_ecc_level = 4; } auto_ecc_level = 5;
}
if ((layers == 2) || (layers == 3)) {
auto_ecc_level = 4;
}
ecc_level = auto_ecc_level; ecc_level = auto_ecc_level;
if (data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) { if (data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) {
layers++; layers++;
@ -1033,10 +1166,14 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
data_max = 1313; data_max = 1313;
switch (ecc_level) { switch (ecc_level) {
case 2: data_max = 1167; break; case 2: data_max = 1167;
case 3: data_max = 1021; break; break;
case 4: data_max = 875; break; case 3: data_max = 1021;
case 5: data_max = 729; break; break;
case 4: data_max = 875;
break;
case 5: data_max = 729;
break;
} }
if (data_cw > data_max) { if (data_cw > data_max) {

View File

@ -1,7 +1,7 @@
/* gridmtx.h - definitions for Grid Matrix /* gridmtx.h - definitions for Grid Matrix
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -47,9 +47,13 @@ static const char shift_set[] = {
';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~' ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~'
}; };
static const int gm_recommend_cw[] = { 9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021 }; static const int gm_recommend_cw[] = {
static const int gm_max_cw[] = { 11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313 }; 9, 30, 59, 114, 170, 237, 315, 405, 506, 618, 741, 875, 1021
//static const int gm_total_cw[] = { 18, 50, 98, 162, 242, 338, 450, 578, 722, 882, 1058, 1250, 1458 }; };
static const int gm_max_cw[] = {
11, 40, 79, 146, 218, 305, 405, 521, 650, 794, 953, 1125, 1313
};
static const int gm_data_codewords[] = { static const int gm_data_codewords[] = {
0, 15, 13, 11, 9, 0, 15, 13, 11, 9,
@ -67,9 +71,17 @@ static const int gm_data_codewords[] = {
1313, 1167, 1021, 875, 729 1313, 1167, 1021, 875, 729
}; };
static const int gm_n1[] = { 18, 50, 98, 81, 121, 113, 113, 116, 121, 126, 118, 125, 122 }; static const int gm_n1[] = {
static const int gm_b1[] = { 1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6 }; 18, 50, 98, 81, 121, 113, 113, 116, 121, 126, 118, 125, 122
static const int gm_b2[] = { 0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6 }; };
static const int gm_b1[] = {
1, 1, 1, 2, 2, 2, 2, 3, 2, 7, 5, 10, 6
};
static const int gm_b2[] = {
0, 0, 0, 0, 0, 1, 2, 2, 4, 0, 4, 0, 6
};
static const int gm_ebeb[] = { static const int gm_ebeb[] = {
/* E1 B3 E2 B4 */ /* E1 B3 E2 B4 */

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -43,8 +43,7 @@
to be bulletproof, nor does it report very accurately what problem was found to be bulletproof, nor does it report very accurately what problem was found
or where, but should prevent some of the more common encoding errors */ or where, but should prevent some of the more common encoding errors */
void itostr(char ai_string[], int ai_value) void itostr(char ai_string[], int ai_value) {
{
int thou, hund, ten, unit; int thou, hund, ten, unit;
char temp[2]; char temp[2];
@ -55,8 +54,14 @@ void itostr(char ai_string[], int ai_value)
unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten)); unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten));
temp[1] = '\0'; temp[1] = '\0';
if(ai_value >= 1000) { temp[0] = itoc(thou); concat(ai_string, temp); } if (ai_value >= 1000) {
if(ai_value >= 100) { temp[0] = itoc(hund); concat(ai_string, temp); } temp[0] = itoc(thou);
concat(ai_string, temp);
}
if (ai_value >= 100) {
temp[0] = itoc(hund);
concat(ai_string, temp);
}
temp[0] = itoc(ten); temp[0] = itoc(ten);
concat(ai_string, temp); concat(ai_string, temp);
temp[0] = itoc(unit); temp[0] = itoc(unit);
@ -64,8 +69,7 @@ void itostr(char ai_string[], int ai_value)
concat(ai_string, ")"); concat(ai_string, ")");
} }
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]) int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]) {
{
int i, j, last_ai, ai_latch; int i, j, last_ai, ai_latch;
char ai_string[6]; char ai_string[6];
int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length; int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length;
@ -99,16 +103,27 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
ai_latch = 0; ai_latch = 0;
for (i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
ai_length += j; ai_length += j;
if(((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) { ai_latch = 1; } if (((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) {
if(source[i] == '[') { bracket_level++; j = 1; } ai_latch = 1;
}
if (source[i] == '[') {
bracket_level++;
j = 1;
}
if (source[i] == ']') { if (source[i] == ']') {
bracket_level--; bracket_level--;
if(ai_length < min_ai_length) { min_ai_length = ai_length; } if (ai_length < min_ai_length) {
min_ai_length = ai_length;
}
j = 0; j = 0;
ai_length = 0; ai_length = 0;
} }
if(bracket_level > max_bracket_level) { max_bracket_level = bracket_level; } if (bracket_level > max_bracket_level) {
if(ai_length > max_ai_length) { max_ai_length = ai_length; } max_bracket_level = bracket_level;
}
if (ai_length > max_ai_length) {
max_ai_length = ai_length;
}
} }
min_ai_length--; min_ai_length--;
@ -159,8 +174,12 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
for (i = 0; i < ai_count; i++) { for (i = 0; i < ai_count; i++) {
data_location[i] = ai_location[i] + 3; data_location[i] = ai_location[i] + 3;
if(ai_value[i] >= 100) { data_location[i]++; } if (ai_value[i] >= 100) {
if(ai_value[i] >= 1000) { data_location[i]++; } data_location[i]++;
}
if (ai_value[i] >= 1000) {
data_location[i]++;
}
data_length[i] = 0; data_length[i] = 0;
do { do {
data_length[i]++; data_length[i]++;
@ -180,11 +199,20 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
strcpy(ai_string, ""); strcpy(ai_string, "");
for (i = 0; i < ai_count; i++) { for (i = 0; i < ai_count; i++) {
switch (ai_value[i]) { switch (ai_value[i]) {
case 0: if(data_length[i] != 18) { error_latch = 1; } break; case 0: if (data_length[i] != 18) {
error_latch = 1;
}
break;
case 1: case 1:
case 2: case 2:
case 3: if(data_length[i] != 14) { error_latch = 1; } break; case 3: if (data_length[i] != 14) {
case 4: if(data_length[i] != 16) { error_latch = 1; } break; error_latch = 1;
}
break;
case 4: if (data_length[i] != 16) {
error_latch = 1;
}
break;
case 11: case 11:
case 12: case 12:
case 13: case 13:
@ -193,8 +221,14 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
case 16: case 16:
case 17: case 17:
case 18: case 18:
case 19: if(data_length[i] != 6) { error_latch = 1; } break; case 19: if (data_length[i] != 6) {
case 20: if(data_length[i] != 2) { error_latch = 1; } break; error_latch = 1;
}
break;
case 20: if (data_length[i] != 2) {
error_latch = 1;
}
break;
case 23: case 23:
case 24: case 24:
case 25: case 25:
@ -204,7 +238,8 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
case 42: case 42:
case 70: case 70:
case 80: case 80:
case 81: error_latch = 2; break; case 81: error_latch = 2;
break;
} }
if ( if (
((ai_value[i] >= 100) && (ai_value[i] <= 179)) ((ai_value[i] >= 100) && (ai_value[i] <= 179))
@ -300,8 +335,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne
return 0; return 0;
} }
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]) int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]) {
{
/* Only to keep the compiler happy */ /* Only to keep the compiler happy */
#ifndef _MSC_VER #ifndef _MSC_VER
char temp[src_len + 5]; char temp[src_len + 5];
@ -311,7 +345,9 @@ int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsign
int error_number; int error_number;
error_number = gs1_verify(symbol, source, src_len, temp); error_number = gs1_verify(symbol, source, src_len, temp);
if(error_number != 0) { return error_number; } if (error_number != 0) {
return error_number;
}
if (strlen(temp) < src_len + 5) { if (strlen(temp) < src_len + 5) {
ustrcpy(reduced, (unsigned char*) temp); ustrcpy(reduced, (unsigned char*) temp);

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk> Copyright (C) 2009-2016 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions