Skip to content

Commit

Permalink
* update distribution to include debian packaging
Browse files Browse the repository at this point in the history
  * add consistency checking to zebracam
  * add redundant output suppression to zebraimg
  * fix couple of Code 128 decode table bugs
  * fix reversed Code 128 decode
  * add outstanding scanner edge flush to new_scan()
    - API change: scanner reset/new_scan() now return scan/decode status
    - update zebracam and zebraimg to call this between each walker pass
      (interface still needs improvement...)
    => improves in scan results for many cases
  * fix dbg_scan filename generation so results go in local directory
  • Loading branch information
[email protected] committed May 17, 2007
1 parent 5e72973 commit 72503d4
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 50 deletions.
13 changes: 12 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
current:
version 0.2:
* update distribution to include debian packaging
* add consistency checking to zebracam
* add redundant output suppression to zebraimg
* fix couple of Code 128 decode table bugs
* fix reversed Code 128 decode
* add outstanding scanner edge flush to new_scan()
- API change: scanner reset/new_scan() now return scan/decode status
- update zebracam and zebraimg to call this between each walker pass
(interface still needs improvement...)
=> improves in scan results for many cases
* fix dbg_scan filename generation so results go in local directory
* continue Code 128 refinement
- finish character set C decode/expansion
- add per-character validation
Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ include $(srcdir)/zebracam/Makefile.am.inc
endif
include $(srcdir)/test/Makefile.am.inc
include $(srcdir)/doc/Makefile.am.inc

EXTRA_DIST += debian/changelog debian/compat debian/control debian/copyright \
debian/docs debian/libzebra0.install debian/libzebra-dev.install \
debian/rules debian/shlibs.local debian/zebra-tools.install
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Zebra Barcode Reader

version 0.2 (2007-05-16):
this release introduces significant enhancements, bug fixes and new
features! basic EAN-13/UPC-A reading has been improved and should
now be much more reliable. by popular request, new support has been
added for decoding Code 128. additionally, the build process was
improved and there is even basic documentation for the application
commands

version 0.1 (2007-03-24):
first official Zebra release!
supports basic scanning and decoding of EAN-13 and UPC-A symbols
Expand Down
5 changes: 3 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
* rpm packaging
* redundant output suppression for zebraimg
* frame consistency checks for zebracam
* handle Code 128 function characters (FNC1-4)
* decoder needs symbology/feature enable/disable
* better C++ interface to img_walker
* nice to match STL iterator interface
* space lead in/out from each scan line
* img_walker skip uselessly short scan lines
* img_walker pattern selection
* higher img_walker pattern density (cfg even better)
* support for other v4l image formats
* decode hook (program/script) to zebracam/(zebraimg?)
* finish UPC-E, EAN-8 and addon decoding
* add library version query interface
Expand Down
7 changes: 3 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.61])
AC_INIT([zebra], [0.1], [[email protected]])
AC_INIT([zebra], [0.2], [[email protected]])
AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign subdir-objects std-options dist-bzip2])
AC_CONFIG_HEADERS([include/config.h])
AC_CONFIG_SRCDIR(zebra/scanner.c)
Expand All @@ -16,14 +16,13 @@ AC_CONFIG_SRCDIR(zebra/scanner.c)
# then increment age.
# - If any interfaces have been removed since the last public release,
# then set age to 0.
AC_SUBST([LIB_VERSION], [1:0:1])
AC_SUBST([RELDATE], [2007-03-24])
AC_SUBST([LIB_VERSION], [2:0:2])
AC_SUBST([RELDATE], [2007-05-16])

AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_PROG_RANLIB

AC_ARG_VAR([XMLTO], [location of xmlto, used for optional \
documentation generation])
Expand Down
4 changes: 2 additions & 2 deletions include/zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ extern void zebra_scanner_destroy(zebra_scanner_t *scanner);
/* clear all scanner state.
* also resets an associated decoder
*/
extern void zebra_scanner_reset(zebra_scanner_t *scanner);
extern zebra_symbol_type_t zebra_scanner_reset(zebra_scanner_t *scanner);

/* mark start of a new scan pass, resets color to SPACE.
* also updates an associated decoder
*/
extern void zebra_scanner_new_scan(zebra_scanner_t *scanner);
extern zebra_symbol_type_t zebra_scanner_new_scan(zebra_scanner_t *scanner);

