aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Howell <leo@lwh.jp>2009-11-03 15:29:45 +0900
committerLeo Howell <leo@lwh.jp>2009-11-03 15:30:57 +0900
commit062feace6167f28036ba6a7bcc8edf0ff9c7a5f8 (patch)
tree803da282e936822ae877c33d016720260aef38fa
parentb22b76aa7ad8b619232f83f3b910a877871fa3c9 (diff)
downloadwork-tools-062feace6167f28036ba6a7bcc8edf0ff9c7a5f8.tar.gz
work-tools-062feace6167f28036ba6a7bcc8edf0ff9c7a5f8.tar.xz
work-tools-062feace6167f28036ba6a7bcc8edf0ff9c7a5f8.zip
Fix the output block order
-rw-r--r--libqr/code-create.c24
-rw-r--r--libqr/rs-encode.c1
2 files changed, 18 insertions, 7 deletions
diff --git a/libqr/code-create.c b/libqr/code-create.c
index ae23acc..1a38967 100644
--- a/libqr/code-create.c
+++ b/libqr/code-create.c
@@ -179,7 +179,7 @@ static struct qr_bitstream * make_data(int version,
const size_t total_words = total_bits / 8;
const size_t total_data = QR_DATA_WORD_COUNT[version - 1][ec ^ 0x1];
size_t total_blocks, block_count[2], data_words, rs_words;
- size_t i;
+ size_t i, w;
struct qr_bitstream * dcopy = 0;
struct qr_bitstream * out = 0;
struct qr_bitstream ** blocks = 0;
@@ -235,12 +235,24 @@ static struct qr_bitstream * make_data(int version,
}
/* Finally, write everything out in the correct order */
- qr_bitstream_seek(dcopy, 0);
- for (i = 0; i < total_blocks; ++i) {
- size_t dw = data_words + (i >= block_count[0]);
- qr_bitstream_copy(out, dcopy, dw * 8);
- qr_bitstream_cat(out, blocks[i]);
+ for (w = 0; w < data_words + 1; ++w) {
+ for (i = (w == data_words ? block_count[0] : 0); i < total_blocks; ++i) {
+ size_t di = w + (i < block_count[0] ?
+ i * data_words :
+ i * (data_words + 1) - block_count[0]);
+
+ qr_bitstream_seek(dcopy, di * 8);
+ qr_bitstream_write(out,
+ qr_bitstream_read(dcopy, 8), 8);
+ }
}
+ for (i = 0; i < total_blocks; ++i)
+ qr_bitstream_seek(blocks[i], 0);
+ for (w = 0; w < rs_words; ++w)
+ for (i = 0; i < total_blocks; ++i)
+ qr_bitstream_write(out,
+ qr_bitstream_read(blocks[i], 8), 8);
+
qr_bitstream_write(out, 0, total_bits - total_words * 8);
fputs("Final bitstream:\n", stderr);
diff --git a/libqr/rs-encode.c b/libqr/rs-encode.c
index 42b404f..a8ecc73 100644
--- a/libqr/rs-encode.c
+++ b/libqr/rs-encode.c
@@ -74,7 +74,6 @@ struct qr_bitstream * rs_generate_words(struct qr_bitstream * data,
goto fail;
/* First, prepare the registers (b) with data bits */
- qr_bitstream_seek(data, 0);
for (i = 0; i < data_words; ++i) {
unsigned int x = b[n-1] ^ qr_bitstream_read(data, 8);
for (r = n-1; r > 0; --r)