qrinput.h 3.6 KB

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