/* process next sample intensity value (y)
* intensity is in arbitrary relative units
Expand Down
13 changes: 9 additions & 4 deletions test/dbg_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <Magick++.h>
#include <iostream>
#include <fstream>
#include <libgen.h>
#include <zebra.h>

using namespace std;
Expand Down Expand Up @@ -60,7 +61,11 @@ void scan_image (const char *filename)

Image image;
image.read(filename);
ofstream svg((image.baseFilename() + ".svg").c_str());
string file = image.baseFilename();
unsigned baseidx = file.rfind('/');
if(baseidx != string::npos)
file = file.substr(baseidx + 1, file.length() - baseidx - 1);
ofstream svg((file + ".svg").c_str());

unsigned width = image.columns() + 4 /* for flush */;
unsigned height = image.rows();
Expand Down Expand Up @@ -97,7 +102,7 @@ void scan_image (const char *filename)
<< "]]></style></defs>" << endl
<< "<image width='" << width * 2 << "' height='384'"
<< " preserveAspectRatio='none'"
<< " xlink:href='" << image.baseFilename() << ".png'/>" << endl
<< " xlink:href='" << file << ".png'/>" << endl
<< "<g transform='translate(1,384) scale(2,-.5)'>" << endl;

// brute force
Expand Down Expand Up @@ -128,13 +133,13 @@ void scan_image (const char *filename)
<< "</g>" << endl;
}
image.depth(8);
image.write(image.baseFilename() + ".png");
image.write(file + ".png");

// process scan and capture calculated values
unsigned cur_edge[width], last_edge[width];
int y0[width], y1[width], y2[width], y1_thr[width];

svg << "<g transform='translate(-4)'>" << endl;
svg << "<g transform='translate(-3)'>" << endl;
for(unsigned i = 0; i < width; i++) {
int edge = scanner.scan_y(raw[i]);
unsigned x;
Expand Down
12 changes: 6 additions & 6 deletions zebra/code128.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static const char characters[NUM_CHARS] = {
0x5f, 0xe4, /* [0a] 03 */

0x6b, 0xe8, 0x69, 0xa7, 0xe7, /* [0c] 10 */
0xc1, 0x51, 0x1e, 0x83, 0xc9, 0x00, 0x84, 0x1f, /* [11] 11 */
0xc1, 0x51, 0x1e, 0x83, 0xd9, 0x00, 0x84, 0x1f, /* [11] 11 */
0xc7, 0x0d, 0x33, 0x86, 0xb5, 0x0e, 0x15, 0x87, /* [19] 12 */
0x10, 0xda, 0x11, /* [21] 13 */

Expand Down Expand Up @@ -171,7 +171,7 @@ static inline char decode_hi (int sig)
case 0x1134: idx = 0xa; break;
case 0x1242: idx = 0xb; break;
case 0x1243: idx = 0xc; break;
case 0x1441: idx = 0xd; break;
case 0x1441: idx = 0xd; rev = 0; break;
default: return(-1);
}
if(rev)
Expand Down Expand Up @@ -244,7 +244,7 @@ static inline char validate_checksum (zebra_decoder_t *dcode)
/* calculate sum in reverse to avoid multiply operations */
unsigned i, acc = 0;
for(i = dcode128->character - 3; i; i--) {
idx = (dcode128->direction) ? dcode128->character - i : i;
idx = (dcode128->direction) ? dcode128->character - 1 - i : i;
acc += dcode->buf[idx];
if(acc >= 103)
acc -= 103;
Expand Down Expand Up @@ -325,7 +325,7 @@ static inline char postprocess (zebra_decoder_t *dcode)
dcode->buf[i] = dcode->buf[j];
dcode->buf[j] = code;
}
assert(code == STOP_REV);
assert(dcode->buf[dcode128->character - 1] == STOP_REV);
}
else
assert(dcode->buf[dcode128->character - 1] == STOP_FWD);
Expand Down Expand Up @@ -407,6 +407,7 @@ zebra_symbol_type_t zebra_decode_code128 (zebra_decoder_t *dcode)
/* decode color based on direction */
(get_color(dcode) != dcode128->direction))
return(0);
dcode128->element = 0;

