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