qrinput.h 3.0 KB

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