From 825c45bed29693e9420abecdeb4ebcd03aa3accd Mon Sep 17 00:00:00 2001 From: Leo Howell Date: Sat, 26 Sep 2009 11:44:37 +0900 Subject: implement bitstream_cat() --- lpg/libqr/bitstream.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lpg/libqr/bitstream.c') diff --git a/lpg/libqr/bitstream.c b/lpg/libqr/bitstream.c index a2b2b58..fd58ea3 100644 --- a/lpg/libqr/bitstream.c +++ b/lpg/libqr/bitstream.c @@ -201,3 +201,32 @@ int bitstream_pack(struct bitstream * stream, return 0; } +int bitstream_cat(struct bitstream * dest, const struct bitstream * src) +{ + size_t count = bitstream_size(src); + size_t srcpos; + + if (ensure_available(dest, count) != 0) + return -1; + + srcpos = bitstream_tell(src); + bitstream_seek((struct bitstream *)src, 0); + + /* uint must be at least 16 bits */ + for (; count >= 16; count -= 16) + bitstream_write( + dest, + bitstream_read((struct bitstream *)src, 16), + 16); + + if (count > 0) + bitstream_write( + dest, + bitstream_read((struct bitstream *)src, count), + count); + + bitstream_seek((struct bitstream *)src, srcpos); + + return 0; +} + -- cgit v1.2.3-70-g09d2