Nicolas Jager | 95c526b | 2016-10-20 09:47:03 -0400 | [diff] [blame] | 1 | /* |
| 2 | * qrencode - QR Code encoder |
| 3 | * |
| 4 | * Input data chunk class |
| 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 __QRINPUT_H__ |
| 23 | #define __QRINPUT_H__ |
| 24 | |
| 25 | #include "qrencode.h" |
| 26 | #include "bitstream.h" |
| 27 | |
| 28 | int QRinput_isSplittableMode(QRencodeMode mode); |
| 29 | |
| 30 | /****************************************************************************** |
| 31 | * Entry of input data |
| 32 | *****************************************************************************/ |
| 33 | typedef struct _QRinput_List QRinput_List; |
| 34 | |
| 35 | struct _QRinput_List { |
| 36 | QRencodeMode mode; |
| 37 | int size; ///< Size of data chunk (byte). |
| 38 | unsigned char *data; ///< Data chunk. |
| 39 | BitStream *bstream; |
| 40 | QRinput_List *next; |
| 41 | }; |
| 42 | |
| 43 | /****************************************************************************** |
| 44 | * Input Data |
| 45 | *****************************************************************************/ |
| 46 | struct _QRinput { |
| 47 | int version; |
| 48 | QRecLevel level; |
| 49 | QRinput_List *head; |
| 50 | QRinput_List *tail; |
| 51 | int mqr; |
| 52 | int fnc1; |
| 53 | unsigned char appid; |
| 54 | }; |
| 55 | |
| 56 | /****************************************************************************** |
| 57 | * Structured append input data |
| 58 | *****************************************************************************/ |
| 59 | typedef struct _QRinput_InputList QRinput_InputList; |
| 60 | |
| 61 | struct _QRinput_InputList { |
| 62 | QRinput *input; |
| 63 | QRinput_InputList *next; |
| 64 | }; |
| 65 | |
| 66 | struct _QRinput_Struct { |
| 67 | int size; ///< number of structured symbols |
| 68 | int parity; |
| 69 | QRinput_InputList *head; |
| 70 | QRinput_InputList *tail; |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * Pack all bit streams padding bits into a byte array. |
| 75 | * @param input input data. |
| 76 | * @return padded merged byte stream |
| 77 | */ |
| 78 | extern unsigned char *QRinput_getByteStream(QRinput *input); |
| 79 | |
| 80 | |
| 81 | extern int QRinput_estimateBitsModeNum(int size); |
| 82 | extern int QRinput_estimateBitsModeAn(int size); |
| 83 | extern int QRinput_estimateBitsMode8(int size); |
| 84 | extern int QRinput_estimateBitsModeKanji(int size); |
| 85 | |
| 86 | extern QRinput *QRinput_dup(QRinput *input); |
| 87 | |
| 88 | extern const signed char QRinput_anTable[128]; |
| 89 | |
| 90 | /** |
| 91 | * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). |
| 92 | * @param __c__ character |
| 93 | * @return value |
| 94 | */ |
| 95 | #define QRinput_lookAnTable(__c__) \ |
| 96 | ((__c__ & 0x80)?-1:QRinput_anTable[(int)__c__]) |
| 97 | |
| 98 | /** |
| 99 | * Length of a standard mode indicator in bits. |
| 100 | */ |
| 101 | |
| 102 | #define MODE_INDICATOR_SIZE 4 |
| 103 | |
| 104 | /** |
| 105 | * Length of a segment of structured-append header. |
| 106 | */ |
| 107 | #define STRUCTURE_HEADER_SIZE 20 |
| 108 | |
| 109 | /** |
| 110 | * Maximum number of symbols in a set of structured-appended symbols. |
| 111 | */ |
| 112 | #define MAX_STRUCTURED_SYMBOLS 16 |
| 113 | |
| 114 | #ifdef WITH_TESTS |
| 115 | extern BitStream *QRinput_mergeBitStream(QRinput *input); |
| 116 | extern BitStream *QRinput_getBitStream(QRinput *input); |
| 117 | extern int QRinput_estimateBitStreamSize(QRinput *input, int version); |
| 118 | extern int QRinput_splitEntry(QRinput_List *entry, int bytes); |
| 119 | extern int QRinput_lengthOfCode(QRencodeMode mode, int version, int bits); |
| 120 | extern int QRinput_insertStructuredAppendHeader(QRinput *input, int size, int index, unsigned char parity); |
| 121 | #endif |
| 122 | |
| 123 | #endif /* __QRINPUT_H__ */ |