aboutsummaryrefslogtreecommitdiff
path: root/lpg
diff options
context:
space:
mode:
authorLeo Howell <leo@lwh.jp>2009-10-08 14:48:28 +0900
committerLeo Howell <leo@lwh.jp>2009-10-08 14:52:01 +0900
commit6359bfddcc5868093418784fa2e972581ebd82b6 (patch)
tree6175f5f428d45dcc86410b9578fd98dc3fc08700 /lpg
parent62e8a6f2ad89be06c7e649c0fc4c564ecad2d070 (diff)
downloadpdf-simple-sign-6359bfddcc5868093418784fa2e972581ebd82b6.tar.gz
pdf-simple-sign-6359bfddcc5868093418784fa2e972581ebd82b6.tar.xz
pdf-simple-sign-6359bfddcc5868093418784fa2e972581ebd82b6.zip
render version bits
Diffstat (limited to 'lpg')
-rw-r--r--lpg/libqr/code-create.c29
-rw-r--r--lpg/libqr/code-layout.c9
2 files changed, 36 insertions, 2 deletions
diff --git a/lpg/libqr/code-create.c b/lpg/libqr/code-create.c
index 6c56f45..9936981 100644
--- a/lpg/libqr/code-create.c
+++ b/lpg/libqr/code-create.c
@@ -24,6 +24,7 @@ static int draw_format(struct qr_bitmap * bmp,
enum qr_ec_level ec,
int mask);
static int calc_format_bits(enum qr_ec_level ec, int mask);
+static long calc_version_bits(int version);
static unsigned long gal_residue(unsigned long a, unsigned long m);
/* FIXME: the static functions should be in a better
@@ -508,7 +509,18 @@ static int draw_format(struct qr_bitmap * bmp,
bits >>= 1;
}
- /* XXX: size info for 7~40 */
+ if (code->version >= 7) {
+ bits = calc_version_bits(code->version);
+
+ for (i = 0; i < 18; ++i) {
+ if (bits & 0x1) {
+ int a = i % 3, b = i / 3;
+ setpx(bmp, dim - 11 + a, b);
+ setpx(bmp, b, dim - 11 + a);
+ }
+ bits >>= 1;
+ }
+ }
return 0;
}
@@ -532,6 +544,21 @@ static int calc_format_bits(enum qr_ec_level ec, int mask)
return bits;
}
+static long calc_version_bits(int version)
+{
+ long bits;
+
+ bits = version & 0x3F;
+
+ /* (18, 6) BCH code
+ * G(x) = x^12 + x^11 + x^10 + x^9 + x^8 + x^5 + x^2 + 1
+ */
+ bits <<= 18 - 6;
+ bits |= gal_residue(bits, 0x1F25);
+
+ return bits;
+}
+
/* Calculate the residue of a modulo m */
static unsigned long gal_residue(unsigned long a,
unsigned long m)
diff --git a/lpg/libqr/code-layout.c b/lpg/libqr/code-layout.c
index 4be3871..ed01112 100644
--- a/lpg/libqr/code-layout.c
+++ b/lpg/libqr/code-layout.c
@@ -45,7 +45,14 @@ void qr_layout_init_mask(struct qr_code * code)
if (x < 9 && y >= dim - 8) /* bottom-left */
continue;
- /* XXX: format data */
+ /* version info */
+ if (code->version >= 7) {
+ if (y < 6 && x >= dim - 11)
+ continue;
+ if (x < 6 && y >= dim - 11)
+ continue;
+ }
+
/* XXX: alignment pattern */
row[off] |= bit;