From 55d8ac4768d03001b746ce0af0ad0e15031e4041 Mon Sep 17 00:00:00 2001 From: Leo Howell Date: Tue, 15 Sep 2009 07:56:20 +0900 Subject: RS encode (not working yet) --- lpg/libqr/rs-encode.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lpg/libqr/rs-encode.c (limited to 'lpg/libqr/rs-encode.c') 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 +#include +#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; +} + -- cgit v1.2.3-70-g09d2