From 1d359f151c5a8943607207ea24d1092bd2e08ead Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Tue, 3 Feb 2009 00:27:09 +0100 Subject: [PATCH] add comments about compression algorithm implementation --- rsb-lz.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/rsb-lz.c b/rsb-lz.c index c23dd5a..4dddd9b 100644 --- a/rsb-lz.c +++ b/rsb-lz.c @@ -101,34 +101,42 @@ void write_byte(unsigned char byte, struct data_out_s *data_out) void lz_expand(struct data_in_s *data_in, struct data_out_s *data_out) { unsigned int pos; - unsigned int offset; + unsigned int wordoffset; unsigned int i; unsigned char byte; - unsigned int num; + unsigned int wordlen; unsigned char buf[1024]; pos = 1; while (1) { while (1) { + /* Compressed/uncompressed? */ if (get_next_bit(data_in) == 0) break; + /* Uncompressed byte */ byte = get_next_bits(data_in, 8); write_byte(byte, data_out); + + /* Save byte in buffer, to be reused later */ buf[pos] = byte; pos = (pos + 1) & 0x3ff; } - offset = get_next_bits(data_in, 0x0a); - if(offset == 0) + /* offset for start of dictionary word */ + wordoffset = get_next_bits(data_in, 0x0a); + if(wordoffset == 0) return; - num = get_next_bits(data_in, 0x04) + 1; - for (i = 0; i <= num; i++) { - byte = buf[(offset + i) & 0x3ff]; + /* length of dictionary word used */ + wordlen = get_next_bits(data_in, 0x04) + 1; + for (i = 0; i <= wordlen ; i++) { + /* lookup dictionary byte */ + byte = buf[(wordoffset + i) & 0x3ff]; write_byte(byte, data_out); + /* Save byte in buffer, to be reused later */ buf[pos] = byte; pos = (pos + 1) & 0x3ff; } -- 2.39.5