Minor Dotcode tweaks

Slight modification brings code inline with latest version of draft standard.
Thanks to input from Terry Burton at BWIPP
This commit is contained in:
Robin Stuart 2019-10-31 13:27:36 +00:00
parent c87c86e30a
commit 1a5eb573cf

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2017 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2017-2019 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,6 +32,7 @@
/* /*
* Attempts to encode DotCode according to AIMD013 Rev 1.34a, dated Feb 19, 2009 * Attempts to encode DotCode according to AIMD013 Rev 1.34a, dated Feb 19, 2009
* Incorporating suggestions from Terry Burton at BWIPP
*/ */
#include <stdio.h> #include <stdio.h>
@ -49,6 +50,7 @@
#define GF 113 #define GF 113
#define PM 3 #define PM 3
#define SCORE_UNLIT_EDGE -99999
/* DotCode symbol character dot patterns, from Annex C */ /* DotCode symbol character dot patterns, from Annex C */
static const unsigned short int dot_patterns[113] = { static const unsigned short int dot_patterns[113] = {
@ -105,7 +107,6 @@ const int score_array(char Dots[], int Hgt, int Wid) {
int x, y, worstedge, first, last, sum; int x, y, worstedge, first, last, sum;
int penalty_local = 0; int penalty_local = 0;
int penalty = 0; int penalty = 0;
int t = 0, b = 0, l = 0, r = 0;
// first, guard against "pathelogical" gaps in the array // first, guard against "pathelogical" gaps in the array
if (Hgt & 1) { if (Hgt & 1) {
@ -167,7 +168,7 @@ const int score_array(char Dots[], int Hgt, int Wid) {
worstedge *= Hgt; worstedge *= Hgt;
if (sum == 0) { if (sum == 0) {
t = 1; return SCORE_UNLIT_EDGE; // guard against empty top edge
} }
sum = 0; sum = 0;
@ -190,7 +191,7 @@ const int score_array(char Dots[], int Hgt, int Wid) {
} }
if (sum == 0) { if (sum == 0) {
b = 2; return SCORE_UNLIT_EDGE; // guard against empty bottom edge
} }
sum = 0; sum = 0;
@ -213,7 +214,7 @@ const int score_array(char Dots[], int Hgt, int Wid) {
} }
if (sum == 0) { if (sum == 0) {
l = 4; return SCORE_UNLIT_EDGE; // guard against empty left edge
} }
sum = 0; sum = 0;
@ -236,11 +237,9 @@ const int score_array(char Dots[], int Hgt, int Wid) {
} }
if (sum == 0) { if (sum == 0) {
r = 8; return SCORE_UNLIT_EDGE; // guard against empty right edge
} }
penalty += (t + b + l + r) * 100000;
// throughout the array, count the # of unprinted 5-somes (cross patterns) // throughout the array, count the # of unprinted 5-somes (cross patterns)
// plus the # of printed dots surrounded by 8 unprinted neighbors // plus the # of printed dots surrounded by 8 unprinted neighbors
sum = 0; sum = 0;
@ -667,7 +666,7 @@ int dotcode_encode_message(struct zint_symbol *symbol, const unsigned char sourc
} }
} }
/* Setp B3 */ /* Step B3 */
if ((!done) && (encoding_mode == 'C')) { if ((!done) && (encoding_mode == 'C')) {
if (binary(source, input_position)) { if (binary(source, input_position)) {
if (n_digits(source, input_position + 1, length) > 0) { if (n_digits(source, input_position + 1, length) > 0) {
@ -1442,7 +1441,7 @@ int dotcode(struct zint_symbol *symbol, const unsigned char source[], int length
best_mask = 0; best_mask = 0;
for (i = 1; i < 4; i++) { for (i = 1; i < 4; i++) {
if (mask_score[i] > high_score) { if (mask_score[i] >= high_score) {
high_score = mask_score[i]; high_score = mask_score[i];
best_mask = i; best_mask = i;
} }
@ -1473,7 +1472,7 @@ int dotcode(struct zint_symbol *symbol, const unsigned char source[], int length
} }
for (i = 4; i < 8; i++) { for (i = 4; i < 8; i++) {
if (mask_score[i] > high_score) { if (mask_score[i] >= high_score) {
high_score = mask_score[i]; high_score = mask_score[i];
best_mask = i; best_mask = i;
} }