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 #include <stdio.h>
RyoheiHagimoto 0:56c5742b9e2b 2 #include <stdlib.h>
RyoheiHagimoto 0:56c5742b9e2b 3 #if (0) // png is not used
RyoheiHagimoto 0:56c5742b9e2b 4 #include <png.h>
RyoheiHagimoto 0:56c5742b9e2b 5 #endif
RyoheiHagimoto 0:56c5742b9e2b 6 #include <zbar.h>
RyoheiHagimoto 0:56c5742b9e2b 7
RyoheiHagimoto 0:56c5742b9e2b 8 zbar_image_scanner_t *scanner = NULL;
RyoheiHagimoto 0:56c5742b9e2b 9
RyoheiHagimoto 0:56c5742b9e2b 10 /* to complete a runnable example, this abbreviated implementation of
RyoheiHagimoto 0:56c5742b9e2b 11 * get_data() will use libpng to read an image file. refer to libpng
RyoheiHagimoto 0:56c5742b9e2b 12 * documentation for details
RyoheiHagimoto 0:56c5742b9e2b 13 */
RyoheiHagimoto 0:56c5742b9e2b 14 #if (0) // png is not used
RyoheiHagimoto 0:56c5742b9e2b 15 static void get_data (const char *name,
RyoheiHagimoto 0:56c5742b9e2b 16 int *width, int *height,
RyoheiHagimoto 0:56c5742b9e2b 17 void **raw)
RyoheiHagimoto 0:56c5742b9e2b 18 {
RyoheiHagimoto 0:56c5742b9e2b 19 FILE *file = fopen(name, "rb");
RyoheiHagimoto 0:56c5742b9e2b 20 if(!file) exit(2);
RyoheiHagimoto 0:56c5742b9e2b 21 png_structp png =
RyoheiHagimoto 0:56c5742b9e2b 22 png_create_read_struct(PNG_LIBPNG_VER_STRING,
RyoheiHagimoto 0:56c5742b9e2b 23 NULL, NULL, NULL);
RyoheiHagimoto 0:56c5742b9e2b 24 if(!png) exit(3);
RyoheiHagimoto 0:56c5742b9e2b 25 if(setjmp(png_jmpbuf(png))) exit(4);
RyoheiHagimoto 0:56c5742b9e2b 26 png_infop info = png_create_info_struct(png);
RyoheiHagimoto 0:56c5742b9e2b 27 if(!info) exit(5);
RyoheiHagimoto 0:56c5742b9e2b 28 png_init_io(png, file);
RyoheiHagimoto 0:56c5742b9e2b 29 png_read_info(png, info);
RyoheiHagimoto 0:56c5742b9e2b 30 /* configure for 8bpp grayscale input */
RyoheiHagimoto 0:56c5742b9e2b 31 int color = png_get_color_type(png, info);
RyoheiHagimoto 0:56c5742b9e2b 32 int bits = png_get_bit_depth(png, info);
RyoheiHagimoto 0:56c5742b9e2b 33 if(color & PNG_COLOR_TYPE_PALETTE)
RyoheiHagimoto 0:56c5742b9e2b 34 png_set_palette_to_rgb(png);
RyoheiHagimoto 0:56c5742b9e2b 35 if(color == PNG_COLOR_TYPE_GRAY && bits < 8)
RyoheiHagimoto 0:56c5742b9e2b 36 png_set_gray_1_2_4_to_8(png);
RyoheiHagimoto 0:56c5742b9e2b 37 if(bits == 16)
RyoheiHagimoto 0:56c5742b9e2b 38 png_set_strip_16(png);
RyoheiHagimoto 0:56c5742b9e2b 39 if(color & PNG_COLOR_MASK_ALPHA)
RyoheiHagimoto 0:56c5742b9e2b 40 png_set_strip_alpha(png);
RyoheiHagimoto 0:56c5742b9e2b 41 if(color & PNG_COLOR_MASK_COLOR)
RyoheiHagimoto 0:56c5742b9e2b 42 png_set_rgb_to_gray_fixed(png, 1, -1, -1);
RyoheiHagimoto 0:56c5742b9e2b 43 /* allocate image */
RyoheiHagimoto 0:56c5742b9e2b 44 *width = png_get_image_width(png, info);
RyoheiHagimoto 0:56c5742b9e2b 45 *height = png_get_image_height(png, info);
RyoheiHagimoto 0:56c5742b9e2b 46 *raw = malloc(*width * *height);
RyoheiHagimoto 0:56c5742b9e2b 47 png_bytep rows[*height];
RyoheiHagimoto 0:56c5742b9e2b 48 int i;
RyoheiHagimoto 0:56c5742b9e2b 49 for(i = 0; i < *height; i++)
RyoheiHagimoto 0:56c5742b9e2b 50 rows[i] = *raw + (*width * i);
RyoheiHagimoto 0:56c5742b9e2b 51 png_read_image(png, rows);
RyoheiHagimoto 0:56c5742b9e2b 52 }
RyoheiHagimoto 0:56c5742b9e2b 53 #endif // png is not used
RyoheiHagimoto 0:56c5742b9e2b 54 #if (1) // function name and arguments are changed.
RyoheiHagimoto 0:56c5742b9e2b 55 int zbar_main (void* image_buff, int width, int height)
RyoheiHagimoto 0:56c5742b9e2b 56 #else
RyoheiHagimoto 0:56c5742b9e2b 57 int main (int argc, char **argv)
RyoheiHagimoto 0:56c5742b9e2b 58 #endif
RyoheiHagimoto 0:56c5742b9e2b 59 {
RyoheiHagimoto 0:56c5742b9e2b 60 #if (1) // arguments are changed
RyoheiHagimoto 0:56c5742b9e2b 61 if((image_buff == NULL)||(width < 1)||(height < 1)) return(1);
RyoheiHagimoto 0:56c5742b9e2b 62 #else
RyoheiHagimoto 0:56c5742b9e2b 63 if(argc < 2) return(1);
RyoheiHagimoto 0:56c5742b9e2b 64 #endif
RyoheiHagimoto 0:56c5742b9e2b 65
RyoheiHagimoto 0:56c5742b9e2b 66 /* create a reader */
RyoheiHagimoto 0:56c5742b9e2b 67 scanner = zbar_image_scanner_create();
RyoheiHagimoto 0:56c5742b9e2b 68
RyoheiHagimoto 0:56c5742b9e2b 69 /* configure the reader */
RyoheiHagimoto 0:56c5742b9e2b 70 zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1);
RyoheiHagimoto 0:56c5742b9e2b 71
RyoheiHagimoto 0:56c5742b9e2b 72 /* obtain image data */
RyoheiHagimoto 0:56c5742b9e2b 73 #if (1) // width, height, raw data are fixed
RyoheiHagimoto 0:56c5742b9e2b 74 void *raw = image_buff;
RyoheiHagimoto 0:56c5742b9e2b 75 #else
RyoheiHagimoto 0:56c5742b9e2b 76 int width = 0, height = 0;
RyoheiHagimoto 0:56c5742b9e2b 77 void *raw = NULL;
RyoheiHagimoto 0:56c5742b9e2b 78 get_data(argv[1], &width, &height, &raw);
RyoheiHagimoto 0:56c5742b9e2b 79 #endif
RyoheiHagimoto 0:56c5742b9e2b 80
RyoheiHagimoto 0:56c5742b9e2b 81 /* wrap image data */
RyoheiHagimoto 0:56c5742b9e2b 82 zbar_image_t *image = zbar_image_create();
RyoheiHagimoto 0:56c5742b9e2b 83 zbar_image_set_format(image, *(int*)"Y800");
RyoheiHagimoto 0:56c5742b9e2b 84 zbar_image_set_size(image, width, height);
RyoheiHagimoto 0:56c5742b9e2b 85 zbar_image_set_data(image, raw, width * height, zbar_image_free_data);
RyoheiHagimoto 0:56c5742b9e2b 86
RyoheiHagimoto 0:56c5742b9e2b 87 /* scan the image for barcodes */
RyoheiHagimoto 0:56c5742b9e2b 88 int n = zbar_scan_image(scanner, image);
RyoheiHagimoto 0:56c5742b9e2b 89
RyoheiHagimoto 0:56c5742b9e2b 90 /* extract results */
RyoheiHagimoto 0:56c5742b9e2b 91 const zbar_symbol_t *symbol = zbar_image_first_symbol(image);
RyoheiHagimoto 0:56c5742b9e2b 92 if ( symbol ) {
RyoheiHagimoto 0:56c5742b9e2b 93 for(; symbol; symbol = zbar_symbol_next(symbol)) {
RyoheiHagimoto 0:56c5742b9e2b 94 /* do something useful with results */
RyoheiHagimoto 0:56c5742b9e2b 95 zbar_symbol_type_t typ = zbar_symbol_get_type(symbol);
RyoheiHagimoto 0:56c5742b9e2b 96 const char *data = zbar_symbol_get_data(symbol);
RyoheiHagimoto 0:56c5742b9e2b 97 printf("decoded %s symbol \"%s\"\n",
RyoheiHagimoto 0:56c5742b9e2b 98 zbar_get_symbol_name(typ), data);
RyoheiHagimoto 0:56c5742b9e2b 99 }
RyoheiHagimoto 0:56c5742b9e2b 100 }
RyoheiHagimoto 0:56c5742b9e2b 101 else {
RyoheiHagimoto 0:56c5742b9e2b 102 printf("No Code detected.\n");
RyoheiHagimoto 0:56c5742b9e2b 103 }
RyoheiHagimoto 0:56c5742b9e2b 104
RyoheiHagimoto 0:56c5742b9e2b 105 /* clean up */
RyoheiHagimoto 0:56c5742b9e2b 106 zbar_image_destroy(image);
RyoheiHagimoto 0:56c5742b9e2b 107 zbar_image_scanner_destroy(scanner);
RyoheiHagimoto 0:56c5742b9e2b 108
RyoheiHagimoto 0:56c5742b9e2b 109 return(0);
RyoheiHagimoto 0:56c5742b9e2b 110 }
RyoheiHagimoto 0:56c5742b9e2b 111