aboutsummaryrefslogtreecommitdiff
path: root/lpg/libqr/qr-bitmap.c
diff options
context:
space:
mode:
authorLeo Howell <leo@lwh.jp>2009-09-27 16:31:03 +0900
committerLeo Howell <leo@lwh.jp>2009-09-27 16:31:03 +0900
commit559eb9633e1f97d70112f02538ae5e9a0e46f4d5 (patch)
tree78d3ce4998fc9cf60f55162c16323a415d47a57b /lpg/libqr/qr-bitmap.c
parent24e968c84075344de2b6b31dc054bfe988eacd04 (diff)
downloadpdf-simple-sign-559eb9633e1f97d70112f02538ae5e9a0e46f4d5.tar.gz
pdf-simple-sign-559eb9633e1f97d70112f02538ae5e9a0e46f4d5.tar.xz
pdf-simple-sign-559eb9633e1f97d70112f02538ae5e9a0e46f4d5.zip
bitmap handling routines
Diffstat (limited to 'lpg/libqr/qr-bitmap.c')
-rw-r--r--lpg/libqr/qr-bitmap.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/lpg/libqr/qr-bitmap.c b/lpg/libqr/qr-bitmap.c
new file mode 100644
index 0000000..e42b550
--- /dev/null
+++ b/lpg/libqr/qr-bitmap.c
@@ -0,0 +1,70 @@
+#include <assert.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include "qr-bitmap.h"
+
+struct qr_bitmap * qr_bitmap_create(int width, int height, int masked)
+{
+ struct qr_bitmap * out;
+ size_t size;
+
+ out = malloc(sizeof(*out));
+ if (!out)
+ goto fail;
+
+ out->width = width;
+ out->height = height;
+ out->stride = (width / CHAR_BIT) + (width % CHAR_BIT ? 1 : 0);
+
+ size = out->stride * height;
+
+ out->mask = 0;
+ out->bits = malloc(size);
+ if (!out->bits)
+ goto fail;
+ memset(out->bits, 0, size);
+
+ if (masked) {
+ out->mask = malloc(out->stride * width);
+ if (!out->mask)
+ goto fail;
+ memset(out->bits, 0xFF, size);
+ }
+
+ return out;
+
+fail:
+ qr_bitmap_destroy(out);
+ return 0;
+}
+
+void qr_bitmap_destroy(struct qr_bitmap * bmp)
+{
+ if (bmp) {
+ free(bmp->bits);
+ free(bmp->mask);
+ free(bmp);
+ }
+}
+
+void qr_bitmap_merge(struct qr_bitmap * dest, const struct qr_bitmap * src)
+{
+ unsigned char * d, * s, * m;
+ size_t n;
+
+ assert(dest->stride == src->stride);
+ assert(dest->height == src->height);
+ assert(src->mask);
+
+ n = dest->stride * dest->height;
+ d = dest->bits;
+ s = src->bits;
+ m = src->mask;
+
+ while (n--) {
+ *d &= ~*m;
+ *d++ |= *s++ & *m++;
+ }
+}
+