]> git.zerfleddert.de Git - rsbs2/commitdiff
add comments about compression algorithm implementation
authorMichael Gernoth <michael@gernoth.net>
Mon, 2 Feb 2009 23:27:09 +0000 (00:27 +0100)
committerMichael Gernoth <michael@gernoth.net>
Mon, 2 Feb 2009 23:27:09 +0000 (00:27 +0100)
rsb-lz.c

index c23dd5a02af56450920eb4f43f2e1e1c07155c8b..4dddd9b37997d778f316472bad6cb7e736ab0d59 100644 (file)
--- 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;
                }
Impressum, Datenschutz