diff options
Diffstat (limited to 'lpg')
-rw-r--r-- | lpg/libqr/code-common.c | 15 | ||||
-rw-r--r-- | lpg/libqr/code-common.h | 6 | ||||
-rw-r--r-- | lpg/libqr/code-create.c | 17 | ||||
-rw-r--r-- | lpg/libqr/code-layout.c | 4 | ||||
-rw-r--r-- | lpg/libqr/data-common.c | 6 | ||||
-rw-r--r-- | lpg/libqr/data-common.h | 4 | ||||
-rw-r--r-- | lpg/libqr/data-create.c | 14 | ||||
-rw-r--r-- | lpg/libqr/data-parse.c | 8 |
8 files changed, 33 insertions, 41 deletions
diff --git a/lpg/libqr/code-common.c b/lpg/libqr/code-common.c index 32f6492..dc2a8f0 100644 --- a/lpg/libqr/code-common.c +++ b/lpg/libqr/code-common.c @@ -14,26 +14,21 @@ void qr_code_destroy(struct qr_code * code) int qr_code_width(const struct qr_code * code) { - return code_side_length(code->format); + return code->version * 4 + 17; } -int code_side_length(int format) +size_t code_total_capacity(int version) { - return format * 4 + 17; -} - -size_t code_total_capacity(int format) -{ - int side = format * 4 + 17; + int side = version * 4 + 17; - int alignment_side = format > 1 ? (format / 7) + 2 : 0; + int alignment_side = version > 1 ? (version / 7) + 2 : 0; int alignment_count = alignment_side >= 2 ? alignment_side * alignment_side - 3 : 0; int locator_bits = 8*8*3; - int format_bits = 8*4 - 1 + (format >= 7 ? 6*3*2 : 0); + int format_bits = 8*4 - 1 + (version >= 7 ? 6*3*2 : 0); int timing_bits = 2 * (side - 8*2 - (alignment_side > 2 ? (alignment_side - 2) * 5 : 0)); diff --git a/lpg/libqr/code-common.h b/lpg/libqr/code-common.h index cf96217..11538d8 100644 --- a/lpg/libqr/code-common.h +++ b/lpg/libqr/code-common.h @@ -6,13 +6,11 @@ #include "qr-bitmap.h" struct qr_code { - int format; + int version; struct qr_bitmap * modules; }; -int code_side_length(int format); - -size_t code_total_capacity(int format); +size_t code_total_capacity(int version); #endif diff --git a/lpg/libqr/code-create.c b/lpg/libqr/code-create.c index 9ce46f7..6c56f45 100644 --- a/lpg/libqr/code-create.c +++ b/lpg/libqr/code-create.c @@ -73,7 +73,7 @@ static int draw_functional(struct qr_code * code, unsigned int mask) { struct qr_bitmap * bmp; - int dim = code_side_length(code->format); + int dim = qr_code_width(code); int i; bmp = qr_bitmap_create(dim, dim, 0); @@ -146,11 +146,11 @@ static int pad_data(struct qr_bitstream * bits, size_t limit) return 0; } -static struct qr_bitstream * make_data(int format, - enum qr_ec_level ec, - struct qr_bitstream * data) +static struct qr_bitstream * make_data(int version, + enum qr_ec_level ec, + struct qr_bitstream * data) { - const size_t total_bits = code_total_capacity(format); + const size_t total_bits = code_total_capacity(version); const size_t total_words = total_bits / 8; size_t block_count, data_words, rs_words; size_t i; @@ -246,15 +246,14 @@ struct qr_code * qr_code_create(enum qr_ec_level ec, if (!code) return 0; - dim = code_side_length(data->format); - - code->format = data->format; + code->version = data->version; + dim = qr_code_width(code); code->modules = qr_bitmap_create(dim, dim, 1); if (!code->modules) goto fail; - bits = make_data(data->format, ec, data->bits); + bits = make_data(data->version, ec, data->bits); if (!bits) goto fail; diff --git a/lpg/libqr/code-layout.c b/lpg/libqr/code-layout.c index 46d2800..4be3871 100644 --- a/lpg/libqr/code-layout.c +++ b/lpg/libqr/code-layout.c @@ -19,7 +19,7 @@ struct qr_iterator { void qr_layout_init_mask(struct qr_code * code) { int x, y; - int dim = code_side_length(code->format); + int dim = qr_code_width(code); struct qr_bitmap * bmp = code->modules; assert(bmp->mask); @@ -110,7 +110,7 @@ struct qr_iterator * qr_layout_begin(struct qr_code * code) i = malloc(sizeof(*i)); if (i) { - i->dim = code_side_length(code->format); + i->dim = qr_code_width(code); i->code = code; i->column = i->dim - 1; i->row = i->dim - 1; diff --git a/lpg/libqr/data-common.c b/lpg/libqr/data-common.c index c64527a..ac2f198 100644 --- a/lpg/libqr/data-common.c +++ b/lpg/libqr/data-common.c @@ -29,7 +29,7 @@ void qr_free_data(struct qr_data * data) free(data); } -size_t get_size_field_length(int format, enum qr_data_type type) +size_t get_size_field_length(int version, enum qr_data_type type) { static const size_t QR_SIZE_LENGTHS[3][4] = { { 10, 9, 8, 8 }, @@ -46,9 +46,9 @@ size_t get_size_field_length(int format, enum qr_data_type type) default: return 0; } - if (format < 10) + if (version < 10) row = 0; - else if (format < 27) + else if (version < 27) row = 1; else row = 2; diff --git a/lpg/libqr/data-common.h b/lpg/libqr/data-common.h index 1522b09..bc2b381 100644 --- a/lpg/libqr/data-common.h +++ b/lpg/libqr/data-common.h @@ -6,14 +6,14 @@ #include "qr-bitstream.h" struct qr_data { - int format; /* 1 ~ 40 */ + int version; /* 1 ~ 40 */ struct qr_bitstream * bits; size_t offset; }; extern const enum qr_data_type QR_TYPE_CODES[16]; -size_t get_size_field_length(int format, enum qr_data_type); +size_t get_size_field_length(int version, enum qr_data_type); #endif diff --git a/lpg/libqr/data-create.c b/lpg/libqr/data-create.c index a918413..2c2737f 100644 --- a/lpg/libqr/data-create.c +++ b/lpg/libqr/data-create.c @@ -18,7 +18,7 @@ static void write_type_and_length(struct qr_data * data, { (void)qr_bitstream_write(data->bits, QR_TYPE_CODES[type], 4); (void)qr_bitstream_write(data->bits, length, - get_size_field_length(data->format, type)); + get_size_field_length(data->version, type)); } static struct qr_data * encode_numeric(struct qr_data * data, @@ -28,7 +28,7 @@ static struct qr_data * encode_numeric(struct qr_data * data, struct qr_bitstream * stream = data->bits; size_t bits; - bits = 4 + get_size_field_length(data->format, QR_DATA_NUMERIC) + bits = 4 + get_size_field_length(data->version, QR_DATA_NUMERIC) + 10 * (length / 3); if (length % 3 == 1) @@ -106,7 +106,7 @@ static struct qr_data * encode_alpha(struct qr_data * data, struct qr_bitstream * stream = data->bits; size_t bits; - bits = 4 + get_size_field_length(data->format, QR_DATA_ALPHA) + bits = 4 + get_size_field_length(data->version, QR_DATA_ALPHA) + 11 * (length / 2) + 6 * (length % 2); @@ -150,7 +150,7 @@ static struct qr_data * encode_8bit(struct qr_data * data, struct qr_bitstream * stream = data->bits; size_t bits; - bits = 4 + get_size_field_length(data->format, QR_DATA_8BIT) + bits = 4 + get_size_field_length(data->version, QR_DATA_8BIT) + 8 * length; stream = data->bits; @@ -173,21 +173,21 @@ static struct qr_data * encode_kanji(struct qr_data * data, return 0; } -struct qr_data * qr_create_data(int format, +struct qr_data * qr_create_data(int version, enum qr_data_type type, const char * input, size_t length) { struct qr_data * data; - if (format < 1 || format > 40) + if (version < 1 || version > 40) return 0; data = malloc(sizeof(*data)); if (!data) return 0; - data->format = format; + data->version = version; data->bits = qr_bitstream_create(); data->offset = 0; diff --git a/lpg/libqr/data-parse.c b/lpg/libqr/data-parse.c index d497bdf..4868cd2 100644 --- a/lpg/libqr/data-parse.c +++ b/lpg/libqr/data-parse.c @@ -33,7 +33,7 @@ static enum qr_data_type parse_numeric(const struct qr_data * data, stream = data->bits; buffer = 0; - field_len = get_size_field_length(data->format, QR_DATA_NUMERIC); + field_len = get_size_field_length(data->version, QR_DATA_NUMERIC); if (qr_bitstream_remaining(stream) < field_len) goto invalid; @@ -93,7 +93,7 @@ static enum qr_data_type parse_alpha(const struct qr_data * data, stream = data->bits; buffer = 0; - field_len = get_size_field_length(data->format, QR_DATA_ALPHA); + field_len = get_size_field_length(data->version, QR_DATA_ALPHA); if (qr_bitstream_remaining(stream) < field_len) goto invalid; @@ -150,7 +150,7 @@ static enum qr_data_type parse_8bit(const struct qr_data * data, stream = data->bits; - field_len = get_size_field_length(data->format, QR_DATA_8BIT); + field_len = get_size_field_length(data->version, QR_DATA_8BIT); if (qr_bitstream_remaining(stream) < field_len) return QR_DATA_INVALID; @@ -201,7 +201,7 @@ int qr_get_data_length(const struct qr_data * data) case QR_DATA_ALPHA: case QR_DATA_8BIT: case QR_DATA_KANJI: - field_len = get_size_field_length(data->format, type); + field_len = get_size_field_length(data->version, type); break; default: /* unsupported / invalid */ |