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 "error.h"
RyoheiHagimoto 0:56c5742b9e2b 25 #include <string.h>
RyoheiHagimoto 0:56c5742b9e2b 26
RyoheiHagimoto 0:56c5742b9e2b 27 int _zbar_verbosity = 0;
RyoheiHagimoto 0:56c5742b9e2b 28
RyoheiHagimoto 0:56c5742b9e2b 29 static const char * const sev_str[] = {
RyoheiHagimoto 0:56c5742b9e2b 30 "FATAL ERROR", "ERROR", "OK", "WARNING", "NOTE"
RyoheiHagimoto 0:56c5742b9e2b 31 };
RyoheiHagimoto 0:56c5742b9e2b 32 #define SEV_MAX (strlen(sev_str[0]))
RyoheiHagimoto 0:56c5742b9e2b 33
RyoheiHagimoto 0:56c5742b9e2b 34 static const char * const mod_str[] = {
RyoheiHagimoto 0:56c5742b9e2b 35 "processor", "video", "window", "image scanner", "<unknown>"
RyoheiHagimoto 0:56c5742b9e2b 36 };
RyoheiHagimoto 0:56c5742b9e2b 37 #define MOD_MAX (strlen(mod_str[ZBAR_MOD_IMAGE_SCANNER]))
RyoheiHagimoto 0:56c5742b9e2b 38
RyoheiHagimoto 0:56c5742b9e2b 39 static const char const * err_str[] = {
RyoheiHagimoto 0:56c5742b9e2b 40 "no error", /* OK */
RyoheiHagimoto 0:56c5742b9e2b 41 "out of memory", /* NOMEM */
RyoheiHagimoto 0:56c5742b9e2b 42 "internal library error", /* INTERNAL */
RyoheiHagimoto 0:56c5742b9e2b 43 "unsupported request", /* UNSUPPORTED */
RyoheiHagimoto 0:56c5742b9e2b 44 "invalid request", /* INVALID */
RyoheiHagimoto 0:56c5742b9e2b 45 "system error", /* SYSTEM */
RyoheiHagimoto 0:56c5742b9e2b 46 "locking error", /* LOCKING */
RyoheiHagimoto 0:56c5742b9e2b 47 "all resources busy", /* BUSY */
RyoheiHagimoto 0:56c5742b9e2b 48 "X11 display error", /* XDISPLAY */
RyoheiHagimoto 0:56c5742b9e2b 49 "X11 protocol error", /* XPROTO */
RyoheiHagimoto 0:56c5742b9e2b 50 "output window is closed", /* CLOSED */
RyoheiHagimoto 0:56c5742b9e2b 51 "windows system error", /* WINAPI */
RyoheiHagimoto 0:56c5742b9e2b 52 "unknown error" /* NUM */
RyoheiHagimoto 0:56c5742b9e2b 53 };
RyoheiHagimoto 0:56c5742b9e2b 54 #define ERR_MAX (strlen(err_str[ZBAR_ERR_CLOSED]))
RyoheiHagimoto 0:56c5742b9e2b 55
RyoheiHagimoto 0:56c5742b9e2b 56 int zbar_version (unsigned *major,
RyoheiHagimoto 0:56c5742b9e2b 57 unsigned *minor)
RyoheiHagimoto 0:56c5742b9e2b 58 {
RyoheiHagimoto 0:56c5742b9e2b 59 if(major)
RyoheiHagimoto 0:56c5742b9e2b 60 *major = ZBAR_VERSION_MAJOR;
RyoheiHagimoto 0:56c5742b9e2b 61 if(minor)
RyoheiHagimoto 0:56c5742b9e2b 62 *minor = ZBAR_VERSION_MINOR;
RyoheiHagimoto 0:56c5742b9e2b 63 return(0);
RyoheiHagimoto 0:56c5742b9e2b 64 }
RyoheiHagimoto 0:56c5742b9e2b 65
RyoheiHagimoto 0:56c5742b9e2b 66 void zbar_set_verbosity (int level)
RyoheiHagimoto 0:56c5742b9e2b 67 {
RyoheiHagimoto 0:56c5742b9e2b 68 _zbar_verbosity = level;
RyoheiHagimoto 0:56c5742b9e2b 69 }
RyoheiHagimoto 0:56c5742b9e2b 70
RyoheiHagimoto 0:56c5742b9e2b 71 void zbar_increase_verbosity ()
RyoheiHagimoto 0:56c5742b9e2b 72 {
RyoheiHagimoto 0:56c5742b9e2b 73 if(!_zbar_verbosity)
RyoheiHagimoto 0:56c5742b9e2b 74 _zbar_verbosity++;
RyoheiHagimoto 0:56c5742b9e2b 75 else
RyoheiHagimoto 0:56c5742b9e2b 76 _zbar_verbosity <<= 1;
RyoheiHagimoto 0:56c5742b9e2b 77 }
RyoheiHagimoto 0:56c5742b9e2b 78
RyoheiHagimoto 0:56c5742b9e2b 79 int _zbar_error_spew (const void *container,
RyoheiHagimoto 0:56c5742b9e2b 80 int verbosity)
RyoheiHagimoto 0:56c5742b9e2b 81 {
RyoheiHagimoto 0:56c5742b9e2b 82 const errinfo_t *err = container;
RyoheiHagimoto 0:56c5742b9e2b 83 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 84 fprintf(stderr, "%s", _zbar_error_string(err, verbosity));
RyoheiHagimoto 0:56c5742b9e2b 85 return(-err->sev);
RyoheiHagimoto 0:56c5742b9e2b 86 }
RyoheiHagimoto 0:56c5742b9e2b 87
RyoheiHagimoto 0:56c5742b9e2b 88 zbar_error_t _zbar_get_error_code (const void *container)
RyoheiHagimoto 0:56c5742b9e2b 89 {
RyoheiHagimoto 0:56c5742b9e2b 90 const errinfo_t *err = container;
RyoheiHagimoto 0:56c5742b9e2b 91 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 92 return(err->type);
RyoheiHagimoto 0:56c5742b9e2b 93 }
RyoheiHagimoto 0:56c5742b9e2b 94
RyoheiHagimoto 0:56c5742b9e2b 95 /* ERROR: zbar video in v4l1_set_format():
RyoheiHagimoto 0:56c5742b9e2b 96 * system error: blah[: blah]
RyoheiHagimoto 0:56c5742b9e2b 97 */
RyoheiHagimoto 0:56c5742b9e2b 98
RyoheiHagimoto 0:56c5742b9e2b 99 const char *_zbar_error_string (const void *container,
RyoheiHagimoto 0:56c5742b9e2b 100 int verbosity)
RyoheiHagimoto 0:56c5742b9e2b 101 {
RyoheiHagimoto 0:56c5742b9e2b 102 errinfo_t *err = (errinfo_t*)container;
RyoheiHagimoto 0:56c5742b9e2b 103 assert(err->magic == ERRINFO_MAGIC);
RyoheiHagimoto 0:56c5742b9e2b 104
RyoheiHagimoto 0:56c5742b9e2b 105 const char *sev;
RyoheiHagimoto 0:56c5742b9e2b 106 if(err->sev >= SEV_FATAL && err->sev <= SEV_NOTE)
RyoheiHagimoto 0:56c5742b9e2b 107 sev = sev_str[err->sev + 2];
RyoheiHagimoto 0:56c5742b9e2b 108 else
RyoheiHagimoto 0:56c5742b9e2b 109 sev = sev_str[1];
RyoheiHagimoto 0:56c5742b9e2b 110
RyoheiHagimoto 0:56c5742b9e2b 111 const char *mod;
RyoheiHagimoto 0:56c5742b9e2b 112 if(err->module >= ZBAR_MOD_PROCESSOR &&
RyoheiHagimoto 0:56c5742b9e2b 113 err->module < ZBAR_MOD_UNKNOWN)
RyoheiHagimoto 0:56c5742b9e2b 114 mod = mod_str[err->module];
RyoheiHagimoto 0:56c5742b9e2b 115 else
RyoheiHagimoto 0:56c5742b9e2b 116 mod = mod_str[ZBAR_MOD_UNKNOWN];
RyoheiHagimoto 0:56c5742b9e2b 117
RyoheiHagimoto 0:56c5742b9e2b 118 const char *func = (err->func) ? err->func : "<unknown>";
RyoheiHagimoto 0:56c5742b9e2b 119
RyoheiHagimoto 0:56c5742b9e2b 120 const char *type;
RyoheiHagimoto 0:56c5742b9e2b 121 if(err->type >= 0 && err->type < ZBAR_ERR_NUM)
RyoheiHagimoto 0:56c5742b9e2b 122 type = err_str[err->type];
RyoheiHagimoto 0:56c5742b9e2b 123 else
RyoheiHagimoto 0:56c5742b9e2b 124 type = err_str[ZBAR_ERR_NUM];
RyoheiHagimoto 0:56c5742b9e2b 125
RyoheiHagimoto 0:56c5742b9e2b 126 char basefmt[] = "%s: zbar %s in %s():\n %s: ";
RyoheiHagimoto 0:56c5742b9e2b 127 int len = SEV_MAX + MOD_MAX + ERR_MAX + strlen(func) + sizeof(basefmt);
RyoheiHagimoto 0:56c5742b9e2b 128 err->buf = realloc(err->buf, len);
RyoheiHagimoto 0:56c5742b9e2b 129 len = sprintf(err->buf, basefmt, sev, mod, func, type);
RyoheiHagimoto 0:56c5742b9e2b 130 if(len <= 0)
RyoheiHagimoto 0:56c5742b9e2b 131 return("<unknown>");
RyoheiHagimoto 0:56c5742b9e2b 132
RyoheiHagimoto 0:56c5742b9e2b 133 if(err->detail) {
RyoheiHagimoto 0:56c5742b9e2b 134 int newlen = len + strlen(err->detail) + 1;
RyoheiHagimoto 0:56c5742b9e2b 135 if(strstr(err->detail, "%s")) {
RyoheiHagimoto 0:56c5742b9e2b 136 #if (0)
RyoheiHagimoto 0:56c5742b9e2b 137 if(!err->arg_str)
RyoheiHagimoto 0:56c5742b9e2b 138 err->arg_str = strdup("<?>");
RyoheiHagimoto 0:56c5742b9e2b 139 #endif
RyoheiHagimoto 0:56c5742b9e2b 140 err->buf = realloc(err->buf, newlen + strlen(err->arg_str));
RyoheiHagimoto 0:56c5742b9e2b 141 len += sprintf(err->buf + len, err->detail, err->arg_str);
RyoheiHagimoto 0:56c5742b9e2b 142 }
RyoheiHagimoto 0:56c5742b9e2b 143 else if(strstr(err->detail, "%d") || strstr(err->detail, "%x")) {
RyoheiHagimoto 0:56c5742b9e2b 144 err->buf = realloc(err->buf, newlen + 32);
RyoheiHagimoto 0:56c5742b9e2b 145 len += sprintf(err->buf + len, err->detail, err->arg_int);
RyoheiHagimoto 0:56c5742b9e2b 146 }
RyoheiHagimoto 0:56c5742b9e2b 147 else {
RyoheiHagimoto 0:56c5742b9e2b 148 err->buf = realloc(err->buf, newlen);
RyoheiHagimoto 0:56c5742b9e2b 149 len += sprintf(err->buf + len, "%s", err->detail);
RyoheiHagimoto 0:56c5742b9e2b 150 }
RyoheiHagimoto 0:56c5742b9e2b 151 if(len <= 0)
RyoheiHagimoto 0:56c5742b9e2b 152 return("<unknown>");
RyoheiHagimoto 0:56c5742b9e2b 153 }
RyoheiHagimoto 0:56c5742b9e2b 154
RyoheiHagimoto 0:56c5742b9e2b 155 if(err->type == ZBAR_ERR_SYSTEM) {
RyoheiHagimoto 0:56c5742b9e2b 156 char sysfmt[] = ": %s (%d)\n";
RyoheiHagimoto 0:56c5742b9e2b 157 const char *syserr = strerror(err->errnum);
RyoheiHagimoto 0:56c5742b9e2b 158 err->buf = realloc(err->buf, len + strlen(sysfmt) + strlen(syserr));
RyoheiHagimoto 0:56c5742b9e2b 159 len += sprintf(err->buf + len, sysfmt, syserr, err->errnum);
RyoheiHagimoto 0:56c5742b9e2b 160 }
RyoheiHagimoto 0:56c5742b9e2b 161 #ifdef _WIN32
RyoheiHagimoto 0:56c5742b9e2b 162 else if(err->type == ZBAR_ERR_WINAPI) {
RyoheiHagimoto 0:56c5742b9e2b 163 char *syserr = NULL;
RyoheiHagimoto 0:56c5742b9e2b 164 if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
RyoheiHagimoto 0:56c5742b9e2b 165 FORMAT_MESSAGE_ALLOCATE_BUFFER |
RyoheiHagimoto 0:56c5742b9e2b 166 FORMAT_MESSAGE_IGNORE_INSERTS,
RyoheiHagimoto 0:56c5742b9e2b 167 NULL, err->errnum, 0, (LPTSTR)&syserr, 1, NULL) &&
RyoheiHagimoto 0:56c5742b9e2b 168 syserr) {
RyoheiHagimoto 0:56c5742b9e2b 169 char sysfmt[] = ": %s (%d)\n";
RyoheiHagimoto 0:56c5742b9e2b 170 err->buf = realloc(err->buf, len + strlen(sysfmt) + strlen(syserr));
RyoheiHagimoto 0:56c5742b9e2b 171 len += sprintf(err->buf + len, sysfmt, syserr, err->errnum);
RyoheiHagimoto 0:56c5742b9e2b 172 LocalFree(syserr);
RyoheiHagimoto 0:56c5742b9e2b 173 }
RyoheiHagimoto 0:56c5742b9e2b 174 }
RyoheiHagimoto 0:56c5742b9e2b 175 #endif
RyoheiHagimoto 0:56c5742b9e2b 176 else {
RyoheiHagimoto 0:56c5742b9e2b 177 err->buf = realloc(err->buf, len + 2);
RyoheiHagimoto 0:56c5742b9e2b 178 len += sprintf(err->buf + len, "\n");
RyoheiHagimoto 0:56c5742b9e2b 179 }
RyoheiHagimoto 0:56c5742b9e2b 180 return(err->buf);
RyoheiHagimoto 0:56c5742b9e2b 181 }
RyoheiHagimoto 0:56c5742b9e2b 182