dprintf(2, " code128[%c%02d+%x]:",
(dcode128->direction) ? '<' : '>',
Expand All @@ -433,14 +434,13 @@ zebra_symbol_type_t zebra_decode_code128 (zebra_decoder_t *dcode)
dprintf(2, " dir=%x [valid start]", dcode128->direction);
}
else if((c < 0) ||
((dcode128->character > BUFFER_MIN) &&
((dcode128->character >= BUFFER_MIN) &&
size_buf(dcode, dcode128->character + 1))) {
dprintf(1, (c < 0) ? " [aborted]\n" : " [overflow]\n");
dcode->lock = 0;
code128_reset(dcode128);
return(0);
}
dcode128->element = 0;

assert(dcode->buflen > dcode128->character);
dcode->buf[dcode128->character++] = c;
Expand Down
2 changes: 1 addition & 1 deletion zebra/code128.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/* Code 128 specific decode state */
typedef struct code128_decoder_s {
int direction : 1; /* scan direction: 0=fwd/space, 1=rev/bar */
unsigned direction : 1; /* scan direction: 0=fwd/space, 1=rev/bar */
unsigned element : 3; /* element offset 0-5 */
int character : 12; /* character position in symbol */
char buf[6]; /* holding buffer */
Expand Down
29 changes: 17 additions & 12 deletions zebra/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,13 @@ void zebra_scanner_destroy (zebra_scanner_t *scn)
free(scn);
}

void zebra_scanner_reset (zebra_scanner_t *scn)
zebra_symbol_type_t zebra_scanner_reset (zebra_scanner_t *scn)
{
memset(&scn->x, 0, sizeof(zebra_scanner_t) + (void*)scn - (void*)&scn->x);
scn->y1_thresh = scn->y1_min_thresh;
if(scn->decoder)
zebra_decoder_reset(scn->decoder);
}

void zebra_scanner_new_scan (zebra_scanner_t *scn)
{
/* reset color to SPACE
* (actually just resets everything)
*/
memset(&scn->x, 0, sizeof(zebra_scanner_t) + (void*)scn - (void*)&scn->x);
scn->y1_thresh = scn->y1_min_thresh;
if(scn->decoder)
zebra_decoder_new_scan(scn->decoder);
return(ZEBRA_NONE);
}

unsigned zebra_scanner_get_width (const zebra_scanner_t *scn)
Expand Down Expand Up @@ -168,6 +158,21 @@ static inline zebra_symbol_type_t process_edge (zebra_scanner_t *scn,
return(ZEBRA_NONE);
}

zebra_symbol_type_t zebra_scanner_new_scan (zebra_scanner_t *scn)
{
/* finalize outstanding edge */
zebra_symbol_type_t edge = process_edge(scn, 0);

/* reset color to SPACE
* (actually just resets everything)
*/
memset(&scn->x, 0, sizeof(zebra_scanner_t) + (void*)scn - (void*)&scn->x);
scn->y1_thresh = scn->y1_min_thresh;
if(scn->decoder)
zebra_decoder_new_scan(scn->decoder);
return(edge);
}

zebra_symbol_type_t zebra_scan_y (zebra_scanner_t *scn,
int y)
{
Expand Down
47 changes: 35 additions & 12 deletions zebracam/zebracam.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@

#define DUMP_NAME_MAX 0x20
#define PPM_HDR_MAX 0x20
#define SYM_MAX 0x20
#define SYM_MAX 0x200
#define SYM_HYST 2000 /* ms */
#define UNCERTAINTY 20 /* frames */
#define CERTAINTY 3 /* frames */

static int cam_fd;
static struct video_capability vcap;
Expand All @@ -66,6 +68,8 @@ int tone_period = 20;
zebra_symbol_type_t last_sym_type;
char last_sym_data[SYM_MAX];
double last_sym_time = 0;
uint64_t last_sym_frame = 0;
uint32_t last_sym_count = 0;

double beep_time = 0;

Expand Down Expand Up @@ -281,6 +285,7 @@ static inline void process ()
{
zebra_scanner_new_scan(scanner);
zebra_img_walk(walker, buf);
zebra_scanner_new_scan(scanner); /* flush scan */
}

static void symbol_handler (zebra_decoder_t *decoder)
Expand All @@ -290,19 +295,33 @@ static void symbol_handler (zebra_decoder_t *decoder)
return;
const char *data = zebra_decoder_get_data(decoder);

double ms = SDL_GetTicks();
/* edge detect symbol change w/some hysteresis */
if(sym == last_sym_type &&
!strncmp(data, last_sym_data, SYM_MAX) &&
((ms - last_sym_time) < SYM_HYST)) {
last_sym_time = ms;
int match = (sym == last_sym_type &&
!strncmp(data, last_sym_data, SYM_MAX));
int uncertain = nframes > (last_sym_frame + UNCERTAINTY);

last_sym_frame = nframes;
last_sym_type = sym;

/* uncertainty filtering
* symbols are only reported after they have been
* observed consistently in several nearby frames
*/
if(!match || uncertain) {
strncpy(last_sym_data, data, SYM_MAX);
last_sym_count = 0;
return;
}
if(++last_sym_count < CERTAINTY)
return;

/* report new symbol */
/* edge detect symbol change w/some hysteresis */
double ms = SDL_GetTicks();
int edge = match && ((ms - last_sym_time) < SYM_HYST);
last_sym_time = ms;
last_sym_type = sym;
strncpy(last_sym_data, data, SYM_MAX);
if(edge)
return;

/* report new symbol */
printf("%s%s: %s\n",
zebra_get_symbol_name(sym),
zebra_get_addon_name(sym),
Expand All @@ -314,8 +333,12 @@ static void symbol_handler (zebra_decoder_t *decoder)
static char pixel_handler (zebra_img_walker_t *walker,
void *p)
{
if(zebra_scan_rgb24(scanner, p) > ZEBRA_PARTIAL)
return(1);
if(!zebra_img_walker_get_col(walker) ||
!zebra_img_walker_get_row(walker))
zebra_scanner_new_scan(scanner);

zebra_scan_rgb24(scanner, p);

*((uint8_t*)p - buf + (uint8_t*)screen->pixels + 2) = 0xff;
return(0);
}
Expand Down
Loading

0 comments on commit 72503d4

Please sign in to comment.