ZBar bar code reader . http://zbar.sourceforge.net/ ZBar is licensed under the GNU LGPL 2.1 to enable development of both open source and commercial projects.

Dependents:   GR-PEACH_Camera_in_barcode levkov_ov7670

LICENSE

The ZBar Bar Code Reader is Copyright (C) 2007-2009 Jeff Brown <spadix@users.sourceforge.net> The QR Code reader is Copyright (C) 1999-2009 Timothy B. Terriberry <tterribe@xiph.org>

You can redistribute this library and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

ISAAC is based on the public domain implementation by Robert J. Jenkins Jr., and is itself public domain.

Portions of the bit stream reader are copyright (C) The Xiph.Org Foundation 1994-2008, and are licensed under a BSD-style license.

The Reed-Solomon decoder is derived from an implementation (C) 1991-1995 Henry Minsky (hqm@ua.com, hqm@ai.mit.edu), and is licensed under the LGPL with permission.

Committer:
RyoheiHagimoto
Date:
Tue Apr 19 02:19:39 2016 +0000
Revision:
1:500d42699c34
Parent:
0:56c5742b9e2b
Add copying.txt and license.txt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:56c5742b9e2b 1 /*------------------------------------------------------------------------
RyoheiHagimoto 0:56c5742b9e2b 2 * Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net>
RyoheiHagimoto 0:56c5742b9e2b 3 *
RyoheiHagimoto 0:56c5742b9e2b 4 * This file is part of the ZBar Bar Code Reader.
RyoheiHagimoto 0:56c5742b9e2b 5 *
RyoheiHagimoto 0:56c5742b9e2b 6 * The ZBar Bar Code Reader is free software; you can redistribute it
RyoheiHagimoto 0:56c5742b9e2b 7 * and/or modify it under the terms of the GNU Lesser Public License as
RyoheiHagimoto 0:56c5742b9e2b 8 * published by the Free Software Foundation; either version 2.1 of
RyoheiHagimoto 0:56c5742b9e2b 9 * the License, or (at your option) any later version.
RyoheiHagimoto 0:56c5742b9e2b 10 *
RyoheiHagimoto 0:56c5742b9e2b 11 * The ZBar Bar Code Reader is distributed in the hope that it will be
RyoheiHagimoto 0:56c5742b9e2b 12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
RyoheiHagimoto 0:56c5742b9e2b 13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
RyoheiHagimoto 0:56c5742b9e2b 14 * GNU Lesser Public License for more details.
RyoheiHagimoto 0:56c5742b9e2b 15 *
RyoheiHagimoto 0:56c5742b9e2b 16 * You should have received a copy of the GNU Lesser Public License
RyoheiHagimoto 0:56c5742b9e2b 17 * along with the ZBar Bar Code Reader; if not, write to the Free
RyoheiHagimoto 0:56c5742b9e2b 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
RyoheiHagimoto 0:56c5742b9e2b 19 * Boston, MA 02110-1301 USA
RyoheiHagimoto 0:56c5742b9e2b 20 *
RyoheiHagimoto 0:56c5742b9e2b 21 * http://sourceforge.net/projects/zbar
RyoheiHagimoto 0:56c5742b9e2b 22 *------------------------------------------------------------------------*/
RyoheiHagimoto 0:56c5742b9e2b 23
RyoheiHagimoto 0:56c5742b9e2b 24 #include <config.h>
RyoheiHagimoto 0:56c5742b9e2b 25 #include <stdlib.h> /* malloc, calloc, free */
RyoheiHagimoto 0:56c5742b9e2b 26 #include <stdio.h> /* snprintf */
RyoheiHagimoto 0:56c5742b9e2b 27 #include <string.h> /* memset, strlen */
RyoheiHagimoto 0:56c5742b9e2b 28
RyoheiHagimoto 0:56c5742b9e2b 29 #include <zbar.h>
RyoheiHagimoto 0:56c5742b9e2b 30 #include "decoder.h"
RyoheiHagimoto 0:56c5742b9e2b 31
RyoheiHagimoto 0:56c5742b9e2b 32 #if defined(DEBUG_DECODER) || defined(DEBUG_EAN) || \
RyoheiHagimoto 0:56c5742b9e2b 33 defined(DEBUG_CODE39) || defined(DEBUG_I25) || \
RyoheiHagimoto 0:56c5742b9e2b 34 defined(DEBUG_CODE128) || defined(DEBUG_QR_FINDER) || \
RyoheiHagimoto 0:56c5742b9e2b 35 (defined(DEBUG_PDF417) && (DEBUG_PDF417 >= 4))
RyoheiHagimoto 0:56c5742b9e2b 36 # define DEBUG_LEVEL 1
RyoheiHagimoto 0:56c5742b9e2b 37 #endif
RyoheiHagimoto 0:56c5742b9e2b 38 #include "zbar_debug.h"
RyoheiHagimoto 0:56c5742b9e2b 39
RyoheiHagimoto 0:56c5742b9e2b 40 zbar_decoder_t *zbar_decoder_create ()
RyoheiHagimoto 0:56c5742b9e2b 41 {
RyoheiHagimoto 0:56c5742b9e2b 42 zbar_decoder_t *dcode = calloc(1, sizeof(zbar_decoder_t));
RyoheiHagimoto 0:56c5742b9e2b 43 dcode->buf_alloc = BUFFER_MIN;
RyoheiHagimoto 0:56c5742b9e2b 44 dcode->buf = malloc(dcode->buf_alloc);
RyoheiHagimoto 0:56c5742b9e2b 45
RyoheiHagimoto 0:56c5742b9e2b 46 /* initialize default configs */
RyoheiHagimoto 0:56c5742b9e2b 47 #ifdef ENABLE_EAN
RyoheiHagimoto 0:56c5742b9e2b 48 dcode->ean.enable = 1;
RyoheiHagimoto 0:56c5742b9e2b 49 dcode->ean.ean13_config = ((1 << ZBAR_CFG_ENABLE) |
RyoheiHagimoto 0:56c5742b9e2b 50 (1 << ZBAR_CFG_EMIT_CHECK));
RyoheiHagimoto 0:56c5742b9e2b 51 dcode->ean.ean8_config = ((1 << ZBAR_CFG_ENABLE) |
RyoheiHagimoto 0:56c5742b9e2b 52 (1 << ZBAR_CFG_EMIT_CHECK));
RyoheiHagimoto 0:56c5742b9e2b 53 dcode->ean.upca_config = 1 << ZBAR_CFG_EMIT_CHECK;
RyoheiHagimoto 0:56c5742b9e2b 54 dcode->ean.upce_config = 1 << ZBAR_CFG_EMIT_CHECK;
RyoheiHagimoto 0:56c5742b9e2b 55 dcode->ean.isbn10_config = 1 << ZBAR_CFG_EMIT_CHECK;
RyoheiHagimoto 0:56c5742b9e2b 56 dcode->ean.isbn13_config = 1 << ZBAR_CFG_EMIT_CHECK;
RyoheiHagimoto 0:56c5742b9e2b 57 #endif
RyoheiHagimoto 0:56c5742b9e2b 58 #ifdef ENABLE_I25
RyoheiHagimoto 0:56c5742b9e2b 59 dcode->i25.config = 1 << ZBAR_CFG_ENABLE;
RyoheiHagimoto 0:56c5742b9e2b 60 CFG(dcode->i25, ZBAR_CFG_MIN_LEN) = 6;
RyoheiHagimoto 0:56c5742b9e2b 61 #endif
RyoheiHagimoto 0:56c5742b9e2b 62 #ifdef ENABLE_CODE39
RyoheiHagimoto 0:56c5742b9e2b 63 dcode->code39.config = 1 << ZBAR_CFG_ENABLE;
RyoheiHagimoto 0:56c5742b9e2b 64 CFG(dcode->code39, ZBAR_CFG_MIN_LEN) = 1;
RyoheiHagimoto 0:56c5742b9e2b 65 #endif
RyoheiHagimoto 0:56c5742b9e2b 66 #ifdef ENABLE_CODE128
RyoheiHagimoto 0:56c5742b9e2b 67 dcode->code128.config = 1 << ZBAR_CFG_ENABLE;
RyoheiHagimoto 0:56c5742b9e2b 68 #endif
RyoheiHagimoto 0:56c5742b9e2b 69 #ifdef ENABLE_PDF417
RyoheiHagimoto 0:56c5742b9e2b 70 dcode->pdf417.config = 1 << ZBAR_CFG_ENABLE;
RyoheiHagimoto 0:56c5742b9e2b 71 #endif
RyoheiHagimoto 0:56c5742b9e2b 72 #ifdef ENABLE_QRCODE
RyoheiHagimoto 0:56c5742b9e2b 73 dcode->qrf.config = 1 << ZBAR_CFG_ENABLE;
RyoheiHagimoto 0:56c5742b9e2b 74 #endif
RyoheiHagimoto 0:56c5742b9e2b 75
RyoheiHagimoto 0:56c5742b9e2b 76 zbar_decoder_reset(dcode);
RyoheiHagimoto 0:56c5742b9e2b 77 return(dcode);
RyoheiHagimoto 0:56c5742b9e2b 78 }
RyoheiHagimoto 0:56c5742b9e2b 79
RyoheiHagimoto 0:56c5742b9e2b 80 void zbar_decoder_destroy (zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 81 {
RyoheiHagimoto 0:56c5742b9e2b 82 if(dcode->buf)
RyoheiHagimoto 0:56c5742b9e2b 83 free(dcode->buf);
RyoheiHagimoto 0:56c5742b9e2b 84 free(dcode);
RyoheiHagimoto 0:56c5742b9e2b 85 }
RyoheiHagimoto 0:56c5742b9e2b 86
RyoheiHagimoto 0:56c5742b9e2b 87 void zbar_decoder_reset (zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 88 {
RyoheiHagimoto 0:56c5742b9e2b 89 memset(dcode, 0, (long)&dcode->buf_alloc - (long)dcode);
RyoheiHagimoto 0:56c5742b9e2b 90 #ifdef ENABLE_EAN
RyoheiHagimoto 0:56c5742b9e2b 91 ean_reset(&dcode->ean);
RyoheiHagimoto 0:56c5742b9e2b 92 #endif
RyoheiHagimoto 0:56c5742b9e2b 93 #ifdef ENABLE_I25
RyoheiHagimoto 0:56c5742b9e2b 94 i25_reset(&dcode->i25);
RyoheiHagimoto 0:56c5742b9e2b 95 #endif
RyoheiHagimoto 0:56c5742b9e2b 96 #ifdef ENABLE_CODE39
RyoheiHagimoto 0:56c5742b9e2b 97 code39_reset(&dcode->code39);
RyoheiHagimoto 0:56c5742b9e2b 98 #endif
RyoheiHagimoto 0:56c5742b9e2b 99 #ifdef ENABLE_CODE128
RyoheiHagimoto 0:56c5742b9e2b 100 code128_reset(&dcode->code128);
RyoheiHagimoto 0:56c5742b9e2b 101 #endif
RyoheiHagimoto 0:56c5742b9e2b 102 #ifdef ENABLE_PDF417
RyoheiHagimoto 0:56c5742b9e2b 103 pdf417_reset(&dcode->pdf417);
RyoheiHagimoto 0:56c5742b9e2b 104 #endif
RyoheiHagimoto 0:56c5742b9e2b 105 #ifdef ENABLE_QRCODE
RyoheiHagimoto 0:56c5742b9e2b 106 qr_finder_reset(&dcode->qrf);
RyoheiHagimoto 0:56c5742b9e2b 107 #endif
RyoheiHagimoto 0:56c5742b9e2b 108 }
RyoheiHagimoto 0:56c5742b9e2b 109
RyoheiHagimoto 0:56c5742b9e2b 110 void zbar_decoder_new_scan (zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 111 {
RyoheiHagimoto 0:56c5742b9e2b 112 /* soft reset decoder */
RyoheiHagimoto 0:56c5742b9e2b 113 memset(dcode->w, 0, sizeof(dcode->w));
RyoheiHagimoto 0:56c5742b9e2b 114 dcode->lock = 0;
RyoheiHagimoto 0:56c5742b9e2b 115 dcode->idx = 0;
RyoheiHagimoto 0:56c5742b9e2b 116 #ifdef ENABLE_EAN
RyoheiHagimoto 0:56c5742b9e2b 117 ean_new_scan(&dcode->ean);
RyoheiHagimoto 0:56c5742b9e2b 118 #endif
RyoheiHagimoto 0:56c5742b9e2b 119 #ifdef ENABLE_I25
RyoheiHagimoto 0:56c5742b9e2b 120 i25_reset(&dcode->i25);
RyoheiHagimoto 0:56c5742b9e2b 121 #endif
RyoheiHagimoto 0:56c5742b9e2b 122 #ifdef ENABLE_CODE39
RyoheiHagimoto 0:56c5742b9e2b 123 code39_reset(&dcode->code39);
RyoheiHagimoto 0:56c5742b9e2b 124 #endif
RyoheiHagimoto 0:56c5742b9e2b 125 #ifdef ENABLE_CODE128
RyoheiHagimoto 0:56c5742b9e2b 126 code128_reset(&dcode->code128);
RyoheiHagimoto 0:56c5742b9e2b 127 #endif
RyoheiHagimoto 0:56c5742b9e2b 128 #ifdef ENABLE_PDF417
RyoheiHagimoto 0:56c5742b9e2b 129 pdf417_reset(&dcode->pdf417);
RyoheiHagimoto 0:56c5742b9e2b 130 #endif
RyoheiHagimoto 0:56c5742b9e2b 131 #ifdef ENABLE_QRCODE
RyoheiHagimoto 0:56c5742b9e2b 132 qr_finder_reset(&dcode->qrf);
RyoheiHagimoto 0:56c5742b9e2b 133 #endif
RyoheiHagimoto 0:56c5742b9e2b 134 }
RyoheiHagimoto 0:56c5742b9e2b 135
RyoheiHagimoto 0:56c5742b9e2b 136
RyoheiHagimoto 0:56c5742b9e2b 137 zbar_color_t zbar_decoder_get_color (const zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 138 {
RyoheiHagimoto 0:56c5742b9e2b 139 return(get_color(dcode));
RyoheiHagimoto 0:56c5742b9e2b 140 }
RyoheiHagimoto 0:56c5742b9e2b 141
RyoheiHagimoto 0:56c5742b9e2b 142 const char *zbar_decoder_get_data (const zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 143 {
RyoheiHagimoto 0:56c5742b9e2b 144 return((char*)dcode->buf);
RyoheiHagimoto 0:56c5742b9e2b 145 }
RyoheiHagimoto 0:56c5742b9e2b 146
RyoheiHagimoto 0:56c5742b9e2b 147 unsigned int zbar_decoder_get_data_length (const zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 148 {
RyoheiHagimoto 0:56c5742b9e2b 149 return(dcode->buflen);
RyoheiHagimoto 0:56c5742b9e2b 150 }
RyoheiHagimoto 0:56c5742b9e2b 151
RyoheiHagimoto 0:56c5742b9e2b 152 zbar_decoder_handler_t *
RyoheiHagimoto 0:56c5742b9e2b 153 zbar_decoder_set_handler (zbar_decoder_t *dcode,
RyoheiHagimoto 0:56c5742b9e2b 154 zbar_decoder_handler_t handler)
RyoheiHagimoto 0:56c5742b9e2b 155 {
RyoheiHagimoto 0:56c5742b9e2b 156 zbar_decoder_handler_t *result = dcode->handler;
RyoheiHagimoto 0:56c5742b9e2b 157 dcode->handler = handler;
RyoheiHagimoto 0:56c5742b9e2b 158 return(result);
RyoheiHagimoto 0:56c5742b9e2b 159 }
RyoheiHagimoto 0:56c5742b9e2b 160
RyoheiHagimoto 0:56c5742b9e2b 161 void zbar_decoder_set_userdata (zbar_decoder_t *dcode,
RyoheiHagimoto 0:56c5742b9e2b 162 void *userdata)
RyoheiHagimoto 0:56c5742b9e2b 163 {
RyoheiHagimoto 0:56c5742b9e2b 164 dcode->userdata = userdata;
RyoheiHagimoto 0:56c5742b9e2b 165 }
RyoheiHagimoto 0:56c5742b9e2b 166
RyoheiHagimoto 0:56c5742b9e2b 167 void *zbar_decoder_get_userdata (const zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 168 {
RyoheiHagimoto 0:56c5742b9e2b 169 return(dcode->userdata);
RyoheiHagimoto 0:56c5742b9e2b 170 }
RyoheiHagimoto 0:56c5742b9e2b 171
RyoheiHagimoto 0:56c5742b9e2b 172 zbar_symbol_type_t zbar_decoder_get_type (const zbar_decoder_t *dcode)
RyoheiHagimoto 0:56c5742b9e2b 173 {
RyoheiHagimoto 0:56c5742b9e2b 174 return(dcode->type);
RyoheiHagimoto 0:56c5742b9e2b 175 }
RyoheiHagimoto 0:56c5742b9e2b 176
RyoheiHagimoto 0:56c5742b9e2b 177 zbar_symbol_type_t zbar_decode_width (zbar_decoder_t *dcode,
RyoheiHagimoto 0:56c5742b9e2b 178 unsigned w)
RyoheiHagimoto 0:56c5742b9e2b 179 {
RyoheiHagimoto 0:56c5742b9e2b 180 dcode->w[dcode->idx & (DECODE_WINDOW - 1)] = w;
RyoheiHagimoto 0:56c5742b9e2b 181 dprintf(1, " decode[%x]: w=%d (%g)\n", dcode->idx, w, (w / 32.));
RyoheiHagimoto 0:56c5742b9e2b 182
RyoheiHagimoto 0:56c5742b9e2b 183 /* each decoder processes width stream in parallel */
RyoheiHagimoto 0:56c5742b9e2b 184 zbar_symbol_type_t sym = dcode->type = ZBAR_NONE;
RyoheiHagimoto 0:56c5742b9e2b 185
RyoheiHagimoto 0:56c5742b9e2b 186 #ifdef ENABLE_EAN
RyoheiHagimoto 0:56c5742b9e2b 187 if((dcode->ean.enable) &&
RyoheiHagimoto 0:56c5742b9e2b 188 (sym = _zbar_decode_ean(dcode)))
RyoheiHagimoto 0:56c5742b9e2b 189 dcode->type = sym;
RyoheiHagimoto 0:56c5742b9e2b 190 #endif
RyoheiHagimoto 0:56c5742b9e2b 191 #ifdef ENABLE_CODE39
RyoheiHagimoto 0:56c5742b9e2b 192 if(TEST_CFG(dcode->code39.config, ZBAR_CFG_ENABLE) &&
RyoheiHagimoto 0:56c5742b9e2b 193 (sym = _zbar_decode_code39(dcode)) > ZBAR_PARTIAL)
RyoheiHagimoto 0:56c5742b9e2b 194 dcode->type = sym;
RyoheiHagimoto 0:56c5742b9e2b 195 #endif
RyoheiHagimoto 0:56c5742b9e2b 196 #ifdef ENABLE_CODE128
RyoheiHagimoto 0:56c5742b9e2b 197 if(TEST_CFG(dcode->code128.config, ZBAR_CFG_ENABLE) &&
RyoheiHagimoto 0:56c5742b9e2b 198 (sym = _zbar_decode_code128(dcode)) > ZBAR_PARTIAL)
RyoheiHagimoto 0:56c5742b9e2b 199 dcode->type = sym;
RyoheiHagimoto 0:56c5742b9e2b 200 #endif
RyoheiHagimoto 0:56c5742b9e2b 201 #ifdef ENABLE_I25
RyoheiHagimoto 0:56c5742b9e2b 202 if(TEST_CFG(dcode->i25.config, ZBAR_CFG_ENABLE) &&
RyoheiHagimoto 0:56c5742b9e2b 203 (sym = _zbar_decode_i25(dcode)) > ZBAR_PARTIAL)
RyoheiHagimoto 0:56c5742b9e2b 204 dcode->type = sym;
RyoheiHagimoto 0:56c5742b9e2b 205 #endif
RyoheiHagimoto 0:56c5742b9e2b 206 #ifdef ENABLE_PDF417
RyoheiHagimoto 0:56c5742b9e2b 207 if(TEST_CFG(dcode->pdf417.config, ZBAR_CFG_ENABLE) &&
RyoheiHagimoto 0:56c5742b9e2b 208 (sym = _zbar_decode_pdf417(dcode)) > ZBAR_PARTIAL)
RyoheiHagimoto 0:56c5742b9e2b 209 dcode->type = sym;
RyoheiHagimoto 0:56c5742b9e2b 210 #endif
RyoheiHagimoto 0:56c5742b9e2b 211 #ifdef ENABLE_QRCODE
RyoheiHagimoto 0:56c5742b9e2b 212 if(TEST_CFG(dcode->qrf.config, ZBAR_CFG_ENABLE) &&
RyoheiHagimoto 0:56c5742b9e2b 213 (sym = _zbar_find_qr(dcode)) > ZBAR_PARTIAL)
RyoheiHagimoto 0:56c5742b9e2b 214 dcode->type = sym;
RyoheiHagimoto 0:56c5742b9e2b 215 #endif
RyoheiHagimoto 0:56c5742b9e2b 216
RyoheiHagimoto 0:56c5742b9e2b 217 dcode->idx++;
RyoheiHagimoto 0:56c5742b9e2b 218 if(dcode->type) {
RyoheiHagimoto 0:56c5742b9e2b 219 if(dcode->handler)
RyoheiHagimoto 0:56c5742b9e2b 220 dcode->handler(dcode);
RyoheiHagimoto 0:56c5742b9e2b 221 if(dcode->lock && dcode->type > ZBAR_PARTIAL)
RyoheiHagimoto 0:56c5742b9e2b 222 dcode->lock = 0;
RyoheiHagimoto 0:56c5742b9e2b 223 }
RyoheiHagimoto 0:56c5742b9e2b 224 return(dcode->type);
RyoheiHagimoto 0:56c5742b9e2b 225 }
RyoheiHagimoto 0:56c5742b9e2b 226
RyoheiHagimoto 0:56c5742b9e2b 227 static inline int decoder_set_config_bool (zbar_decoder_t *dcode,
RyoheiHagimoto 0:56c5742b9e2b 228 zbar_symbol_type_t sym,
RyoheiHagimoto 0:56c5742b9e2b 229 zbar_config_t cfg,
RyoheiHagimoto 0:56c5742b9e2b 230 int val)
RyoheiHagimoto 0:56c5742b9e2b 231 {
RyoheiHagimoto 0:56c5742b9e2b 232 unsigned *config = NULL;
RyoheiHagimoto 0:56c5742b9e2b 233 switch(sym) {
RyoheiHagimoto 0:56c5742b9e2b 234 #ifdef ENABLE_EAN
RyoheiHagimoto 0:56c5742b9e2b 235 case ZBAR_EAN13:
RyoheiHagimoto 0:56c5742b9e2b 236 config = &dcode->ean.ean13_config;
RyoheiHagimoto 0:56c5742b9e2b 237 break;
RyoheiHagimoto 0:56c5742b9e2b 238
RyoheiHagimoto 0:56c5742b9e2b 239 case ZBAR_EAN8:
RyoheiHagimoto 0:56c5742b9e2b 240 config = &dcode->ean.ean8_config;
RyoheiHagimoto 0:56c5742b9e2b 241 break;
RyoheiHagimoto 0:56c5742b9e2b 242
RyoheiHagimoto 0:56c5742b9e2b 243 case ZBAR_UPCA:
RyoheiHagimoto 0:56c5742b9e2b 244 config = &dcode->ean.upca_config;
RyoheiHagimoto 0:56c5742b9e2b 245 break;
RyoheiHagimoto 0:56c5742b9e2b 246
RyoheiHagimoto 0:56c5742b9e2b 247 case ZBAR_UPCE:
RyoheiHagimoto 0:56c5742b9e2b 248 config = &dcode->ean.upce_config;
RyoheiHagimoto 0:56c5742b9e2b 249 break;
RyoheiHagimoto 0:56c5742b9e2b 250
RyoheiHagimoto 0:56c5742b9e2b 251 case ZBAR_ISBN10:
RyoheiHagimoto 0:56c5742b9e2b 252 config = &dcode->ean.isbn10_config;
RyoheiHagimoto 0:56c5742b9e2b 253 break;
RyoheiHagimoto 0:56c5742b9e2b 254
RyoheiHagimoto 0:56c5742b9e2b 255 case ZBAR_ISBN13:
RyoheiHagimoto 0:56c5742b9e2b 256 config = &dcode->ean.isbn13_config;
RyoheiHagimoto 0:56c5742b9e2b 257 break;
RyoheiHagimoto 0:56c5742b9e2b 258 #endif
RyoheiHagimoto 0:56c5742b9e2b 259
RyoheiHagimoto 0:56c5742b9e2b 260 #ifdef ENABLE_I25
RyoheiHagimoto 0:56c5742b9e2b 261 case ZBAR_I25:
RyoheiHagimoto 0:56c5742b9e2b 262 config = &dcode->i25.config;
RyoheiHagimoto 0:56c5742b9e2b 263 break;
RyoheiHagimoto 0:56c5742b9e2b 264 #endif
RyoheiHagimoto 0:56c5742b9e2b 265
RyoheiHagimoto 0:56c5742b9e2b 266 #ifdef ENABLE_CODE39
RyoheiHagimoto 0:56c5742b9e2b 267 case ZBAR_CODE39:
RyoheiHagimoto 0:56c5742b9e2b 268 config = &dcode->code39.config;
RyoheiHagimoto 0:56c5742b9e2b 269 break;
RyoheiHagimoto 0:56c5742b9e2b 270 #endif
RyoheiHagimoto 0:56c5742b9e2b 271
RyoheiHagimoto 0:56c5742b9e2b 272 #ifdef ENABLE_CODE128
RyoheiHagimoto 0:56c5742b9e2b 273 case ZBAR_CODE128:
RyoheiHagimoto 0:56c5742b9e2b 274 config = &dcode->code128.config;
RyoheiHagimoto 0:56c5742b9e2b 275 break;
RyoheiHagimoto 0:56c5742b9e2b 276 #endif
RyoheiHagimoto 0:56c5742b9e2b 277
RyoheiHagimoto 0:56c5742b9e2b 278 #ifdef ENABLE_PDF417
RyoheiHagimoto 0:56c5742b9e2b 279 case ZBAR_PDF417:
RyoheiHagimoto 0:56c5742b9e2b 280 config = &dcode->pdf417.config;
RyoheiHagimoto 0:56c5742b9e2b 281 break;
RyoheiHagimoto 0:56c5742b9e2b 282 #endif
RyoheiHagimoto 0:56c5742b9e2b 283
RyoheiHagimoto 0:56c5742b9e2b 284 #ifdef ENABLE_QRCODE
RyoheiHagimoto 0:56c5742b9e2b 285 case ZBAR_QRCODE:
RyoheiHagimoto 0:56c5742b9e2b 286 config = &dcode->qrf.config;
RyoheiHagimoto 0:56c5742b9e2b 287 break;
RyoheiHagimoto 0:56c5742b9e2b 288 #endif
RyoheiHagimoto 0:56c5742b9e2b 289
RyoheiHagimoto 0:56c5742b9e2b 290 /* FIXME handle addons */
RyoheiHagimoto 0:56c5742b9e2b 291
RyoheiHagimoto 0:56c5742b9e2b 292 default:
RyoheiHagimoto 0:56c5742b9e2b 293 return(1);
RyoheiHagimoto 0:56c5742b9e2b 294 }
RyoheiHagimoto 0:56c5742b9e2b 295 if(!config || cfg >= ZBAR_CFG_NUM)
RyoheiHagimoto 0:56c5742b9e2b 296 return(1);
RyoheiHagimoto 0:56c5742b9e2b 297
RyoheiHagimoto 0:56c5742b9e2b 298 if(!val)
RyoheiHagimoto 0:56c5742b9e2b 299 *config &= ~(1 << cfg);
RyoheiHagimoto 0:56c5742b9e2b 300 else if(val == 1)
RyoheiHagimoto 0:56c5742b9e2b 301 *config |= (1 << cfg);
RyoheiHagimoto 0:56c5742b9e2b 302 else
RyoheiHagimoto 0:56c5742b9e2b 303 return(1);
RyoheiHagimoto 0:56c5742b9e2b 304
RyoheiHagimoto 0:56c5742b9e2b 305 #ifdef ENABLE_EAN
RyoheiHagimoto 0:56c5742b9e2b 306 dcode->ean.enable = TEST_CFG(dcode->ean.ean13_config |
RyoheiHagimoto 0:56c5742b9e2b 307 dcode->ean.ean8_config |
RyoheiHagimoto 0:56c5742b9e2b 308 dcode->ean.upca_config |
RyoheiHagimoto 0:56c5742b9e2b 309 dcode->ean.upce_config |
RyoheiHagimoto 0:56c5742b9e2b 310 dcode->ean.isbn10_config |
RyoheiHagimoto 0:56c5742b9e2b 311 dcode->ean.isbn13_config,
RyoheiHagimoto 0:56c5742b9e2b 312 ZBAR_CFG_ENABLE);
RyoheiHagimoto 0:56c5742b9e2b 313 #endif
RyoheiHagimoto 0:56c5742b9e2b 314
RyoheiHagimoto 0:56c5742b9e2b 315 return(0);
RyoheiHagimoto 0:56c5742b9e2b 316 }
RyoheiHagimoto 0:56c5742b9e2b 317
RyoheiHagimoto 0:56c5742b9e2b 318 static inline int decoder_set_config_int (zbar_decoder_t *dcode,
RyoheiHagimoto 0:56c5742b9e2b 319 zbar_symbol_type_t sym,
RyoheiHagimoto 0:56c5742b9e2b 320 zbar_config_t cfg,
RyoheiHagimoto 0:56c5742b9e2b 321 int val)
RyoheiHagimoto 0:56c5742b9e2b 322 {
RyoheiHagimoto 0:56c5742b9e2b 323 switch(sym) {
RyoheiHagimoto 0:56c5742b9e2b 324
RyoheiHagimoto 0:56c5742b9e2b 325 #ifdef ENABLE_I25
RyoheiHagimoto 0:56c5742b9e2b 326 case ZBAR_I25:
RyoheiHagimoto 0:56c5742b9e2b 327 CFG(dcode->i25, cfg) = val;
RyoheiHagimoto 0:56c5742b9e2b 328 break;
RyoheiHagimoto 0:56c5742b9e2b 329 #endif
RyoheiHagimoto 0:56c5742b9e2b 330 #ifdef ENABLE_CODE39
RyoheiHagimoto 0:56c5742b9e2b 331 case ZBAR_CODE39:
RyoheiHagimoto 0:56c5742b9e2b 332 CFG(dcode->code39, cfg) = val;
RyoheiHagimoto 0:56c5742b9e2b 333 break;
RyoheiHagimoto 0:56c5742b9e2b 334 #endif
RyoheiHagimoto 0:56c5742b9e2b 335 #ifdef ENABLE_CODE128
RyoheiHagimoto 0:56c5742b9e2b 336 case ZBAR_CODE128:
RyoheiHagimoto 0:56c5742b9e2b 337 CFG(dcode->code128, cfg) = val;
RyoheiHagimoto 0:56c5742b9e2b 338 break;
RyoheiHagimoto 0:56c5742b9e2b 339 #endif
RyoheiHagimoto 0:56c5742b9e2b 340 #ifdef ENABLE_PDF417
RyoheiHagimoto 0:56c5742b9e2b 341 case ZBAR_PDF417:
RyoheiHagimoto 0:56c5742b9e2b 342 CFG(dcode->pdf417, cfg) = val;
RyoheiHagimoto 0:56c5742b9e2b 343 break;
RyoheiHagimoto 0:56c5742b9e2b 344 #endif
RyoheiHagimoto 0:56c5742b9e2b 345
RyoheiHagimoto 0:56c5742b9e2b 346 default:
RyoheiHagimoto 0:56c5742b9e2b 347 return(1);
RyoheiHagimoto 0:56c5742b9e2b 348 }
RyoheiHagimoto 0:56c5742b9e2b 349 return(0);
RyoheiHagimoto 0:56c5742b9e2b 350 }
RyoheiHagimoto 0:56c5742b9e2b 351
RyoheiHagimoto 0:56c5742b9e2b 352 int zbar_decoder_set_config (zbar_decoder_t *dcode,
RyoheiHagimoto 0:56c5742b9e2b 353 zbar_symbol_type_t sym,
RyoheiHagimoto 0:56c5742b9e2b 354 zbar_config_t cfg,
RyoheiHagimoto 0:56c5742b9e2b 355 int val)
RyoheiHagimoto 0:56c5742b9e2b 356 {
RyoheiHagimoto 0:56c5742b9e2b 357 if(sym == ZBAR_NONE) {
RyoheiHagimoto 0:56c5742b9e2b 358 zbar_decoder_set_config(dcode, ZBAR_EAN13, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 359 zbar_decoder_set_config(dcode, ZBAR_EAN8, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 360 zbar_decoder_set_config(dcode, ZBAR_UPCA, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 361 zbar_decoder_set_config(dcode, ZBAR_UPCE, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 362 zbar_decoder_set_config(dcode, ZBAR_ISBN10, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 363 zbar_decoder_set_config(dcode, ZBAR_ISBN13, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 364 zbar_decoder_set_config(dcode, ZBAR_I25, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 365 zbar_decoder_set_config(dcode, ZBAR_CODE39, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 366 zbar_decoder_set_config(dcode, ZBAR_CODE128, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 367 zbar_decoder_set_config(dcode, ZBAR_PDF417, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 368 zbar_decoder_set_config(dcode, ZBAR_QRCODE, cfg, val);
RyoheiHagimoto 0:56c5742b9e2b 369 return(0);
RyoheiHagimoto 0:56c5742b9e2b 370 }
RyoheiHagimoto 0:56c5742b9e2b 371
RyoheiHagimoto 0:56c5742b9e2b 372 if(cfg >= 0 && cfg < ZBAR_CFG_NUM)
RyoheiHagimoto 0:56c5742b9e2b 373 return(decoder_set_config_bool(dcode, sym, cfg, val));
RyoheiHagimoto 0:56c5742b9e2b 374 else if(cfg >= ZBAR_CFG_MIN_LEN && cfg <= ZBAR_CFG_MAX_LEN)
RyoheiHagimoto 0:56c5742b9e2b 375 return(decoder_set_config_int(dcode, sym, cfg, val));
RyoheiHagimoto 0:56c5742b9e2b 376 else
RyoheiHagimoto 0:56c5742b9e2b 377 return(1);
RyoheiHagimoto 0:56c5742b9e2b 378 }
RyoheiHagimoto 0:56c5742b9e2b 379
RyoheiHagimoto 0:56c5742b9e2b 380
RyoheiHagimoto 0:56c5742b9e2b 381 static char *decoder_dump = NULL;
RyoheiHagimoto 0:56c5742b9e2b 382 static unsigned decoder_dumplen = 0;
RyoheiHagimoto 0:56c5742b9e2b 383
RyoheiHagimoto 0:56c5742b9e2b 384 const char *_zbar_decoder_buf_dump (unsigned char *buf,
RyoheiHagimoto 0:56c5742b9e2b 385 unsigned int buflen)
RyoheiHagimoto 0:56c5742b9e2b 386 {
RyoheiHagimoto 0:56c5742b9e2b 387 int dumplen = (buflen * 3) + 12;
RyoheiHagimoto 0:56c5742b9e2b 388 if(!decoder_dump || dumplen > decoder_dumplen) {
RyoheiHagimoto 0:56c5742b9e2b 389 if(decoder_dump)
RyoheiHagimoto 0:56c5742b9e2b 390 free(decoder_dump);
RyoheiHagimoto 0:56c5742b9e2b 391 decoder_dump = malloc(dumplen);
RyoheiHagimoto 0:56c5742b9e2b 392 decoder_dumplen = dumplen;
RyoheiHagimoto 0:56c5742b9e2b 393 }
RyoheiHagimoto 0:56c5742b9e2b 394 char *p = decoder_dump +
RyoheiHagimoto 0:56c5742b9e2b 395 snprintf(decoder_dump, 12, "buf[%04x]=",
RyoheiHagimoto 0:56c5742b9e2b 396 (buflen > 0xffff) ? 0xffff : buflen);
RyoheiHagimoto 0:56c5742b9e2b 397 int i;
RyoheiHagimoto 0:56c5742b9e2b 398 for(i = 0; i < buflen; i++)
RyoheiHagimoto 0:56c5742b9e2b 399 p += snprintf(p, 4, "%s%02x", (i) ? " " : "", buf[i]);
RyoheiHagimoto 0:56c5742b9e2b 400 return(decoder_dump);
RyoheiHagimoto 0:56c5742b9e2b 401 }
RyoheiHagimoto 0:56c5742b9e2b 402