zbar.h 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. /*------------------------------------------------------------------------
  2. * Copyright 2007-2010 (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 <stdint.h>
  26. /** @file
  27. * ZBar Barcode Reader C API definition
  28. */
  29. /** @mainpage
  30. *
  31. * interface to the barcode reader is available at several levels.
  32. * most applications will want to use the high-level interfaces:
  33. *
  34. * @section high-level High-Level Interfaces
  35. *
  36. * these interfaces wrap all library functionality into an easy-to-use
  37. * package for a specific toolkit:
  38. * - the "GTK+ 2.x widget" may be used with GTK GUI applications. a
  39. * Python wrapper is included for PyGtk
  40. * - the @ref zbar::QZBar "Qt4 widget" may be used with Qt GUI
  41. * applications
  42. * - the Processor interface (in @ref c-processor "C" or @ref
  43. * zbar::Processor "C++") adds a scanning window to an application
  44. * with no GUI.
  45. *
  46. * @section mid-level Intermediate Interfaces
  47. *
  48. * building blocks used to construct high-level interfaces:
  49. * - the ImageScanner (in @ref c-imagescanner "C" or @ref
  50. * zbar::ImageScanner "C++") looks for barcodes in a library defined
  51. * image object
  52. * - the Window abstraction (in @ref c-window "C" or @ref
  53. * zbar::Window "C++") sinks library images, displaying them on the
  54. * platform display
  55. * - the Video abstraction (in @ref c-video "C" or @ref zbar::Video
  56. * "C++") sources library images from a video device
  57. *
  58. * @section low-level Low-Level Interfaces
  59. *
  60. * direct interaction with barcode scanning and decoding:
  61. * - the Scanner (in @ref c-scanner "C" or @ref zbar::Scanner "C++")
  62. * looks for barcodes in a linear intensity sample stream
  63. * - the Decoder (in @ref c-decoder "C" or @ref zbar::Decoder "C++")
  64. * extracts barcodes from a stream of bar and space widths
  65. */
  66. #ifdef __cplusplus
  67. /** C++ namespace for library interfaces */
  68. namespace zbar {
  69. extern "C" {
  70. #endif
  71. /** @name Global library interfaces */
  72. /*@{*/
  73. /** "color" of element: bar or space. */
  74. typedef enum zbar_color_e {
  75. ZBAR_SPACE = 0, /**< light area or space between bars */
  76. ZBAR_BAR = 1, /**< dark area or colored bar segment */
  77. } zbar_color_t;
  78. /** decoded symbol type. */
  79. typedef enum zbar_symbol_type_e {
  80. ZBAR_NONE = 0, /**< no symbol decoded */
  81. ZBAR_PARTIAL = 1, /**< intermediate status */
  82. ZBAR_EAN2 = 2, /**< GS1 2-digit add-on */
  83. ZBAR_EAN5 = 5, /**< GS1 5-digit add-on */
  84. ZBAR_EAN8 = 8, /**< EAN-8 */
  85. ZBAR_UPCE = 9, /**< UPC-E */
  86. ZBAR_ISBN10 = 10, /**< ISBN-10 (from EAN-13). @since 0.4 */
  87. ZBAR_UPCA = 12, /**< UPC-A */
  88. ZBAR_EAN13 = 13, /**< EAN-13 */
  89. ZBAR_ISBN13 = 14, /**< ISBN-13 (from EAN-13). @since 0.4 */
  90. ZBAR_COMPOSITE = 15, /**< EAN/UPC composite */
  91. ZBAR_I25 = 25, /**< Interleaved 2 of 5. @since 0.4 */
  92. ZBAR_DATABAR = 34, /**< GS1 DataBar (RSS). @since 0.11 */
  93. ZBAR_DATABAR_EXP = 35, /**< GS1 DataBar Expanded. @since 0.11 */
  94. ZBAR_CODABAR = 38, /**< Codabar. @since 0.11 */
  95. ZBAR_CODE39 = 39, /**< Code 39. @since 0.4 */
  96. ZBAR_PDF417 = 57, /**< PDF417. @since 0.6 */
  97. ZBAR_QRCODE = 64, /**< QR Code. @since 0.10 */
  98. ZBAR_SQCODE = 80, /**< SQ Code. @since 0.20.1 */
  99. ZBAR_CODE93 = 93, /**< Code 93. @since 0.11 */
  100. ZBAR_CODE128 = 128, /**< Code 128 */
  101. /*
  102. * Please see _zbar_get_symbol_hash() if adding
  103. * anything after 128
  104. */
  105. /** mask for base symbol type.
  106. * @deprecated in 0.11, remove this from existing code
  107. */
  108. ZBAR_SYMBOL = 0x00ff,
  109. /** 2-digit add-on flag.
  110. * @deprecated in 0.11, a ::ZBAR_EAN2 component is used for
  111. * 2-digit GS1 add-ons
  112. */
  113. ZBAR_ADDON2 = 0x0200,
  114. /** 5-digit add-on flag.
  115. * @deprecated in 0.11, a ::ZBAR_EAN5 component is used for
  116. * 5-digit GS1 add-ons
  117. */
  118. ZBAR_ADDON5 = 0x0500,
  119. /** add-on flag mask.
  120. * @deprecated in 0.11, GS1 add-ons are represented using composite
  121. * symbols of type ::ZBAR_COMPOSITE; add-on components use ::ZBAR_EAN2
  122. * or ::ZBAR_EAN5
  123. */
  124. ZBAR_ADDON = 0x0700,
  125. } zbar_symbol_type_t;
  126. /** decoded symbol coarse orientation.
  127. * @since 0.11
  128. */
  129. typedef enum zbar_orientation_e {
  130. ZBAR_ORIENT_UNKNOWN = -1, /**< unable to determine orientation */
  131. ZBAR_ORIENT_UP, /**< upright, read left to right */
  132. ZBAR_ORIENT_RIGHT, /**< sideways, read top to bottom */
  133. ZBAR_ORIENT_DOWN, /**< upside-down, read right to left */
  134. ZBAR_ORIENT_LEFT, /**< sideways, read bottom to top */
  135. } zbar_orientation_t;
  136. /** error codes. */
  137. typedef enum zbar_error_e {
  138. ZBAR_OK = 0, /**< no error */
  139. ZBAR_ERR_NOMEM, /**< out of memory */
  140. ZBAR_ERR_INTERNAL, /**< internal library error */
  141. ZBAR_ERR_UNSUPPORTED, /**< unsupported request */
  142. ZBAR_ERR_INVALID, /**< invalid request */
  143. ZBAR_ERR_SYSTEM, /**< system error */
  144. ZBAR_ERR_LOCKING, /**< locking error */
  145. ZBAR_ERR_BUSY, /**< all resources busy */
  146. ZBAR_ERR_XDISPLAY, /**< X11 display error */
  147. ZBAR_ERR_XPROTO, /**< X11 protocol error */
  148. ZBAR_ERR_CLOSED, /**< output window is closed */
  149. ZBAR_ERR_WINAPI, /**< windows system error */
  150. ZBAR_ERR_NUM /**< number of error codes */
  151. } zbar_error_t;
  152. /** decoder configuration options.
  153. * @since 0.4
  154. */
  155. typedef enum zbar_config_e {
  156. ZBAR_CFG_ENABLE = 0, /**< enable symbology/feature */
  157. ZBAR_CFG_ADD_CHECK, /**< enable check digit when optional */
  158. ZBAR_CFG_EMIT_CHECK, /**< return check digit when present */
  159. ZBAR_CFG_ASCII, /**< enable full ASCII character set */
  160. ZBAR_CFG_NUM, /**< number of boolean decoder configs */
  161. ZBAR_CFG_MIN_LEN = 0x20, /**< minimum data length for valid decode */
  162. ZBAR_CFG_MAX_LEN, /**< maximum data length for valid decode */
  163. ZBAR_CFG_UNCERTAINTY = 0x40,/**< required video consistency frames */
  164. ZBAR_CFG_POSITION = 0x80, /**< enable scanner to collect position data */
  165. ZBAR_CFG_TEST_INVERTED, /**< if fails to decode, test inverted */
  166. ZBAR_CFG_X_DENSITY = 0x100, /**< image scanner vertical scan density */
  167. ZBAR_CFG_Y_DENSITY, /**< image scanner horizontal scan density */
  168. } zbar_config_t;
  169. /** decoder symbology modifier flags.
  170. * @since 0.11
  171. */
  172. typedef enum zbar_modifier_e {
  173. /** barcode tagged as GS1 (EAN.UCC) reserved
  174. * (eg, FNC1 before first data character).
  175. * data may be parsed as a sequence of GS1 AIs
  176. */
  177. ZBAR_MOD_GS1 = 0,
  178. /** barcode tagged as AIM reserved
  179. * (eg, FNC1 after first character or digit pair)
  180. */
  181. ZBAR_MOD_AIM,
  182. /** number of modifiers */
  183. ZBAR_MOD_NUM,
  184. } zbar_modifier_t;
  185. typedef enum video_control_type_e {
  186. VIDEO_CNTL_INTEGER = 1,
  187. VIDEO_CNTL_MENU,
  188. VIDEO_CNTL_BUTTON,
  189. VIDEO_CNTL_INTEGER64,
  190. VIDEO_CNTL_STRING,
  191. VIDEO_CNTL_BOOLEAN,
  192. } video_control_type_t;
  193. /** store video control menu
  194. * @param name name of the menu item
  195. * @param val integer value associated with the item
  196. */
  197. typedef struct video_control_menu_s {
  198. char *name;
  199. int64_t value;
  200. } video_control_menu_t;
  201. /** store video controls
  202. * @param name name of the control
  203. * @param group name of the control group/class
  204. * @param type type of the control
  205. * @param min minimum value of control (if control is integer)
  206. * @param max maximum value of control (if control is integer)
  207. * @param def default value of control (if control is integer)
  208. * @param step increment steps (if control is integer)
  209. * @param menu menu array
  210. * @param menu_size menu size
  211. * @since 0.20
  212. */
  213. typedef struct video_controls_s {
  214. char *name;
  215. char *group;
  216. video_control_type_t type;
  217. int64_t min, max, def;
  218. uint64_t step;
  219. unsigned int menu_size;
  220. video_control_menu_t *menu;
  221. void *next;
  222. // video drivers may add extra private data in the end of this struct
  223. } video_controls_t;
  224. /** store a video resolution
  225. * @param width width of the video window
  226. * @param height length of the video window
  227. * @param max_fps maximum streaming speed, in frames per second
  228. * @since 0.22
  229. */
  230. struct video_resolution_s {
  231. unsigned int width, height;
  232. float max_fps;
  233. };
  234. /** retrieve runtime library version information.
  235. * @param major set to the running major version (unless NULL)
  236. * @param minor set to the running minor version (unless NULL)
  237. * @returns 0
  238. */
  239. extern int zbar_version(unsigned *major,
  240. unsigned *minor,
  241. unsigned *patch);
  242. /** set global library debug level.
  243. * @param verbosity desired debug level. higher values create more spew
  244. */
  245. extern void zbar_set_verbosity(int verbosity);
  246. /** increase global library debug level.
  247. * eg, for -vvvv
  248. */
  249. extern void zbar_increase_verbosity(void);
  250. /** retrieve string name for symbol encoding.
  251. * @param sym symbol type encoding
  252. * @returns the static string name for the specified symbol type,
  253. * or "UNKNOWN" if the encoding is not recognized
  254. */
  255. extern const char *zbar_get_symbol_name(zbar_symbol_type_t sym);
  256. /** retrieve string name for addon encoding.
  257. * @param sym symbol type encoding
  258. * @returns static string name for any addon, or the empty string
  259. * if no addons were decoded
  260. * @deprecated in 0.11
  261. */
  262. extern const char *zbar_get_addon_name(zbar_symbol_type_t sym);
  263. /** retrieve string name for configuration setting.
  264. * @param config setting to name
  265. * @returns static string name for config,
  266. * or the empty string if value is not a known config
  267. */
  268. extern const char *zbar_get_config_name(zbar_config_t config);
  269. /** retrieve string name for modifier.
  270. * @param modifier flag to name
  271. * @returns static string name for modifier,
  272. * or the empty string if the value is not a known flag
  273. */
  274. extern const char *zbar_get_modifier_name(zbar_modifier_t modifier);
  275. /** retrieve string name for orientation.
  276. * @param orientation orientation encoding
  277. * @returns the static string name for the specified orientation,
  278. * or "UNKNOWN" if the orientation is not recognized
  279. * @since 0.11
  280. */
  281. extern const char *zbar_get_orientation_name(zbar_orientation_t orientation);
  282. /** parse a configuration string of the form "[symbology.]config[=value]".
  283. * the config must match one of the recognized names.
  284. * the symbology, if present, must match one of the recognized names.
  285. * if symbology is unspecified, it will be set to 0.
  286. * if value is unspecified it will be set to 1.
  287. * @returns 0 if the config is parsed successfully, 1 otherwise
  288. * @since 0.4
  289. */
  290. extern int zbar_parse_config(const char *config_string,
  291. zbar_symbol_type_t *symbology,
  292. zbar_config_t *config,
  293. int *value);
  294. /** consistently compute fourcc values across architectures
  295. * (adapted from v4l2 specification)
  296. * @since 0.11
  297. */
  298. #define zbar_fourcc(a, b, c, d) \
  299. ((unsigned long)(a) | \
  300. ((unsigned long)(b) << 8) | \
  301. ((unsigned long)(c) << 16) | \
  302. ((unsigned long)(d) << 24))
  303. /** parse a fourcc string into its encoded integer value.
  304. * @since 0.11
  305. */
  306. static inline unsigned long zbar_fourcc_parse (const char *format)
  307. {
  308. unsigned long fourcc = 0;
  309. if(format) {
  310. int i;
  311. for(i = 0; i < 4 && format[i]; i++)
  312. fourcc |= ((unsigned long)format[i]) << (i * 8);
  313. }
  314. return(fourcc);
  315. }
  316. /** @internal type unsafe error API (don't use) */
  317. extern int _zbar_error_spew(const void *object,
  318. int verbosity);
  319. extern const char *_zbar_error_string(const void *object,
  320. int verbosity);
  321. extern zbar_error_t _zbar_get_error_code(const void *object);
  322. /*@}*/
  323. struct zbar_symbol_s;
  324. typedef struct zbar_symbol_s zbar_symbol_t;
  325. struct zbar_symbol_set_s;
  326. typedef struct zbar_symbol_set_s zbar_symbol_set_t;
  327. /*------------------------------------------------------------*/
  328. /** @name Symbol interface
  329. * decoded barcode symbol result object. stores type, data, and image
  330. * location of decoded symbol. all memory is owned by the library
  331. */
  332. /*@{*/
  333. /** @typedef zbar_symbol_t
  334. * opaque decoded symbol object.
  335. */
  336. /** symbol reference count manipulation.
  337. * increment the reference count when you store a new reference to the
  338. * symbol. decrement when the reference is no longer used. do not
  339. * refer to the symbol once the count is decremented and the
  340. * containing image has been recycled or destroyed.
  341. * @note the containing image holds a reference to the symbol, so you
  342. * only need to use this if you keep a symbol after the image has been
  343. * destroyed or reused.
  344. * @since 0.9
  345. */
  346. extern void zbar_symbol_ref(const zbar_symbol_t *symbol,
  347. int refs);
  348. /** retrieve type of decoded symbol.
  349. * @returns the symbol type
  350. */
  351. extern zbar_symbol_type_t zbar_symbol_get_type(const zbar_symbol_t *symbol);
  352. /** retrieve symbology boolean config settings.
  353. * @returns a bitmask indicating which configs were set for the detected
  354. * symbology during decoding.
  355. * @since 0.11
  356. */
  357. extern unsigned int zbar_symbol_get_configs(const zbar_symbol_t *symbol);
  358. /** retrieve symbology modifier flag settings.
  359. * @returns a bitmask indicating which characteristics were detected
  360. * during decoding.
  361. * @since 0.11
  362. */
  363. extern unsigned int zbar_symbol_get_modifiers(const zbar_symbol_t *symbol);
  364. /** retrieve data decoded from symbol.
  365. * @returns the data string
  366. */
  367. extern const char *zbar_symbol_get_data(const zbar_symbol_t *symbol);
  368. /** retrieve length of binary data.
  369. * @returns the length of the decoded data
  370. */
  371. extern unsigned int zbar_symbol_get_data_length(const zbar_symbol_t *symbol);
  372. /** retrieve a symbol confidence metric.
  373. * @returns an unscaled, relative quantity: larger values are better
  374. * than smaller values, where "large" and "small" are application
  375. * dependent.
  376. * @note expect the exact definition of this quantity to change as the
  377. * metric is refined. currently, only the ordered relationship
  378. * between two values is defined and will remain stable in the future
  379. * @since 0.9
  380. */
  381. extern int zbar_symbol_get_quality(const zbar_symbol_t *symbol);
  382. /** retrieve current cache count. when the cache is enabled for the
  383. * image_scanner this provides inter-frame reliability and redundancy
  384. * information for video streams.
  385. * @returns < 0 if symbol is still uncertain.
  386. * @returns 0 if symbol is newly verified.
  387. * @returns > 0 for duplicate symbols
  388. */
  389. extern int zbar_symbol_get_count(const zbar_symbol_t *symbol);
  390. /** retrieve the number of points in the location polygon. the
  391. * location polygon defines the image area that the symbol was
  392. * extracted from.
  393. * @returns the number of points in the location polygon
  394. * @note this is currently not a polygon, but the scan locations
  395. * where the symbol was decoded
  396. */
  397. extern unsigned zbar_symbol_get_loc_size(const zbar_symbol_t *symbol);
  398. /** retrieve location polygon x-coordinates.
  399. * points are specified by 0-based index.
  400. * @returns the x-coordinate for a point in the location polygon.
  401. * @returns -1 if index is out of range
  402. */
  403. extern int zbar_symbol_get_loc_x(const zbar_symbol_t *symbol,
  404. unsigned index);
  405. /** retrieve location polygon y-coordinates.
  406. * points are specified by 0-based index.
  407. * @returns the y-coordinate for a point in the location polygon.
  408. * @returns -1 if index is out of range
  409. */
  410. extern int zbar_symbol_get_loc_y(const zbar_symbol_t *symbol,
  411. unsigned index);
  412. /** retrieve general orientation of decoded symbol.
  413. * @returns a coarse, axis-aligned indication of symbol orientation or
  414. * ::ZBAR_ORIENT_UNKNOWN if unknown
  415. * @since 0.11
  416. */
  417. extern zbar_orientation_t
  418. zbar_symbol_get_orientation(const zbar_symbol_t *symbol);
  419. /** iterate the set to which this symbol belongs (there can be only one).
  420. * @returns the next symbol in the set, or
  421. * @returns NULL when no more results are available
  422. */
  423. extern const zbar_symbol_t *zbar_symbol_next(const zbar_symbol_t *symbol);
  424. /** retrieve components of a composite result.
  425. * @returns the symbol set containing the components
  426. * @returns NULL if the symbol is already a physical symbol
  427. * @since 0.10
  428. */
  429. extern const zbar_symbol_set_t*
  430. zbar_symbol_get_components(const zbar_symbol_t *symbol);
  431. /** iterate components of a composite result.
  432. * @returns the first physical component symbol of a composite result
  433. * @returns NULL if the symbol is already a physical symbol
  434. * @since 0.10
  435. */
  436. extern const zbar_symbol_t*
  437. zbar_symbol_first_component(const zbar_symbol_t *symbol);
  438. /** print XML symbol element representation to user result buffer.
  439. * @see http://zbar.sourceforge.net/2008/barcode.xsd for the schema.
  440. * @param symbol is the symbol to print
  441. * @param buffer is the inout result pointer, it will be reallocated
  442. * with a larger size if necessary.
  443. * @param buflen is inout length of the result buffer.
  444. * @returns the buffer pointer
  445. * @since 0.6
  446. */
  447. extern char *zbar_symbol_xml(const zbar_symbol_t *symbol,
  448. char **buffer,
  449. unsigned *buflen);
  450. /*@}*/
  451. /*------------------------------------------------------------*/
  452. /** @name Symbol Set interface
  453. * container for decoded result symbols associated with an image
  454. * or a composite symbol.
  455. * @since 0.10
  456. */
  457. /*@{*/
  458. /** @typedef zbar_symbol_set_t
  459. * opaque symbol iterator object.
  460. * @since 0.10
  461. */
  462. /** reference count manipulation.
  463. * increment the reference count when you store a new reference.
  464. * decrement when the reference is no longer used. do not refer to
  465. * the object any longer once references have been released.
  466. * @since 0.10
  467. */
  468. extern void zbar_symbol_set_ref(const zbar_symbol_set_t *symbols,
  469. int refs);
  470. /** retrieve set size.
  471. * @returns the number of symbols in the set.
  472. * @since 0.10
  473. */
  474. extern int zbar_symbol_set_get_size(const zbar_symbol_set_t *symbols);
  475. /** set iterator.
  476. * @returns the first decoded symbol result in a set
  477. * @returns NULL if the set is empty
  478. * @since 0.10
  479. */
  480. extern const zbar_symbol_t*
  481. zbar_symbol_set_first_symbol(const zbar_symbol_set_t *symbols);
  482. /** raw result iterator.
  483. * @returns the first decoded symbol result in a set, *before* filtering
  484. * @returns NULL if the set is empty
  485. * @since 0.11
  486. */
  487. extern const zbar_symbol_t*
  488. zbar_symbol_set_first_unfiltered(const zbar_symbol_set_t *symbols);
  489. /*@}*/
  490. /*------------------------------------------------------------*/
  491. /** @name Image interface
  492. * stores image data samples along with associated format and size
  493. * metadata
  494. */
  495. /*@{*/
  496. struct zbar_image_s;
  497. /**
  498. * zbar_image_t: opaque image object.
  499. */
  500. typedef struct zbar_image_s zbar_image_t;
  501. /** cleanup handler callback function.
  502. * called to free sample data when an image is destroyed.
  503. */
  504. typedef void (zbar_image_cleanup_handler_t)(zbar_image_t *image);
  505. /** data handler callback function.
  506. * called when decoded symbol results are available for an image
  507. */
  508. typedef void (zbar_image_data_handler_t)(zbar_image_t *image,
  509. const void *userdata);
  510. /** new image constructor.
  511. * @returns a new image object with uninitialized data and format.
  512. * this image should be destroyed (using zbar_image_destroy()) as
  513. * soon as the application is finished with it
  514. */
  515. extern zbar_image_t *zbar_image_create(void);
  516. /** image destructor. all images created by or returned to the
  517. * application should be destroyed using this function. when an image
  518. * is destroyed, the associated data cleanup handler will be invoked
  519. * if available
  520. * @note make no assumptions about the image or the data buffer.
  521. * they may not be destroyed/cleaned immediately if the library
  522. * is still using them. if necessary, use the cleanup handler hook
  523. * to keep track of image data buffers
  524. */
  525. extern void zbar_image_destroy(zbar_image_t *image);
  526. /** image reference count manipulation.
  527. * increment the reference count when you store a new reference to the
  528. * image. decrement when the reference is no longer used. do not
  529. * refer to the image any longer once the count is decremented.
  530. * zbar_image_ref(image, -1) is the same as zbar_image_destroy(image)
  531. * @since 0.5
  532. */
  533. extern void zbar_image_ref(zbar_image_t *image,
  534. int refs);
  535. /** image format conversion. refer to the documentation for supported
  536. * image formats
  537. * @returns a @em new image with the sample data from the original image
  538. * converted to the requested format. the original image is
  539. * unaffected.
  540. * @note the converted image size may be rounded (up) due to format
  541. * constraints
  542. */
  543. extern zbar_image_t *zbar_image_convert(const zbar_image_t *image,
  544. unsigned long format);
  545. /** image format conversion with crop/pad.
  546. * if the requested size is larger than the image, the last row/column
  547. * are duplicated to cover the difference. if the requested size is
  548. * smaller than the image, the extra rows/columns are dropped from the
  549. * right/bottom.
  550. * @returns a @em new image with the sample data from the original
  551. * image converted to the requested format and size.
  552. * @note the image is @em not scaled
  553. * @see zbar_image_convert()
  554. * @since 0.4
  555. */
  556. extern zbar_image_t *zbar_image_convert_resize(const zbar_image_t *image,
  557. unsigned long format,
  558. unsigned width,
  559. unsigned height);
  560. /** retrieve the image format.
  561. * @returns the fourcc describing the format of the image sample data
  562. */
  563. extern unsigned long zbar_image_get_format(const zbar_image_t *image);
  564. /** retrieve a "sequence" (page/frame) number associated with this image.
  565. * @since 0.6
  566. */
  567. extern unsigned zbar_image_get_sequence(const zbar_image_t *image);
  568. /** retrieve the width of the image.
  569. * @returns the width in sample columns
  570. */
  571. extern unsigned zbar_image_get_width(const zbar_image_t *image);
  572. /** retrieve the height of the image.
  573. * @returns the height in sample rows
  574. */
  575. extern unsigned zbar_image_get_height(const zbar_image_t *image);
  576. /** retrieve both dimensions of the image.
  577. * fills in the width and height in samples
  578. */
  579. extern void zbar_image_get_size(const zbar_image_t *image,
  580. unsigned *width,
  581. unsigned *height);
  582. /** retrieve the crop rectangle.
  583. * fills in the image coordinates of the upper left corner and size
  584. * of an axis-aligned rectangular area of the image that will be scanned.
  585. * defaults to the full image
  586. * @since 0.11
  587. */
  588. extern void zbar_image_get_crop(const zbar_image_t *image,
  589. unsigned *x,
  590. unsigned *y,
  591. unsigned *width,
  592. unsigned *height);
  593. /** return the image sample data. the returned data buffer is only
  594. * valid until zbar_image_destroy() is called
  595. */
  596. extern const void *zbar_image_get_data(const zbar_image_t *image);
  597. /** return the size of image data.
  598. * @since 0.6
  599. */
  600. extern unsigned long zbar_image_get_data_length(const zbar_image_t *img);
  601. /** retrieve the decoded results.
  602. * @returns the (possibly empty) set of decoded symbols
  603. * @returns NULL if the image has not been scanned
  604. * @since 0.10
  605. */
  606. extern const zbar_symbol_set_t*
  607. zbar_image_get_symbols(const zbar_image_t *image);
  608. /** associate the specified symbol set with the image, replacing any
  609. * existing results. use NULL to release the current results from the
  610. * image.
  611. * @see zbar_image_scanner_recycle_image()
  612. * @since 0.10
  613. */
  614. extern void zbar_image_set_symbols(zbar_image_t *image,
  615. const zbar_symbol_set_t *symbols);
  616. /** image_scanner decode result iterator.
  617. * @returns the first decoded symbol result for an image
  618. * or NULL if no results are available
  619. */
  620. extern const zbar_symbol_t*
  621. zbar_image_first_symbol(const zbar_image_t *image);
  622. /** specify the fourcc image format code for image sample data.
  623. * refer to the documentation for supported formats.
  624. * @note this does not convert the data!
  625. * (see zbar_image_convert() for that)
  626. */
  627. extern void zbar_image_set_format(zbar_image_t *image,
  628. unsigned long format);
  629. /** associate a "sequence" (page/frame) number with this image.
  630. * @since 0.6
  631. */
  632. extern void zbar_image_set_sequence(zbar_image_t *image,
  633. unsigned sequence_num);
  634. /** specify the pixel size of the image.
  635. * @note this also resets the crop rectangle to the full image
  636. * (0, 0, width, height)
  637. * @note this does not affect the data!
  638. */
  639. extern void zbar_image_set_size(zbar_image_t *image,
  640. unsigned width,
  641. unsigned height);
  642. /** specify a rectangular region of the image to scan.
  643. * the rectangle will be clipped to the image boundaries.
  644. * defaults to the full image specified by zbar_image_set_size()
  645. */
  646. extern void zbar_image_set_crop(zbar_image_t *image,
  647. unsigned x,
  648. unsigned y,
  649. unsigned width,
  650. unsigned height);
  651. /** specify image sample data. when image data is no longer needed by
  652. * the library the specific data cleanup handler will be called
  653. * (unless NULL)
  654. * @note application image data will not be modified by the library
  655. */
  656. extern void zbar_image_set_data(zbar_image_t *image,
  657. const void *data,
  658. unsigned long data_byte_length,
  659. zbar_image_cleanup_handler_t *cleanup_hndlr);
  660. /** built-in cleanup handler.
  661. * passes the image data buffer to free()
  662. */
  663. extern void zbar_image_free_data(zbar_image_t *image);
  664. /** associate user specified data value with an image.
  665. * @since 0.5
  666. */
  667. extern void zbar_image_set_userdata(zbar_image_t *image,
  668. void *userdata);
  669. /** return user specified data value associated with the image.
  670. * @since 0.5
  671. */
  672. extern void *zbar_image_get_userdata(const zbar_image_t *image);
  673. /** dump raw image data to a file for debug.
  674. * the data will be prefixed with a 16 byte header consisting of:
  675. * - 4 bytes uint = 0x676d697a ("zimg")
  676. * - 4 bytes format fourcc
  677. * - 2 bytes width
  678. * - 2 bytes height
  679. * - 4 bytes size of following image data in bytes
  680. * this header can be dumped w/eg:
  681. * @verbatim
  682. od -Ax -tx1z -N16 -w4 [file]
  683. @endverbatim
  684. * for some formats the image can be displayed/converted using
  685. * ImageMagick, eg:
  686. * @verbatim
  687. display -size 640x480+16 [-depth ?] [-sampling-factor ?x?] \
  688. {GRAY,RGB,UYVY,YUV}:[file]
  689. @endverbatim
  690. *
  691. * @param image the image object to dump
  692. * @param filebase base filename, appended with ".XXXX.zimg" where
  693. * XXXX is the format fourcc
  694. * @returns 0 on success or a system error code on failure
  695. */
  696. extern int zbar_image_write(const zbar_image_t *image,
  697. const char *filebase);
  698. /** read back an image in the format written by zbar_image_write()
  699. * @note TBD
  700. */
  701. extern zbar_image_t *zbar_image_read(char *filename);
  702. /*@}*/
  703. /*------------------------------------------------------------*/
  704. /** @name Processor interface
  705. * @anchor c-processor
  706. * high-level self-contained image processor.
  707. * processes video and images for barcodes, optionally displaying
  708. * images to a library owned output window
  709. */
  710. /*@{*/
  711. struct zbar_processor_s;
  712. /** opaque standalone processor object. */
  713. typedef struct zbar_processor_s zbar_processor_t;
  714. /** constructor.
  715. * if threaded is set and threading is available the processor
  716. * will spawn threads where appropriate to avoid blocking and
  717. * improve responsiveness
  718. */
  719. extern zbar_processor_t *zbar_processor_create(int threaded);
  720. /** destructor. cleans up all resources associated with the processor
  721. */
  722. extern void zbar_processor_destroy(zbar_processor_t *processor);
  723. /** (re)initialization.
  724. * opens a video input device and/or prepares to display output
  725. */
  726. extern int zbar_processor_init(zbar_processor_t *processor,
  727. const char *video_device,
  728. int enable_display);
  729. /** request a preferred size for the video image from the device.
  730. * the request may be adjusted or completely ignored by the driver.
  731. * @note must be called before zbar_processor_init()
  732. * @since 0.6
  733. */
  734. extern int zbar_processor_request_size(zbar_processor_t *processor,
  735. unsigned width,
  736. unsigned height);
  737. /** request a preferred video driver interface version for
  738. * debug/testing.
  739. * @note must be called before zbar_processor_init()
  740. * @since 0.6
  741. */
  742. extern int zbar_processor_request_interface(zbar_processor_t *processor,
  743. int version);
  744. /** request a preferred video I/O mode for debug/testing. You will
  745. * get errors if the driver does not support the specified mode.
  746. * @verbatim
  747. 0 = auto-detect
  748. 1 = force I/O using read()
  749. 2 = force memory mapped I/O using mmap()
  750. 3 = force USERPTR I/O (v4l2 only)
  751. @endverbatim
  752. * @note must be called before zbar_processor_init()
  753. * @since 0.7
  754. */
  755. extern int zbar_processor_request_iomode(zbar_processor_t *video,
  756. int iomode);
  757. /** force specific input and output formats for debug/testing.
  758. * @note must be called before zbar_processor_init()
  759. */
  760. extern int zbar_processor_force_format(zbar_processor_t *processor,
  761. unsigned long input_format,
  762. unsigned long output_format);
  763. /** setup result handler callback.
  764. * the specified function will be called by the processor whenever
  765. * new results are available from the video stream or a static image.
  766. * pass a NULL value to disable callbacks.
  767. * @param processor the object on which to set the handler.
  768. * @param handler the function to call when new results are available.
  769. * @param userdata is set as with zbar_processor_set_userdata().
  770. * @returns the previously registered handler
  771. */
  772. extern zbar_image_data_handler_t*
  773. zbar_processor_set_data_handler(zbar_processor_t *processor,
  774. zbar_image_data_handler_t *handler,
  775. const void *userdata);
  776. /** associate user specified data value with the processor.
  777. * @since 0.6
  778. */
  779. extern void zbar_processor_set_userdata(zbar_processor_t *processor,
  780. void *userdata);
  781. /** return user specified data value associated with the processor.
  782. * @since 0.6
  783. */
  784. extern void *zbar_processor_get_userdata(const zbar_processor_t *processor);
  785. /** set config for indicated symbology (0 for all) to specified value.
  786. * @returns 0 for success, non-0 for failure (config does not apply to
  787. * specified symbology, or value out of range)
  788. * @see zbar_decoder_set_config()
  789. * @since 0.4
  790. */
  791. extern int zbar_processor_set_config(zbar_processor_t *processor,
  792. zbar_symbol_type_t symbology,
  793. zbar_config_t config,
  794. int value);
  795. /** set video control value
  796. * @returns 0 for success, non-0 for failure
  797. * @since 0.20
  798. * @see zbar_video_set_control()
  799. */
  800. extern int zbar_processor_set_control (zbar_processor_t *processor,
  801. const char *control_name,
  802. int value);
  803. /** get video control value
  804. * @returns 0 for success, non-0 for failure
  805. * @since 0.20
  806. * @see zbar_video_get_control()
  807. */
  808. extern int zbar_processor_get_control (zbar_processor_t *processor,
  809. const char *control_name,
  810. int *value);
  811. /** parse configuration string using zbar_parse_config()
  812. * and apply to processor using zbar_processor_set_config().
  813. * @returns 0 for success, non-0 for failure
  814. * @see zbar_parse_config()
  815. * @see zbar_processor_set_config()
  816. * @since 0.4
  817. */
  818. static inline int zbar_processor_parse_config (zbar_processor_t *processor,
  819. const char *config_string)
  820. {
  821. zbar_symbol_type_t sym;
  822. zbar_config_t cfg;
  823. int val;
  824. return(zbar_parse_config(config_string, &sym, &cfg, &val) ||
  825. zbar_processor_set_config(processor, sym, cfg, val));
  826. }
  827. /** retrieve the current state of the output window.
  828. * @returns 1 if the output window is currently displayed, 0 if not.
  829. * @returns -1 if an error occurs
  830. */
  831. extern int zbar_processor_is_visible(zbar_processor_t *processor);
  832. /** show or hide the display window owned by the library.
  833. * the size will be adjusted to the input size
  834. */
  835. extern int zbar_processor_set_visible(zbar_processor_t *processor,
  836. int visible);
  837. /** control the processor in free running video mode.
  838. * only works if video input is initialized. if threading is in use,
  839. * scanning will occur in the background, otherwise this is only
  840. * useful wrapping calls to zbar_processor_user_wait(). if the
  841. * library output window is visible, video display will be enabled.
  842. */
  843. extern int zbar_processor_set_active(zbar_processor_t *processor,
  844. int active);
  845. /** retrieve decode results for last scanned image/frame.
  846. * @returns the symbol set result container or NULL if no results are
  847. * available
  848. * @note the returned symbol set has its reference count incremented;
  849. * ensure that the count is decremented after use
  850. * @since 0.10
  851. */
  852. extern const zbar_symbol_set_t*
  853. zbar_processor_get_results(const zbar_processor_t *processor);
  854. /** wait for input to the display window from the user
  855. * (via mouse or keyboard).
  856. * @returns >0 when input is received, 0 if timeout ms expired
  857. * with no input or -1 in case of an error
  858. */
  859. extern int zbar_processor_user_wait(zbar_processor_t *processor,
  860. int timeout);
  861. /** process from the video stream until a result is available,
  862. * or the timeout (in milliseconds) expires.
  863. * specify a timeout of -1 to scan indefinitely
  864. * (zbar_processor_set_active() may still be used to abort the scan
  865. * from another thread).
  866. * if the library window is visible, video display will be enabled.
  867. * @note that multiple results may still be returned (despite the
  868. * name).
  869. * @returns >0 if symbols were successfully decoded,
  870. * 0 if no symbols were found (ie, the timeout expired)
  871. * or -1 if an error occurs
  872. */
  873. extern int zbar_process_one(zbar_processor_t *processor,
  874. int timeout);
  875. /** process the provided image for barcodes.
  876. * if the library window is visible, the image will be displayed.
  877. * @returns >0 if symbols were successfully decoded,
  878. * 0 if no symbols were found or -1 if an error occurs
  879. */
  880. extern int zbar_process_image(zbar_processor_t *processor,
  881. zbar_image_t *image);
  882. /** enable dbus IPC API.
  883. * @returns 0 successful
  884. */
  885. int zbar_processor_request_dbus(zbar_processor_t *proc,
  886. int req_dbus_enabled);
  887. /** display detail for last processor error to stderr.
  888. * @returns a non-zero value suitable for passing to exit()
  889. */
  890. static inline int
  891. zbar_processor_error_spew (const zbar_processor_t *processor,
  892. int verbosity)
  893. {
  894. return(_zbar_error_spew(processor, verbosity));
  895. }
  896. /** retrieve the detail string for the last processor error. */
  897. static inline const char*
  898. zbar_processor_error_string (const zbar_processor_t *processor,
  899. int verbosity)
  900. {
  901. return(_zbar_error_string(processor, verbosity));
  902. }
  903. /** retrieve the type code for the last processor error. */
  904. static inline zbar_error_t
  905. zbar_processor_get_error_code (const zbar_processor_t *processor)
  906. {
  907. return(_zbar_get_error_code(processor));
  908. }
  909. /*@}*/
  910. /*------------------------------------------------------------*/
  911. /** @name Video interface
  912. * @anchor c-video
  913. * mid-level video source abstraction.
  914. * captures images from a video device
  915. */
  916. /*@{*/
  917. struct zbar_video_s;
  918. /** opaque video object. */
  919. typedef struct zbar_video_s zbar_video_t;
  920. /** constructor. */
  921. extern zbar_video_t *zbar_video_create(void);
  922. /** destructor. */
  923. extern void zbar_video_destroy(zbar_video_t *video);
  924. /** open and probe a video device.
  925. * the device specified by platform specific unique name
  926. * (v4l device node path in *nix eg "/dev/video",
  927. * DirectShow DevicePath property in windows).
  928. * @returns 0 if successful or -1 if an error occurs
  929. */
  930. extern int zbar_video_open(zbar_video_t *video,
  931. const char *device);
  932. /** retrieve file descriptor associated with open *nix video device
  933. * useful for using select()/poll() to tell when new images are
  934. * available (NB v4l2 only!!).
  935. * @returns the file descriptor or -1 if the video device is not open
  936. * or the driver only supports v4l1
  937. */
  938. extern int zbar_video_get_fd(const zbar_video_t *video);
  939. /** request a preferred size for the video image from the device.
  940. * the request may be adjusted or completely ignored by the driver.
  941. * @returns 0 if successful or -1 if the video device is already
  942. * initialized
  943. * @since 0.6
  944. */
  945. extern int zbar_video_request_size(zbar_video_t *video,
  946. unsigned width,
  947. unsigned height);
  948. /** request a preferred driver interface version for debug/testing.
  949. * @note must be called before zbar_video_open()
  950. * @since 0.6
  951. */
  952. extern int zbar_video_request_interface(zbar_video_t *video,
  953. int version);
  954. /** request a preferred I/O mode for debug/testing. You will get
  955. * errors if the driver does not support the specified mode.
  956. * @verbatim
  957. 0 = auto-detect
  958. 1 = force I/O using read()
  959. 2 = force memory mapped I/O using mmap()
  960. 3 = force USERPTR I/O (v4l2 only)
  961. @endverbatim
  962. * @note must be called before zbar_video_open()
  963. * @since 0.7
  964. */
  965. extern int zbar_video_request_iomode(zbar_video_t *video,
  966. int iomode);
  967. /** retrieve current output image width.
  968. * @returns the width or 0 if the video device is not open
  969. */
  970. extern int zbar_video_get_width(const zbar_video_t *video);
  971. /** retrieve current output image height.
  972. * @returns the height or 0 if the video device is not open
  973. */
  974. extern int zbar_video_get_height(const zbar_video_t *video);
  975. /** initialize video using a specific format for debug.
  976. * use zbar_negotiate_format() to automatically select and initialize
  977. * the best available format
  978. */
  979. extern int zbar_video_init(zbar_video_t *video,
  980. unsigned long format);
  981. /** start/stop video capture.
  982. * all buffered images are retired when capture is disabled.
  983. * @returns 0 if successful or -1 if an error occurs
  984. */
  985. extern int zbar_video_enable(zbar_video_t *video,
  986. int enable);
  987. /** retrieve next captured image. blocks until an image is available.
  988. * @returns NULL if video is not enabled or an error occurs
  989. */
  990. extern zbar_image_t *zbar_video_next_image(zbar_video_t *video);
  991. /** set video control value (integer).
  992. * @returns 0 for success, non-0 for failure
  993. * @since 0.20
  994. * @see zbar_processor_set_control()
  995. */
  996. extern int zbar_video_set_control (zbar_video_t *video,
  997. const char *control_name,
  998. int value);
  999. /** get video control value (integer).
  1000. * @returns 0 for success, non-0 for failure
  1001. * @since 0.20
  1002. * @see zbar_processor_get_control()
  1003. */
  1004. extern int zbar_video_get_control (zbar_video_t *video,
  1005. const char *control_name,
  1006. int *value);
  1007. /** get available controls from video source
  1008. * @returns 0 for success, non-0 for failure
  1009. * @since 0.20
  1010. */
  1011. extern struct video_controls_s
  1012. *zbar_video_get_controls (const zbar_video_t *video,
  1013. int index);
  1014. /** get available video resolutions from video source
  1015. * @returns 0 for success, non-0 for failure
  1016. * @since 0.22
  1017. */
  1018. extern struct video_resolution_s
  1019. *zbar_video_get_resolutions (const zbar_video_t *vdo,
  1020. int index);
  1021. /** display detail for last video error to stderr.
  1022. * @returns a non-zero value suitable for passing to exit()
  1023. */
  1024. static inline int zbar_video_error_spew (const zbar_video_t *video,
  1025. int verbosity)
  1026. {
  1027. return(_zbar_error_spew(video, verbosity));
  1028. }
  1029. /** retrieve the detail string for the last video error. */
  1030. static inline const char *zbar_video_error_string (const zbar_video_t *video,
  1031. int verbosity)
  1032. {
  1033. return(_zbar_error_string(video, verbosity));
  1034. }
  1035. /** retrieve the type code for the last video error. */
  1036. static inline zbar_error_t
  1037. zbar_video_get_error_code (const zbar_video_t *video)
  1038. {
  1039. return(_zbar_get_error_code(video));
  1040. }
  1041. /*@}*/
  1042. /*------------------------------------------------------------*/
  1043. /** @name Window interface
  1044. * @anchor c-window
  1045. * mid-level output window abstraction.
  1046. * displays images to user-specified platform specific output window
  1047. */
  1048. /*@{*/
  1049. struct zbar_window_s;
  1050. /** opaque window object. */
  1051. typedef struct zbar_window_s zbar_window_t;
  1052. /** constructor. */
  1053. extern zbar_window_t *zbar_window_create(void);
  1054. /** destructor. */
  1055. extern void zbar_window_destroy(zbar_window_t *window);
  1056. /** associate reader with an existing platform window.
  1057. * This can be any "Drawable" for X Windows or a "HWND" for windows.
  1058. * input images will be scaled into the output window.
  1059. * pass NULL to detach from the resource, further input will be
  1060. * ignored
  1061. */
  1062. extern int zbar_window_attach(zbar_window_t *window,
  1063. void *x11_display_w32_hwnd,
  1064. unsigned long x11_drawable);
  1065. /** control content level of the reader overlay.
  1066. * the overlay displays graphical data for informational or debug
  1067. * purposes. higher values increase the level of annotation (possibly
  1068. * decreasing performance). @verbatim
  1069. 0 = disable overlay
  1070. 1 = outline decoded symbols (default)
  1071. 2 = also track and display input frame rate
  1072. @endverbatim
  1073. */
  1074. extern void zbar_window_set_overlay(zbar_window_t *window,
  1075. int level);
  1076. /** retrieve current content level of reader overlay.
  1077. * @see zbar_window_set_overlay()
  1078. * @since 0.10
  1079. */
  1080. extern int zbar_window_get_overlay(const zbar_window_t *window);
  1081. /** draw a new image into the output window. */
  1082. extern int zbar_window_draw(zbar_window_t *window,
  1083. zbar_image_t *image);
  1084. /** redraw the last image (exposure handler). */
  1085. extern int zbar_window_redraw(zbar_window_t *window);
  1086. /** resize the image window (reconfigure handler).
  1087. * this does @em not update the contents of the window
  1088. * @since 0.3, changed in 0.4 to not redraw window
  1089. */
  1090. extern int zbar_window_resize(zbar_window_t *window,
  1091. unsigned width,
  1092. unsigned height);
  1093. /** display detail for last window error to stderr.
  1094. * @returns a non-zero value suitable for passing to exit()
  1095. */
  1096. static inline int zbar_window_error_spew (const zbar_window_t *window,
  1097. int verbosity)
  1098. {
  1099. return(_zbar_error_spew(window, verbosity));
  1100. }
  1101. /** retrieve the detail string for the last window error. */
  1102. static inline const char*
  1103. zbar_window_error_string (const zbar_window_t *window,
  1104. int verbosity)
  1105. {
  1106. return(_zbar_error_string(window, verbosity));
  1107. }
  1108. /** retrieve the type code for the last window error. */
  1109. static inline zbar_error_t
  1110. zbar_window_get_error_code (const zbar_window_t *window)
  1111. {
  1112. return(_zbar_get_error_code(window));
  1113. }
  1114. /** select a compatible format between video input and output window.
  1115. * the selection algorithm attempts to use a format shared by
  1116. * video input and window output which is also most useful for
  1117. * barcode scanning. if a format conversion is necessary, it will
  1118. * heuristically attempt to minimize the cost of the conversion
  1119. */
  1120. extern int zbar_negotiate_format(zbar_video_t *video,
  1121. zbar_window_t *window);
  1122. /*@}*/
  1123. /*------------------------------------------------------------*/
  1124. /** @name Image Scanner interface
  1125. * @anchor c-imagescanner
  1126. * mid-level image scanner interface.
  1127. * reads barcodes from 2-D images
  1128. */
  1129. /*@{*/
  1130. struct zbar_image_scanner_s;
  1131. /** opaque image scanner object. */
  1132. typedef struct zbar_image_scanner_s zbar_image_scanner_t;
  1133. /** constructor. */
  1134. extern zbar_image_scanner_t *zbar_image_scanner_create(void);
  1135. /** destructor. */
  1136. extern void zbar_image_scanner_destroy(zbar_image_scanner_t *scanner);
  1137. /** setup result handler callback.
  1138. * the specified function will be called by the scanner whenever
  1139. * new results are available from a decoded image.
  1140. * pass a NULL value to disable callbacks.
  1141. * @returns the previously registered handler
  1142. */
  1143. extern zbar_image_data_handler_t*
  1144. zbar_image_scanner_set_data_handler(zbar_image_scanner_t *scanner,
  1145. zbar_image_data_handler_t *handler,
  1146. const void *userdata);
  1147. /** request sending decoded codes via D-Bus
  1148. * @see zbar_processor_parse_config()
  1149. * @since 0.21
  1150. */
  1151. extern int zbar_image_scanner_request_dbus(zbar_image_scanner_t *scanner,
  1152. int req_dbus_enabled);
  1153. /** set config for indicated symbology (0 for all) to specified value.
  1154. * @returns 0 for success, non-0 for failure (config does not apply to
  1155. * specified symbology, or value out of range)
  1156. * @see zbar_decoder_set_config()
  1157. * @since 0.4
  1158. */
  1159. extern int zbar_image_scanner_set_config(zbar_image_scanner_t *scanner,
  1160. zbar_symbol_type_t symbology,
  1161. zbar_config_t config,
  1162. int value);
  1163. /** get config for indicated symbology
  1164. * @returns 0 for success, non-0 for failure (config does not apply to
  1165. * specified symbology, or value out of range). On success, *value is filled.
  1166. * @since 0.22
  1167. */
  1168. extern int zbar_image_scanner_get_config(zbar_image_scanner_t *scanner,
  1169. zbar_symbol_type_t symbology,
  1170. zbar_config_t config,
  1171. int *value);
  1172. /** parse configuration string using zbar_parse_config()
  1173. * and apply to image scanner using zbar_image_scanner_set_config().
  1174. * @returns 0 for success, non-0 for failure
  1175. * @see zbar_parse_config()
  1176. * @see zbar_image_scanner_set_config()
  1177. * @since 0.4
  1178. */
  1179. static inline int
  1180. zbar_image_scanner_parse_config (zbar_image_scanner_t *scanner,
  1181. const char *config_string)
  1182. {
  1183. zbar_symbol_type_t sym;
  1184. zbar_config_t cfg;
  1185. int val;
  1186. return(zbar_parse_config(config_string, &sym, &cfg, &val) ||
  1187. zbar_image_scanner_set_config(scanner, sym, cfg, val));
  1188. }
  1189. /** enable or disable the inter-image result cache (default disabled).
  1190. * mostly useful for scanning video frames, the cache filters
  1191. * duplicate results from consecutive images, while adding some
  1192. * consistency checking and hysteresis to the results.
  1193. * this interface also clears the cache
  1194. */
  1195. extern void zbar_image_scanner_enable_cache(zbar_image_scanner_t *scanner,
  1196. int enable);
  1197. /** remove any previously decoded results from the image scanner and the
  1198. * specified image. somewhat more efficient version of
  1199. * zbar_image_set_symbols(image, NULL) which may retain memory for
  1200. * subsequent decodes
  1201. * @since 0.10
  1202. */
  1203. extern void zbar_image_scanner_recycle_image(zbar_image_scanner_t *scanner,
  1204. zbar_image_t *image);
  1205. /** retrieve decode results for last scanned image.
  1206. * @returns the symbol set result container or NULL if no results are
  1207. * available
  1208. * @note the symbol set does not have its reference count adjusted;
  1209. * ensure that the count is incremented if the results may be kept
  1210. * after the next image is scanned
  1211. * @since 0.10
  1212. */
  1213. extern const zbar_symbol_set_t*
  1214. zbar_image_scanner_get_results(const zbar_image_scanner_t *scanner);
  1215. /** scan for symbols in provided image. The image format must be
  1216. * "Y800" or "GRAY".
  1217. * @returns >0 if symbols were successfully decoded from the image,
  1218. * 0 if no symbols were found or -1 if an error occurs
  1219. * @see zbar_image_convert()
  1220. * @since 0.9 - changed to only accept grayscale images
  1221. */
  1222. extern int zbar_scan_image(zbar_image_scanner_t *scanner,
  1223. zbar_image_t *image);
  1224. /*@}*/
  1225. /*------------------------------------------------------------*/
  1226. /** @name Decoder interface
  1227. * @anchor c-decoder
  1228. * low-level bar width stream decoder interface.
  1229. * identifies symbols and extracts encoded data
  1230. */
  1231. /*@{*/
  1232. struct zbar_decoder_s;
  1233. /** opaque decoder object. */
  1234. typedef struct zbar_decoder_s zbar_decoder_t;
  1235. /** decoder data handler callback function.
  1236. * called by decoder when new data has just been decoded
  1237. */
  1238. typedef void (zbar_decoder_handler_t)(zbar_decoder_t *decoder);
  1239. /** constructor. */
  1240. extern zbar_decoder_t *zbar_decoder_create(void);
  1241. /** destructor. */
  1242. extern void zbar_decoder_destroy(zbar_decoder_t *decoder);
  1243. /** set config for indicated symbology (0 for all) to specified value.
  1244. * @returns 0 for success, non-0 for failure (config does not apply to
  1245. * specified symbology, or value out of range)
  1246. * @since 0.4
  1247. */
  1248. extern int zbar_decoder_set_config(zbar_decoder_t *decoder,
  1249. zbar_symbol_type_t symbology,
  1250. zbar_config_t config,
  1251. int value);
  1252. /** get config for indicated symbology
  1253. * @returns 0 for success, non-0 for failure (config does not apply to
  1254. * specified symbology, or value out of range). On success, *value is filled.
  1255. * @since 0.22
  1256. */
  1257. extern int zbar_decoder_get_config(zbar_decoder_t *decoder,
  1258. zbar_symbol_type_t symbology,
  1259. zbar_config_t config,
  1260. int *value);
  1261. /** parse configuration string using zbar_parse_config()
  1262. * and apply to decoder using zbar_decoder_set_config().
  1263. * @returns 0 for success, non-0 for failure
  1264. * @see zbar_parse_config()
  1265. * @see zbar_decoder_set_config()
  1266. * @since 0.4
  1267. */
  1268. static inline int zbar_decoder_parse_config (zbar_decoder_t *decoder,
  1269. const char *config_string)
  1270. {
  1271. zbar_symbol_type_t sym;
  1272. zbar_config_t cfg;
  1273. int val;
  1274. return(zbar_parse_config(config_string, &sym, &cfg, &val) ||
  1275. zbar_decoder_set_config(decoder, sym, cfg, val));
  1276. }
  1277. /** retrieve symbology boolean config settings.
  1278. * @returns a bitmask indicating which configs are currently set for the
  1279. * specified symbology.
  1280. * @since 0.11
  1281. */
  1282. extern unsigned int zbar_decoder_get_configs(const zbar_decoder_t *decoder,
  1283. zbar_symbol_type_t symbology);
  1284. /** clear all decoder state.
  1285. * any partial symbols are flushed
  1286. */
  1287. extern void zbar_decoder_reset(zbar_decoder_t *decoder);
  1288. /** mark start of a new scan pass.
  1289. * clears any intra-symbol state and resets color to ::ZBAR_SPACE.
  1290. * any partially decoded symbol state is retained
  1291. */
  1292. extern void zbar_decoder_new_scan(zbar_decoder_t *decoder);
  1293. /** process next bar/space width from input stream.
  1294. * the width is in arbitrary relative units. first value of a scan
  1295. * is ::ZBAR_SPACE width, alternating from there.
  1296. * @returns appropriate symbol type if width completes
  1297. * decode of a symbol (data is available for retrieval)
  1298. * @returns ::ZBAR_PARTIAL as a hint if part of a symbol was decoded
  1299. * @returns ::ZBAR_NONE (0) if no new symbol data is available
  1300. */
  1301. extern zbar_symbol_type_t zbar_decode_width(zbar_decoder_t *decoder,
  1302. unsigned width);
  1303. /** retrieve color of @em next element passed to
  1304. * zbar_decode_width(). */
  1305. extern zbar_color_t zbar_decoder_get_color(const zbar_decoder_t *decoder);
  1306. /** retrieve last decoded data.
  1307. * @returns the data string or NULL if no new data available.
  1308. * the returned data buffer is owned by library, contents are only
  1309. * valid between non-0 return from zbar_decode_width and next library
  1310. * call
  1311. */
  1312. extern const char *zbar_decoder_get_data(const zbar_decoder_t *decoder);
  1313. /** retrieve length of binary data.
  1314. * @returns the length of the decoded data or 0 if no new data
  1315. * available.
  1316. */
  1317. extern unsigned int
  1318. zbar_decoder_get_data_length(const zbar_decoder_t *decoder);
  1319. /** retrieve last decoded symbol type.
  1320. * @returns the type or ::ZBAR_NONE if no new data available
  1321. */
  1322. extern zbar_symbol_type_t
  1323. zbar_decoder_get_type(const zbar_decoder_t *decoder);
  1324. /** retrieve modifier flags for the last decoded symbol.
  1325. * @returns a bitmask indicating which characteristics were detected
  1326. * during decoding.
  1327. * @since 0.11
  1328. */
  1329. extern unsigned int zbar_decoder_get_modifiers(const zbar_decoder_t *decoder);
  1330. /** retrieve last decode direction.
  1331. * @returns 1 for forward and -1 for reverse
  1332. * @returns 0 if the decode direction is unknown or does not apply
  1333. * @since 0.11
  1334. */
  1335. extern int zbar_decoder_get_direction(const zbar_decoder_t *decoder);
  1336. /** setup data handler callback.
  1337. * the registered function will be called by the decoder
  1338. * just before zbar_decode_width() returns a non-zero value.
  1339. * pass a NULL value to disable callbacks.
  1340. * @returns the previously registered handler
  1341. */
  1342. extern zbar_decoder_handler_t*
  1343. zbar_decoder_set_handler(zbar_decoder_t *decoder,
  1344. zbar_decoder_handler_t *handler);
  1345. /** associate user specified data value with the decoder. */
  1346. extern void zbar_decoder_set_userdata(zbar_decoder_t *decoder,
  1347. void *userdata);
  1348. /** return user specified data value associated with the decoder. */
  1349. extern void *zbar_decoder_get_userdata(const zbar_decoder_t *decoder);
  1350. /*@}*/
  1351. /*------------------------------------------------------------*/
  1352. /** @name Scanner interface
  1353. * @anchor c-scanner
  1354. * low-level linear intensity sample stream scanner interface.
  1355. * identifies "bar" edges and measures width between them.
  1356. * optionally passes to bar width decoder
  1357. */
  1358. /*@{*/
  1359. struct zbar_scanner_s;
  1360. /** opaque scanner object. */
  1361. typedef struct zbar_scanner_s zbar_scanner_t;
  1362. /** constructor.
  1363. * if decoder is non-NULL it will be attached to scanner
  1364. * and called automatically at each new edge
  1365. * current color is initialized to ::ZBAR_SPACE
  1366. * (so an initial BAR->SPACE transition may be discarded)
  1367. */
  1368. extern zbar_scanner_t *zbar_scanner_create(zbar_decoder_t *decoder);
  1369. /** destructor. */
  1370. extern void zbar_scanner_destroy(zbar_scanner_t *scanner);
  1371. /** clear all scanner state.
  1372. * also resets an associated decoder
  1373. */
  1374. extern zbar_symbol_type_t zbar_scanner_reset(zbar_scanner_t *scanner);
  1375. /** mark start of a new scan pass. resets color to ::ZBAR_SPACE.
  1376. * also updates an associated decoder.
  1377. * @returns any decode results flushed from the pipeline
  1378. * @note when not using callback handlers, the return value should
  1379. * be checked the same as zbar_scan_y()
  1380. * @note call zbar_scanner_flush() at least twice before calling this
  1381. * method to ensure no decode results are lost
  1382. */
  1383. extern zbar_symbol_type_t zbar_scanner_new_scan(zbar_scanner_t *scanner);
  1384. /** flush scanner processing pipeline.
  1385. * forces current scanner position to be a scan boundary.
  1386. * call multiple times (max 3) to completely flush decoder.
  1387. * @returns any decode/scan results flushed from the pipeline
  1388. * @note when not using callback handlers, the return value should
  1389. * be checked the same as zbar_scan_y()
  1390. * @since 0.9
  1391. */
  1392. extern zbar_symbol_type_t zbar_scanner_flush(zbar_scanner_t *scanner);
  1393. /** process next sample intensity value.
  1394. * intensity (y) is in arbitrary relative units.
  1395. * @returns result of zbar_decode_width() if a decoder is attached,
  1396. * otherwise @returns (::ZBAR_PARTIAL) when new edge is detected
  1397. * or 0 (::ZBAR_NONE) if no new edge is detected
  1398. */
  1399. extern zbar_symbol_type_t zbar_scan_y(zbar_scanner_t *scanner,
  1400. int y);
  1401. /** process next sample from RGB (or BGR) triple. */
  1402. static inline zbar_symbol_type_t zbar_scan_rgb24 (zbar_scanner_t *scanner,
  1403. unsigned char *rgb)
  1404. {
  1405. return(zbar_scan_y(scanner, rgb[0] + rgb[1] + rgb[2]));
  1406. }
  1407. /** retrieve last scanned width. */
  1408. extern unsigned zbar_scanner_get_width(const zbar_scanner_t *scanner);
  1409. /** retrieve sample position of last edge.
  1410. * @since 0.10
  1411. */
  1412. extern unsigned zbar_scanner_get_edge(const zbar_scanner_t *scn,
  1413. unsigned offset,
  1414. int prec);
  1415. /** retrieve last scanned color. */
  1416. extern zbar_color_t zbar_scanner_get_color(const zbar_scanner_t *scanner);
  1417. /*@}*/
  1418. #ifdef __cplusplus
  1419. }
  1420. }
  1421. # include "zbar/Exception.h"
  1422. # include "zbar/Decoder.h"
  1423. # include "zbar/Scanner.h"
  1424. # include "zbar/Symbol.h"
  1425. # include "zbar/Image.h"
  1426. # include "zbar/ImageScanner.h"
  1427. # include "zbar/Video.h"
  1428. # include "zbar/Window.h"
  1429. # include "zbar/Processor.h"
  1430. #endif
  1431. #endif