mirror of
https://git.code.sf.net/p/zint/code
synced 2026-01-25 04:45:58 +00:00
synchronized with master
This commit is contained in:
@@ -36,6 +36,10 @@ static char *C25IndustTable[10] = {"1111313111", "3111111131", "1131111131", "31
|
||||
static char *C25InterTable[10] = {"11331", "31113", "13113", "33111", "11313", "31311", "13311", "11133",
|
||||
"31131", "13131"};
|
||||
|
||||
static inline char check_digit(unsigned int count)
|
||||
{
|
||||
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) */
|
||||
@@ -235,7 +239,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
|
||||
int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count, check_digit;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
|
||||
error_number = 0;
|
||||
@@ -269,9 +273,7 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
count += 2 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
localstr[13] = itoc(check_digit);
|
||||
localstr[13] = check_digit(count);
|
||||
localstr[14] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
@@ -281,7 +283,7 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Deutshe Post Leitcode */
|
||||
int i, error_number;
|
||||
unsigned int count, check_digit;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
int zeroes;
|
||||
|
||||
@@ -310,9 +312,7 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
localstr[13] = itoc(check_digit);
|
||||
localstr[13] = check_digit(count);
|
||||
localstr[14] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
@@ -322,7 +322,7 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Deutsche Post Identcode */
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count, check_digit;
|
||||
unsigned int count;
|
||||
char localstr[16];
|
||||
|
||||
count = 0;
|
||||
@@ -349,9 +349,7 @@ int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
count += 5 * ctoi(localstr[i]);
|
||||
}
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
localstr[11] = itoc(check_digit);
|
||||
localstr[11] = check_digit(count);
|
||||
localstr[12] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
|
||||
@@ -43,39 +43,24 @@ static char *AusBarTable[64] = {"000", "001", "002", "003", "010", "011", "012",
|
||||
#include "common.h"
|
||||
#include "reedsol.h"
|
||||
|
||||
static inline char convert_pattern(char data, int shift)
|
||||
{
|
||||
return (data - '0') << shift;
|
||||
}
|
||||
|
||||
void rs_error(char data_pattern[])
|
||||
{
|
||||
/* Adds Reed-Solomon error correction to auspost */
|
||||
|
||||
int reader, triple_writer;
|
||||
int reader, triple_writer = 0;
|
||||
char triple[31], inv_triple[31];
|
||||
unsigned char result[5];
|
||||
|
||||
triple_writer = 0;
|
||||
|
||||
for(reader = 2; reader < strlen(data_pattern); reader+= 3)
|
||||
{
|
||||
triple[triple_writer] = 0;
|
||||
switch(data_pattern[reader])
|
||||
for(reader = 2; reader < strlen(data_pattern); reader += 3, triple_writer++)
|
||||
{
|
||||
case '1': triple[triple_writer] += 16; break;
|
||||
case '2': triple[triple_writer] += 32; break;
|
||||
case '3': triple[triple_writer] += 48; break;
|
||||
}
|
||||
switch(data_pattern[reader + 1])
|
||||
{
|
||||
case '1': triple[triple_writer] += 4; break;
|
||||
case '2': triple[triple_writer] += 8; break;
|
||||
case '3': triple[triple_writer] += 12; break;
|
||||
}
|
||||
switch(data_pattern[reader + 2])
|
||||
{
|
||||
case '1': triple[triple_writer] += 1; break;
|
||||
case '2': triple[triple_writer] += 2; break;
|
||||
case '3': triple[triple_writer] += 3; break;
|
||||
}
|
||||
triple_writer++;
|
||||
|
||||
triple[triple_writer] = convert_pattern(data_pattern[reader], 4)
|
||||
+ convert_pattern(data_pattern[reader + 1], 2)
|
||||
+ convert_pattern(data_pattern[reader + 2], 0);
|
||||
}
|
||||
|
||||
for(reader = 0; reader < triple_writer; reader++)
|
||||
@@ -113,23 +98,35 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
char data_pattern[200];
|
||||
char fcc[3] = { 0 };
|
||||
char dpid[10];
|
||||
char localstr[30];
|
||||
char localstr[30] = { 0 };
|
||||
|
||||
error_number = 0;
|
||||
strcpy(localstr, "");
|
||||
|
||||
/* Do all of the length checking first to avoid stack smashing */
|
||||
if(symbol->symbology == BARCODE_AUSPOST) {
|
||||
/* Format control code (FCC) */
|
||||
switch(length)
|
||||
{
|
||||
case 8: strcpy(fcc, "11"); break;
|
||||
case 13: strcpy(fcc, "59"); break;
|
||||
case 16: strcpy(fcc, "59"); error_number = is_sane(NEON, source, length); break;
|
||||
case 18: strcpy(fcc, "62"); break;
|
||||
case 23: strcpy(fcc, "62"); error_number = is_sane(NEON, source, length); break;
|
||||
default: strcpy(symbol->errtxt, "Auspost input is wrong length");
|
||||
return ZERROR_TOO_LONG;
|
||||
case 8:
|
||||
strcpy(fcc, "11");
|
||||
break;
|
||||
case 13:
|
||||
strcpy(fcc, "59");
|
||||
break;
|
||||
case 16:
|
||||
strcpy(fcc, "59");
|
||||
error_number = is_sane(NEON, source, length);
|
||||
break;
|
||||
case 18:
|
||||
strcpy(fcc, "62");
|
||||
break;
|
||||
case 23:
|
||||
strcpy(fcc, "62");
|
||||
error_number = is_sane(NEON, source, length);
|
||||
break;
|
||||
default:
|
||||
strcpy(symbol->errtxt, "Auspost input is wrong length");
|
||||
return ZERROR_TOO_LONG;
|
||||
break;
|
||||
}
|
||||
if(error_number == ZERROR_INVALID_DATA) {
|
||||
@@ -150,7 +147,6 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
/* Add leading zeros as required */
|
||||
zeroes = 8 - length;
|
||||
memset(localstr, '0', zeroes);
|
||||
localstr[8] = '\0';
|
||||
}
|
||||
|
||||
concat(localstr, (char*)source);
|
||||
@@ -195,7 +191,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
lookup(GDSET, AusCTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
if((h == 16) || (h == 23)) {
|
||||
else if((h == 16) || (h == 23)) {
|
||||
for(reader = 8; reader < h; reader++) {
|
||||
lookup(NEON, AusNTable, localstr[reader], data_pattern);
|
||||
}
|
||||
|
||||
@@ -1200,29 +1200,8 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
data_blocks = c1_blocks[size - 1];
|
||||
|
||||
/*
|
||||
Section 2.2.5.1 states:
|
||||
"The polynomial arithmetic... is calculated using bit-wise modulo 2 arithmetic
|
||||
and byte-wise modulo 100101101 arithmetic (this is a Galois Field of 2^8 with
|
||||
100101101 representing the field's prime modulus polynomial:
|
||||
x^8 + x^5 + x^3 + x^2 + 1)."
|
||||
This is the same as Data Matrix (ISO/IEC 16022) however the calculations in Appendix F
|
||||
of the Code One specification do not agree with those in Annex E of ISO/IEC 16022.
|
||||
For example Code One Appendix F states:
|
||||
"The polynomial divisor for generating ten check characters for Version T-16
|
||||
and Version A is:
|
||||
g(x)=x^10 + 136x^9 + 141x^8 + 113x^7 + 76x^6 + 218x^5 + 43x^4 + 85x^3
|
||||
+ 182x^2 + 31x + 52."
|
||||
Whereas ISO/IEC 16022 Annex E states:
|
||||
"The polynomial divisor for generating 10 check characters is:
|
||||
g(x)=x^10 + 61x^9 + 110x^8 + 255x^7 + 116x^6 + 248x^5 + 223x^4 + 166x^3
|
||||
+ 185x^2 + 24x + 28."
|
||||
For this code I have assumed that ISO/IEC 16022 is correct and the USS Code One
|
||||
specifications are incorrect
|
||||
*/
|
||||
|
||||
rs_init_gf(0x12d);
|
||||
rs_init_code(c1_ecc_blocks[size - 1], 1);
|
||||
rs_init_code(c1_ecc_blocks[size - 1], 0);
|
||||
for(i = 0; i < data_blocks; i++) {
|
||||
for(j = 0; j < c1_data_blocks[size - 1]; j++) {
|
||||
|
||||
|
||||
@@ -775,7 +775,7 @@ void add_tail(unsigned char target[], int tp, int tail_length, int last_mode)
|
||||
|
||||
int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int i, skew = 0;
|
||||
int inputlen, i, skew = 0;
|
||||
unsigned char binary[2200];
|
||||
int binlen;
|
||||
int symbolsize, optionsize, calcsize;
|
||||
@@ -783,6 +783,7 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
|
||||
int H, W, FH, FW, datablock, bytes, rsblock;
|
||||
int last_mode;
|
||||
unsigned char *grid = 0;
|
||||
inputlen = length;
|
||||
|
||||
binlen = dm200encode(symbol, source, binary, &last_mode, length);
|
||||
|
||||
|
||||
@@ -602,6 +602,9 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
if((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */
|
||||
if(lp == 0){ /* Mode set manually means lp doesn't get set */
|
||||
lp = strlen(symbol->primary);
|
||||
}
|
||||
if(lp != 15) {
|
||||
strcpy(symbol->errtxt, "Invalid Primary String");
|
||||
return ZERROR_INVALID_DATA;
|
||||
|
||||
Reference in New Issue
Block a user