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:00:37 2016 +0000
Revision:
0:56c5742b9e2b
First revicion

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 #ifndef _ERROR_H_
RyoheiHagimoto 0:56c5742b9e2b 24 #define _ERROR_H_
RyoheiHagimoto 0:56c5742b9e2b 25
RyoheiHagimoto 0:56c5742b9e2b 26 #include <config.h>
RyoheiHagimoto 0:56c5742b9e2b 27 #ifdef HAVE_INTTYPES_H
RyoheiHagimoto 0:56c5742b9e2b 28 # include <inttypes.h>
RyoheiHagimoto 0:56c5742b9e2b 29 #endif
RyoheiHagimoto 0:56c5742b9e2b 30 #include <stdlib.h>
RyoheiHagimoto 0:56c5742b9e2b 31 #include <stdio.h>
RyoheiHagimoto 0:56c5742b9e2b 32 #include <string.h>
RyoheiHagimoto 0:56c5742b9e2b 33 #include <errno.h>
RyoheiHagimoto 0:56c5742b9e2b 34 #include <assert.h>
RyoheiHagimoto 0:56c5742b9e2b 35
RyoheiHagimoto 0:56c5742b9e2b 36 #include <zbar.h>
RyoheiHagimoto 0:56c5742b9e2b 37
RyoheiHagimoto 0:56c5742b9e2b 38 #ifdef _WIN32
RyoheiHagimoto 0:56c5742b9e2b 39 # include <windows.h>
RyoheiHagimoto 0:56c5742b9e2b 40 #endif
RyoheiHagimoto 0:56c5742b9e2b 41
RyoheiHagimoto 0:56c5742b9e2b 42 #if __STDC_VERSION__ < 199901L
RyoheiHagimoto 0:56c5742b9e2b 43 # if __GNUC__ >= 2
RyoheiHagimoto 0:56c5742b9e2b 44 # define __func__ __FUNCTION__
RyoheiHagimoto 0:56c5742b9e2b 45 # else
RyoheiHagimoto 0:56c5742b9e2b 46 # define __func__ "<unknown>"
RyoheiHagimoto 0:56c5742b9e2b 47 # endif
RyoheiHagimoto 0:56c5742b9e2b 48 #endif
RyoheiHagimoto 0:56c5742b9e2b 49
RyoheiHagimoto 0:56c5742b9e2b 50 #define ERRINFO_MAGIC (0x5252457a) /* "zERR" (LE) */
RyoheiHagimoto 0:56c5742b9e2b 51
RyoheiHagimoto 0:56c5742b9e2b 52 typedef enum errsev_e {
RyoheiHagimoto 0:56c5742b9e2b 53 SEV_FATAL = -2, /* application must terminate */
RyoheiHagimoto 0:56c5742b9e2b 54 SEV_ERROR = -1, /* might be able to recover and continue */
RyoheiHagimoto 0:56c5742b9e2b 55 SEV_OK = 0,
RyoheiHagimoto 0:56c5742b9e2b 56 SEV_WARNING = 1, /* unexpected condition */
RyoheiHagimoto 0:56c5742b9e2b 57 SEV_NOTE = 2, /* fyi */
RyoheiHagimoto 0:56c5742b9e2b 58 } errsev_t;
RyoheiHagimoto 0:56c5742b9e2b 59
RyoheiHagimoto 0:56c5742b9e2b 60 typedef enum errmodule_e {
RyoheiHagimoto 0:56c5742b9e2b 61 ZBAR_MOD_PROCESSOR,
RyoheiHagimoto 0:56c5742b9e2b 62 ZBAR_MOD_VIDEO,
RyoheiHagimoto 0:56c5742b9e2b 63 ZBAR_MOD_WINDOW,
RyoheiHagimoto 0:56c5742b9e2b 64 ZBAR_MOD_IMAGE_SCANNER,
RyoheiHagimoto 0:56c5742b9e2b 65 ZBAR_MOD_UNKNOWN,
RyoheiHagimoto 0:56c5742b9e2b 66 } errmodule_t;
RyoheiHagimoto 0:56c5742b9e2b 67
RyoheiHagimoto 0:56c5742b9e2b 68 typedef struct errinfo_s {
RyoheiHagimoto 0:56c5742b9e2b 69 uint32_t magic; /* just in case */
RyoheiHagimoto 0:56c5742b9e2b 70 errmodule_t module; /* reporting module */
RyoheiHagimoto 0:56c5742b9e2b 71 char *buf; /* formatted and passed to application */
RyoheiHagimoto 0:56c5742b9e2b 72 int errnum; /* errno for system errors */
RyoheiHagimoto 0:56c5742b9e2b 73
RyoheiHagimoto 0:56c5742b9e2b 74 errsev_t sev;
RyoheiHagimoto 0:56c5742b9e2b 75 zbar_error_t type;
RyoheiHagimoto 0:56c5742b9e2b 76 const char *func; /* reporting function */
RyoheiHagimoto 0:56c5742b9e2b 77 const char *detail; /* description */
RyoheiHagimoto 0:56c5742b9e2b 78 char *arg_str; /* single string argument */
RyoheiHagimoto 0:56c5742b9e2b 79 int arg_int; /* single integer argument */
RyoheiHagimoto 0:56c5742b9e2b 80 } errinfo_t;
RyoheiHagimoto 0:56c5742b9e2b 81
RyoheiHagimoto 0:56c5742b9e2b 82 extern int _zbar_verbosity;
RyoheiHagimoto 0:56c5742b9e2b 83
RyoheiHagimoto 0:56c5742b9e2b 84 /* FIXME don't we need varargs hacks here? */
RyoheiHagimoto 0:56c5742b9e2b 85
RyoheiHagimoto 0:56c5742b9e2b 86 #ifdef _WIN32
RyoheiHagimoto 0:56c5742b9e2b 87 # define ZFLUSH fflush(stderr);
RyoheiHagimoto 0:56c5742b9e2b 88 #else
RyoheiHagimoto 0:56c5742b9e2b 89 # define ZFLUSH
RyoheiHagimoto 0:56c5742b9e2b 90 #endif
RyoheiHagimoto 0:56c5742b9e2b 91
RyoheiHagimoto 0:56c5742b9e2b 92 #ifdef ZNO_MESSAGES
RyoheiHagimoto 0:56c5742b9e2b 93
RyoheiHagimoto 0:56c5742b9e2b 94 # ifdef __GNUC__
RyoheiHagimoto 0:56c5742b9e2b 95 /* older versions of gcc (< 2.95) require a named varargs parameter */
RyoheiHagimoto 0:56c5742b9e2b 96 # define zprintf(args...)
RyoheiHagimoto 0:56c5742b9e2b 97 # else
RyoheiHagimoto 0:56c5742b9e2b 98 /* unfortunately named vararg parameter is a gcc-specific extension */
RyoheiHagimoto 0:56c5742b9e2b 99 # define zprintf(...)
RyoheiHagimoto 0:56c5742b9e2b 100 # endif
RyoheiHagimoto 0:56c5742b9e2b 101
RyoheiHagimoto 0:56c5742b9e2b 102 #else
RyoheiHagimoto 0:56c5742b9e2b 103
RyoheiHagimoto 0:56c5742b9e2b 104 # ifdef __GNUC__
RyoheiHagimoto 0:56c5742b9e2b 105 # define zprintf(level, format, args...) do { \
RyoheiHagimoto 0:56c5742b9e2b 106 if(_zbar_verbosity >= level) { \
RyoheiHagimoto 0:56c5742b9e2b 107 fprintf(stderr, "%s: " format, __func__ , ##args); \
RyoheiHagimoto 0:56c5742b9e2b 108 ZFLUSH \
RyoheiHagimoto 0:56c5742b9e2b 109 } \
RyoheiHagimoto 0:56c5742b9e2b 110 } while(0)
RyoheiHagimoto 0:56c5742b9e2b 111 # else
RyoheiHagimoto 0:56c5742b9e2b 112 # define zprintf(level, format, ...) do { \
RyoheiHagimoto 0:56c5742b9e2b 113 if(_zbar_verbosity >= level) { \
RyoheiHagimoto 0:56c5742b9e2b 114 fprintf(stderr, "%s: " format, __func__ , ##__VA_ARGS__); \
RyoheiHagimoto 0:56c5742b9e2b 115 ZFLUSH \
RyoheiHagimoto 0:56c5742b9e2b 116 } \
RyoheiHagimoto 0:56c5742b9e2b 117 } while(0)
RyoheiHagimoto 0:56c5742b9e2b 118 # endif
RyoheiHagimoto 0:56c5742b9e2b 119
RyoheiHagimoto 0:56c5742b9e2b 120 #endif
RyoheiHagimoto 0:56c5742b9e2b 121
RyoheiHagimoto 0:56c5742b9e2b 122 static inline int err_copy (void *dst_c,
RyoheiHagimoto 0:56c5742b9e2b 123 void *src_c)
RyoheiHagimoto 0:56c5742b9e2b 124 {
RyoheiHagimoto 0:56c5742b9e2b 125 errinfo_t *dst = dst_c;
RyoheiHagimoto 0:56c5742b9e2b 126 errinfo_t *src = src_c;
RyoheiHagimoto 0:56c5742b9e2b 127 assert(dst->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 128 assert(src->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 129
RyoheiHagimoto 0:56c5742b9e2b 130 dst->errnum = src->errnum;
RyoheiHagimoto 0:56c5742b9e2b 131 dst->sev = src->sev;
RyoheiHagimoto 0:56c5742b9e2b 132 dst->type = src->type;
RyoheiHagimoto 0:56c5742b9e2b 133 dst->func = src->func;
RyoheiHagimoto 0:56c5742b9e2b 134 dst->detail = src->detail;
RyoheiHagimoto 0:56c5742b9e2b 135 dst->arg_str = src->arg_str;
RyoheiHagimoto 0:56c5742b9e2b 136 src->arg_str = NULL; /* unused at src, avoid double free */
RyoheiHagimoto 0:56c5742b9e2b 137 dst->arg_int = src->arg_int;
RyoheiHagimoto 0:56c5742b9e2b 138 return(-1);
RyoheiHagimoto 0:56c5742b9e2b 139 }
RyoheiHagimoto 0:56c5742b9e2b 140
RyoheiHagimoto 0:56c5742b9e2b 141 static inline int err_capture (const void *container,
RyoheiHagimoto 0:56c5742b9e2b 142 errsev_t sev,
RyoheiHagimoto 0:56c5742b9e2b 143 zbar_error_t type,
RyoheiHagimoto 0:56c5742b9e2b 144 const char *func,
RyoheiHagimoto 0:56c5742b9e2b 145 const char *detail)
RyoheiHagimoto 0:56c5742b9e2b 146 {
RyoheiHagimoto 0:56c5742b9e2b 147 errinfo_t *err = (errinfo_t*)container;
RyoheiHagimoto 0:56c5742b9e2b 148 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 149 if(type == ZBAR_ERR_SYSTEM)
RyoheiHagimoto 0:56c5742b9e2b 150 err->errnum = errno;
RyoheiHagimoto 0:56c5742b9e2b 151 #ifdef _WIN32
RyoheiHagimoto 0:56c5742b9e2b 152 else if(type == ZBAR_ERR_WINAPI)
RyoheiHagimoto 0:56c5742b9e2b 153 err->errnum = GetLastError();
RyoheiHagimoto 0:56c5742b9e2b 154 #endif
RyoheiHagimoto 0:56c5742b9e2b 155 err->sev = sev;
RyoheiHagimoto 0:56c5742b9e2b 156 err->type = type;
RyoheiHagimoto 0:56c5742b9e2b 157 err->func = func;
RyoheiHagimoto 0:56c5742b9e2b 158 err->detail = detail;
RyoheiHagimoto 0:56c5742b9e2b 159 if(_zbar_verbosity >= 1)
RyoheiHagimoto 0:56c5742b9e2b 160 _zbar_error_spew(err, 0);
RyoheiHagimoto 0:56c5742b9e2b 161 return(-1);
RyoheiHagimoto 0:56c5742b9e2b 162 }
RyoheiHagimoto 0:56c5742b9e2b 163
RyoheiHagimoto 0:56c5742b9e2b 164 static inline int err_capture_str (const void *container,
RyoheiHagimoto 0:56c5742b9e2b 165 errsev_t sev,
RyoheiHagimoto 0:56c5742b9e2b 166 zbar_error_t type,
RyoheiHagimoto 0:56c5742b9e2b 167 const char *func,
RyoheiHagimoto 0:56c5742b9e2b 168 const char *detail,
RyoheiHagimoto 0:56c5742b9e2b 169 const char *arg)
RyoheiHagimoto 0:56c5742b9e2b 170 {
RyoheiHagimoto 0:56c5742b9e2b 171 errinfo_t *err = (errinfo_t*)container;
RyoheiHagimoto 0:56c5742b9e2b 172 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 173 if(err->arg_str)
RyoheiHagimoto 0:56c5742b9e2b 174 free(err->arg_str);
RyoheiHagimoto 0:56c5742b9e2b 175 err->arg_str = strdup(arg);
RyoheiHagimoto 0:56c5742b9e2b 176 return(err_capture(container, sev, type, func, detail));
RyoheiHagimoto 0:56c5742b9e2b 177 }
RyoheiHagimoto 0:56c5742b9e2b 178
RyoheiHagimoto 0:56c5742b9e2b 179 static inline int err_capture_int (const void *container,
RyoheiHagimoto 0:56c5742b9e2b 180 errsev_t sev,
RyoheiHagimoto 0:56c5742b9e2b 181 zbar_error_t type,
RyoheiHagimoto 0:56c5742b9e2b 182 const char *func,
RyoheiHagimoto 0:56c5742b9e2b 183 const char *detail,
RyoheiHagimoto 0:56c5742b9e2b 184 int arg)
RyoheiHagimoto 0:56c5742b9e2b 185 {
RyoheiHagimoto 0:56c5742b9e2b 186 errinfo_t *err = (errinfo_t*)container;
RyoheiHagimoto 0:56c5742b9e2b 187 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 188 err->arg_int = arg;
RyoheiHagimoto 0:56c5742b9e2b 189 return(err_capture(container, sev, type, func, detail));
RyoheiHagimoto 0:56c5742b9e2b 190 }
RyoheiHagimoto 0:56c5742b9e2b 191
RyoheiHagimoto 0:56c5742b9e2b 192 static inline int err_capture_num (const void *container,
RyoheiHagimoto 0:56c5742b9e2b 193 errsev_t sev,
RyoheiHagimoto 0:56c5742b9e2b 194 zbar_error_t type,
RyoheiHagimoto 0:56c5742b9e2b 195 const char *func,
RyoheiHagimoto 0:56c5742b9e2b 196 const char *detail,
RyoheiHagimoto 0:56c5742b9e2b 197 int num)
RyoheiHagimoto 0:56c5742b9e2b 198 {
RyoheiHagimoto 0:56c5742b9e2b 199 errinfo_t *err = (errinfo_t*)container;
RyoheiHagimoto 0:56c5742b9e2b 200 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 201 err->errnum = num;
RyoheiHagimoto 0:56c5742b9e2b 202 return(err_capture(container, sev, type, func, detail));
RyoheiHagimoto 0:56c5742b9e2b 203 }
RyoheiHagimoto 0:56c5742b9e2b 204
RyoheiHagimoto 0:56c5742b9e2b 205 static inline void err_init (errinfo_t *err,
RyoheiHagimoto 0:56c5742b9e2b 206 errmodule_t module)
RyoheiHagimoto 0:56c5742b9e2b 207 {
RyoheiHagimoto 0:56c5742b9e2b 208 err->magic = ERRINFO_MAGIC;
RyoheiHagimoto 0:56c5742b9e2b 209 err->module = module;
RyoheiHagimoto 0:56c5742b9e2b 210 }
RyoheiHagimoto 0:56c5742b9e2b 211
RyoheiHagimoto 0:56c5742b9e2b 212 static inline void err_cleanup (errinfo_t *err)
RyoheiHagimoto 0:56c5742b9e2b 213 {
RyoheiHagimoto 0:56c5742b9e2b 214 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 215 if(err->buf) {
RyoheiHagimoto 0:56c5742b9e2b 216 free(err->buf);
RyoheiHagimoto 0:56c5742b9e2b 217 err->buf = NULL;
RyoheiHagimoto 0:56c5742b9e2b 218 }
RyoheiHagimoto 0:56c5742b9e2b 219 if(err->arg_str) {
RyoheiHagimoto 0:56c5742b9e2b 220 free(err->arg_str);
RyoheiHagimoto 0:56c5742b9e2b 221 err->arg_str = NULL;
RyoheiHagimoto 0:56c5742b9e2b 222 }
RyoheiHagimoto 0:56c5742b9e2b 223 }
RyoheiHagimoto 0:56c5742b9e2b 224
RyoheiHagimoto 0:56c5742b9e2b 225 #endif
RyoheiHagimoto 0:56c5742b9e2b 226