From a916e2e2aa01f59552a2db83a95cf23a80347df8 Mon Sep 17 00:00:00 2001 From: Jan Luebbe Date: Wed, 18 Feb 2009 13:17:49 +0100 Subject: [PATCH] Imported Upstream version 0.2 --- CHANGELOG | 12 +++ CREDITS | 6 +- INSTALL | 7 +- Makefile | 36 +++++-- README | 2 +- TODO | 3 +- iec16022.1 | 23 ++--- iec16022.c | 134 +++++++++++++++--------- iec16022ecc200.c | 200 +++++++++++++++++++++++------------- iec16022ecc200.h | 10 +- image.c | 71 +++++-------- image.h | 5 + reedsol.c | 12 +-- reedsol.h | 4 + test/testsuite-example.bin | 1 + test/testsuite-example.eps | 15 +++ test/testsuite-example.hex | 2 + test/testsuite-example.png | Bin 0 -> 412 bytes test/testsuite-example.text | 32 ++++++ test/testsuite.sh | 19 ++++ 20 files changed, 391 insertions(+), 203 deletions(-) create mode 100644 test/testsuite-example.bin create mode 100644 test/testsuite-example.eps create mode 100644 test/testsuite-example.hex create mode 100644 test/testsuite-example.png create mode 100644 test/testsuite-example.text create mode 100755 test/testsuite.sh diff --git a/CHANGELOG b/CHANGELOG index 7f1e6b4..ec24722 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,15 @@ +0.2 + - Rewrite Makefile. + - Documentation update. + - Exclude double include of header files. + - Layout cahnges. Place return value in front of function name. + - 80 character per line. + - Print version number before usage. + - Tests + +2006-02-06 Stefan Schmidt + + 0.1 - Initial release. - INSTALL, README, TODO, CREDITS, Makefile, LICENSE and CHANGELOG files diff --git a/CREDITS b/CREDITS index c37d23d..37e2bcc 100644 --- a/CREDITS +++ b/CREDITS @@ -3,4 +3,8 @@ find it at http://aa.gg/free/ Cliff Hones for the RS coding. -Jan Luebbe for writing the manual page. +Jan Luebbe for writing the manual page and maintaining +the debian package. + +Daniel Willman for maintaining the gentoo +ebuild. diff --git a/INSTALL b/INSTALL index 69cadcb..102a61e 100644 --- a/INSTALL +++ b/INSTALL @@ -1,3 +1,8 @@ +To install this software you need the following libraries installed: +- libpopt +- zlib + Installing iec16022 is really simple. Just do a 'make' and 'make install'. + In standard configuration the binary will be installed in /usr/local/bin. You -can change this behavior in the Makefile via DESTDIR. +can change the prefix and DESTDIR in the Makefile. diff --git a/Makefile b/Makefile index c8fb665..4929afd 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,39 @@ CC=/usr/bin/cc INSTALL=/usr/bin/install GZIP=/bin/gzip -DESTDIR=/usr/local - -prefix=$(DESTDIR) +prefix=/usr/local bindir=$(prefix)/bin mandir=$(prefix)/share/man -all: - $(CC) -o iec16022 iec16022.c -DLIB image.c reedsol.c iec16022ecc200.c -lz -lpopt +CFLAGS=-Wall + +.PHONY: test clean + +all: iec16022 manpage + +iec16022: iec16022ecc200.o image.o iec16022.c + $(CC) -c iec16022.c + $(CC) -o iec16022 $(CFLAGS) reedsol.o iec16022.o image.o iec16022ecc200.o -lz -lpopt + +manpage: iec16022.1 $(GZIP) -f --best < iec16022.1 > iec16022.1.gz install: all - $(INSTALL) -m 755 iec16022 $(bindir) - $(INSTALL) -m 644 iec16022.1.gz $(mandir)/man1 + $(INSTALL) -d -m 755 $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man1 + $(INSTALL) -m 755 iec16022 $(DESTDIR)$(bindir) + $(INSTALL) -m 644 iec16022.1.gz $(DESTDIR)$(mandir)/man1 + +test: iec16022 + cd test; ./testsuite.sh + +iec16022ecc200.o: iec16022ecc200.c iec16022ecc200.h reedsol.o + $(CC) -c iec16022ecc200.c + +image.o: image.c image.h + $(CC) -c image.c +reedsol.o: reedsol.c reedsol.h + $(CC) -DLIB -c reedsol.c clean: - rm -f iec16022 - rm -f iec16022.1.gz + rm -f iec16022 iec16022.1.gz *.o diff --git a/README b/README index cf4aef8..072c0ae 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ With iec16022 you can produce 2d barcodes. Also known as Data Matrix. These -barcodes are defined in ISO IEC16022. +barcodes are defined in ISO/IEC 16022. The code was originally written by Andrews & Arnold Ltd. You can download this code from http://aa.gg/free/. diff --git a/TODO b/TODO index 41c0ea9..d0f24d1 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ -- Set textwidth to 80. - Fix compiler warnings. +- Test on 64bit, powerpc, arm, etc. Anyone? +- Test stamp feature. Anyone? - Get ISO standard to verify code. diff --git a/iec16022.1 b/iec16022.1 index e725482..681c3a7 100644 --- a/iec16022.1 +++ b/iec16022.1 @@ -1,20 +1,4 @@ -.\" Hey, EMACS: -*- nroff -*- -.\" First parameter, NAME, should be all caps -.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection -.\" other parameters are allowed: see man(7), man(1) -.TH IEC16022 1 "December 28, 2005" -.\" Please adjust this date whenever revising the manpage. -.\" -.\" Some roff macros, for reference: -.\" .nh disable hyphenation -.\" .hy enable hyphenation -.\" .ad l left justify -.\" .ad b justify to both left and right margins -.\" .nf disable filling -.\" .fi enable filling -.\" .br insert line break -.\" .sp insert n+1 empty lines -.\" for manpage-specific macros, see man(7) +.TH iec16022 1 2006-01-14 "iec16022 0.1" .SH NAME iec16022 \- program to generate 2d barcodes .SH SYNOPSIS @@ -56,6 +40,11 @@ Show summary of options. .TP .B \-\-usage Show short overview of options. +.SH EXAMPLE +To produce a datamatrix barcode for foobar in PNG format you need the following +arguments: +.TP +.B iec16022 -f PNG -c foobar -o foobar.png .SH AUTHOR iec16022 was written by Adrian Kennard, Andrews & Arnold Ltd. .PP diff --git a/iec16022.c b/iec16022.c index 3c73935..3686710 100644 --- a/iec16022.c +++ b/iec16022.c @@ -23,6 +23,7 @@ * */ +#define IEC16022_VERSION "0.2" #include #include @@ -35,8 +36,7 @@ #include "iec16022ecc200.h" // simple checked response malloc -void * -safemalloc (int n) +void * safemalloc (int n) { void *p = malloc (n); if (!p) @@ -48,8 +48,7 @@ safemalloc (int n) } // hex dump - bottom left pixel first -void -dumphex (unsigned char *grid, int W, int H, unsigned char p) +void dumphex (unsigned char *grid, int W, int H, unsigned char p) { int c = 0, y; @@ -88,8 +87,7 @@ dumphex (unsigned char *grid, int W, int H, unsigned char p) printf ("\n"); } -int -main (int argc, const char *argv[]) +int main (int argc, const char *argv[]) { char c; int W = 0, @@ -118,12 +116,15 @@ main (int argc, const char *argv[]) { "infile", 'i', POPT_ARG_STRING, &infile, 0, "Barcode file", "filename"}, { - "outfile", 'o', POPT_ARG_STRING, &outfile, 0, "Output filename", "filename"}, + "outfile", 'o', POPT_ARG_STRING, &outfile, 0, "Output filename", \ + "filename"}, { - "encoding", 'e', POPT_ARG_STRING, &encoding, 0, "Encoding template", "[CTXEAB]* for ecc200 or 11/27/41/37/128/256"}, + "encoding", 'e', POPT_ARG_STRING, &encoding, 0, "Encoding template", \ + "[CTXEAB]* for ecc200 or 11/27/41/37/128/256"}, { - "format", 'f', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_STRING, &format, 0, "Output format", "Text/EPS/PNG/Bin/Hex/Stamp"}, - POPT_AUTOHELP { + "format", 'f', POPT_ARGFLAG_SHOW_DEFAULT | POPT_ARG_STRING, &format, 0, \ + "Output format", "Text/EPS/PNG/Bin/Hex/Stamp"}, + POPT_AUTOHELP { NULL, 0, 0, NULL, 0} }; optCon = poptGetContext (NULL, argc, argv, optionsTable, 0); @@ -131,7 +132,8 @@ main (int argc, const char *argv[]) if ((c = poptGetNextOpt (optCon)) < -1) { /* an error occurred during option processing */ - fprintf (stderr, "%s: %s\n", poptBadOption (optCon, POPT_BADOPTION_NOALIAS), poptStrerror (c)); + fprintf (stderr, "%s: %s\n", poptBadOption (optCon, \ + POPT_BADOPTION_NOALIAS), poptStrerror (c)); return 1; } @@ -139,7 +141,8 @@ main (int argc, const char *argv[]) barcode = (char *) poptGetArg (optCon); if (poptPeekArg (optCon) || !barcode && !infile || barcode && infile) { - poptPrintUsage (optCon, stderr, 0); + fprintf (stderr, "Version: %s\n", IEC16022_VERSION); + poptPrintUsage (optCon, stderr, 0); return -1; } if (outfile && !freopen (outfile, "w", stdout)) @@ -197,8 +200,9 @@ main (int argc, const char *argv[]) else ecc = 0; } - if (ecc && ecc != 50 && ecc != 80 && ecc != 100 && ecc != 140 || ecc == 50 && W < 11 || ecc == 80 && W < 13 - || ecc == 100 && W < 13 || ecc == 140 && W < 17) + if (ecc && ecc != 50 && ecc != 80 && ecc != 100 && ecc != 140 || \ + ecc == 50 && W < 11 || ecc == 80 && W < 13 || ecc == 100 \ + && W < 13 || ecc == 140 && W < 17) { fprintf (stderr, "ECC%03d invalid for %dx%d\n", ecc, W, H); return 1; @@ -224,7 +228,9 @@ main (int argc, const char *argv[]) else { // auto size if (!eccstr) - ecc = 200; // default is even sizes only unless explicit ecc set to force odd sizes + // default is even sizes only unless explicit ecc set to force odd + // sizes + ecc = 200; } if (tolower (*format) == 's') @@ -238,11 +244,13 @@ main (int argc, const char *argv[]) else { int n; - for (n = 0; n < barcodelen && (barcode[n] == ' ' || isdigit (barcode[n]) || isupper (barcode[n])); n++); + for (n = 0; n < barcodelen && (barcode[n] == ' ' || \ + isdigit (barcode[n]) || isupper (barcode[n])); n++); if (n < barcodelen) fprintf (stderr, "Has invalid characters for a stamp\n"); else - { // Generate simplistic encoding rules as used by the windows app + { + // Generate simplistic encoding rules as used by the windows app // TBA - does not always match the windows app... n = 0; encoding = safemalloc (barcodelen + 1); @@ -251,10 +259,12 @@ main (int argc, const char *argv[]) // ASCII while (1) { - if (n == barcodelen || n + 3 <= barcodelen && (!isdigit (barcode[n]) || !isdigit (barcode[n + 1]))) + if (n == barcodelen || n + 3 <= barcodelen && (!isdigit \ + (barcode[n]) || !isdigit (barcode[n + 1]))) break; encoding[n++] = 'A'; - if (n < barcodelen && isdigit (barcode[n - 1]) && isdigit (barcode[n])) + if (n < barcodelen && isdigit (barcode[n - 1]) && isdigit \ + (barcode[n])) encoding[n++] = 'A'; } // C40 @@ -281,7 +291,8 @@ main (int argc, const char *argv[]) fprintf (stderr, "Not done odd sizes yet, sorry\n"); } else { // even sizes - grid = iec16022ecc200 (&W, &H, &encoding, barcodelen, barcode, &len, &maxlen, &ecclen); + grid = iec16022ecc200 (&W, &H, &encoding, barcodelen, barcode, &len, \ + &maxlen, &ecclen); } // output @@ -294,7 +305,8 @@ main (int argc, const char *argv[]) { case 'i': // info printf ("Size : %dx%d\n", W, H); - printf ("Encoded : %d of %d bytes with %d bytes of ecc\n", len, maxlen, ecclen); + printf ("Encoded : %d of %d bytes with %d bytes of ecc\n", len, maxlen, \ + ecclen); printf ("Barcode : %s\n", barcode); printf ("Encoding: %s\n", encoding); break; @@ -339,9 +351,13 @@ main (int argc, const char *argv[]) } break; case 'e': // EPS - printf ("%%!PS-Adobe-3.0 EPSF-3.0\n" "%%%%Creator: IEC16022 barcode/stamp generator\n" "%%%%BarcodeData: %s\n" - "%%%%BarcodeSize: %dx%d\n" "%%%%BarcodeFormat: ECC200\n" "%%%%DocumentData: Clean7Bit\n" "%%%%LanguageLevel: 1\n" - "%%%%Pages: 1\n" "%%%%BoundingBox: 0 0 %d %d\n" "%%%%EndComments\n" "%%%%Page: 1 1\n" "%d %d 1[1 0 0 1 -1 -1]{<\n", + printf ("%%!PS-Adobe-3.0 EPSF-3.0\n" + "%%%%Creator: IEC16022 barcode/stamp generator\n" + "%%%%BarcodeData: %s\n" "%%%%BarcodeSize: %dx%d\n" + "%%%%BarcodeFormat: ECC200\n" "%%%%DocumentData: Clean7Bit\n" + "%%%%LanguageLevel: 1\n" "%%%%Pages: 1\n" + "%%%%BoundingBox: 0 0 %d %d\n" "%%%%EndComments\n" + "%%%%Page: 1 1\n" "%d %d 1[1 0 0 1 -1 -1]{<\n", barcode, W, H, W + 2, H + 2, W, H); dumphex (grid, W, H, 0xFF); printf (">}image\n"); @@ -371,63 +387,89 @@ main (int argc, const char *argv[]) t = *gmtime (&now); temp[46] = 0; v = atoi (temp + 36); - printf ("%%!PS-Adobe-3.0 EPSF-3.0\n" "%%%%Creator: IEC16022 barcode/stamp generator\n" "%%%%BarcodeData: %s\n" - "%%%%BarcodeSize: %dx%d\n" "%%%%DocumentData: Clean7Bit\n" "%%%%LanguageLevel: 1\n" - "%%%%Pages: 1\n" "%%%%BoundingBox: 0 0 190 80\n" "%%%%EndComments\n" "%%%%Page: 1 1\n" - "10 dict begin/f{findfont exch scalefont setfont}bind def/rm/rmoveto load def/m/moveto load def/rl/rlineto load def\n" - "/l/lineto load def/cp/closepath load def/c{dup stringwidth pop -2 div 0 rmoveto show}bind def\n" - "gsave 72 25.4 div dup scale 0 0 m 67 0 rl 0 28 rl -67 0 rl cp clip 1 setgray fill 0 setgray 0.5 0 translate 0.3 setlinewidth\n" - "32 32 1[2 0 0 2 0 -11]{<\n", barcode, W, H); + printf ("%%!PS-Adobe-3.0 EPSF-3.0\n" + "%%%%Creator: IEC16022 barcode/stamp generator\n" + "%%%%BarcodeData: %s\n" "%%%%BarcodeSize: %dx%d\n" + "%%%%DocumentData: Clean7Bit\n" "%%%%LanguageLevel: 1\n" + "%%%%Pages: 1\n" "%%%%BoundingBox: 0 0 190 80\n" + "%%%%EndComments\n" "%%%%Page: 1 1\n" + "10 dict begin/f{findfont exch scalefont \ + setfont}bind def/rm/rmoveto load def/m/moveto load \ + def/rl/rlineto load def\n" + "/l/lineto load def/cp/closepath load def/c{dup stringwidth \ + pop -2 div 0 rmoveto show}bind def\n" + "gsave 72 25.4 div dup scale 0 0 m 67 0 rl 0 28 rl -67 0 rl \ + cp clip 1 setgray fill 0 setgray 0.5 0 translate 0.3 \ + setlinewidth\n" "32 32 1[2 0 0 2 0 -11]{<\n", barcode, W, H); dumphex (grid, W, H, 0xFF); printf (">}image\n" "3.25/Helvetica-Bold f 8 25.3 m(\\243%d.%02d)c\n" "2.6/Helvetica f 8 22.3 m(%.4s %.4s)c\n" "1.5/Helvetica f 8 3.3 m(POST BY)c\n" "3.3/Helvetica f 8 0.25 m(%02d.%02d.%02d)c\n", - v / 100, v % 100, temp + 6, temp + 10, t.tm_mday, t.tm_mon + 1, t.tm_year % 100); + v / 100, v % 100, temp + 6, temp + 10, t.tm_mday, t.tm_mon + \ + 1, t.tm_year % 100); if (c == '1' || c == '2' || c == 'A' || c == 'S') { if (c == '2') - printf ("42 0 m 10 0 rl 0 28 rl -10 0 rl cp 57 0 m 5 0 rl 0 28 rl -5 0 rl cp"); + printf ("42 0 m 10 0 rl 0 28 rl -10 0 rl cp 57 0 m 5 0 rl 0 \ + 28 rl -5 0 rl cp"); else - printf ("42 0 m 5 0 rl 0 28 rl -5 0 rl cp 52 0 m 10 0 rl 0 28 rl -10 0 rl cp"); + printf ("42 0 m 5 0 rl 0 28 rl -5 0 rl cp 52 0 m 10 0 rl 0 \ + 28 rl -10 0 rl cp"); printf (" 21 0 m 16 0 rl 0 28 rl -16 0 rl cp fill\n" - "21.3 0.3 m 15.4 0 rl 0 13 rl -15.4 0 rl cp 1 setgray fill gsave 21.3 0.3 15.4 27.4 rectclip newpath\n"); + "21.3 0.3 m 15.4 0 rl 0 13 rl -15.4 0 rl cp 1 setgray \ + fill gsave 21.3 0.3 15.4 27.4 rectclip newpath\n"); switch (c) { case '1': printf - ("27/Helvetica-Bold f 27 8.7 m(1)show grestore 0 setgray 1.5/Helvetica-Bold f 22 3.3 m(POSTAGE PAID GB)show 1.7/Helvetica f 29 1.5 m(DumbStamp.co.uk)c\n"); + ("27/Helvetica-Bold f 27 8.7 m(1)show grestore 0 setgray \ + 1.5/Helvetica-Bold f 22 3.3 m(POSTAGE PAID GB)show \ + 1.7/Helvetica f 29 1.5 m(DumbStamp.co.uk)c\n"); break; case '2': printf - ("21/Helvetica-Bold f 23.5 13 m(2)1.25 1 scale show grestore 0 setgray 1.5/Helvetica-Bold f 22 3.3 m(POSTAGE PAID GB)show 1.7/Helvetica f 29 1.5 m(DumbStamp.co.uk)c\n"); + ("21/Helvetica-Bold f 23.5 13 m(2)1.25 1 scale show grestore \ + 0 setgray 1.5/Helvetica-Bold f 22 3.3 \ + m(POSTAGE PAID GB)show 1.7/Helvetica f 29 1.5 \ + m(DumbStamp.co.uk)c\n"); break; case 'A': printf - ("16/Helvetica-Bold f 29 14.75 m 1.1 1 scale(A)c grestore 0 setgray 1.5/Helvetica-Bold f 22 3.3 m(POSTAGE PAID GB)show 1.7/Helvetica f 22 1.5 m(Par Avion)show\n"); + ("16/Helvetica-Bold f 29 14.75 m 1.1 1 scale(A)c grestore 0 \ + setgray 1.5/Helvetica-Bold f 22 3.3 m(POSTAGE PAID GB)show \ + 1.7/Helvetica f 22 1.5 m(Par Avion)show\n"); break; case 'S': - printf ("10/Helvetica-Bold f 29 17 m(SU)c grestore 0 setgray 1.5/Helvetica-Bold f 22 1.5 m(POSTAGE PAID GB)show\n"); + printf ("10/Helvetica-Bold f 29 17 m(SU)c grestore 0 setgray \ + 1.5/Helvetica-Bold f 22 1.5 m(POSTAGE PAID GB)show\n"); break; } printf ("2.3/Helvetica-Bold f 29 10 m(LOYAL MAIL)c\n"); } else if (c == 'P') { // Standard Parcels printf ("21 0 m 41 0 rl 0 28 rl -41 0 rl cp fill\n" - "37.7 0.3 m 24 0 rl 0 27.4 rl -24 0 rl cp 1 setgray fill gsave 21.3 0.3 16.4 27.4 rectclip newpath\n" - "22.5/Helvetica-Bold f 37.75 -1.25 m 90 rotate(SP)show grestore 0 setgray\n" + "37.7 0.3 m 24 0 rl 0 27.4 rl -24 0 rl cp 1 setgray fill \ + gsave 21.3 0.3 16.4 27.4 rectclip newpath\n" + "22.5/Helvetica-Bold f 37.75 -1.25 m 90 rotate(SP)show \ + grestore 0 setgray\n" "3.5/Helvetica-Bold f 49.7 21.5 m(LOYAL MAIL)c\n" - "2.3/Helvetica-Bold f 49.7 7 m(POSTAGE PAID GB)c\n" "2.6/Helveica f 49.7 4.25 m(DumbStamp.co.uk)c\n"); + "2.3/Helvetica-Bold f 49.7 7 m(POSTAGE PAID GB)c\n" \ + "2.6/Helveica f 49.7 4.25 m(DumbStamp.co.uk)c\n"); } else if (c == '3') printf ("21.15 0.15 40.7 27.7 rectstroke\n" "21 0 m 41 0 rl 0 5 rl -41 0 rl cp fill\n" - "0 1 2{0 1 18{dup 1.525 mul 22.9 add 24 3 index 1.525 mul add 3 -1 roll 9 add 29 div 0 360 arc fill}for pop}for\n" + "0 1 2{0 1 18{dup 1.525 mul 22.9 add 24 3 index 1.525 mul \ + add 3 -1 roll 9 add 29 div 0 360 arc fill}for pop}for\n" "50.5 23.07 m 11.5 0 rl 0 5 rl -11.5 0 rl cp fill\n" "5.85/Helvetica f 23.7 15.6 m(Loyal Mail)show\n" - "4.75/Helvetica-Bold f 24 11 m(special)show 4.9/Helvetica f(delivery)show\n" - "gsave 1 setgray 3.2/Helvetica-Bold f 24 1.6 m(next day)show 26 10.15 m 2 0 rl stroke grestore\n" - "21.15 9.9 m 53.8 9.9 l stroke 53.8 9.9 0.4 0 360 arc fill\n"); + "4.75/Helvetica-Bold f 24 11 m(special)show 4.9/Helvetica \ + f(delivery)show\n" + "gsave 1 setgray 3.2/Helvetica-Bold f 24 1.6 \ + m(next day)show 26 10.15 m 2 0 rl stroke grestore\n" + "21.15 9.9 m 53.8 9.9 l stroke 53.8 9.9 0.4 0 360 \ + arc fill\n"); printf ("end grestore\n"); } break; diff --git a/iec16022ecc200.c b/iec16022ecc200.c index c5bc79e..da67a97 100644 --- a/iec16022ecc200.c +++ b/iec16022ecc200.c @@ -80,8 +80,7 @@ ecc200matrix[] = }; // simple checked response malloc -static void * -safemalloc (int n) +static void * safemalloc (int n) { void *p = malloc (n); if (!p) @@ -93,8 +92,8 @@ safemalloc (int n) } // 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) { @@ -109,8 +108,8 @@ ecc200placementbit (int *array, int NR, int NC, int r, int c, int p, char b) array[r * NC + c] = (p << 3) + b; } -static void -ecc200placementblock (int *array, int NR, int NC, int r, int c, int p) +static void ecc200placementblock (int *array, int NR, int NC, int r, \ + int c, int p) { ecc200placementbit (array, NR, NC, r - 2, c - 2, p, 7); ecc200placementbit (array, NR, NC, r - 2, c - 1, p, 6); @@ -122,8 +121,7 @@ ecc200placementblock (int *array, int NR, int NC, int r, int c, int p) 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, 1, p, 6); @@ -135,8 +133,7 @@ ecc200placementcornerA (int *array, int NR, int NC, int p) 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 - 2, 0, p, 6); @@ -148,8 +145,7 @@ ecc200placementcornerB (int *array, int NR, int NC, int p) 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 - 2, 0, p, 6); @@ -161,8 +157,7 @@ ecc200placementcornerC (int *array, int NR, int NC, int p) 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, NC - 1, p, 6); @@ -175,8 +170,7 @@ ecc200placementcornerD (int *array, int NR, int NC, int p) } // 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, @@ -230,8 +224,8 @@ ecc200placement (int *array, int NR, int NC) } // calculate and append ecc code, and if necessary interleave -static void -ecc200 (unsigned char *binary, int bytes, int datablock, int rsblock) +static void ecc200 (unsigned char *binary, int bytes, int datablock, \ + int rsblock) { int blocks = (bytes + 2) / datablock, b; @@ -252,10 +246,14 @@ ecc200 (unsigned char *binary, int bytes, int datablock, int rsblock) } } -// perform encoding for ecc200, source s len sl, to target t len tl, using optional encoding control string e -// return 1 if OK, 0 if failed. Does all necessary padding to tl -char -ecc200encode (unsigned char *t, int tl, unsigned char *s, int sl, char *encoding, int *lenp) +/* + * perform encoding for ecc200, source s len sl, to target t len tl, using + * optional encoding control string e return 1 if OK, 0 if failed. Does all + * necessary padding to tl + */ + +char ecc200encode (unsigned char *t, int tl, unsigned char *s, int sl, \ + char *encoding, int *lenp) { char enc = 'a'; // start in ASCII encoding mode int tp = 0, @@ -269,7 +267,8 @@ ecc200encode (unsigned char *t, int tl, unsigned char *s, int sl, char *encoding while (sp < sl && tp < tl) { char newenc = enc; // suggest new encoding - if (tl - tp <= 1 && (enc == 'c' || enc == 't') || tl - tp <= 2 && enc == 'x') + if (tl - tp <= 1 && (enc == 'c' || enc == 't') || tl - tp <= 2 && enc \ + == 'x') enc = 'a'; // auto revert to ASCII newenc = tolower (encoding[sp]); switch (newenc) @@ -340,7 +339,8 @@ ecc200encode (unsigned char *t, int tl, unsigned char *s, int sl, char *encoding out[p++] = (w - s3); } else { - fprintf (stderr, "Could not encode 0x%02X, should not happen\n", c); + fprintf (stderr, "Could not encode 0x%02X, should \ + not happen\n", c); return 0; } } @@ -475,7 +475,10 @@ ecc200encode (unsigned char *t, int tl, unsigned char *s, int sl, char *encoding } if (tp > tl || sp < sl) return 0; // did not fit - //for (tp = 0; tp < tl; tp++) fprintf (stderr, "%02X ", t[tp]); fprintf (stderr, "\n"); + /* + * for (tp = 0; tp < tl; tp++) fprintf (stderr, "%02X ", t[tp]); \ + * fprintf (stderr, "\n"); + */ return 1; // OK } @@ -502,25 +505,36 @@ unsigned char switchcost[E_MAX][E_MAX] = { 0, 1, 1, 1, 1, 0, // From E_BINARY }; -// Creates a encoding list (malloc) -// returns encoding string -// if lenp not null, target len stored -// if error, null returned -// if exact specified, then assumes shortcuts applicable for exact fit in target -// 1. No unlatch to return to ASCII for last encoded byte after C40 or Text or X12 -// 2. No unlatch to return to ASCII for last 1 or 2 encoded bytes after EDIFACT -// 3. Final C40 or text encoding exactly in last 2 bytes can have a shift 0 to pad to make a tripple -// Only use the encoding from an exact request if the len matches the target, otherwise free the result and try again with exact=0 -static char * -encmake (int l, unsigned char *s, int *lenp, char exact) +/* + * Creates a encoding list (malloc) + * returns encoding string + * if lenp not null, target len stored + * if error, null returned + * if exact specified, then assumes shortcuts applicable for exact fit + * in target + * 1. No unlatch to return to ASCII for last encoded byte after C40 or + * Text or X12 + * 2. No unlatch to return to ASCII for last 1 or 2 encoded bytes after + * EDIFACT + * 3. Final C40 or text encoding exactly in last 2 bytes can have a shift + * 0 to pad to make a tripple + * Only use the encoding from an exact request if the len matches the target, + * otherwise free the result and try again with exact=0 + */ + +static char * encmake (int l, unsigned char *s, int *lenp, char exact) { char *encoding = 0; int p = l; char e; struct { - short s; // number of bytes of source that can be encoded in a row at this point using this encoding mode - short t; // number of bytes of target generated encoding from this point to end if already in this encoding mode + // number of bytes of source that can be encoded in a row at this point + // using this encoding mode + short s; + // number of bytes of target generated encoding from this point to end if + // already in this encoding mode + short t; } enc[MAXBARCODE][E_MAX]; memset (&enc, 0, sizeof (enc)); if (!l) @@ -545,7 +559,8 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + switchcost[E_ASCII][e]) < bl || !bl)) + if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + \ + switchcost[E_ASCII][e]) < bl || !bl)) { bl = t; b = e; @@ -574,7 +589,9 @@ encmake (int l, unsigned char *s, int *lenp, char exact) } } while (sub && p + sl < l); if (exact && sub == 2 && p + sl == l) - { // special case, can encode last block with shift 0 at end (Is this valid when not end of target buffer?) + { + // special case, can encode last block with shift 0 at end (Is this + // valid when not end of target buffer?) sub = 0; tl += 2; } @@ -583,13 +600,15 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + switchcost[E_C40][e]) < bl || !bl)) + if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + \ + switchcost[E_C40][e]) < bl || !bl)) { bl = t; b = e; } if (exact && enc[p + sl][E_ASCII].t == 1 && 1 < bl) - { // special case, switch to ASCII for last bytes + { + // special case, switch to ASCII for last bytes bl = 1; b = E_ASCII; } @@ -618,7 +637,9 @@ encmake (int l, unsigned char *s, int *lenp, char exact) } } while (sub && p + sl < l); if (exact && sub == 2 && p + sl == l) - { // special case, can encode last block with shift 0 at end (Is this valid when not end of target buffer?) + { + // special case, can encode last block with shift 0 at end (Is this + // valid when not end of target buffer?) sub = 0; tl += 2; } @@ -627,7 +648,8 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + switchcost[E_TEXT][e]) < bl || !bl)) + if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + \ + switchcost[E_TEXT][e]) < bl || !bl)) { bl = t; b = e; @@ -647,7 +669,8 @@ encmake (int l, unsigned char *s, int *lenp, char exact) do { unsigned char c = s[p + sl++]; - if (c != 13 && c != '*' && c != '>' && c != ' ' && !isdigit (c) && !isupper (c)) + if (c != 13 && c != '*' && c != '>' && c != ' ' && !isdigit (c) && \ + !isupper (c)) { sl = 0; break; @@ -664,13 +687,15 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bl = 0; if (p + sl < l) for (e = 0; e < E_MAX; e++) - if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + switchcost[E_X12][e]) < bl || !bl)) + if (enc[p + sl][e].t && ((t = enc[p + sl][e].t + \ + switchcost[E_X12][e]) < bl || !bl)) { bl = t; b = e; } if (exact && enc[p + sl][E_ASCII].t == 1 && 1 < bl) - { // special case, switch to ASCII for last bytes + { + // special case, switch to ASCII for last bytes bl = 1; b = E_ASCII; } @@ -690,7 +715,9 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bs = 1; } else for (e = 0; e < E_MAX; e++) - if (e != E_EDIFACT && enc[p + 1][e].t && ((t = 2 + enc[p + 1][e].t + switchcost[E_ASCII][e]) < bl || !bl)) // E_ASCII as allowed for unlatch + if (e != E_EDIFACT && enc[p + 1][e].t && ((t = 2 + \ + enc[p + 1][e].t + switchcost[E_ASCII][e]) \ + < bl || !bl)) // E_ASCII as allowed for unlatch { bs = 1; bl = t; @@ -704,7 +731,9 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bs = 2; } else for (e = 0; e < E_MAX; e++) - if (e != E_EDIFACT && enc[p + 2][e].t && ((t = 3 + enc[p + 2][e].t + switchcost[E_ASCII][e]) < bl || !bl)) // E_ASCII as allowed for unlatch + if (e != E_EDIFACT && enc[p + 2][e].t && ((t = 3 + \ + enc[p + 2][e].t + switchcost[E_ASCII][e]) \ + < bl || !bl)) // E_ASCII as allowed for unlatch { bs = 2; bl = t; @@ -718,7 +747,9 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bs = 3; } else for (e = 0; e < E_MAX; e++) - if (e != E_EDIFACT && enc[p + 3][e].t && ((t = 3 + enc[p + 3][e].t + switchcost[E_ASCII][e]) < bl || !bl)) // E_ASCII as allowed for unlatch + if (e != E_EDIFACT && enc[p + 3][e].t && ((t = 3 + \ + enc[p + 3][e].t + switchcost[E_ASCII][e]) \ + < bl || !bl)) // E_ASCII as allowed for unlatch { bs = 3; bl = t; @@ -733,14 +764,18 @@ encmake (int l, unsigned char *s, int *lenp, char exact) } else { for (e = 0; e < E_MAX; e++) - if (enc[p + 4][e].t && ((t = 3 + enc[p + 4][e].t + switchcost[E_EDIFACT][e]) < bl || !bl)) + if (enc[p + 4][e].t && ((t = 3 + enc[p + 4][e].t + \ + switchcost[E_EDIFACT][e]) < bl || !bl)) { bs = 4; bl = t; b = e; } - if (exact && enc[p + 4][E_ASCII].t && enc[p + 4][E_ASCII].t <= 2 && (t = 3 + enc[p + 4][E_ASCII].t) < bl) - { // special case, switch to ASCII for last 1 ot two bytes + if (exact && enc[p + 4][E_ASCII].t && enc[p + \ + 4][E_ASCII].t <= 2 && (t = 3 + enc[p + \ + 4][E_ASCII].t) < bl) + { + // special case, switch to ASCII for last 1 ot two bytes bs = 4; bl = t; b = E_ASCII; @@ -758,7 +793,9 @@ encmake (int l, unsigned char *s, int *lenp, char exact) bl = 0; for (e = 0; e < E_MAX; e++) if (enc[p + 1][e].t - && ((t = enc[p + 1][e].t + switchcost[E_BINARY][e] + ((e == E_BINARY && enc[p + 1][e].t == 249) ? 1 : 0)) < bl || !bl)) + && ((t = enc[p + 1][e].t + switchcost[E_BINARY][e] + ((e == \ + E_BINARY && enc[p + 1][e].t == 249) ? 1 : 0)) \ + < bl || !bl)) { bl = t; b = e; @@ -767,7 +804,11 @@ encmake (int l, unsigned char *s, int *lenp, char exact) enc[p][E_BINARY].s = 1; if (bl && b == E_BINARY) enc[p][b].s += enc[p + 1][b].s; - //fprintf (stderr, "%d:", p); for (e = 0; e < E_MAX; e++) fprintf (stderr, " %c*%d/%d", encchr[e], enc[p][e].s, enc[p][e].t); fprintf (stderr, "\n"); + /* + * fprintf (stderr, "%d:", p); for (e = 0; e < E_MAX; e++) fprintf \ + * (stderr, " %c*%d/%d", encchr[e], enc[p][e].s, enc[p][e].t); \ + * fprintf (stderr, "\n"); + */ } encoding = safemalloc (l + 1); p = 0; @@ -779,7 +820,8 @@ encmake (int l, unsigned char *s, int *lenp, char exact) m = 0; char b = 0; for (e = 0; e < E_MAX; e++) - if (enc[p][e].t && ((t = enc[p][e].t + switchcost[cur][e]) < m || t == m && e == cur || !m)) + if (enc[p][e].t && ((t = enc[p][e].t + switchcost[cur][e]) < m || \ + t == m && e == cur || !m)) { b = e; m = t; @@ -795,18 +837,24 @@ encmake (int l, unsigned char *s, int *lenp, char exact) encoding[p] = 0; return encoding; } +/* + * Main encoding function + * Returns the grid (malloced) containing the matrix. L corner at 0,0. + * Takes suggested size in *Wptr, *Hptr, or 0,0. Fills in actual size. + * Takes barcodelen and barcode to be encoded + * Note, if *encodingptr is null, then fills with auto picked (malloced) + * encoding + * If lenp not null, then the length of encoded data before any final + * unlatch or pad is stored + * If maxp not null, then the max storage of this size code is stored + * If eccp not null, then the number of ecc bytes used in this size is + * stored + * Returns 0 on error (writes to stderr with details). + */ -// Main encoding function -// Returns the grid (malloced) containing the matrix. L corner at 0,0. -// Takes suggested size in *Wptr, *Hptr, or 0,0. Fills in actual size. -// Takes barcodelen and barcode to be encoded -// Note, if *encodingptr is null, then fills with auto picked (malloced) encoding -// If lenp not null, then the length of encoded data before any final unlatch or pad is stored -// If maxp not null, then the max storage of this size code is stored -// If eccp not null, then the number of ecc bytes used in this size is stored -// Returns 0 on error (writes to stderr with details). -unsigned char * -iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsigned char *barcode, int *lenp, int *maxp, int *eccp) +unsigned char * iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, \ + int barcodelen, unsigned char *barcode, \ + int *lenp, int *maxp, int *eccp) { unsigned char binary[3000]; // encoded raw data and ecc to place in barcode int W = 0, @@ -825,7 +873,8 @@ iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsign // encoding if (W) { // known size - for (matrix = ecc200matrix; matrix->W && (matrix->W != W || matrix->H != H); matrix++); + for (matrix = ecc200matrix; matrix->W && (matrix->W != W || \ + matrix->H != H); matrix++); if (!matrix->W) { fprintf (stderr, "Invalid size %dx%d\n", W, H); @@ -852,19 +901,22 @@ iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsign if (encoding) { // find one that fits chosen encoding for (matrix = ecc200matrix; matrix->W; matrix++) - if (ecc200encode (binary, matrix->bytes, barcode, barcodelen, encoding, 0)) + if (ecc200encode (binary, matrix->bytes, barcode, barcodelen, \ + encoding, 0)) break; } else { int len; char *e; e = encmake (barcodelen, barcode, &len, 1); - for (matrix = ecc200matrix; matrix->W && matrix->bytes != len; matrix++); + for (matrix = ecc200matrix; matrix->W && matrix->bytes != len; \ + matrix++); if (e && !matrix->W) { // try for non exact fit free (e); e = encmake (barcodelen, barcode, &len, 0); - for (matrix = ecc200matrix; matrix->W && matrix->bytes < len; matrix++); + for (matrix = ecc200matrix; matrix->W && matrix->bytes < len; \ + matrix++); } encoding = e; } @@ -876,7 +928,8 @@ iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsign W = matrix->W; H = matrix->H; } - if (!ecc200encode (binary, matrix->bytes, barcode, barcodelen, encoding, lenp)) + if (!ecc200encode (binary, matrix->bytes, barcode, barcodelen, \ + encoding, lenp)) { fprintf (stderr, "Barcode too long for %dx%d\n", W, H); return 0; @@ -916,7 +969,8 @@ iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, unsign int v = places[(NR - y - 1) * NC + x]; //fprintf (stderr, "%4d", v); if (v == 1 || v > 7 && (binary[(v >> 3) - 1] & (1 << (v & 7)))) - grid[(1 + y + 2 * (y / (matrix->FH - 2))) * W + 1 + x + 2 * (x / (matrix->FW - 2))] = 1; + grid[(1 + y + 2 * (y / (matrix->FH - 2))) * W + 1 + x + 2 * \ + (x / (matrix->FW - 2))] = 1; } //fprintf (stderr, "\n"); } diff --git a/iec16022ecc200.h b/iec16022ecc200.h index 265dd31..762b8ae 100644 --- a/iec16022ecc200.h +++ b/iec16022ecc200.h @@ -37,8 +37,12 @@ */ -unsigned char * -iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, int barcodelen, \ - unsigned char *barcode, int *lenp,int *maxp,int *eccp); +#ifndef __IEC16022ECC200_H +#define __IEC16022ECC200_H + +unsigned char * iec16022ecc200 (int *Wptr, int *Hptr, char **encodingptr, \ + int barcodelen, unsigned char *barcode, \ + int *lenp,int *maxp,int *eccp); #define MAXBARCODE 3116 +#endif /* __IEC16022ECC200_H */ diff --git a/image.c b/image.c index 46a828d..b420447 100644 --- a/image.c +++ b/image.c @@ -183,8 +183,7 @@ unsigned char const small[] = { 0x09, 0x04, 0x12, //% }; -Image * -ImageNew (int w, int h, int c) +Image * ImageNew (int w, int h, int c) { // create a new blank image Image *i; if (!w || !h) @@ -218,8 +217,7 @@ ImageNew (int w, int h, int c) return i; } -void -ImageFree (Image * i) +void ImageFree (Image * i) { // free an image if (i) { @@ -250,15 +248,13 @@ typedef struct strPrivate } Private; -static -LZWFlush (Private * p) +static LZWFlush (Private * p) { // flush this block write (p->fh, p->block, *p->block + 1); *p->block = 0; } -static -LZWOut (Private * p, short v) +static LZWOut (Private * p, short v) { // output a value p->blockv |= (v << p->blockb); p->blockb += p->lzwbits; @@ -272,8 +268,7 @@ LZWOut (Private * p, short v) } } -static -LZWClear (Private * p) +static LZWClear (Private * p) { int c; p->lzwbits = p->colbits + 1; @@ -283,12 +278,12 @@ LZWClear (Private * p) for (c = 0; c < p->cols; c++) { p->lzw[p->cols][c] = c; // links to literal entries - memset (&p->lzw[c], -1, p->cols * 2); // links from literals, dead ends initially + // links from literals, dead ends initially + memset (&p->lzw[c], -1, p->cols * 2); } } -static -ImageStart (Private * p) +static ImageStart (Private * p) { unsigned char b = p->colbits; write (p->fh, &b, 1); @@ -299,18 +294,16 @@ ImageStart (Private * p) LZWOut (p, p->cols); // clear code } -static -ImageEnd (Private * p) +static ImageEnd (Private * p) { LZWOut (p, p->lzwcode); // last prefix LZWOut (p, p->cols + 1); // end code if (p->blockb) - p->block[++*p->block] = p->blockv; // last partial byte + p->block[++*p->block] = p->blockv; // last partial byte LZWFlush (p); } -static -ImageOut (Private * p, unsigned char c) +static ImageOut (Private * p, unsigned char c) { short next = p->lzw[p->lzwcode][c]; if (next == -1) @@ -340,12 +333,12 @@ ImageOut (Private * p, unsigned char c) } // write GIF image -void -ImageWriteGif (Image * i, int fh, int back, int trans, char *comment) +void ImageWriteGif (Image * i, int fh, int back, int trans, char *comment) { struct strPrivate p; p.fh = fh; - for (p.colbits = 2, p.cols = 4; p.cols < i->C; p.cols *= 2, p.colbits++); // count colours, min 4 + // count colours, min 4 + for (p.colbits = 2, p.cols = 4; p.cols < i->C; p.cols *= 2, p.colbits++); { // headers char buf[1500]; int n = 0; @@ -448,8 +441,7 @@ ImageWriteGif (Image * i, int fh, int back, int trans, char *comment) write (fh, "\x3B", 1); // trailer } -void -ImageText (Image * i, int x, int y, int col, char *text) +void ImageText (Image * i, int x, int y, int col, char *text) { // writes 8x8 text if (i && text) while (*text) @@ -473,8 +465,7 @@ ImageText (Image * i, int x, int y, int col, char *text) } } -void -ImageSmall (Image * i, int x, int y, int col, char *text) +void ImageSmall (Image * i, int x, int y, int col, char *text) { // writes 4x6 digits if (i && text) while (*text) @@ -508,8 +499,7 @@ ImageSmall (Image * i, int x, int y, int col, char *text) } } -void -ImageRect (Image * i, int x, int y, int w, int h, int c) +void ImageRect (Image * i, int x, int y, int w, int h, int c) { // fill a box if (i && w && h) { @@ -530,8 +520,7 @@ ImageRect (Image * i, int x, int y, int w, int h, int c) static unsigned int crc_table[256]; /* Make the table for a fast CRC. */ -void -make_crc_table (void) +void make_crc_table (void) { unsigned int c; int n, @@ -555,8 +544,7 @@ make_crc_table (void) is the 1's complement of the final running CRC (see the crc() routine below)). */ -unsigned int -update_crc (unsigned int crc, unsigned char *buf, int len) +unsigned int update_crc (unsigned int crc, unsigned char *buf, int len) { unsigned int c = crc; int n; @@ -568,14 +556,12 @@ update_crc (unsigned int crc, unsigned char *buf, int len) } /* Return the CRC of the bytes buf[0..len-1]. */ -unsigned int -crc (unsigned char *buf, int len) +unsigned int crc (unsigned char *buf, int len) { return update_crc (0xffffffffL, buf, len) ^ 0xffffffffL; } -unsigned int -writecrc (int fh, char *ptr, int len, unsigned int c) +unsigned int writecrc (int fh, char *ptr, int len, unsigned int c) { write (fh, ptr, len); while (len--) @@ -583,8 +569,7 @@ writecrc (int fh, char *ptr, int len, unsigned int c) return c; } -void -writechunk (int fh, char *typ, void *ptr, int len) +void writechunk (int fh, char *typ, void *ptr, int len) { unsigned int v = htonl (len), crc; @@ -597,8 +582,7 @@ writechunk (int fh, char *typ, void *ptr, int len) } #ifndef USEZLIB -unsigned int -adlersum (unsigned char *p, int l, unsigned int adler) +unsigned int adlersum (unsigned char *p, int l, unsigned int adler) { unsigned int s1 = (adler & 65535), s2 = (adler >> 16); @@ -614,8 +598,7 @@ adlersum (unsigned char *p, int l, unsigned int adler) #endif // write PNG image -void -ImageWritePNG (Image * i, int fh, int back, int trans, char *comment) +void ImageWritePNG (Image * i, int fh, int back, int trans, char *comment) { make_crc_table (); write (fh, "\211PNG\r\n\032\n", 8); // PNG header @@ -672,9 +655,11 @@ ImageWritePNG (Image * i, int fh, int back, int trans, char *comment) unsigned char alpha[256]; int n; for (n = 0; n < i->C; n++) - alpha[n] = 255 - (i->Colour[n] >> 24); // 4th palette byte treated as 0=opaque, 255-transparrent + // 4th palette byte treated as 0=opaque, 255-transparren + alpha[n] = 255 - (i->Colour[n] >> 24); if (trans >= 0 && trans < i->C) - alpha[trans] = 0; // manual set of specific transparrent colour + // manual set of specific transparrent colour + alpha[trans] = 0; writechunk (fh, "tRNS", alpha, i->C); } #ifndef USEZLIB diff --git a/image.h b/image.h index b742bf4..6d56da3 100644 --- a/image.h +++ b/image.h @@ -18,6 +18,9 @@ * */ +#ifndef __IMAGE_H +#define __IMAGE_H + typedef unsigned int Colour; // RGB value // Image object @@ -44,3 +47,5 @@ void ImageText(Image *i,int x,int y,int c,char *text); // write 8x8 text void ImageSmall(Image *i,int x,int y,int c,char *text); // write 4x6 text void ImageRect(Image *i,int x,int y,int w,int h,int c); // fill a box #define ImageWrite ImageWritePNG // default + +#endif /* __IMAGE_H */ diff --git a/reedsol.c b/reedsol.c index fee1dc5..13f71bb 100644 --- a/reedsol.c +++ b/reedsol.c @@ -61,8 +61,7 @@ static int *log = NULL, // polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is // a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d. -void -rs_init_gf (int poly) +void rs_init_gf (int poly) { int m, b, @@ -107,8 +106,7 @@ rs_init_gf (int poly) // (x + 2**i)*(x + 2**(i+1))*... [nsym terms] // For ECC200, index is 1. -void -rs_init_code (int nsym, int index) +void rs_init_code (int nsym, int index) { int i, k; @@ -138,8 +136,7 @@ rs_init_code (int nsym, int index) // symbol sizes up to 8 bits. Just change the data type of data and res // to unsigned int * for larger symbols. -void -rs_encode (int len, unsigned char *data, unsigned char *res) +void rs_encode (int len, unsigned char *data, unsigned char *res) { int i, k, @@ -165,8 +162,7 @@ rs_encode (int len, unsigned char *data, unsigned char *res) #ifndef LIB // The following tests the routines with the ISO/IEC 16022 Annexe R data -int -main (void) +int main (void) { register int i; diff --git a/reedsol.h b/reedsol.h index 487b18f..d889efa 100644 --- a/reedsol.h +++ b/reedsol.h @@ -19,7 +19,11 @@ * */ +#ifndef __REEDSOL_H +#define __REEDSOL_H + void rs_init_gf(int poly); void rs_init_code(int nsym, int index); void rs_encode(int len, unsigned char *data, unsigned char *res); +#endif /* __REEDSOL_H */ diff --git a/test/testsuite-example.bin b/test/testsuite-example.bin new file mode 100644 index 0000000..02a4436 --- /dev/null +++ b/test/testsuite-example.bin @@ -0,0 +1 @@ +ÿÿÿÿ¿`ïÁ϶mÜ>ýÜÏÃðŠ¼N¯·«9š‚±¤Ë»¾ƒÐ@¨ÄÌEÙù£,Æ<°Ü-öb°:Çw×ɪªªªÿÿÿÿŸÀŽöÊÕï—¦‘¸%kûhŽÔ«-¨Û£0ËQ³kâÛ€Éôå£ÂÍ~„ögëTåགྷ絪ªªª \ No newline at end of file diff --git a/test/testsuite-example.eps b/test/testsuite-example.eps new file mode 100644 index 0000000..9f97c22 --- /dev/null +++ b/test/testsuite-example.eps @@ -0,0 +1,15 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Creator: IEC16022 barcode/stamp generator +%%BarcodeData: Aolash3l dee6Ieke OhBohm1C MengaR9m zaHaoQu2 huW3Uer8 ieg7chaJ haiKua1o +%%BarcodeSize: 32x32 +%%BarcodeFormat: ECC200 +%%DocumentData: Clean7Bit +%%LanguageLevel: 1 +%%Pages: 1 +%%BoundingBox: 0 0 34 34 +%%EndComments +%%Page: 1 1 +32 32 1[1 0 0 1 -1 -1]{< +00000000 409F10E5 3E304992 23C102F9 23E0303C 0F7543B1 504854C6 657D4E5B 3444417C 2FBF573B 33BA2606 5CD339C3 4FE823D2 099D4FC5 38882836 55555555 +00000000 603F7109 352A10F0 68596EFB 47DA7094 0497712B 54D257E4 24ED5CCF 34AE4C94 1DE524E1 7F360B1A 5C3D3281 7BE60998 14AB1A1F 427C184A 55555555 +>}image diff --git a/test/testsuite-example.hex b/test/testsuite-example.hex new file mode 100644 index 0000000..874101c --- /dev/null +++ b/test/testsuite-example.hex @@ -0,0 +1,2 @@ +FFFFFFFF BF60EF1A C1CFB66D DC3EFD06 DC1FCFC3 F08ABC4E AFB7AB39 9A82B1A4 CBBBBE83 D040A8C4 CC45D9F9 A32CC63C B017DC2D F662B03A C777D7C9 AAAAAAAA +FFFFFFFF 9FC08EF6 CAD5EF0F 97A69104 B8258F6B FB688ED4 AB2DA81B DB12A330 CB51B36B E21ADB1E 80C9F4E5 A3C2CD7E 8419F667 EB54E5E0 BD83E7B5 AAAAAAAA diff --git a/test/testsuite-example.png b/test/testsuite-example.png new file mode 100644 index 0000000000000000000000000000000000000000..050d1f0e3caa110df74ac9b8a34777f6fe794ca5 GIT binary patch literal 412 zcmeAS@N?(olHy`uVBq!ia0vp^N+8U^3=*07`vZ_-3-AeX{r~?zkQsXDavhLjO!9Vj zVd!9$^#F4GOI#yLobz*YQ}ap~9P@J$i!+RK6jD-C%{)`HQx*I(oboer4V@KyQ}faj zgDi6usuDdC^8-tb6f#P~jYCt5EEFBQ|bti1MFy8XRl zc=F+!Co_GHc{F}&|N8u)_?3MMSn;^w6Vo9ft(PI% zI)ZInFWhHn-xl(|#3Z`Y&tdAh$P_mDyn_rmTb&Fi&g`Cb`gGOG=?-D-VP+0u9LZff z1Lk(#Yx**&igWD(>A8l}vR3-<6q$VWb=vel+T4jZe7E)lOc!Etw)csfv)0|in5iv6 z;_!(lau=(5{Zph5-%-+CJITIzea@AatK-(aW)`t!a(r`X?sA|v89ZJ6T-G@yGywp2 CdY@GQ literal 0 HcmV?d00001 diff --git a/test/testsuite-example.text b/test/testsuite-example.text new file mode 100644 index 0000000..097a7d1 --- /dev/null +++ b/test/testsuite-example.text @@ -0,0 +1,32 @@ +* * * * * * * * * * * * * * * * +* **** ** ***** **** ** * * +*** * ** * * * *** * **** +* * ** ***** ** ** *** +* * **** * ** ** * ****** +* ** * ***** * *** * * +*** * ** * ** ** ** **** +** * ** * * ** ** ** ** * ** +** ** ** * * * * ** ** +* * * ** * ** ** * * ** ** +***** ** ** * * *** ** * * +* *** * * ** **** ** * ** +* * **** * ** * * * * +** * * ** * * **** **** **** +* ******* * *** **** ** +******************************** +* * * * * * * * * * * * * * * * +** *** *** ***** * ***** * * +**** ** ** * * ** *** * +* ** * ***** *** * ** * +* * ** * ** ** ** **** +** ** * * *** ** ****** * +** * * * * * ** * +** * *** *** *** ***** * ** +* ** * * * * ** ** * * +* * ***** ** **** * * ** *** * +**** * * * * **** * *** +** *** ******* ****** ** +** *** ***** ****** * ** +** *** ***** ** ** ** ** * +* ****** ** *** **** ** * +******************************** diff --git a/test/testsuite.sh b/test/testsuite.sh new file mode 100755 index 0000000..82a100a --- /dev/null +++ b/test/testsuite.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +FAILED=0 + +../iec16022 -o testsuite-test.text -f Text -c "Aolash3l dee6Ieke OhBohm1C MengaR9m zaHaoQu2 huW3Uer8 ieg7chaJ haiKua1o" +../iec16022 -o testsuite-test.eps -f EPS -c "Aolash3l dee6Ieke OhBohm1C MengaR9m zaHaoQu2 huW3Uer8 ieg7chaJ haiKua1o" +../iec16022 -o testsuite-test.png -f PNG -c "Aolash3l dee6Ieke OhBohm1C MengaR9m zaHaoQu2 huW3Uer8 ieg7chaJ haiKua1o" +../iec16022 -o testsuite-test.bin -f Bin -c "Aolash3l dee6Ieke OhBohm1C MengaR9m zaHaoQu2 huW3Uer8 ieg7chaJ haiKua1o" +../iec16022 -o testsuite-test.hex -f Hex -c "Aolash3l dee6Ieke OhBohm1C MengaR9m zaHaoQu2 huW3Uer8 ieg7chaJ haiKua1o" + +diff -b testsuite-test.text testsuite-example.text && echo "Text test passed" || echo "Text test FAILED" || FAILED=1 +diff -b testsuite-test.eps testsuite-example.eps && echo "EPS test passed" || echo "EPS test FAILED" || FAILED=1 +diff -b testsuite-test.png testsuite-example.png && echo "PNG test passed" || echo "PNG test FAILED" || FAILED=1 +diff -b testsuite-test.bin testsuite-example.bin && echo "Bin test passed" || echo "Bin test FAILED" || FAILED=1 +diff -b testsuite-test.hex testsuite-example.hex && echo "Hex test passed" || echo "Hex test FAILED" || FAILED=1 + +rm testsuite-test.* + +exit $FAILED -- 2.39.5