symbol.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 _SYMBOL_H_
  24. #define _SYMBOL_H_
  25. //#include <stdlib.h>
  26. #include <zbar.h>
  27. #include "refcnt.h"
  28. typedef struct point_s {
  29. int x, y;
  30. } point_t;
  31. struct zbar_symbol_set_s {
  32. refcnt_t refcnt;
  33. int nsyms; /* number of filtered symbols */
  34. zbar_symbol_t *head; /* first of decoded symbol results */
  35. zbar_symbol_t *tail; /* last of unfiltered symbol results */
  36. };
  37. struct zbar_symbol_s {
  38. zbar_symbol_type_t type; /* symbol type */
  39. unsigned int data_alloc; /* allocation size of data */
  40. unsigned int datalen; /* length of binary symbol data */
  41. char *data; /* symbol data */
  42. unsigned pts_alloc; /* allocation size of pts */
  43. unsigned npts; /* number of points in location polygon */
  44. point_t *pts; /* list of points in location polygon */
  45. refcnt_t refcnt; /* reference count */
  46. zbar_symbol_t *next; /* linked list of results (or siblings) */
  47. zbar_symbol_set_t *syms; /* components of composite result */
  48. unsigned long time; /* relative symbol capture time */
  49. int cache_count; /* cache state */
  50. int quality; /* relative symbol reliability metric */
  51. };
  52. extern void _zbar_symbol_free(zbar_symbol_t*);
  53. extern zbar_symbol_set_t *_zbar_symbol_set_create(void);
  54. extern void _zbar_symbol_set_free(zbar_symbol_set_t*);
  55. static inline void sym_add_point (zbar_symbol_t *sym,
  56. int x,
  57. int y)
  58. {
  59. int i = sym->npts;
  60. if(++sym->npts >= sym->pts_alloc)
  61. sym->pts = realloc(sym->pts, ++sym->pts_alloc * sizeof(point_t));
  62. sym->pts[i].x = x;
  63. sym->pts[i].y = y;
  64. }
  65. static inline void _zbar_symbol_refcnt (zbar_symbol_t *sym,
  66. int delta)
  67. {
  68. if(!_zbar_refcnt(&sym->refcnt, delta) && delta <= 0)
  69. _zbar_symbol_free(sym);
  70. }
  71. static inline void _zbar_symbol_set_add (zbar_symbol_set_t *syms,
  72. zbar_symbol_t *sym)
  73. {
  74. sym->next = syms->head;
  75. syms->head = sym;
  76. syms->nsyms++;
  77. _zbar_symbol_refcnt(sym, 1);
  78. }
  79. #endif