1 /*Copyright (C) 2008-2009 Timothy B. Terriberry (tterribe@xiph.org) 2 You can redistribute this library and/or modify it under the terms of the 3 GNU Lesser General Public License as published by the Free Software 4 Foundation; either version 2.1 of the License, or (at your option) any later 5 version.*/ 6 #if !defined(_qrdec_H) 7 # define _qrdec_H (1) 8 9 #include <zbar.h> 10 11 typedef struct qr_code_data_entry qr_code_data_entry; 12 typedef struct qr_code_data qr_code_data; 13 typedef struct qr_code_data_list qr_code_data_list; 14 15 typedef enum qr_mode{ 16 /*Numeric digits ('0'...'9').*/ 17 QR_MODE_NUM=1, 18 /*Alphanumeric characters ('0'...'9', 'A'...'Z', plus the punctuation 19 ' ', '$', '%', '*', '+', '-', '.', '/', ':').*/ 20 QR_MODE_ALNUM, 21 /*Structured-append header.*/ 22 QR_MODE_STRUCT, 23 /*Raw 8-bit bytes.*/ 24 QR_MODE_BYTE, 25 /*FNC1 marker (for more info, see http://www.mecsw.com/specs/uccean128.html). 26 In the "first position" data is formatted in accordance with GS1 General 27 Specifications.*/ 28 QR_MODE_FNC1_1ST, 29 /*Mode 6 reserved?*/ 30 /*Extended Channel Interpretation code.*/ 31 QR_MODE_ECI=7, 32 /*SJIS kanji characters.*/ 33 QR_MODE_KANJI, 34 /*FNC1 marker (for more info, see http://www.mecsw.com/specs/uccean128.html). 35 In the "second position" data is formatted in accordance with an industry 36 application as specified by AIM Inc.*/ 37 QR_MODE_FNC1_2ND 38 }qr_mode; 39 40 /*Check if a mode has a data buffer associated with it. 41 Currently this is only modes with exactly one bit set.*/ 42 #define QR_MODE_HAS_DATA(_mode) (!((_mode)&(_mode)-1)) 43 44 /*ECI may be used to signal a character encoding for the data.*/ 45 typedef enum qr_eci_encoding{ 46 /*GLI0 is like CP437, but the encoding is reset at the beginning of each 47 structured append symbol.*/ 48 QR_ECI_GLI0, 49 /*GLI1 is like ISO8859_1, but the encoding is reset at the beginning of each 50 structured append symbol.*/ 51 QR_ECI_GLI1, 52 /*The remaining encodings do not reset at the start of the next structured 53 append symbol.*/ 54 QR_ECI_CP437, 55 /*Western European.*/ 56 QR_ECI_ISO8859_1, 57 /*Central European.*/ 58 QR_ECI_ISO8859_2, 59 /*South European.*/ 60 QR_ECI_ISO8859_3, 61 /*North European.*/ 62 QR_ECI_ISO8859_4, 63 /*Cyrillic.*/ 64 QR_ECI_ISO8859_5, 65 /*Arabic.*/ 66 QR_ECI_ISO8859_6, 67 /*Greek.*/ 68 QR_ECI_ISO8859_7, 69 /*Hebrew.*/ 70 QR_ECI_ISO8859_8, 71 /*Turkish.*/ 72 QR_ECI_ISO8859_9, 73 /*Nordic.*/ 74 QR_ECI_ISO8859_10, 75 /*Thai.*/ 76 QR_ECI_ISO8859_11, 77 /*There is no ISO/IEC 8859-12.*/ 78 /*Baltic rim.*/ 79 QR_ECI_ISO8859_13=QR_ECI_ISO8859_11+2, 80 /*Celtic.*/ 81 QR_ECI_ISO8859_14, 82 /*Western European with euro.*/ 83 QR_ECI_ISO8859_15, 84 /*South-Eastern European (with euro).*/ 85 QR_ECI_ISO8859_16, 86 /*ECI 000019 is reserved?*/ 87 /*Shift-JIS.*/ 88 QR_ECI_SJIS=20 89 }qr_eci_encoding; 90 91 92 /*A single unit of parsed QR code data.*/ 93 struct qr_code_data_entry{ 94 /*The mode of this data block.*/ 95 qr_mode mode; 96 union{ 97 /*Data buffer for modes that have one.*/ 98 struct{ 99 unsigned char *buf; 100 int len; 101 }data; 102 /*Decoded "Extended Channel Interpretation" data.*/ 103 unsigned eci; 104 /*Structured-append header data.*/ 105 struct{ 106 unsigned char sa_index; 107 unsigned char sa_size; 108 unsigned char sa_parity; 109 }sa; 110 }payload; 111 }; 112 113 114 115 /*Low-level QR code data.*/ 116 struct qr_code_data{ 117 /*The decoded data entries.*/ 118 qr_code_data_entry *entries; 119 int nentries; 120 /*The code version (1...40).*/ 121 unsigned char version; 122 /*The ECC level (0...3, corresponding to 'L', 'M', 'Q', and 'H').*/ 123 unsigned char ecc_level; 124 /*Structured-append information.*/ 125 /*The index of this code in the structured-append group. 126 If sa_size is zero, this is undefined.*/ 127 unsigned char sa_index; 128 /*The size of the structured-append group, or 0 if there was no S-A header.*/ 129 unsigned char sa_size; 130 /*The parity of the entire structured-append group. 131 If sa_size is zero, this is undefined.*/ 132 unsigned char sa_parity; 133 /*The parity of this code. 134 If sa_size is zero, this is undefined.*/ 135 unsigned char self_parity; 136 /*An approximate bounding box for the code. 137 Points appear in the order up-left, up-right, down-left, down-right, 138 relative to the orientation of the QR code.*/ 139 qr_point bbox[4]; 140 }; 141 142 143 struct qr_code_data_list{ 144 qr_code_data *qrdata; 145 int nqrdata; 146 int cqrdata; 147 }; 148 149 150 /*Extract symbol data from a list of QR codes and attach to the image. 151 All text is converted to UTF-8. 152 Any structured-append group that does not have all of its members is decoded 153 as ZBAR_PARTIAL with ZBAR_PARTIAL components for the discontinuities. 154 Note that isolated members of a structured-append group may be decoded with 155 the wrong character set, since the correct setting cannot be propagated 156 between codes. 157 Return: The number of symbols which were successfully extracted from the 158 codes; this will be at most the number of codes.*/ 159 int qr_code_data_list_extract_text(const qr_code_data_list *_qrlist, 160 zbar_image_scanner_t *iscn, 161 unsigned width, unsigned height); 162 163 164 /*TODO: Parse DoCoMo standard barcode data formats. 165 See http://www.nttdocomo.co.jp/english/service/imode/make/content/barcode/function/application/ 166 for details.*/ 167 168 #endif 169