aboutsummaryrefslogtreecommitdiff
path: root/lpg/libqr/qr-mask.c
diff options
context:
space:
mode:
authorLeo Howell <leo@lwh.jp>2009-09-28 22:09:47 +0900
committerLeo Howell <leo@lwh.jp>2009-09-28 22:09:47 +0900
commit36f38e01ddd23f332374093fa213ca08429729b1 (patch)
treea0a8fd4b198346501353eb33a6463f934141249d /lpg/libqr/qr-mask.c
parent388507a61df32c0bddf7e61c5da013c3f29d32d4 (diff)
downloadpdf-simple-sign-36f38e01ddd23f332374093fa213ca08429729b1.tar.gz
pdf-simple-sign-36f38e01ddd23f332374093fa213ca08429729b1.tar.xz
pdf-simple-sign-36f38e01ddd23f332374093fa213ca08429729b1.zip
QR masks
Diffstat (limited to 'lpg/libqr/qr-mask.c')
-rw-r--r--lpg/libqr/qr-mask.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/lpg/libqr/qr-mask.c b/lpg/libqr/qr-mask.c
new file mode 100644
index 0000000..2a63c0b
--- /dev/null
+++ b/lpg/libqr/qr-mask.c
@@ -0,0 +1,46 @@
+#include <limits.h>
+#include <stdlib.h>
+#include "qr-bitmap.h"
+#include "qr-mask.h"
+
+struct qr_bitmap * qr_mask_apply(const struct qr_bitmap * orig,
+ unsigned int mask)
+{
+ struct qr_bitmap * bmp;
+ int i, j;
+
+ if (mask & ~0x7)
+ return 0;
+
+ bmp = qr_bitmap_clone(orig);
+ if (!bmp)
+ return 0;
+
+ /* Slow version for now; we can optimize later */
+
+ for (i = 0; i < bmp->height; ++i) {
+ unsigned char * p = bmp->bits + i * bmp->stride;
+
+ for (j = 0; j < bmp->width; ++j) {
+ int bit = j % CHAR_BIT;
+ size_t off = j / CHAR_BIT;
+ int t;
+
+ switch (mask) {
+ case 0: t = (i + j) % 2; break;
+ case 1: t = i % 2; break;
+ case 2: t = j % 3; break;
+ case 3: t = (i + j) % 3; break;
+ case 4: t = (i/2 + j/3) % 2; break;
+ case 5: t = ((i*j) % 2) + ((i*j) % 3); break;
+ case 6: t = (((i*j) % 2) + ((i*j) % 3)) % 2; break;
+ case 7: t = (((i*j) % 3) + ((i+j) % 2)) % 2; break;
+ }
+
+ p[off] ^= (t == 0) << bit;
+ }
+ }
+
+ return bmp;
+}
+