diff options
Diffstat (limited to 'lpg')
-rw-r--r-- | lpg/libqr/Makefile | 3 | ||||
-rw-r--r-- | lpg/libqr/code-create.c | 11 | ||||
-rw-r--r-- | lpg/libqr/rs-encode.c | 47 | ||||
-rw-r--r-- | lpg/libqr/rs.h | 9 | ||||
-rw-r--r-- | lpg/libqr/test.c | 1 |
5 files changed, 69 insertions, 2 deletions
diff --git a/lpg/libqr/Makefile b/lpg/libqr/Makefile index e36b09f..1f34caf 100644 --- a/lpg/libqr/Makefile +++ b/lpg/libqr/Makefile @@ -5,7 +5,8 @@ OBJECTS := bitstream.o \ code-render.o \ data-common.o \ data-create.o \ - data-parse.o + data-parse.o \ + rs-encode.o CFLAGS := -std=c89 -pedantic -I. -Wall CFLAGS += -g diff --git a/lpg/libqr/code-create.c b/lpg/libqr/code-create.c index d09c2fe..484dbe3 100644 --- a/lpg/libqr/code-create.c +++ b/lpg/libqr/code-create.c @@ -5,6 +5,7 @@ #include "code-common.h" #include "data-common.h" +#include "rs.h" #define MIN(a, b) ((b) < (a) ? (b) : (a)) @@ -29,7 +30,15 @@ static int add_ecc(struct bitstream * bits, int format, enum qr_ec_level ec) { puts("Before ecc:"); x_dump(bits); - + { + const int g[10] = { 251, 67, 61, 118, 70, 64, 94, 32, 45 }; + int rs_words = 10; /* 1-M */ + struct bitstream * rs; + + rs = rs_generate_words(rs_words, g, bits); + puts("ecc part:"); + x_dump(rs); + } return -1; } diff --git a/lpg/libqr/rs-encode.c b/lpg/libqr/rs-encode.c new file mode 100644 index 0000000..ec99c6b --- /dev/null +++ b/lpg/libqr/rs-encode.c @@ -0,0 +1,47 @@ +#include <assert.h> +#include <stdlib.h> +#include "bitstream.h" +#include "rs.h" + +struct bitstream * rs_generate_words(int k, const int * coeff, struct bitstream * data) +{ + struct bitstream * ec = 0; + unsigned int * b = 0; + size_t n, i, dlen; + + dlen = bitstream_size(data); + assert(dlen % 8 == 0); + dlen /= 8; + + ec = bitstream_create(); + if (!ec) + return 0; + + if (bitstream_resize(ec, k * 8) != 0) + goto fail; + + b = calloc(k, sizeof(*b)); + if (!b) + goto fail; + + /* First, prepare the registers (b) with data bits. Note that + * the registers are in reverse of the normal order + */ + bitstream_seek(data, 0); + for (n = 0; n < dlen; ++n) { + unsigned int x = b[0] + bitstream_read(data, 8); + for (i = 0; i < k-1; ++i) + b[i] = b[i+1] + coeff[(k-1) - i] * x; + b[k-1] = coeff[0] * x; + } + + /* Read off the registers */ + bitstream_pack(ec, b, k, 8); + + free(b); + return ec; +fail: + bitstream_destroy(ec); + return 0; +} + diff --git a/lpg/libqr/rs.h b/lpg/libqr/rs.h new file mode 100644 index 0000000..98e3aa0 --- /dev/null +++ b/lpg/libqr/rs.h @@ -0,0 +1,9 @@ +#ifndef RS_H +#define RS_H + +#include "bitstream.h" + +struct bitstream * rs_generate_words(int k, const int * coeff, struct bitstream * data); + +#endif + diff --git a/lpg/libqr/test.c b/lpg/libqr/test.c index 76d0b97..ec77bfe 100644 --- a/lpg/libqr/test.c +++ b/lpg/libqr/test.c @@ -5,6 +5,7 @@ #include <qr/data.h> #include "bitstream.h" +#include "code-common.h" int main() { |