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