From 688c1b52ed356d024ba2e72ba52f7da64b7d74ed Mon Sep 17 00:00:00 2001 From: Leo Howell Date: Tue, 3 Nov 2009 00:12:30 +0900 Subject: generate alignment pattern --- lpg/libqr/code-create.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'lpg/libqr/code-create.c') diff --git a/lpg/libqr/code-create.c b/lpg/libqr/code-create.c index 36ebb24..ae23acc 100644 --- a/lpg/libqr/code-create.c +++ b/lpg/libqr/code-create.c @@ -79,6 +79,8 @@ static int draw_functional(struct qr_code * code, struct qr_bitmap * bmp; int dim = qr_code_width(code); int i; + int x, y; + int am_side; bmp = qr_bitmap_create(dim, dim, 0); if (!bmp) @@ -95,7 +97,26 @@ static int draw_functional(struct qr_code * code, setpx(bmp, 6, i); } - /* XXX: alignment pattern */ + /* Alignment pattern */ + am_side = code->version > 1 ? (code->version / 7) + 2 : 0; + for (y = 0; y < am_side; ++y) { + const int * am_pos = QR_ALIGNMENT_LOCATION[code->version - 1]; + + for (x = 0; x < am_side; ++x) { + if ((x == 0 && y == 0) || + (x == 0 && y == am_side - 1) || + (x == am_side - 1 && y == 0)) + continue; + + for (i = -2; i < 2; ++i) { + setpx(bmp, am_pos[x] + i, am_pos[y] - 2); + setpx(bmp, am_pos[x] + 2, am_pos[y] + i); + setpx(bmp, am_pos[x] - i, am_pos[y] + 2); + setpx(bmp, am_pos[x] - 2, am_pos[y] - i); + } + setpx(bmp, am_pos[x], am_pos[y]); + } + } /* Format info */ setpx(bmp, 8, dim - 8); -- cgit v1.2.3-70-g09d2