From ef01767c732629b7eff7d1601e76a1bac58f5bfd Mon Sep 17 00:00:00 2001 From: Leo Howell Date: Sat, 5 Sep 2009 09:33:22 +0900 Subject: The story so far --- lpg/libqr/data-common.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lpg/libqr/data-common.c (limited to 'lpg/libqr/data-common.c') diff --git a/lpg/libqr/data-common.c b/lpg/libqr/data-common.c new file mode 100644 index 0000000..123e5c4 --- /dev/null +++ b/lpg/libqr/data-common.c @@ -0,0 +1,58 @@ +#include +#include + +#include "bitstream.h" +#include "data-common.h" + +const enum qr_data_type QR_TYPE_CODES[16] = { + QR_DATA_INVALID, /* 0000 */ + QR_DATA_NUMERIC, /* 0001 */ + QR_DATA_ALPHA, /* 0010 */ + QR_DATA_MIXED, /* 0011 */ + QR_DATA_8BIT, /* 0100 */ + QR_DATA_FNC1, /* 0101 */ + QR_DATA_INVALID, /* 0110 */ + QR_DATA_ECI, /* 0111 */ + QR_DATA_KANJI, /* 1000 */ + QR_DATA_FNC1, /* 1001 */ + QR_DATA_INVALID, /* 1010 */ + QR_DATA_INVALID, /* 1011 */ + QR_DATA_INVALID, /* 1100 */ + QR_DATA_INVALID, /* 1101 */ + QR_DATA_INVALID, /* 1110 */ + QR_DATA_INVALID, /* 1111 */ +}; + +void qr_free_data(struct qr_data * data) +{ + bitstream_destroy(data->bits); + free(data); +} + +size_t get_size_field_length(int format, enum qr_data_type type) +{ + static const size_t QR_SIZE_LENGTHS[3][4] = { + { 10, 9, 8, 8 }, + { 12, 11, 16, 10 }, + { 14, 13, 16, 12 } + }; + int row, col; + + switch (type) { + case QR_DATA_NUMERIC: col = 0; break; + case QR_DATA_ALPHA: col = 1; break; + case QR_DATA_8BIT: col = 2; break; + case QR_DATA_KANJI: col = 3; break; + default: return 0; + } + + if (format < 10) + row = 0; + else if (format < 27) + row = 1; + else + row = 2; + + return QR_SIZE_LENGTHS[row][col]; +} + -- cgit v1.2.3-70-g09d2