quirc_internal.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* quirc -- QR-code recognition library
  2. * Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef QUIRC_INTERNAL_H_
  17. #define QUIRC_INTERNAL_H_
  18. #include <quirc.h>
  19. #define QUIRC_PIXEL_WHITE 0
  20. #define QUIRC_PIXEL_BLACK 1
  21. #define QUIRC_PIXEL_REGION 2
  22. #ifndef QUIRC_MAX_REGIONS
  23. #define QUIRC_MAX_REGIONS 254
  24. #endif
  25. #define QUIRC_MAX_CAPSTONES 32
  26. #define QUIRC_MAX_GRIDS 8
  27. #define QUIRC_PERSPECTIVE_PARAMS 8
  28. #if QUIRC_MAX_REGIONS < UINT8_MAX
  29. #define QUIRC_PIXEL_ALIAS_IMAGE 1
  30. typedef uint8_t quirc_pixel_t;
  31. #elif QUIRC_MAX_REGIONS < UINT16_MAX
  32. #define QUIRC_PIXEL_ALIAS_IMAGE 0
  33. typedef uint16_t quirc_pixel_t;
  34. #else
  35. #error "QUIRC_MAX_REGIONS > 65534 is not supported"
  36. #endif
  37. struct quirc_region {
  38. struct quirc_point seed;
  39. int count;
  40. int capstone;
  41. };
  42. struct quirc_capstone {
  43. int ring;
  44. int stone;
  45. struct quirc_point corners[4];
  46. struct quirc_point center;
  47. double c[QUIRC_PERSPECTIVE_PARAMS];
  48. int qr_grid;
  49. };
  50. struct quirc_grid {
  51. /* Capstone indices */
  52. int caps[3];
  53. /* Alignment pattern region and corner */
  54. int align_region;
  55. struct quirc_point align;
  56. /* Timing pattern endpoints */
  57. struct quirc_point tpep[3];
  58. int hscan;
  59. int vscan;
  60. /* Grid size and perspective transform */
  61. int grid_size;
  62. double c[QUIRC_PERSPECTIVE_PARAMS];
  63. };
  64. struct quirc {
  65. uint8_t *image;
  66. quirc_pixel_t *pixels;
  67. int w;
  68. int h;
  69. int num_regions;
  70. struct quirc_region regions[QUIRC_MAX_REGIONS];
  71. int num_capstones;
  72. struct quirc_capstone capstones[QUIRC_MAX_CAPSTONES];
  73. int num_grids;
  74. struct quirc_grid grids[QUIRC_MAX_GRIDS];
  75. };
  76. /************************************************************************
  77. * QR-code version information database
  78. */
  79. #define QUIRC_MAX_VERSION 40
  80. #define QUIRC_MAX_ALIGNMENT 7
  81. struct quirc_rs_params {
  82. int bs; /* Small block size */
  83. int dw; /* Small data words */
  84. int ns; /* Number of small blocks */
  85. };
  86. struct quirc_version_info {
  87. int data_bytes;
  88. int apat[QUIRC_MAX_ALIGNMENT];
  89. struct quirc_rs_params ecc[4];
  90. };
  91. extern const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1];
  92. #endif