qrspec.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * qrencode - QR Code encoder
  3. *
  4. * QR Code specification in convenient format.
  5. * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef __QRSPEC_H__
  22. #define __QRSPEC_H__
  23. #include "qrencode.h"
  24. /******************************************************************************
  25. * Version and capacity
  26. *****************************************************************************/
  27. /**
  28. * Maximum version (size) of QR-code symbol.
  29. */
  30. #define QRSPEC_VERSION_MAX 40
  31. /**
  32. * Maximum width of a symbol
  33. */
  34. #define QRSPEC_WIDTH_MAX 177
  35. /**
  36. * Return maximum data code length (bytes) for the version.
  37. * @param version
  38. * @param level
  39. * @return maximum size (bytes)
  40. */
  41. extern int QRspec_getDataLength(int version, QRecLevel level);
  42. /**
  43. * Return maximum error correction code length (bytes) for the version.
  44. * @param version
  45. * @param level
  46. * @return ECC size (bytes)
  47. */
  48. extern int QRspec_getECCLength(int version, QRecLevel level);
  49. /**
  50. * Return a version number that satisfies the input code length.
  51. * @param size input code length (byte)
  52. * @param level
  53. * @return version number
  54. */
  55. extern int QRspec_getMinimumVersion(int size, QRecLevel level);
  56. /**
  57. * Return the width of the symbol for the version.
  58. * @param version
  59. * @return width
  60. */
  61. extern int QRspec_getWidth(int version);
  62. /**
  63. * Return the numer of remainder bits.
  64. * @param version
  65. * @return number of remainder bits
  66. */
  67. extern int QRspec_getRemainder(int version);
  68. /******************************************************************************
  69. * Length indicator
  70. *****************************************************************************/
  71. /**
  72. * Return the size of lenght indicator for the mode and version.
  73. * @param mode
  74. * @param version
  75. * @return the size of the appropriate length indicator (bits).
  76. */
  77. extern int QRspec_lengthIndicator(QRencodeMode mode, int version);
  78. /**
  79. * Return the maximum length for the mode and version.
  80. * @param mode
  81. * @param version
  82. * @return the maximum length (bytes)
  83. */
  84. extern int QRspec_maximumWords(QRencodeMode mode, int version);
  85. /******************************************************************************
  86. * Error correction code
  87. *****************************************************************************/
  88. /**
  89. * Return an array of ECC specification.
  90. * @param version
  91. * @param level
  92. * @param spec an array of ECC specification contains as following:
  93. * {# of type1 blocks, # of data code, # of ecc code,
  94. * # of type2 blocks, # of data code}
  95. */
  96. void QRspec_getEccSpec(int version, QRecLevel level, int spec[5]);
  97. #define QRspec_rsBlockNum(__spec__) (__spec__[0] + __spec__[3])
  98. #define QRspec_rsBlockNum1(__spec__) (__spec__[0])
  99. #define QRspec_rsDataCodes1(__spec__) (__spec__[1])
  100. #define QRspec_rsEccCodes1(__spec__) (__spec__[2])
  101. #define QRspec_rsBlockNum2(__spec__) (__spec__[3])
  102. #define QRspec_rsDataCodes2(__spec__) (__spec__[4])
  103. #define QRspec_rsEccCodes2(__spec__) (__spec__[2])
  104. #define QRspec_rsDataLength(__spec__) \
  105. ((QRspec_rsBlockNum1(__spec__) * QRspec_rsDataCodes1(__spec__)) + \
  106. (QRspec_rsBlockNum2(__spec__) * QRspec_rsDataCodes2(__spec__)))
  107. #define QRspec_rsEccLength(__spec__) \
  108. (QRspec_rsBlockNum(__spec__) * QRspec_rsEccCodes1(__spec__))
  109. /******************************************************************************
  110. * Version information pattern
  111. *****************************************************************************/
  112. /**
  113. * Return BCH encoded version information pattern that is used for the symbol
  114. * of version 7 or greater. Use lower 18 bits.
  115. * @param version
  116. * @return BCH encoded version information pattern
  117. */
  118. extern unsigned int QRspec_getVersionPattern(int version);
  119. /******************************************************************************
  120. * Format information
  121. *****************************************************************************/
  122. /**
  123. * Return BCH encoded format information pattern.
  124. * @param mask
  125. * @param level
  126. * @return BCH encoded format information pattern
  127. */
  128. extern unsigned int QRspec_getFormatInfo(int mask, QRecLevel level);
  129. /******************************************************************************
  130. * Frame
  131. *****************************************************************************/
  132. /**
  133. * Return a copy of initialized frame.
  134. * When the same version is requested twice or more, a copy of cached frame
  135. * is returned.
  136. * WARNING: Thread unsafe!!!
  137. * @param version
  138. * @return Array of unsigned char. You can free it by free().
  139. */
  140. extern unsigned char *QRspec_newFrame(int version);
  141. /**
  142. * Clear the frame cache. Typically for debug.
  143. * WARNING: Thread unsafe!!!
  144. */
  145. extern void QRspec_clearCache(void);
  146. #endif /* __QRSPEC_H__ */