qrdec.h 5.2 KB

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