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