From 35baea42d794bec1fd5f2200f1f6f48877c5c26c Mon Sep 17 00:00:00 2001 From: Leo Uino Date: Thu, 14 Jul 2011 11:06:47 +0900 Subject: First attempt at parsing --- lpg/libqr/qrparse.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lpg/libqr/qrparse.c (limited to 'lpg/libqr/qrparse.c') diff --git a/lpg/libqr/qrparse.c b/lpg/libqr/qrparse.c new file mode 100644 index 0000000..4a9312f --- /dev/null +++ b/lpg/libqr/qrparse.c @@ -0,0 +1,59 @@ +#include +#include +#include + +#include +#include +#include + +#include "testqr.xbm" + +int main(int argc, char ** argv) +{ + struct qr_data * data; + int ret; + + ret = qr_code_parse(testqr_bits, + testqr_width, + (testqr_width + CHAR_BIT - 1) / CHAR_BIT, + testqr_height, + &data); + + fprintf(stderr, "qr_code_parse returned %d\n", ret); + + if (ret == 0) { + const char * ec_str, * type_str; + char * data_str; + size_t data_len; + enum qr_data_type data_type; + + fprintf(stderr, "version = %d\n", data->version); + switch (data->ec) { + case QR_EC_LEVEL_L: ec_str = "L"; break; + case QR_EC_LEVEL_M: ec_str = "M"; break; + case QR_EC_LEVEL_Q: ec_str = "Q"; break; + case QR_EC_LEVEL_H: ec_str = "H"; break; + default: ec_str = "(unknown)"; break; + } + fprintf(stderr, "EC level %s\n", ec_str); + + data_type = qr_parse_data(data, &data_str, &data_len); + switch (data_type) { + case QR_DATA_INVALID: type_str = "(invalid)"; break; + case QR_DATA_ECI: type_str = "ECI"; break; + case QR_DATA_NUMERIC: type_str = "numeric"; break; + case QR_DATA_ALPHA: type_str = "alpha"; break; + case QR_DATA_8BIT: type_str = "8-bit"; break; + case QR_DATA_KANJI: type_str = "kanji"; break; + case QR_DATA_MIXED: type_str = "mixed"; break; + case QR_DATA_FNC1: type_str = "FNC1"; break; + default: type_str = "(unknown)"; break; + } + fprintf(stderr, "Data type: %s; %lu bytes\nContent: %s\n", type_str, data_len, data_str); + free(data_str); + qr_free_data(data); + } + + return 0; +} + -- cgit v1.2.3-70-g09d2 From 1ea62d837531c4d5795381da5a2566606e03ac4b Mon Sep 17 00:00:00 2001 From: Leo Uino Date: Tue, 19 Jul 2011 12:06:08 +0900 Subject: Consistent function names --- lpg/libqr/data-common.c | 2 +- lpg/libqr/data-create.c | 2 +- lpg/libqr/qr/data.h | 4 ++-- lpg/libqr/qrgen.c | 4 ++-- lpg/libqr/qrparse.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lpg/libqr/qrparse.c') diff --git a/lpg/libqr/data-common.c b/lpg/libqr/data-common.c index 8a05f4a..af3a766 100644 --- a/lpg/libqr/data-common.c +++ b/lpg/libqr/data-common.c @@ -3,7 +3,7 @@ #include #include -void qr_free_data(struct qr_data * data) +void qr_data_destroy(struct qr_data * data) { qr_bitstream_destroy(data->bits); free(data); diff --git a/lpg/libqr/data-create.c b/lpg/libqr/data-create.c index 6437bc1..8ab127d 100644 --- a/lpg/libqr/data-create.c +++ b/lpg/libqr/data-create.c @@ -182,7 +182,7 @@ static int calc_min_version(enum qr_data_type type, return -1; } -struct qr_data * qr_create_data(int version, +struct qr_data * qr_data_create(int version, enum qr_ec_level ec, enum qr_data_type type, const char * input, diff --git a/lpg/libqr/qr/data.h b/lpg/libqr/qr/data.h index 3cc665a..f2b4b45 100644 --- a/lpg/libqr/qr/data.h +++ b/lpg/libqr/qr/data.h @@ -11,13 +11,13 @@ struct qr_data { size_t offset; }; -struct qr_data * qr_create_data(int format, /* 1 ~ 40; 0=auto */ +struct qr_data * qr_data_create(int format, /* 1 ~ 40; 0=auto */ enum qr_ec_level ec, enum qr_data_type type, const char * input, size_t length); -void qr_free_data(struct qr_data *); +void qr_data_destroy(struct qr_data *); enum qr_data_type qr_data_type(const struct qr_data *); diff --git a/lpg/libqr/qrgen.c b/lpg/libqr/qrgen.c index 3007011..d59954d 100644 --- a/lpg/libqr/qrgen.c +++ b/lpg/libqr/qrgen.c @@ -31,7 +31,7 @@ struct qr_code * create(int version, len = strlen(input); - data = qr_create_data(version, ec, dtype, input, len); + data = qr_data_create(version, ec, dtype, input, len); if (!data) { /* BUG: this could also indicate OOM or @@ -42,7 +42,7 @@ struct qr_code * create(int version, } code = qr_code_create(data); - qr_free_data(data); + qr_data_destroy(data); if (!code) { perror("Failed to create code"); diff --git a/lpg/libqr/qrparse.c b/lpg/libqr/qrparse.c index 4a9312f..013066b 100644 --- a/lpg/libqr/qrparse.c +++ b/lpg/libqr/qrparse.c @@ -51,7 +51,7 @@ int main(int argc, char ** argv) } fprintf(stderr, "Data type: %s; %lu bytes\nContent: %s\n", type_str, data_len, data_str); free(data_str); - qr_free_data(data); + qr_data_destroy(data); } return 0; -- cgit v1.2.3-70-g09d2 From 96433dc8cbc6242adc11f78590068f37f88cfc30 Mon Sep 17 00:00:00 2001 From: Leo Uino Date: Mon, 24 Dec 2012 21:47:33 +0900 Subject: Fixes thanks to Roland Illig --- lpg/libqr/code-parse.c | 4 ++-- lpg/libqr/data-create.c | 20 ++++++++++++-------- lpg/libqr/qrparse.c | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) (limited to 'lpg/libqr/qrparse.c') diff --git a/lpg/libqr/code-parse.c b/lpg/libqr/code-parse.c index 3fca4b2..a84df72 100644 --- a/lpg/libqr/code-parse.c +++ b/lpg/libqr/code-parse.c @@ -216,10 +216,10 @@ int qr_code_parse(const void * buffer, struct qr_code code; enum qr_ec_level ec; int mask; - struct qr_bitstream * data_bits; + struct qr_bitstream * data_bits = NULL; int status; - fprintf(stderr, "parsing code bitmap %lux%lu\n", line_bits, line_count); + fprintf(stderr, "parsing code bitmap %lux%lu\n", (unsigned long) line_bits, (unsigned long) line_count); if (line_bits != line_count || line_bits < 21 diff --git a/lpg/libqr/data-create.c b/lpg/libqr/data-create.c index 8ab127d..09d6653 100644 --- a/lpg/libqr/data-create.c +++ b/lpg/libqr/data-create.c @@ -19,7 +19,7 @@ static void write_type_and_length(struct qr_data * data, } static struct qr_data * encode_numeric(struct qr_data * data, - const char * input, + const unsigned char * input, size_t length) { struct qr_bitstream * stream = data->bits; @@ -92,7 +92,7 @@ static int get_alpha_code(char c) } static struct qr_data * encode_alpha(struct qr_data * data, - const char * input, + const unsigned char * input, size_t length) { struct qr_bitstream * stream = data->bits; @@ -135,7 +135,7 @@ static struct qr_data * encode_alpha(struct qr_data * data, } static struct qr_data * encode_8bit(struct qr_data * data, - const char * input, + const unsigned char * input, size_t length) { struct qr_bitstream * stream = data->bits; @@ -158,7 +158,7 @@ static struct qr_data * encode_8bit(struct qr_data * data, } static struct qr_data * encode_kanji(struct qr_data * data, - const char * input, + const unsigned char * input, size_t length) { return 0; @@ -213,13 +213,17 @@ struct qr_data * qr_data_create(int version, switch (type) { case QR_DATA_NUMERIC: - ret = encode_numeric(data, input, length); break; + ret = encode_numeric(data, (const unsigned char *) input, length); + break; case QR_DATA_ALPHA: - ret = encode_alpha(data, input, length); break; + ret = encode_alpha(data, (const unsigned char *) input, length); + break; case QR_DATA_8BIT: - ret = encode_8bit(data, input, length); break; + ret = encode_8bit(data, (const unsigned char *) input, length); + break; case QR_DATA_KANJI: - ret = encode_kanji(data, input, length); break; + ret = encode_kanji(data, (const unsigned char *) input, length); + break; default: /* unsupported / invalid */ ret = 0; diff --git a/lpg/libqr/qrparse.c b/lpg/libqr/qrparse.c index 013066b..1b5c80e 100644 --- a/lpg/libqr/qrparse.c +++ b/lpg/libqr/qrparse.c @@ -49,7 +49,7 @@ int main(int argc, char ** argv) case QR_DATA_FNC1: type_str = "FNC1"; break; default: type_str = "(unknown)"; break; } - fprintf(stderr, "Data type: %s; %lu bytes\nContent: %s\n", type_str, data_len, data_str); + fprintf(stderr, "Data type: %s; %lu bytes\nContent: %s\n", type_str, (unsigned long) data_len, data_str); free(data_str); qr_data_destroy(data); } -- cgit v1.2.3-70-g09d2