From: Michael Gernoth Date: Mon, 2 Feb 2009 23:27:09 +0000 (+0100) Subject: add comments about compression algorithm implementation X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/commitdiff_plain/1d359f151c5a8943607207ea24d1092bd2e08ead add comments about compression algorithm implementation --- 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; }