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 <stdio.h>
RyoheiHagimoto 0:56c5742b9e2b 26 #include <string.h>
RyoheiHagimoto 0:56c5742b9e2b 27 #include <assert.h>
RyoheiHagimoto 0:56c5742b9e2b 28
RyoheiHagimoto 0:56c5742b9e2b 29 #include <zbar.h>
RyoheiHagimoto 0:56c5742b9e2b 30 #include "symbol.h"
RyoheiHagimoto 0:56c5742b9e2b 31
RyoheiHagimoto 0:56c5742b9e2b 32 const char *zbar_get_symbol_name (zbar_symbol_type_t sym)
RyoheiHagimoto 0:56c5742b9e2b 33 {
RyoheiHagimoto 0:56c5742b9e2b 34 switch(sym & ZBAR_SYMBOL) {
RyoheiHagimoto 0:56c5742b9e2b 35 case ZBAR_EAN8: return("EAN-8");
RyoheiHagimoto 0:56c5742b9e2b 36 case ZBAR_UPCE: return("UPC-E");
RyoheiHagimoto 0:56c5742b9e2b 37 case ZBAR_ISBN10: return("ISBN-10");
RyoheiHagimoto 0:56c5742b9e2b 38 case ZBAR_UPCA: return("UPC-A");
RyoheiHagimoto 0:56c5742b9e2b 39 case ZBAR_EAN13: return("EAN-13");
RyoheiHagimoto 0:56c5742b9e2b 40 case ZBAR_ISBN13: return("ISBN-13");
RyoheiHagimoto 0:56c5742b9e2b 41 case ZBAR_I25: return("I2/5");
RyoheiHagimoto 0:56c5742b9e2b 42 case ZBAR_CODE39: return("CODE-39");
RyoheiHagimoto 0:56c5742b9e2b 43 case ZBAR_CODE128: return("CODE-128");
RyoheiHagimoto 0:56c5742b9e2b 44 case ZBAR_PDF417: return("PDF417");
RyoheiHagimoto 0:56c5742b9e2b 45 case ZBAR_QRCODE: return("QR-Code");
RyoheiHagimoto 0:56c5742b9e2b 46 default: return("UNKNOWN");
RyoheiHagimoto 0:56c5742b9e2b 47 }
RyoheiHagimoto 0:56c5742b9e2b 48 }
RyoheiHagimoto 0:56c5742b9e2b 49
RyoheiHagimoto 0:56c5742b9e2b 50 const char *zbar_get_addon_name (zbar_symbol_type_t sym)
RyoheiHagimoto 0:56c5742b9e2b 51 {
RyoheiHagimoto 0:56c5742b9e2b 52 switch(sym & ZBAR_ADDON) {
RyoheiHagimoto 0:56c5742b9e2b 53 case ZBAR_ADDON2: return("+2");
RyoheiHagimoto 0:56c5742b9e2b 54 case ZBAR_ADDON5: return("+5");
RyoheiHagimoto 0:56c5742b9e2b 55 default: return("");
RyoheiHagimoto 0:56c5742b9e2b 56 }
RyoheiHagimoto 0:56c5742b9e2b 57 }
RyoheiHagimoto 0:56c5742b9e2b 58
RyoheiHagimoto 0:56c5742b9e2b 59
RyoheiHagimoto 0:56c5742b9e2b 60 void _zbar_symbol_free (zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 61 {
RyoheiHagimoto 0:56c5742b9e2b 62 if(sym->syms) {
RyoheiHagimoto 0:56c5742b9e2b 63 zbar_symbol_set_ref(sym->syms, -1);
RyoheiHagimoto 0:56c5742b9e2b 64 sym->syms = NULL;
RyoheiHagimoto 0:56c5742b9e2b 65 }
RyoheiHagimoto 0:56c5742b9e2b 66 if(sym->pts)
RyoheiHagimoto 0:56c5742b9e2b 67 free(sym->pts);
RyoheiHagimoto 0:56c5742b9e2b 68 if(sym->data_alloc && sym->data)
RyoheiHagimoto 0:56c5742b9e2b 69 free(sym->data);
RyoheiHagimoto 0:56c5742b9e2b 70 free(sym);
RyoheiHagimoto 0:56c5742b9e2b 71 }
RyoheiHagimoto 0:56c5742b9e2b 72
RyoheiHagimoto 0:56c5742b9e2b 73 void zbar_symbol_ref (const zbar_symbol_t *sym,
RyoheiHagimoto 0:56c5742b9e2b 74 int refs)
RyoheiHagimoto 0:56c5742b9e2b 75 {
RyoheiHagimoto 0:56c5742b9e2b 76 zbar_symbol_t *ncsym = (zbar_symbol_t*)sym;
RyoheiHagimoto 0:56c5742b9e2b 77 _zbar_symbol_refcnt(ncsym, refs);
RyoheiHagimoto 0:56c5742b9e2b 78 }
RyoheiHagimoto 0:56c5742b9e2b 79
RyoheiHagimoto 0:56c5742b9e2b 80 zbar_symbol_type_t zbar_symbol_get_type (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 81 {
RyoheiHagimoto 0:56c5742b9e2b 82 return(sym->type);
RyoheiHagimoto 0:56c5742b9e2b 83 }
RyoheiHagimoto 0:56c5742b9e2b 84
RyoheiHagimoto 0:56c5742b9e2b 85 const char *zbar_symbol_get_data (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 86 {
RyoheiHagimoto 0:56c5742b9e2b 87 return(sym->data);
RyoheiHagimoto 0:56c5742b9e2b 88 }
RyoheiHagimoto 0:56c5742b9e2b 89
RyoheiHagimoto 0:56c5742b9e2b 90 unsigned int zbar_symbol_get_data_length (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 91 {
RyoheiHagimoto 0:56c5742b9e2b 92 return(sym->datalen);
RyoheiHagimoto 0:56c5742b9e2b 93 }
RyoheiHagimoto 0:56c5742b9e2b 94
RyoheiHagimoto 0:56c5742b9e2b 95 int zbar_symbol_get_count (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 96 {
RyoheiHagimoto 0:56c5742b9e2b 97 return(sym->cache_count);
RyoheiHagimoto 0:56c5742b9e2b 98 }
RyoheiHagimoto 0:56c5742b9e2b 99
RyoheiHagimoto 0:56c5742b9e2b 100 int zbar_symbol_get_quality (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 101 {
RyoheiHagimoto 0:56c5742b9e2b 102 return(sym->quality);
RyoheiHagimoto 0:56c5742b9e2b 103 }
RyoheiHagimoto 0:56c5742b9e2b 104
RyoheiHagimoto 0:56c5742b9e2b 105 unsigned zbar_symbol_get_loc_size (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 106 {
RyoheiHagimoto 0:56c5742b9e2b 107 return(sym->npts);
RyoheiHagimoto 0:56c5742b9e2b 108 }
RyoheiHagimoto 0:56c5742b9e2b 109
RyoheiHagimoto 0:56c5742b9e2b 110 int zbar_symbol_get_loc_x (const zbar_symbol_t *sym,
RyoheiHagimoto 0:56c5742b9e2b 111 unsigned idx)
RyoheiHagimoto 0:56c5742b9e2b 112 {
RyoheiHagimoto 0:56c5742b9e2b 113 if(idx < sym->npts)
RyoheiHagimoto 0:56c5742b9e2b 114 return(sym->pts[idx].x);
RyoheiHagimoto 0:56c5742b9e2b 115 else
RyoheiHagimoto 0:56c5742b9e2b 116 return(-1);
RyoheiHagimoto 0:56c5742b9e2b 117 }
RyoheiHagimoto 0:56c5742b9e2b 118
RyoheiHagimoto 0:56c5742b9e2b 119 int zbar_symbol_get_loc_y (const zbar_symbol_t *sym,
RyoheiHagimoto 0:56c5742b9e2b 120 unsigned idx)
RyoheiHagimoto 0:56c5742b9e2b 121 {
RyoheiHagimoto 0:56c5742b9e2b 122 if(idx < sym->npts)
RyoheiHagimoto 0:56c5742b9e2b 123 return(sym->pts[idx].y);
RyoheiHagimoto 0:56c5742b9e2b 124 else
RyoheiHagimoto 0:56c5742b9e2b 125 return(-1);
RyoheiHagimoto 0:56c5742b9e2b 126 }
RyoheiHagimoto 0:56c5742b9e2b 127
RyoheiHagimoto 0:56c5742b9e2b 128 const zbar_symbol_t *zbar_symbol_next (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 129 {
RyoheiHagimoto 0:56c5742b9e2b 130 return((sym) ? sym->next : NULL);
RyoheiHagimoto 0:56c5742b9e2b 131 }
RyoheiHagimoto 0:56c5742b9e2b 132
RyoheiHagimoto 0:56c5742b9e2b 133 const zbar_symbol_set_t*
RyoheiHagimoto 0:56c5742b9e2b 134 zbar_symbol_get_components (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 135 {
RyoheiHagimoto 0:56c5742b9e2b 136 return(sym->syms);
RyoheiHagimoto 0:56c5742b9e2b 137 }
RyoheiHagimoto 0:56c5742b9e2b 138
RyoheiHagimoto 0:56c5742b9e2b 139 const zbar_symbol_t *zbar_symbol_first_component (const zbar_symbol_t *sym)
RyoheiHagimoto 0:56c5742b9e2b 140 {
RyoheiHagimoto 0:56c5742b9e2b 141 return((sym && sym->syms) ? sym->syms->head : NULL);
RyoheiHagimoto 0:56c5742b9e2b 142 }
RyoheiHagimoto 0:56c5742b9e2b 143
RyoheiHagimoto 0:56c5742b9e2b 144
RyoheiHagimoto 0:56c5742b9e2b 145 static const char *xmlfmt[] = {
RyoheiHagimoto 0:56c5742b9e2b 146 "<symbol type='%s' quality='%d'",
RyoheiHagimoto 0:56c5742b9e2b 147 " count='%d'",
RyoheiHagimoto 0:56c5742b9e2b 148 "><data><![CDATA[",
RyoheiHagimoto 0:56c5742b9e2b 149 "]]></data></symbol>",
RyoheiHagimoto 0:56c5742b9e2b 150 };
RyoheiHagimoto 0:56c5742b9e2b 151
RyoheiHagimoto 0:56c5742b9e2b 152 /* FIXME suspect... */
RyoheiHagimoto 0:56c5742b9e2b 153 #define MAX_INT_DIGITS 10
RyoheiHagimoto 0:56c5742b9e2b 154
RyoheiHagimoto 0:56c5742b9e2b 155 char *zbar_symbol_xml (const zbar_symbol_t *sym,
RyoheiHagimoto 0:56c5742b9e2b 156 char **buf,
RyoheiHagimoto 0:56c5742b9e2b 157 unsigned *len)
RyoheiHagimoto 0:56c5742b9e2b 158 {
RyoheiHagimoto 0:56c5742b9e2b 159 const char *type = zbar_get_symbol_name(sym->type);
RyoheiHagimoto 0:56c5742b9e2b 160 /* FIXME binary data */
RyoheiHagimoto 0:56c5742b9e2b 161 unsigned datalen = strlen(sym->data);
RyoheiHagimoto 0:56c5742b9e2b 162 unsigned maxlen = (strlen(xmlfmt[0]) + strlen(xmlfmt[1]) +
RyoheiHagimoto 0:56c5742b9e2b 163 strlen(xmlfmt[2]) + strlen(xmlfmt[3]) +
RyoheiHagimoto 0:56c5742b9e2b 164 strlen(type) + datalen + MAX_INT_DIGITS + 1);
RyoheiHagimoto 0:56c5742b9e2b 165 if(!*buf || (*len < maxlen)) {
RyoheiHagimoto 0:56c5742b9e2b 166 if(*buf)
RyoheiHagimoto 0:56c5742b9e2b 167 free(*buf);
RyoheiHagimoto 0:56c5742b9e2b 168 *buf = malloc(maxlen);
RyoheiHagimoto 0:56c5742b9e2b 169 /* FIXME check OOM */
RyoheiHagimoto 0:56c5742b9e2b 170 *len = maxlen;
RyoheiHagimoto 0:56c5742b9e2b 171 }
RyoheiHagimoto 0:56c5742b9e2b 172
RyoheiHagimoto 0:56c5742b9e2b 173 int n = snprintf(*buf, maxlen, xmlfmt[0], type, sym->quality);
RyoheiHagimoto 0:56c5742b9e2b 174 assert(n > 0);
RyoheiHagimoto 0:56c5742b9e2b 175 assert(n <= maxlen);
RyoheiHagimoto 0:56c5742b9e2b 176
RyoheiHagimoto 0:56c5742b9e2b 177 if(sym->cache_count) {
RyoheiHagimoto 0:56c5742b9e2b 178 int i = snprintf(*buf + n, maxlen - n, xmlfmt[1], sym->cache_count);
RyoheiHagimoto 0:56c5742b9e2b 179 assert(i > 0);
RyoheiHagimoto 0:56c5742b9e2b 180 n += i;
RyoheiHagimoto 0:56c5742b9e2b 181 assert(n <= maxlen);
RyoheiHagimoto 0:56c5742b9e2b 182 }
RyoheiHagimoto 0:56c5742b9e2b 183
RyoheiHagimoto 0:56c5742b9e2b 184 int i = strlen(xmlfmt[2]);
RyoheiHagimoto 0:56c5742b9e2b 185 memcpy(*buf + n, xmlfmt[2], i + 1);
RyoheiHagimoto 0:56c5742b9e2b 186 n += i;
RyoheiHagimoto 0:56c5742b9e2b 187 assert(n <= maxlen);
RyoheiHagimoto 0:56c5742b9e2b 188
RyoheiHagimoto 0:56c5742b9e2b 189 /* FIXME binary data */
RyoheiHagimoto 0:56c5742b9e2b 190 /* FIXME handle "]]>" */
RyoheiHagimoto 0:56c5742b9e2b 191 strncpy(*buf + n, sym->data, datalen + 1);
RyoheiHagimoto 0:56c5742b9e2b 192 n += datalen;
RyoheiHagimoto 0:56c5742b9e2b 193 assert(n <= maxlen);
RyoheiHagimoto 0:56c5742b9e2b 194
RyoheiHagimoto 0:56c5742b9e2b 195 i = strlen(xmlfmt[3]);
RyoheiHagimoto 0:56c5742b9e2b 196 memcpy(*buf + n, xmlfmt[3], i + 1);
RyoheiHagimoto 0:56c5742b9e2b 197 n += i;
RyoheiHagimoto 0:56c5742b9e2b 198 assert(n <= maxlen);
RyoheiHagimoto 0:56c5742b9e2b 199
RyoheiHagimoto 0:56c5742b9e2b 200 *len = n;
RyoheiHagimoto 0:56c5742b9e2b 201 return(*buf);
RyoheiHagimoto 0:56c5742b9e2b 202 }
RyoheiHagimoto 0:56c5742b9e2b 203
RyoheiHagimoto 0:56c5742b9e2b 204
RyoheiHagimoto 0:56c5742b9e2b 205 zbar_symbol_set_t *_zbar_symbol_set_create ()
RyoheiHagimoto 0:56c5742b9e2b 206 {
RyoheiHagimoto 0:56c5742b9e2b 207 zbar_symbol_set_t *syms = calloc(1, sizeof(*syms));
RyoheiHagimoto 0:56c5742b9e2b 208 _zbar_refcnt(&syms->refcnt, 1);
RyoheiHagimoto 0:56c5742b9e2b 209 return(syms);
RyoheiHagimoto 0:56c5742b9e2b 210 }
RyoheiHagimoto 0:56c5742b9e2b 211
RyoheiHagimoto 0:56c5742b9e2b 212 inline void _zbar_symbol_set_free (zbar_symbol_set_t *syms)
RyoheiHagimoto 0:56c5742b9e2b 213 {
RyoheiHagimoto 0:56c5742b9e2b 214 zbar_symbol_t *sym, *next;
RyoheiHagimoto 0:56c5742b9e2b 215 for(sym = syms->head; sym; sym = next) {
RyoheiHagimoto 0:56c5742b9e2b 216 next = sym->next;
RyoheiHagimoto 0:56c5742b9e2b 217 sym->next = NULL;
RyoheiHagimoto 0:56c5742b9e2b 218 _zbar_symbol_refcnt(sym, -1);
RyoheiHagimoto 0:56c5742b9e2b 219 }
RyoheiHagimoto 0:56c5742b9e2b 220 syms->head = NULL;
RyoheiHagimoto 0:56c5742b9e2b 221 free(syms);
RyoheiHagimoto 0:56c5742b9e2b 222 }
RyoheiHagimoto 0:56c5742b9e2b 223
RyoheiHagimoto 0:56c5742b9e2b 224 void zbar_symbol_set_ref (const zbar_symbol_set_t *syms,
RyoheiHagimoto 0:56c5742b9e2b 225 int delta)
RyoheiHagimoto 0:56c5742b9e2b 226 {
RyoheiHagimoto 0:56c5742b9e2b 227 zbar_symbol_set_t *ncsyms = (zbar_symbol_set_t*)syms;
RyoheiHagimoto 0:56c5742b9e2b 228 if(!_zbar_refcnt(&ncsyms->refcnt, delta) && delta <= 0)
RyoheiHagimoto 0:56c5742b9e2b 229 _zbar_symbol_set_free(ncsyms);
RyoheiHagimoto 0:56c5742b9e2b 230 }
RyoheiHagimoto 0:56c5742b9e2b 231
RyoheiHagimoto 0:56c5742b9e2b 232 int zbar_symbol_set_get_size (const zbar_symbol_set_t *syms)
RyoheiHagimoto 0:56c5742b9e2b 233 {
RyoheiHagimoto 0:56c5742b9e2b 234 return(syms->nsyms);
RyoheiHagimoto 0:56c5742b9e2b 235 }
RyoheiHagimoto 0:56c5742b9e2b 236
RyoheiHagimoto 0:56c5742b9e2b 237 const zbar_symbol_t*
RyoheiHagimoto 0:56c5742b9e2b 238 zbar_symbol_set_first_symbol (const zbar_symbol_set_t *syms)
RyoheiHagimoto 0:56c5742b9e2b 239 {
RyoheiHagimoto 0:56c5742b9e2b 240 zbar_symbol_t *sym = syms->tail;
RyoheiHagimoto 0:56c5742b9e2b 241 if(sym)
RyoheiHagimoto 0:56c5742b9e2b 242 return(sym->next);
RyoheiHagimoto 0:56c5742b9e2b 243 return(syms->head);
RyoheiHagimoto 0:56c5742b9e2b 244 }
RyoheiHagimoto 0:56c5742b9e2b 245