zbar.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. /*------------------------------------------------------------------------
  2. * Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net>
  3. *
  4. * This file is part of the ZBar Bar Code Reader.
  5. *
  6. * The ZBar Bar Code Reader is free software; you can redistribute it
  7. * and/or modify it under the terms of the GNU Lesser Public License as
  8. * published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * The ZBar Bar Code Reader is distributed in the hope that it will be
  12. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser Public License
  17. * along with the ZBar Bar Code Reader; if not, write to the Free
  18. * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  19. * Boston, MA 02110-1301 USA
  20. *
  21. * http://sourceforge.net/projects/zbar
  22. *------------------------------------------------------------------------*/
  23. #ifndef _ZBAR_H_
  24. #define _ZBAR_H_
  25. #include "stdio.h"
  26. #include "stdlib.h"
  27. #include "string.h"
  28. #include "zbar_config.h"
  29. #include "cs_types.h"
  30. #ifdef WIN32
  31. typedef unsigned int uint32_t;
  32. typedef unsigned char uint8_t;
  33. typedef unsigned short uint16_t;
  34. typedef unsigned int size_t;
  35. #define inline
  36. #define HAVE_INTTYPES_H
  37. #endif
  38. /** @file
  39. * ZBar Barcode Reader C API definition
  40. */
  41. /** @mainpage
  42. *
  43. * interface to the barcode reader is available at several levels.
  44. * most applications will want to use the high-level interfaces:
  45. *
  46. * @section high-level High-Level Interfaces
  47. *
  48. * these interfaces wrap all library functionality into an easy-to-use
  49. * package for a specific toolkit:
  50. * - the "GTK+ 2.x widget" may be used with GTK GUI applications. a
  51. * Python wrapper is included for PyGtk
  52. * - the @ref zbar::QZBar "Qt4 widget" may be used with Qt GUI
  53. * applications
  54. * - the Processor interface (in @ref c-processor "C" or @ref
  55. * zbar::Processor "C++") adds a scanning window to an application
  56. * with no GUI.
  57. *
  58. * @section mid-level Intermediate Interfaces
  59. *
  60. * building blocks used to construct high-level interfaces:
  61. * - the ImageScanner (in @ref c-imagescanner "C" or @ref
  62. * zbar::ImageScanner "C++") looks for barcodes in a library defined
  63. * image object
  64. * - the Window abstraction (in @ref c-window "C" or @ref
  65. * zbar::Window "C++") sinks library images, displaying them on the
  66. * platform display
  67. * - the Video abstraction (in @ref c-video "C" or @ref zbar::Video
  68. * "C++") sources library images from a video device
  69. *
  70. * @section low-level Low-Level Interfaces
  71. *
  72. * direct interaction with barcode scanning and decoding:
  73. * - the Scanner (in @ref c-scanner "C" or @ref zbar::Scanner "C++")
  74. * looks for barcodes in a linear intensity sample stream
  75. * - the Decoder (in @ref c-decoder "C" or @ref zbar::Decoder "C++")
  76. * extracts barcodes from a stream of bar and space widths
  77. */
  78. #define INT_MIN (-1<<30)
  79. #ifdef __cplusplus
  80. /** C++ namespace for library interfaces */
  81. namespace zbar {
  82. extern "C" {
  83. #endif
  84. /** @name Global library interfaces */
  85. /*@{*/
  86. /** "color" of element: bar or space. */
  87. typedef enum zbar_color_e {
  88. ZBAR_SPACE = 0, /**< light area or space between bars */
  89. ZBAR_BAR = 1, /**< dark area or colored bar segment */
  90. } zbar_color_t;
  91. /** decoded symbol type. */
  92. typedef enum zbar_symbol_type_e {
  93. ZBAR_NONE = 0, /**< no symbol decoded */
  94. ZBAR_PARTIAL = 1, /**< intermediate status */
  95. ZBAR_EAN8 = 8, /**< EAN-8 */
  96. ZBAR_UPCE = 9, /**< UPC-E */
  97. ZBAR_ISBN10 = 10, /**< ISBN-10 (from EAN-13). @since 0.4 */
  98. ZBAR_UPCA = 12, /**< UPC-A */
  99. ZBAR_EAN13 = 13, /**< EAN-13 */
  100. ZBAR_ISBN13 = 14, /**< ISBN-13 (from EAN-13). @since 0.4 */
  101. ZBAR_I25 = 25, /**< Interleaved 2 of 5. @since 0.4 */
  102. ZBAR_CODE39 = 39, /**< Code 39. @since 0.4 */
  103. ZBAR_PDF417 = 57, /**< PDF417. @since 0.6 */
  104. ZBAR_QRCODE = 64, /**< QR Code. @since 0.10 */
  105. ZBAR_CODE128 = 128, /**< Code 128 */
  106. ZBAR_SYMBOL = 0x00ff, /**< mask for base symbol type */
  107. ZBAR_ADDON2 = 0x0200, /**< 2-digit add-on flag */
  108. ZBAR_ADDON5 = 0x0500, /**< 5-digit add-on flag */
  109. ZBAR_ADDON = 0x0700, /**< add-on flag mask */
  110. } zbar_symbol_type_t;
  111. /** error codes. */
  112. typedef enum zbar_error_e {
  113. ZBAR_OK = 0, /**< no error */
  114. ZBAR_ERR_NOMEM, /**< out of memory */
  115. ZBAR_ERR_INTERNAL, /**< internal library error */
  116. ZBAR_ERR_UNSUPPORTED, /**< unsupported request */
  117. ZBAR_ERR_INVALID, /**< invalid request */
  118. ZBAR_ERR_SYSTEM, /**< system error */
  119. ZBAR_ERR_LOCKING, /**< locking error */
  120. ZBAR_ERR_BUSY, /**< all resources busy */
  121. ZBAR_ERR_XDISPLAY, /**< X11 display error */
  122. ZBAR_ERR_XPROTO, /**< X11 protocol error */
  123. ZBAR_ERR_CLOSED, /**< output window is closed */
  124. ZBAR_ERR_WINAPI, /**< windows system error */
  125. ZBAR_ERR_NUM /**< number of error codes */
  126. } zbar_error_t;
  127. /** decoder configuration options.
  128. * @since 0.4
  129. */
  130. typedef enum zbar_config_e {
  131. ZBAR_CFG_ENABLE = 0, /**< enable symbology/feature */
  132. ZBAR_CFG_ADD_CHECK, /**< enable check digit when optional */
  133. ZBAR_CFG_EMIT_CHECK, /**< return check digit when present */
  134. ZBAR_CFG_ASCII, /**< enable full ASCII character set */
  135. ZBAR_CFG_NUM, /**< number of boolean decoder configs */
  136. ZBAR_CFG_MIN_LEN = 0x20, /**< minimum data length for valid decode */
  137. ZBAR_CFG_MAX_LEN, /**< maximum data length for valid decode */
  138. ZBAR_CFG_POSITION = 0x80, /**< enable scanner to collect position data */
  139. ZBAR_CFG_X_DENSITY = 0x100, /**< image scanner vertical scan density */
  140. ZBAR_CFG_Y_DENSITY, /**< image scanner horizontal scan density */
  141. } zbar_config_t;
  142. /** retrieve runtime library version information.
  143. * @param major set to the running major version (unless NULL)
  144. * @param minor set to the running minor version (unless NULL)
  145. * @returns 0
  146. */
  147. extern int zbar_version(unsigned *major,
  148. unsigned *minor);
  149. /** set global library debug level.
  150. * @param verbosity desired debug level. higher values create more spew
  151. */
  152. extern void zbar_set_verbosity(int verbosity);
  153. /** increase global library debug level.
  154. * eg, for -vvvv
  155. */
  156. extern void zbar_increase_verbosity(void);
  157. /** retrieve string name for symbol encoding.
  158. * @param sym symbol type encoding
  159. * @returns the static string name for the specified symbol type,
  160. * or "UNKNOWN" if the encoding is not recognized
  161. */
  162. extern const char *zbar_get_symbol_name(zbar_symbol_type_t sym);
  163. /** retrieve string name for addon encoding.
  164. * @param sym symbol type encoding
  165. * @returns static string name for any addon, or the empty string
  166. * if no addons were decoded
  167. */
  168. extern const char *zbar_get_addon_name(zbar_symbol_type_t sym);
  169. /** parse a configuration string of the form "[symbology.]config[=value]".
  170. * the config must match one of the recognized names.
  171. * the symbology, if present, must match one of the recognized names.
  172. * if symbology is unspecified, it will be set to 0.
  173. * if value is unspecified it will be set to 1.
  174. * @returns 0 if the config is parsed successfully, 1 otherwise
  175. * @since 0.4
  176. */
  177. extern int zbar_parse_config(const char *config_string,
  178. zbar_symbol_type_t *symbology,
  179. zbar_config_t *config,
  180. int *value);
  181. /** @internal type unsafe error API (don't use) */
  182. extern int _zbar_error_spew(const void *object,
  183. int verbosity);
  184. extern const char *_zbar_error_string(const void *object,
  185. int verbosity);
  186. extern zbar_error_t _zbar_get_error_code(const void *object);
  187. /*@}*/
  188. struct zbar_symbol_s;
  189. typedef struct zbar_symbol_s zbar_symbol_t;
  190. struct zbar_symbol_set_s;
  191. typedef struct zbar_symbol_set_s zbar_symbol_set_t;
  192. /*------------------------------------------------------------*/
  193. /** @name Symbol interface
  194. * decoded barcode symbol result object. stores type, data, and image
  195. * location of decoded symbol. all memory is owned by the library
  196. */
  197. /*@{*/
  198. /** @typedef zbar_symbol_t
  199. * opaque decoded symbol object.
  200. */
  201. /** symbol reference count manipulation.
  202. * increment the reference count when you store a new reference to the
  203. * symbol. decrement when the reference is no longer used. do not
  204. * refer to the symbol once the count is decremented and the
  205. * containing image has been recycled or destroyed.
  206. * @note the containing image holds a reference to the symbol, so you
  207. * only need to use this if you keep a symbol after the image has been
  208. * destroyed or reused.
  209. * @since 0.9
  210. */
  211. extern void zbar_symbol_ref(const zbar_symbol_t *symbol,
  212. int refs);
  213. /** retrieve type of decoded symbol.
  214. * @returns the symbol type
  215. */
  216. extern zbar_symbol_type_t zbar_symbol_get_type(const zbar_symbol_t *symbol);
  217. /** retrieve data decoded from symbol.
  218. * @returns the data string
  219. */
  220. extern const char *zbar_symbol_get_data(const zbar_symbol_t *symbol);
  221. /** retrieve length of binary data.
  222. * @returns the length of the decoded data
  223. */
  224. extern unsigned int zbar_symbol_get_data_length(const zbar_symbol_t *symbol);
  225. /** retrieve a symbol confidence metric.
  226. * @returns an unscaled, relative quantity: larger values are better
  227. * than smaller values, where "large" and "small" are application
  228. * dependent.
  229. * @note expect the exact definition of this quantity to change as the
  230. * metric is refined. currently, only the ordered relationship
  231. * between two values is defined and will remain stable in the future
  232. * @since 0.9
  233. */
  234. extern int zbar_symbol_get_quality(const zbar_symbol_t *symbol);
  235. /** retrieve current cache count. when the cache is enabled for the
  236. * image_scanner this provides inter-frame reliability and redundancy
  237. * information for video streams.
  238. * @returns < 0 if symbol is still uncertain.
  239. * @returns 0 if symbol is newly verified.
  240. * @returns > 0 for duplicate symbols
  241. */
  242. extern int zbar_symbol_get_count(const zbar_symbol_t *symbol);
  243. /** retrieve the number of points in the location polygon. the
  244. * location polygon defines the image area that the symbol was
  245. * extracted from.
  246. * @returns the number of points in the location polygon
  247. * @note this is currently not a polygon, but the scan locations
  248. * where the symbol was decoded
  249. */
  250. extern unsigned zbar_symbol_get_loc_size(const zbar_symbol_t *symbol);
  251. /** retrieve location polygon x-coordinates.
  252. * points are specified by 0-based index.
  253. * @returns the x-coordinate for a point in the location polygon.
  254. * @returns -1 if index is out of range
  255. */
  256. extern int zbar_symbol_get_loc_x(const zbar_symbol_t *symbol,
  257. unsigned index);
  258. /** retrieve location polygon y-coordinates.
  259. * points are specified by 0-based index.
  260. * @returns the y-coordinate for a point in the location polygon.
  261. * @returns -1 if index is out of range
  262. */
  263. extern int zbar_symbol_get_loc_y(const zbar_symbol_t *symbol,
  264. unsigned index);
  265. /** iterate the set to which this symbol belongs (there can be only one).
  266. * @returns the next symbol in the set, or
  267. * @returns NULL when no more results are available
  268. */
  269. extern const zbar_symbol_t *zbar_symbol_next(const zbar_symbol_t *symbol);
  270. /** retrieve components of a composite result.
  271. * @returns the symbol set containing the components
  272. * @returns NULL if the symbol is already a physical symbol
  273. * @since 0.10
  274. */
  275. extern const zbar_symbol_set_t*
  276. zbar_symbol_get_components(const zbar_symbol_t *symbol);
  277. /** iterate components of a composite result.
  278. * @returns the first physical component symbol of a composite result
  279. * @returns NULL if the symbol is already a physical symbol
  280. * @since 0.10
  281. */
  282. extern const zbar_symbol_t*
  283. zbar_symbol_first_component(const zbar_symbol_t *symbol);
  284. /** print XML symbol element representation to user result buffer.
  285. * @see http://zbar.sourceforge.net/2008/barcode.xsd for the schema.
  286. * @param symbol is the symbol to print
  287. * @param buffer is the inout result pointer, it will be reallocated
  288. * with a larger size if necessary.
  289. * @param buflen is inout length of the result buffer.
  290. * @returns the buffer pointer
  291. * @since 0.6
  292. */
  293. extern char *zbar_symbol_xml(const zbar_symbol_t *symbol,
  294. char **buffer,
  295. unsigned *buflen);
  296. /*@}*/
  297. /*------------------------------------------------------------*/
  298. /** @name Symbol Set interface
  299. * container for decoded result symbols associated with an image
  300. * or a composite symbol.
  301. * @since 0.10
  302. */
  303. /*@{*/
  304. /** @typedef zbar_symbol_set_t
  305. * opaque symbol iterator object.
  306. * @since 0.10
  307. */
  308. /** reference count manipulation.
  309. * increment the reference count when you store a new reference.
  310. * decrement when the reference is no longer used. do not refer to
  311. * the object any longer once references have been released.
  312. * @since 0.10
  313. */
  314. extern void zbar_symbol_set_ref(const zbar_symbol_set_t *symbols,
  315. int refs);
  316. /** retrieve set size.
  317. * @returns the number of symbols in the set.
  318. * @since 0.10
  319. */
  320. extern int zbar_symbol_set_get_size(const zbar_symbol_set_t *symbols);
  321. /** set iterator.
  322. * @returns the first decoded symbol result in a set
  323. * @returns NULL if the set is empty
  324. * @since 0.10
  325. */
  326. extern const zbar_symbol_t*
  327. zbar_symbol_set_first_symbol(const zbar_symbol_set_t *symbols);
  328. /*@}*/
  329. /*------------------------------------------------------------*/
  330. /** @name Image interface
  331. * stores image data samples along with associated format and size
  332. * metadata
  333. */
  334. /*@{*/
  335. struct zbar_image_s;
  336. /** opaque image object. */
  337. typedef struct zbar_image_s zbar_image_t;
  338. /** cleanup handler callback function.
  339. * called to free sample data when an image is destroyed.
  340. */
  341. typedef void (zbar_image_cleanup_handler_t)(zbar_image_t *image);
  342. /** data handler callback function.
  343. * called when decoded symbol results are available for an image
  344. */
  345. typedef void (zbar_image_data_handler_t)(zbar_image_t *image,
  346. const void *userdata);
  347. /** new image constructor.
  348. * @returns a new image object with uninitialized data and format.
  349. * this image should be destroyed (using zbar_image_destroy()) as
  350. * soon as the application is finished with it
  351. */
  352. extern zbar_image_t *zbar_image_create(void);
  353. /** image destructor. all images created by or returned to the
  354. * application should be destroyed using this function. when an image
  355. * is destroyed, the associated data cleanup handler will be invoked
  356. * if available
  357. * @note make no assumptions about the image or the data buffer.
  358. * they may not be destroyed/cleaned immediately if the library
  359. * is still using them. if necessary, use the cleanup handler hook
  360. * to keep track of image data buffers
  361. */
  362. extern void zbar_image_destroy(zbar_image_t *image);
  363. /** image reference count manipulation.
  364. * increment the reference count when you store a new reference to the
  365. * image. decrement when the reference is no longer used. do not
  366. * refer to the image any longer once the count is decremented.
  367. * zbar_image_ref(image, -1) is the same as zbar_image_destroy(image)
  368. * @since 0.5
  369. */
  370. extern void zbar_image_ref(zbar_image_t *image,
  371. int refs);
  372. /** image format conversion. refer to the documentation for supported
  373. * image formats
  374. * @returns a @em new image with the sample data from the original image
  375. * converted to the requested format. the original image is
  376. * unaffected.
  377. * @note the converted image size may be rounded (up) due to format
  378. * constraints
  379. */
  380. extern zbar_image_t *zbar_image_convert(const zbar_image_t *image,
  381. unsigned long format);
  382. /** image format conversion with crop/pad.
  383. * if the requested size is larger than the image, the last row/column
  384. * are duplicated to cover the difference. if the requested size is
  385. * smaller than the image, the extra rows/columns are dropped from the
  386. * right/bottom.
  387. * @returns a @em new image with the sample data from the original
  388. * image converted to the requested format and size.
  389. * @note the image is @em not scaled
  390. * @see zbar_image_convert()
  391. * @since 0.4
  392. */
  393. extern zbar_image_t *zbar_image_convert_resize(const zbar_image_t *image,
  394. unsigned long format,
  395. unsigned width,
  396. unsigned height);
  397. /** retrieve the image format.
  398. * @returns the fourcc describing the format of the image sample data
  399. */
  400. extern unsigned long zbar_image_get_format(const zbar_image_t *image);
  401. /** retrieve a "sequence" (page/frame) number associated with this image.
  402. * @since 0.6
  403. */
  404. extern unsigned zbar_image_get_sequence(const zbar_image_t *image);
  405. /** retrieve the width of the image.
  406. * @returns the width in sample columns
  407. */
  408. extern unsigned zbar_image_get_width(const zbar_image_t *image);
  409. /** retrieve the height of the image.
  410. * @returns the height in sample rows
  411. */
  412. extern unsigned zbar_image_get_height(const zbar_image_t *image);
  413. /** return the image sample data. the returned data buffer is only
  414. * valid until zbar_image_destroy() is called
  415. */
  416. extern const void *zbar_image_get_data(const zbar_image_t *image);
  417. /** return the size of image data.
  418. * @since 0.6
  419. */
  420. extern unsigned long zbar_image_get_data_length(const zbar_image_t *img);
  421. /** retrieve the decoded results.
  422. * @returns the (possibly empty) set of decoded symbols
  423. * @returns NULL if the image has not been scanned
  424. * @since 0.10
  425. */
  426. extern const zbar_symbol_set_t*
  427. zbar_image_get_symbols(const zbar_image_t *image);
  428. /** associate the specified symbol set with the image, replacing any
  429. * existing results. use NULL to release the current results from the
  430. * image.
  431. * @see zbar_image_scanner_recycle_image()
  432. * @since 0.10
  433. */
  434. extern void zbar_image_set_symbols(zbar_image_t *image,
  435. const zbar_symbol_set_t *symbols);
  436. /** image_scanner decode result iterator.
  437. * @returns the first decoded symbol result for an image
  438. * or NULL if no results are available
  439. */
  440. extern const zbar_symbol_t*
  441. zbar_image_first_symbol(const zbar_image_t *image);
  442. /** specify the fourcc image format code for image sample data.
  443. * refer to the documentation for supported formats.
  444. * @note this does not convert the data!
  445. * (see zbar_image_convert() for that)
  446. */
  447. extern void zbar_image_set_format(zbar_image_t *image,
  448. unsigned long format);
  449. /** associate a "sequence" (page/frame) number with this image.
  450. * @since 0.6
  451. */
  452. extern void zbar_image_set_sequence(zbar_image_t *image,
  453. unsigned sequence_num);
  454. /** specify the pixel size of the image.
  455. * @note this does not affect the data!
  456. */
  457. extern void zbar_image_set_size(zbar_image_t *image,
  458. unsigned width,
  459. unsigned height);
  460. /** specify image sample data. when image data is no longer needed by
  461. * the library the specific data cleanup handler will be called
  462. * (unless NULL)
  463. * @note application image data will not be modified by the library
  464. */
  465. extern void zbar_image_set_data(zbar_image_t *image,
  466. const void *data,
  467. unsigned long data_byte_length,
  468. zbar_image_cleanup_handler_t *cleanup_hndlr);
  469. /** built-in cleanup handler.
  470. * passes the image data buffer to free()
  471. */
  472. extern void zbar_image_free_data(zbar_image_t *image);
  473. /** associate user specified data value with an image.
  474. * @since 0.5
  475. */
  476. extern void zbar_image_set_userdata(zbar_image_t *image,
  477. void *userdata);
  478. /** return user specified data value associated with the image.
  479. * @since 0.5
  480. */
  481. extern void *zbar_image_get_userdata(const zbar_image_t *image);
  482. /** dump raw image data to a file for debug.
  483. * the data will be prefixed with a 16 byte header consisting of:
  484. * - 4 bytes uint = 0x676d697a ("zimg")
  485. * - 4 bytes format fourcc
  486. * - 2 bytes width
  487. * - 2 bytes height
  488. * - 4 bytes size of following image data in bytes
  489. * this header can be dumped w/eg:
  490. * @verbatim
  491. od -Ax -tx1z -N16 -w4 [file]
  492. @endverbatim
  493. * for some formats the image can be displayed/converted using
  494. * ImageMagick, eg:
  495. * @verbatim
  496. display -size 640x480+16 [-depth ?] [-sampling-factor ?x?] \
  497. {GRAY,RGB,UYVY,YUV}:[file]
  498. @endverbatim
  499. *
  500. * @param image the image object to dump
  501. * @param filebase base filename, appended with ".XXXX.zimg" where
  502. * XXXX is the format fourcc
  503. * @returns 0 on success or a system error code on failure
  504. */
  505. extern int zbar_image_write(const zbar_image_t *image,
  506. const char *filebase);
  507. /** read back an image in the format written by zbar_image_write()
  508. * @note TBD
  509. */
  510. extern zbar_image_t *zbar_image_read(char *filename);
  511. /*@}*/
  512. /*------------------------------------------------------------*/
  513. /** @name Processor interface
  514. * @anchor c-processor
  515. * high-level self-contained image processor.
  516. * processes video and images for barcodes, optionally displaying
  517. * images to a library owned output window
  518. */
  519. /*@{*/
  520. struct zbar_processor_s;
  521. /** opaque standalone processor object. */
  522. typedef struct zbar_processor_s zbar_processor_t;
  523. /** constructor.
  524. * if threaded is set and threading is available the processor
  525. * will spawn threads where appropriate to avoid blocking and
  526. * improve responsiveness
  527. */
  528. extern zbar_processor_t *zbar_processor_create(int threaded);
  529. /** destructor. cleans up all resources associated with the processor
  530. */
  531. extern void zbar_processor_destroy(zbar_processor_t *processor);
  532. /** (re)initialization.
  533. * opens a video input device and/or prepares to display output
  534. */
  535. extern int zbar_processor_init(zbar_processor_t *processor,
  536. const char *video_device,
  537. int enable_display);
  538. /** request a preferred size for the video image from the device.
  539. * the request may be adjusted or completely ignored by the driver.
  540. * @note must be called before zbar_processor_init()
  541. * @since 0.6
  542. */
  543. extern int zbar_processor_request_size(zbar_processor_t *processor,
  544. unsigned width,
  545. unsigned height);
  546. /** request a preferred video driver interface version for
  547. * debug/testing.
  548. * @note must be called before zbar_processor_init()
  549. * @since 0.6
  550. */
  551. extern int zbar_processor_request_interface(zbar_processor_t *processor,
  552. int version);
  553. /** request a preferred video I/O mode for debug/testing. You will
  554. * get errors if the driver does not support the specified mode.
  555. * @verbatim
  556. 0 = auto-detect
  557. 1 = force I/O using read()
  558. 2 = force memory mapped I/O using mmap()
  559. 3 = force USERPTR I/O (v4l2 only)
  560. @endverbatim
  561. * @note must be called before zbar_processor_init()
  562. * @since 0.7
  563. */
  564. extern int zbar_processor_request_iomode(zbar_processor_t *video,
  565. int iomode);
  566. /** force specific input and output formats for debug/testing.
  567. * @note must be called before zbar_processor_init()
  568. */
  569. extern int zbar_processor_force_format(zbar_processor_t *processor,
  570. unsigned long input_format,
  571. unsigned long output_format);
  572. /** setup result handler callback.
  573. * the specified function will be called by the processor whenever
  574. * new results are available from the video stream or a static image.
  575. * pass a NULL value to disable callbacks.
  576. * @param processor the object on which to set the handler.
  577. * @param handler the function to call when new results are available.
  578. * @param userdata is set as with zbar_processor_set_userdata().
  579. * @returns the previously registered handler
  580. */
  581. extern zbar_image_data_handler_t*
  582. zbar_processor_set_data_handler(zbar_processor_t *processor,
  583. zbar_image_data_handler_t *handler,
  584. const void *userdata);
  585. /** associate user specified data value with the processor.
  586. * @since 0.6
  587. */
  588. extern void zbar_processor_set_userdata(zbar_processor_t *processor,
  589. void *userdata);
  590. /** return user specified data value associated with the processor.
  591. * @since 0.6
  592. */
  593. extern void *zbar_processor_get_userdata(const zbar_processor_t *processor);
  594. /** set config for indicated symbology (0 for all) to specified value.
  595. * @returns 0 for success, non-0 for failure (config does not apply to
  596. * specified symbology, or value out of range)
  597. * @see zbar_decoder_set_config()
  598. * @since 0.4
  599. */
  600. extern int zbar_processor_set_config(zbar_processor_t *processor,
  601. zbar_symbol_type_t symbology,
  602. zbar_config_t config,
  603. int value);
  604. /** parse configuration string using zbar_parse_config()
  605. * and apply to processor using zbar_processor_set_config().
  606. * @returns 0 for success, non-0 for failure
  607. * @see zbar_parse_config()
  608. * @see zbar_processor_set_config()
  609. * @since 0.4
  610. */
  611. static inline int zbar_processor_parse_config (zbar_processor_t *processor,
  612. const char *config_string)
  613. {
  614. zbar_symbol_type_t sym;
  615. zbar_config_t cfg;
  616. int val;
  617. return(zbar_parse_config(config_string, &sym, &cfg, &val) ||
  618. zbar_processor_set_config(processor, sym, cfg, val));
  619. }
  620. /** retrieve the current state of the ouput window.
  621. * @returns 1 if the output window is currently displayed, 0 if not.
  622. * @returns -1 if an error occurs
  623. */
  624. extern int zbar_processor_is_visible(zbar_processor_t *processor);
  625. /** show or hide the display window owned by the library.
  626. * the size will be adjusted to the input size
  627. */
  628. extern int zbar_processor_set_visible(zbar_processor_t *processor,
  629. int visible);
  630. /** control the processor in free running video mode.
  631. * only works if video input is initialized. if threading is in use,
  632. * scanning will occur in the background, otherwise this is only
  633. * useful wrapping calls to zbar_processor_user_wait(). if the
  634. * library output window is visible, video display will be enabled.
  635. */
  636. extern int zbar_processor_set_active(zbar_processor_t *processor,
  637. int active);
  638. /** retrieve decode results for last scanned image/frame.
  639. * @returns the symbol set result container or NULL if no results are
  640. * available
  641. * @note the returned symbol set has its reference count incremented;
  642. * ensure that the count is decremented after use
  643. * @since 0.10
  644. */
  645. extern const zbar_symbol_set_t*
  646. zbar_processor_get_results(const zbar_processor_t *processor);
  647. /** wait for input to the display window from the user
  648. * (via mouse or keyboard).
  649. * @returns >0 when input is received, 0 if timeout ms expired
  650. * with no input or -1 in case of an error
  651. */
  652. extern int zbar_processor_user_wait(zbar_processor_t *processor,
  653. int timeout);
  654. /** process from the video stream until a result is available,
  655. * or the timeout (in milliseconds) expires.
  656. * specify a timeout of -1 to scan indefinitely
  657. * (zbar_processor_set_active() may still be used to abort the scan
  658. * from another thread).
  659. * if the library window is visible, video display will be enabled.
  660. * @note that multiple results may still be returned (despite the
  661. * name).
  662. * @returns >0 if symbols were successfully decoded,
  663. * 0 if no symbols were found (ie, the timeout expired)
  664. * or -1 if an error occurs
  665. */
  666. extern int zbar_process_one(zbar_processor_t *processor,
  667. int timeout);
  668. /** process the provided image for barcodes.
  669. * if the library window is visible, the image will be displayed.
  670. * @returns >0 if symbols were successfully decoded,
  671. * 0 if no symbols were found or -1 if an error occurs
  672. */
  673. extern int zbar_process_image(zbar_processor_t *processor,
  674. zbar_image_t *image);
  675. /** display detail for last processor error to stderr.
  676. * @returns a non-zero value suitable for passing to exit()
  677. */
  678. static inline int
  679. zbar_processor_error_spew (const zbar_processor_t *processor,
  680. int verbosity)
  681. {
  682. return(_zbar_error_spew(processor, verbosity));
  683. }
  684. /** retrieve the detail string for the last processor error. */
  685. static inline const char*
  686. zbar_processor_error_string (const zbar_processor_t *processor,
  687. int verbosity)
  688. {
  689. return(_zbar_error_string(processor, verbosity));
  690. }
  691. /** retrieve the type code for the last processor error. */
  692. static inline zbar_error_t
  693. zbar_processor_get_error_code (const zbar_processor_t *processor)
  694. {
  695. return(_zbar_get_error_code(processor));
  696. }
  697. /*@}*/
  698. /*------------------------------------------------------------*/
  699. /** @name Video interface
  700. * @anchor c-video
  701. * mid-level video source abstraction.
  702. * captures images from a video device
  703. */
  704. /*@{*/
  705. struct zbar_video_s;
  706. /** opaque video object. */
  707. typedef struct zbar_video_s zbar_video_t;
  708. /** constructor. */
  709. extern zbar_video_t *zbar_video_create(void);
  710. /** destructor. */
  711. extern void zbar_video_destroy(zbar_video_t *video);
  712. /** open and probe a video device.
  713. * the device specified by platform specific unique name
  714. * (v4l device node path in *nix eg "/dev/video",
  715. * DirectShow DevicePath property in windows).
  716. * @returns 0 if successful or -1 if an error occurs
  717. */
  718. extern int zbar_video_open(zbar_video_t *video,
  719. const char *device);
  720. /** retrieve file descriptor associated with open *nix video device
  721. * useful for using select()/poll() to tell when new images are
  722. * available (NB v4l2 only!!).
  723. * @returns the file descriptor or -1 if the video device is not open
  724. * or the driver only supports v4l1
  725. */
  726. extern int zbar_video_get_fd(const zbar_video_t *video);
  727. /** request a preferred size for the video image from the device.
  728. * the request may be adjusted or completely ignored by the driver.
  729. * @returns 0 if successful or -1 if the video device is already
  730. * initialized
  731. * @since 0.6
  732. */
  733. extern int zbar_video_request_size(zbar_video_t *video,
  734. unsigned width,
  735. unsigned height);
  736. /** request a preferred driver interface version for debug/testing.
  737. * @note must be called before zbar_video_open()
  738. * @since 0.6
  739. */
  740. extern int zbar_video_request_interface(zbar_video_t *video,
  741. int version);
  742. /** request a preferred I/O mode for debug/testing. You will get
  743. * errors if the driver does not support the specified mode.
  744. * @verbatim
  745. 0 = auto-detect
  746. 1 = force I/O using read()
  747. 2 = force memory mapped I/O using mmap()
  748. 3 = force USERPTR I/O (v4l2 only)
  749. @endverbatim
  750. * @note must be called before zbar_video_open()
  751. * @since 0.7
  752. */
  753. extern int zbar_video_request_iomode(zbar_video_t *video,
  754. int iomode);
  755. /** retrieve current output image width.
  756. * @returns the width or 0 if the video device is not open
  757. */
  758. extern int zbar_video_get_width(const zbar_video_t *video);
  759. /** retrieve current output image height.
  760. * @returns the height or 0 if the video device is not open
  761. */
  762. extern int zbar_video_get_height(const zbar_video_t *video);
  763. /** initialize video using a specific format for debug.
  764. * use zbar_negotiate_format() to automatically select and initialize
  765. * the best available format
  766. */
  767. extern int zbar_video_init(zbar_video_t *video,
  768. unsigned long format);
  769. /** start/stop video capture.
  770. * all buffered images are retired when capture is disabled.
  771. * @returns 0 if successful or -1 if an error occurs
  772. */
  773. extern int zbar_video_enable(zbar_video_t *video,
  774. int enable);
  775. /** retrieve next captured image. blocks until an image is available.
  776. * @returns NULL if video is not enabled or an error occurs
  777. */
  778. extern zbar_image_t *zbar_video_next_image(zbar_video_t *video);
  779. /** display detail for last video error to stderr.
  780. * @returns a non-zero value suitable for passing to exit()
  781. */
  782. static inline int zbar_video_error_spew (const zbar_video_t *video,
  783. int verbosity)
  784. {
  785. return(_zbar_error_spew(video, verbosity));
  786. }
  787. /** retrieve the detail string for the last video error. */
  788. static inline const char *zbar_video_error_string (const zbar_video_t *video,
  789. int verbosity)
  790. {
  791. return(_zbar_error_string(video, verbosity));
  792. }
  793. /** retrieve the type code for the last video error. */
  794. static inline zbar_error_t
  795. zbar_video_get_error_code (const zbar_video_t *video)
  796. {
  797. return(_zbar_get_error_code(video));
  798. }
  799. /*@}*/
  800. /*------------------------------------------------------------*/
  801. /** @name Window interface
  802. * @anchor c-window
  803. * mid-level output window abstraction.
  804. * displays images to user-specified platform specific output window
  805. */
  806. /*@{*/
  807. struct zbar_window_s;
  808. /** opaque window object. */
  809. typedef struct zbar_window_s zbar_window_t;
  810. /** constructor. */
  811. extern zbar_window_t *zbar_window_create(void);
  812. /** destructor. */
  813. extern void zbar_window_destroy(zbar_window_t *window);
  814. /** associate reader with an existing platform window.
  815. * This can be any "Drawable" for X Windows or a "HWND" for windows.
  816. * input images will be scaled into the output window.
  817. * pass NULL to detach from the resource, further input will be
  818. * ignored
  819. */
  820. extern int zbar_window_attach(zbar_window_t *window,
  821. void *x11_display_w32_hwnd,
  822. unsigned long x11_drawable);
  823. /** control content level of the reader overlay.
  824. * the overlay displays graphical data for informational or debug
  825. * purposes. higher values increase the level of annotation (possibly
  826. * decreasing performance). @verbatim
  827. 0 = disable overlay
  828. 1 = outline decoded symbols (default)
  829. 2 = also track and display input frame rate
  830. @endverbatim
  831. */
  832. extern void zbar_window_set_overlay(zbar_window_t *window,
  833. int level);
  834. /** retrieve current content level of reader overlay.
  835. * @see zbar_window_set_overlay()
  836. * @since 0.10
  837. */
  838. extern int zbar_window_get_overlay(const zbar_window_t *window);
  839. /** draw a new image into the output window. */
  840. extern int zbar_window_draw(zbar_window_t *window,
  841. zbar_image_t *image);
  842. /** redraw the last image (exposure handler). */
  843. extern int zbar_window_redraw(zbar_window_t *window);
  844. /** resize the image window (reconfigure handler).
  845. * this does @em not update the contents of the window
  846. * @since 0.3, changed in 0.4 to not redraw window
  847. */
  848. extern int zbar_window_resize(zbar_window_t *window,
  849. unsigned width,
  850. unsigned height);
  851. /** display detail for last window error to stderr.
  852. * @returns a non-zero value suitable for passing to exit()
  853. */
  854. static inline int zbar_window_error_spew (const zbar_window_t *window,
  855. int verbosity)
  856. {
  857. return(_zbar_error_spew(window, verbosity));
  858. }
  859. /** retrieve the detail string for the last window error. */
  860. static inline const char*
  861. zbar_window_error_string (const zbar_window_t *window,
  862. int verbosity)
  863. {
  864. return(_zbar_error_string(window, verbosity));
  865. }
  866. /** retrieve the type code for the last window error. */
  867. static inline zbar_error_t
  868. zbar_window_get_error_code (const zbar_window_t *window)
  869. {
  870. return(_zbar_get_error_code(window));
  871. }
  872. /** select a compatible format between video input and output window.
  873. * the selection algorithm attempts to use a format shared by
  874. * video input and window output which is also most useful for
  875. * barcode scanning. if a format conversion is necessary, it will
  876. * heuristically attempt to minimize the cost of the conversion
  877. */
  878. extern int zbar_negotiate_format(zbar_video_t *video,
  879. zbar_window_t *window);
  880. /*@}*/
  881. /*------------------------------------------------------------*/
  882. /** @name Image Scanner interface
  883. * @anchor c-imagescanner
  884. * mid-level image scanner interface.
  885. * reads barcodes from 2-D images
  886. */
  887. /*@{*/
  888. struct zbar_image_scanner_s;
  889. /** opaque image scanner object. */
  890. typedef struct zbar_image_scanner_s zbar_image_scanner_t;
  891. /** constructor. */
  892. extern zbar_image_scanner_t *zbar_image_scanner_create(void);
  893. /** destructor. */
  894. extern void zbar_image_scanner_destroy(zbar_image_scanner_t *scanner);
  895. /** setup result handler callback.
  896. * the specified function will be called by the scanner whenever
  897. * new results are available from a decoded image.
  898. * pass a NULL value to disable callbacks.
  899. * @returns the previously registered handler
  900. */
  901. extern zbar_image_data_handler_t*
  902. zbar_image_scanner_set_data_handler(zbar_image_scanner_t *scanner,
  903. zbar_image_data_handler_t *handler,
  904. const void *userdata);
  905. /** set config for indicated symbology (0 for all) to specified value.
  906. * @returns 0 for success, non-0 for failure (config does not apply to
  907. * specified symbology, or value out of range)
  908. * @see zbar_decoder_set_config()
  909. * @since 0.4
  910. */
  911. extern int zbar_image_scanner_set_config(zbar_image_scanner_t *scanner,
  912. zbar_symbol_type_t symbology,
  913. zbar_config_t config,
  914. int value);
  915. /** parse configuration string using zbar_parse_config()
  916. * and apply to image scanner using zbar_image_scanner_set_config().
  917. * @returns 0 for success, non-0 for failure
  918. * @see zbar_parse_config()
  919. * @see zbar_image_scanner_set_config()
  920. * @since 0.4
  921. */
  922. static inline int
  923. zbar_image_scanner_parse_config (zbar_image_scanner_t *scanner,
  924. const char *config_string)
  925. {
  926. zbar_symbol_type_t sym;
  927. zbar_config_t cfg;
  928. int val;
  929. return(zbar_parse_config(config_string, &sym, &cfg, &val) ||
  930. zbar_image_scanner_set_config(scanner, sym, cfg, val));
  931. }
  932. /** enable or disable the inter-image result cache (default disabled).
  933. * mostly useful for scanning video frames, the cache filters
  934. * duplicate results from consecutive images, while adding some
  935. * consistency checking and hysteresis to the results.
  936. * this interface also clears the cache
  937. */
  938. extern void zbar_image_scanner_enable_cache(zbar_image_scanner_t *scanner,
  939. int enable);
  940. /** remove any previously decoded results from the image scanner and the
  941. * specified image. somewhat more efficient version of
  942. * zbar_image_set_symbols(image, NULL) which may retain memory for
  943. * subsequent decodes
  944. * @since 0.10
  945. */
  946. extern void zbar_image_scanner_recycle_image(zbar_image_scanner_t *scanner,
  947. zbar_image_t *image);
  948. /** retrieve decode results for last scanned image.
  949. * @returns the symbol set result container or NULL if no results are
  950. * available
  951. * @note the symbol set does not have its reference count adjusted;
  952. * ensure that the count is incremented if the results may be kept
  953. * after the next image is scanned
  954. * @since 0.10
  955. */
  956. extern const zbar_symbol_set_t*
  957. zbar_image_scanner_get_results(const zbar_image_scanner_t *scanner);
  958. /** scan for symbols in provided image. The image format must be
  959. * "Y800" or "GRAY".
  960. * @returns >0 if symbols were successfully decoded from the image,
  961. * 0 if no symbols were found or -1 if an error occurs
  962. * @see zbar_image_convert()
  963. * @since 0.9 - changed to only accept grayscale images
  964. */
  965. extern int zbar_scan_image(zbar_image_scanner_t *scanner,
  966. zbar_image_t *image);
  967. /*@}*/
  968. /*------------------------------------------------------------*/
  969. /** @name Decoder interface
  970. * @anchor c-decoder
  971. * low-level bar width stream decoder interface.
  972. * identifies symbols and extracts encoded data
  973. */
  974. /*@{*/
  975. struct zbar_decoder_s;
  976. /** opaque decoder object. */
  977. typedef struct zbar_decoder_s zbar_decoder_t;
  978. /** decoder data handler callback function.
  979. * called by decoder when new data has just been decoded
  980. */
  981. typedef void (zbar_decoder_handler_t)(zbar_decoder_t *decoder);
  982. /** constructor. */
  983. extern zbar_decoder_t *zbar_decoder_create(void);
  984. /** destructor. */
  985. extern void zbar_decoder_destroy(zbar_decoder_t *decoder);
  986. /** set config for indicated symbology (0 for all) to specified value.
  987. * @returns 0 for success, non-0 for failure (config does not apply to
  988. * specified symbology, or value out of range)
  989. * @since 0.4
  990. */
  991. extern int zbar_decoder_set_config(zbar_decoder_t *decoder,
  992. zbar_symbol_type_t symbology,
  993. zbar_config_t config,
  994. int value);
  995. /** parse configuration string using zbar_parse_config()
  996. * and apply to decoder using zbar_decoder_set_config().
  997. * @returns 0 for success, non-0 for failure
  998. * @see zbar_parse_config()
  999. * @see zbar_decoder_set_config()
  1000. * @since 0.4
  1001. */
  1002. static inline int zbar_decoder_parse_config (zbar_decoder_t *decoder,
  1003. const char *config_string)
  1004. {
  1005. zbar_symbol_type_t sym;
  1006. zbar_config_t cfg;
  1007. int val;
  1008. return(zbar_parse_config(config_string, &sym, &cfg, &val) ||
  1009. zbar_decoder_set_config(decoder, sym, cfg, val));
  1010. }
  1011. /** clear all decoder state.
  1012. * any partial symbols are flushed
  1013. */
  1014. extern void zbar_decoder_reset(zbar_decoder_t *decoder);
  1015. /** mark start of a new scan pass.
  1016. * clears any intra-symbol state and resets color to ::ZBAR_SPACE.
  1017. * any partially decoded symbol state is retained
  1018. */
  1019. extern void zbar_decoder_new_scan(zbar_decoder_t *decoder);
  1020. /** process next bar/space width from input stream.
  1021. * the width is in arbitrary relative units. first value of a scan
  1022. * is ::ZBAR_SPACE width, alternating from there.
  1023. * @returns appropriate symbol type if width completes
  1024. * decode of a symbol (data is available for retrieval)
  1025. * @returns ::ZBAR_PARTIAL as a hint if part of a symbol was decoded
  1026. * @returns ::ZBAR_NONE (0) if no new symbol data is available
  1027. */
  1028. extern zbar_symbol_type_t zbar_decode_width(zbar_decoder_t *decoder,
  1029. unsigned width);
  1030. /** retrieve color of @em next element passed to
  1031. * zbar_decode_width(). */
  1032. extern zbar_color_t zbar_decoder_get_color(const zbar_decoder_t *decoder);
  1033. /** retrieve last decoded data.
  1034. * @returns the data string or NULL if no new data available.
  1035. * the returned data buffer is owned by library, contents are only
  1036. * valid between non-0 return from zbar_decode_width and next library
  1037. * call
  1038. */
  1039. extern const char *zbar_decoder_get_data(const zbar_decoder_t *decoder);
  1040. /** retrieve length of binary data.
  1041. * @returns the length of the decoded data or 0 if no new data
  1042. * available.
  1043. */
  1044. extern unsigned int
  1045. zbar_decoder_get_data_length(const zbar_decoder_t *decoder);
  1046. /** retrieve last decoded symbol type.
  1047. * @returns the type or ::ZBAR_NONE if no new data available
  1048. */
  1049. extern zbar_symbol_type_t
  1050. zbar_decoder_get_type(const zbar_decoder_t *decoder);
  1051. /** setup data handler callback.
  1052. * the registered function will be called by the decoder
  1053. * just before zbar_decode_width() returns a non-zero value.
  1054. * pass a NULL value to disable callbacks.
  1055. * @returns the previously registered handler
  1056. */
  1057. extern zbar_decoder_handler_t*
  1058. zbar_decoder_set_handler(zbar_decoder_t *decoder,
  1059. zbar_decoder_handler_t *handler);
  1060. /** associate user specified data value with the decoder. */
  1061. extern void zbar_decoder_set_userdata(zbar_decoder_t *decoder,
  1062. void *userdata);
  1063. /** return user specified data value associated with the decoder. */
  1064. extern void *zbar_decoder_get_userdata(const zbar_decoder_t *decoder);
  1065. /*@}*/
  1066. /*------------------------------------------------------------*/
  1067. /** @name Scanner interface
  1068. * @anchor c-scanner
  1069. * low-level linear intensity sample stream scanner interface.
  1070. * identifies "bar" edges and measures width between them.
  1071. * optionally passes to bar width decoder
  1072. */
  1073. /*@{*/
  1074. struct zbar_scanner_s;
  1075. /** opaque scanner object. */
  1076. typedef struct zbar_scanner_s zbar_scanner_t;
  1077. /** constructor.
  1078. * if decoder is non-NULL it will be attached to scanner
  1079. * and called automatically at each new edge
  1080. * current color is initialized to ::ZBAR_SPACE
  1081. * (so an initial BAR->SPACE transition may be discarded)
  1082. */
  1083. extern zbar_scanner_t *zbar_scanner_create(zbar_decoder_t *decoder);
  1084. /** destructor. */
  1085. extern void zbar_scanner_destroy(zbar_scanner_t *scanner);
  1086. /** clear all scanner state.
  1087. * also resets an associated decoder
  1088. */
  1089. extern zbar_symbol_type_t zbar_scanner_reset(zbar_scanner_t *scanner);
  1090. /** mark start of a new scan pass. resets color to ::ZBAR_SPACE.
  1091. * also updates an associated decoder.
  1092. * @returns any decode results flushed from the pipeline
  1093. * @note when not using callback handlers, the return value should
  1094. * be checked the same as zbar_scan_y()
  1095. * @note call zbar_scanner_flush() at least twice before calling this
  1096. * method to ensure no decode results are lost
  1097. */
  1098. extern zbar_symbol_type_t zbar_scanner_new_scan(zbar_scanner_t *scanner);
  1099. /** flush scanner processing pipeline.
  1100. * forces current scanner position to be a scan boundary.
  1101. * call multiple times (max 3) to completely flush decoder.
  1102. * @returns any decode/scan results flushed from the pipeline
  1103. * @note when not using callback handlers, the return value should
  1104. * be checked the same as zbar_scan_y()
  1105. * @since 0.9
  1106. */
  1107. extern zbar_symbol_type_t zbar_scanner_flush(zbar_scanner_t *scanner);
  1108. /** process next sample intensity value.
  1109. * intensity (y) is in arbitrary relative units.
  1110. * @returns result of zbar_decode_width() if a decoder is attached,
  1111. * otherwise @returns (::ZBAR_PARTIAL) when new edge is detected
  1112. * or 0 (::ZBAR_NONE) if no new edge is detected
  1113. */
  1114. extern zbar_symbol_type_t zbar_scan_y(zbar_scanner_t *scanner,
  1115. int y);
  1116. /** process next sample from RGB (or BGR) triple. */
  1117. static inline zbar_symbol_type_t zbar_scan_rgb24 (zbar_scanner_t *scanner,
  1118. unsigned char *rgb)
  1119. {
  1120. return(zbar_scan_y(scanner, rgb[0] + rgb[1] + rgb[2]));
  1121. }
  1122. /** retrieve last scanned width. */
  1123. extern unsigned zbar_scanner_get_width(const zbar_scanner_t *scanner);
  1124. /** retrieve sample position of last edge.
  1125. * @since 0.10
  1126. */
  1127. extern unsigned zbar_scanner_get_edge(const zbar_scanner_t *scn,
  1128. unsigned offset,
  1129. int prec);
  1130. /** retrieve last scanned color. */
  1131. extern zbar_color_t zbar_scanner_get_color(const zbar_scanner_t *scanner);
  1132. /*@}*/
  1133. #ifdef __cplusplus
  1134. }
  1135. }
  1136. # include "zbar/Exception.h"
  1137. # include "zbar/Decoder.h"
  1138. # include "zbar/Scanner.h"
  1139. # include "zbar/Symbol.h"
  1140. # include "zbar/Image.h"
  1141. # include "zbar/ImageScanner.h"
  1142. # include "zbar/Video.h"
  1143. # include "zbar/Window.h"
  1144. # include "zbar/Processor.h"
  1145. #endif
  1146. typedef struct
  1147. {
  1148. zbar_image_scanner_t *scanner;
  1149. zbar_image_t *image;
  1150. zbar_symbol_t *symbol;
  1151. }zbar_t;
  1152. zbar_t *zbar_create(void);
  1153. //输入灰度图像点阵,zbar解码,并设置好第一个解出来的数据信息,返回0表示没有解码出数据,其他有数据
  1154. int zbar_run(zbar_t *zbar, int width, int height, void *src);
  1155. //获取解出来的数据,len返回数据长度,函数返回数据内存指针
  1156. char *zbar_get_data_ptr(zbar_t *zbar, unsigned int *len);
  1157. //设置好下一个解出来的数据信息,返回0表示没有数据了,其他有数据
  1158. int zbar_find_next_data(zbar_t *zbar);
  1159. void zbar_destory(zbar_t *zbar);
  1160. void zbar_run_demo(void);
  1161. #endif