qrspec.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * qrencode - QR Code encoder
  3. *
  4. * QR Code specification in convenient format.
  5. * Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
  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 width of a symbol
  29. */
  30. #define QRSPEC_WIDTH_MAX 177
  31. /**
  32. * Return maximum data code length (bytes) for the version.
  33. * @param version version of the symbol
  34. * @param level error correction level
  35. * @return maximum size (bytes)
  36. */
  37. extern int QRspec_getDataLength(int version, QRecLevel level);
  38. /**
  39. * Return maximum error correction code length (bytes) for the version.
  40. * @param version version of the symbol
  41. * @param level error correction level
  42. * @return ECC size (bytes)
  43. */
  44. extern int QRspec_getECCLength(int version, QRecLevel level);
  45. /**
  46. * Return a version number that satisfies the input code length.
  47. * @param size input code length (byte)
  48. * @param level error correction level
  49. * @return version number
  50. */
  51. extern int QRspec_getMinimumVersion(int size, QRecLevel level);
  52. /**
  53. * Return the width of the symbol for the version.
  54. * @param version vesion of the symbol
  55. * @return width of the symbol
  56. */
  57. extern int QRspec_getWidth(int version);
  58. /**
  59. * Return the numer of remainder bits.
  60. * @param version vesion of the symbol
  61. * @return number of remainder bits
  62. */
  63. extern int QRspec_getRemainder(int version);
  64. /******************************************************************************
  65. * Length indicator
  66. *****************************************************************************/
  67. /**
  68. * Return the size of length indicator for the mode and version.
  69. * @param mode encode mode
  70. * @param version vesion of the symbol
  71. * @return the size of the appropriate length indicator (bits).
  72. */
  73. extern int QRspec_lengthIndicator(QRencodeMode mode, int version);
  74. /**
  75. * Return the maximum length for the mode and version.
  76. * @param mode encode mode
  77. * @param version vesion of the symbol
  78. * @return the maximum length (bytes)
  79. */
  80. extern int QRspec_maximumWords(QRencodeMode mode, int version);
  81. /******************************************************************************
  82. * Error correction code
  83. *****************************************************************************/
  84. /**
  85. * Return an array of ECC specification.
  86. * @param version version of the symbol
  87. * @param level error correction level
  88. * @param spec an array of ECC specification contains as following:
  89. * {# of type1 blocks, # of data code, # of ecc code,
  90. * # of type2 blocks, # of data code}
  91. */
  92. void QRspec_getEccSpec(int version, QRecLevel level, int spec[5]);
  93. #define QRspec_rsBlockNum(__spec__) (__spec__[0] + __spec__[3])
  94. #define QRspec_rsBlockNum1(__spec__) (__spec__[0])
  95. #define QRspec_rsDataCodes1(__spec__) (__spec__[1])
  96. #define QRspec_rsEccCodes1(__spec__) (__spec__[2])
  97. #define QRspec_rsBlockNum2(__spec__) (__spec__[3])
  98. #define QRspec_rsDataCodes2(__spec__) (__spec__[4])
  99. #define QRspec_rsEccCodes2(__spec__) (__spec__[2])
  100. #define QRspec_rsDataLength(__spec__) \
  101. ((QRspec_rsBlockNum1(__spec__) * QRspec_rsDataCodes1(__spec__)) + \
  102. (QRspec_rsBlockNum2(__spec__) * QRspec_rsDataCodes2(__spec__)))
  103. #define QRspec_rsEccLength(__spec__) \
  104. (QRspec_rsBlockNum(__spec__) * QRspec_rsEccCodes1(__spec__))
  105. /******************************************************************************
  106. * Version information pattern
  107. *****************************************************************************/
  108. /**
  109. * Return BCH encoded version information pattern that is used for the symbol
  110. * of version 7 or greater. Use lower 18 bits.
  111. * @param version version of the symbol
  112. * @return BCH encoded version information pattern
  113. */
  114. extern unsigned int QRspec_getVersionPattern(int version);
  115. /******************************************************************************
  116. * Format information
  117. *****************************************************************************/
  118. /**
  119. * Return BCH encoded format information pattern.
  120. * @param mask mask number
  121. * @param level error correction level
  122. * @return BCH encoded format information pattern
  123. */
  124. extern unsigned int QRspec_getFormatInfo(int mask, QRecLevel level);
  125. /******************************************************************************
  126. * Frame
  127. *****************************************************************************/
  128. /**
  129. * Return a copy of initialized frame.
  130. * @param version version of the symbol
  131. * @return Array of unsigned char. You can free it by free().
  132. */
  133. extern unsigned char *QRspec_newFrame(int version);
  134. /******************************************************************************
  135. * Mode indicator
  136. *****************************************************************************/
  137. /**
  138. * Mode indicator. See Table 2 of JIS X0510:2004, pp.16.
  139. */
  140. #define QRSPEC_MODEID_ECI 7
  141. #define QRSPEC_MODEID_NUM 1
  142. #define QRSPEC_MODEID_AN 2
  143. #define QRSPEC_MODEID_8 4
  144. #define QRSPEC_MODEID_KANJI 8
  145. #define QRSPEC_MODEID_FNC1FIRST 5
  146. #define QRSPEC_MODEID_FNC1SECOND 9
  147. #define QRSPEC_MODEID_STRUCTURE 3
  148. #define QRSPEC_MODEID_TERMINATOR 0
  149. #endif /* QRSPEC_H */