1 /* quirc -- QR-code recognition library 2 * Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef QUIRC_INTERNAL_H_ 18 #define QUIRC_INTERNAL_H_ 19 20 #include <quirc.h> 21 22 #define QUIRC_PIXEL_WHITE 0 23 #define QUIRC_PIXEL_BLACK 1 24 #define QUIRC_PIXEL_REGION 2 25 26 #ifndef QUIRC_MAX_REGIONS 27 #define QUIRC_MAX_REGIONS 254 28 #endif 29 #define QUIRC_MAX_CAPSTONES 32 30 #define QUIRC_MAX_GRIDS 8 31 32 #define QUIRC_PERSPECTIVE_PARAMS 8 33 34 #if QUIRC_MAX_REGIONS < UINT8_MAX 35 #define QUIRC_PIXEL_ALIAS_IMAGE 1 36 typedef uint8_t quirc_pixel_t; 37 #elif QUIRC_MAX_REGIONS < UINT16_MAX 38 #define QUIRC_PIXEL_ALIAS_IMAGE 0 39 typedef uint16_t quirc_pixel_t; 40 #else 41 #error "QUIRC_MAX_REGIONS > 65534 is not supported" 42 #endif 43 44 struct quirc_region { 45 struct quirc_point seed; 46 int count; 47 int capstone; 48 }; 49 50 struct quirc_capstone { 51 int ring; 52 int stone; 53 54 struct quirc_point corners[4]; 55 struct quirc_point center; 56 double c[QUIRC_PERSPECTIVE_PARAMS]; 57 58 int qr_grid; 59 }; 60 61 struct quirc_grid { 62 /* Capstone indices */ 63 int caps[3]; 64 65 /* Alignment pattern region and corner */ 66 int align_region; 67 struct quirc_point align; 68 69 /* Timing pattern endpoints */ 70 struct quirc_point tpep[3]; 71 int hscan; 72 int vscan; 73 74 /* Grid size and perspective transform */ 75 int grid_size; 76 double c[QUIRC_PERSPECTIVE_PARAMS]; 77 }; 78 79 struct quirc { 80 uint8_t *image; 81 quirc_pixel_t *pixels; 82 int w; 83 int h; 84 85 int num_regions; 86 struct quirc_region regions[QUIRC_MAX_REGIONS]; 87 88 int num_capstones; 89 struct quirc_capstone capstones[QUIRC_MAX_CAPSTONES]; 90 91 int num_grids; 92 struct quirc_grid grids[QUIRC_MAX_GRIDS]; 93 }; 94 95 /************************************************************************ 96 * QR-code version information database 97 */ 98 99 #define QUIRC_MAX_VERSION 40 100 #define QUIRC_MAX_ALIGNMENT 7 101 102 struct quirc_rs_params { 103 int bs; /* Small block size */ 104 int dw; /* Small data words */ 105 int ns; /* Number of small blocks */ 106 }; 107 108 struct quirc_version_info { 109 int data_bytes; 110 int apat[QUIRC_MAX_ALIGNMENT]; 111 struct quirc_rs_params ecc[4]; 112 }; 113 114 extern const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1]; 115 116 #endif 117