aboutsummaryrefslogtreecommitdiff
path: root/lpg/libqr/code-common.c
diff options
context:
space:
mode:
authorLeo Uino <leo@norisys.jp>2011-07-14 14:31:07 +0900
committerLeo Uino <leo@norisys.jp>2011-07-14 14:31:07 +0900
commit9f4843d686bca0d75bee174d8249fbf72527b94a (patch)
treecbe61addaa9a05ba1477af91e9d69cbcd8d95fb5 /lpg/libqr/code-common.c
parent3af4ffd175dcaf8aaf735f3f9564da54c4f29403 (diff)
downloadpdf-simple-sign-9f4843d686bca0d75bee174d8249fbf72527b94a.tar.gz
pdf-simple-sign-9f4843d686bca0d75bee174d8249fbf72527b94a.tar.xz
pdf-simple-sign-9f4843d686bca0d75bee174d8249fbf72527b94a.zip
Move RS block size calculation to a separate function
Diffstat (limited to 'lpg/libqr/code-common.c')
-rw-r--r--lpg/libqr/code-common.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/lpg/libqr/code-common.c b/lpg/libqr/code-common.c
index a0b8fcc..422f2ac 100644
--- a/lpg/libqr/code-common.c
+++ b/lpg/libqr/code-common.c
@@ -2,9 +2,11 @@
#include <limits.h>
#include <stdlib.h>
-#include <qr/code.h>
#include <qr/bitmap.h>
#include <qr/bitstream.h>
+#include <qr/code.h>
+#include <qr/common.h>
+#include "constants.h"
void qr_code_destroy(struct qr_code * code)
{
@@ -41,6 +43,37 @@ size_t qr_code_total_capacity(int version)
return side * side - function_bits;
}
+void qr_get_rs_block_sizes(int version,
+ enum qr_ec_level ec,
+ int block_count[2],
+ int data_length[2],
+ int ec_length[2])
+{
+ /* FIXME: rather than using a big static table, better to
+ * calculate these values.
+ */
+ int total_words = qr_code_total_capacity(version) / 8;
+ int data_words = QR_DATA_WORD_COUNT[version - 1][ec ^ 0x1];
+ int ec_words = total_words - data_words;
+ int total_blocks;
+
+ block_count[0] = QR_RS_BLOCK_COUNT[version - 1][ec ^ 0x1][0];
+ block_count[1] = QR_RS_BLOCK_COUNT[version - 1][ec ^ 0x1][1];
+ total_blocks = block_count[0] + block_count[1];
+
+ data_length[0] = data_words / total_blocks;
+ data_length[1] = data_length[0] + 1;
+
+ assert(data_length[0] * block_count[0] +
+ data_length[1] * block_count[1] == data_words);
+
+ ec_length[0] = ec_length[1] = ec_words / total_blocks;
+
+ assert(ec_length[0] * block_count[0] +
+ ec_length[1] * block_count[1] == ec_words);
+ assert(data_words + ec_words == total_words);
+}
+
struct qr_bitmap * qr_mask_apply(const struct qr_bitmap * orig,
unsigned int mask)
{