diff options
author | Leo Uino <leo@norisys.jp> | 2011-07-15 14:20:41 +0900 |
---|---|---|
committer | Leo Uino <leo@norisys.jp> | 2011-07-15 14:20:41 +0900 |
commit | 4670274ec303082e0fb86ff3be1ea4170a17662f (patch) | |
tree | e51c1a8fe6cbc5ac04516337b9fce0a2f6aebd09 /lpg | |
parent | 9f4843d686bca0d75bee174d8249fbf72527b94a (diff) | |
download | pdf-simple-sign-4670274ec303082e0fb86ff3be1ea4170a17662f.tar.gz pdf-simple-sign-4670274ec303082e0fb86ff3be1ea4170a17662f.tar.xz pdf-simple-sign-4670274ec303082e0fb86ff3be1ea4170a17662f.zip |
qr_mask_apply() works in-place
Diffstat (limited to 'lpg')
-rw-r--r-- | lpg/libqr/code-common.c | 14 | ||||
-rw-r--r-- | lpg/libqr/code-create.c | 3 | ||||
-rw-r--r-- | lpg/libqr/code-parse.c | 8 | ||||
-rw-r--r-- | lpg/libqr/qr/common.h | 3 |
4 files changed, 9 insertions, 19 deletions
diff --git a/lpg/libqr/code-common.c b/lpg/libqr/code-common.c index 422f2ac..1cb1745 100644 --- a/lpg/libqr/code-common.c +++ b/lpg/libqr/code-common.c @@ -74,18 +74,12 @@ void qr_get_rs_block_sizes(int version, assert(data_words + ec_words == total_words); } -struct qr_bitmap * qr_mask_apply(const struct qr_bitmap * orig, - unsigned int mask) +void qr_mask_apply(struct qr_bitmap * bmp, int mask) { - struct qr_bitmap * bmp; int i, j; - if (mask > 7) - return 0; - - bmp = qr_bitmap_clone(orig); - if (!bmp) - return 0; + assert((mask & 0x7) == mask); + mask &= 0x7; /* Slow version for now; we can optimize later */ @@ -111,7 +105,5 @@ struct qr_bitmap * qr_mask_apply(const struct qr_bitmap * orig, p[off] ^= (t == 0) << bit; } } - - return bmp; } diff --git a/lpg/libqr/code-create.c b/lpg/libqr/code-create.c index 680b405..f29778f 100644 --- a/lpg/libqr/code-create.c +++ b/lpg/libqr/code-create.c @@ -332,11 +332,12 @@ static int mask_data(struct qr_code * code) /* Generate bitmap for each mask and evaluate */ for (i = 0; i < 8; ++i) { - test = qr_mask_apply(code->modules, i); + test = qr_bitmap_clone(code->modules); if (!test) { qr_bitmap_destroy(mask); return -1; } + qr_mask_apply(test, i); score = score_mask(test); fprintf(stderr, "mask %d scored %d\n", i, score); if (!mask || score < best) { diff --git a/lpg/libqr/code-parse.c b/lpg/libqr/code-parse.c index 29d96bb..7a98280 100644 --- a/lpg/libqr/code-parse.c +++ b/lpg/libqr/code-parse.c @@ -212,11 +212,9 @@ int qr_code_parse(const void * buffer, fprintf(stderr, "detected ec type %d; mask %d\n", ec, mask); - code.modules = qr_mask_apply(&src_bmp, mask); - if (code.modules == NULL) { - fprintf(stderr, "failed to apply mask\n"); - return -1; - } + code.modules = qr_bitmap_clone(&src_bmp); + /* XXX: check return */ + qr_mask_apply(code.modules, mask); qr_layout_init_mask(&code); diff --git a/lpg/libqr/qr/common.h b/lpg/libqr/qr/common.h index f2bd127..640696a 100644 --- a/lpg/libqr/qr/common.h +++ b/lpg/libqr/qr/common.h @@ -3,8 +3,7 @@ #include <qr/types.h> -struct qr_bitmap * qr_mask_apply(const struct qr_bitmap * orig, - unsigned int mask); +void qr_mask_apply(struct qr_bitmap * bmp, int mask); size_t qr_code_total_capacity(int version); |