ean.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 _EAN_H_
  24. #define _EAN_H_
  25. /* state of each parallel decode attempt */
  26. typedef struct ean_pass_s {
  27. signed char state; /* module position of w[idx] in symbol */
  28. #define STATE_ADDON 0x40 /* scanning add-on */
  29. #define STATE_IDX 0x1f /* element offset into symbol */
  30. unsigned char raw[7]; /* decode in process */
  31. } ean_pass_t;
  32. /* EAN/UPC specific decode state */
  33. typedef struct ean_decoder_s {
  34. ean_pass_t pass[4]; /* state of each parallel decode attempt */
  35. zbar_symbol_type_t left; /* current holding buffer contents */
  36. zbar_symbol_type_t right;
  37. zbar_symbol_type_t addon;
  38. unsigned s4; /* character width */
  39. signed char buf[18]; /* holding buffer */
  40. signed char enable;
  41. unsigned ean13_config;
  42. unsigned ean8_config;
  43. unsigned upca_config;
  44. unsigned upce_config;
  45. unsigned isbn10_config;
  46. unsigned isbn13_config;
  47. } ean_decoder_t;
  48. /* reset EAN/UPC pass specific state */
  49. static inline void ean_new_scan (ean_decoder_t *ean)
  50. {
  51. ean->pass[0].state = ean->pass[1].state = -1;
  52. ean->pass[2].state = ean->pass[3].state = -1;
  53. ean->s4 = 0;
  54. }
  55. /* reset all EAN/UPC state */
  56. static inline void ean_reset (ean_decoder_t *ean)
  57. {
  58. ean_new_scan(ean);
  59. ean->left = ean->right = ean->addon = ZBAR_NONE;
  60. }
  61. static inline unsigned ean_get_config (ean_decoder_t *ean,
  62. zbar_symbol_type_t sym)
  63. {
  64. switch(sym & ZBAR_SYMBOL) {
  65. case ZBAR_EAN13: return(ean->ean13_config);
  66. case ZBAR_EAN8: return(ean->ean8_config);
  67. case ZBAR_UPCA: return(ean->upca_config);
  68. case ZBAR_UPCE: return(ean->upce_config);
  69. case ZBAR_ISBN10: return(ean->isbn10_config);
  70. case ZBAR_ISBN13: return(ean->isbn13_config);
  71. default: return(0);
  72. }
  73. }
  74. /* decode EAN/UPC symbols */
  75. zbar_symbol_type_t _zbar_decode_ean(zbar_decoder_t *dcode);
  76. #endif