changeset 1053:a726c1b9a41e

Add some clarifying comments.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Mar 2015 22:27:08 +0200
parents 16a30319cb1c
children d98fcb10df6a
files src/dmzlib.c
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/dmzlib.c	Sun Mar 01 22:06:58 2015 +0200
+++ b/src/dmzlib.c	Sun Mar 01 22:27:08 2015 +0200
@@ -3,6 +3,11 @@
  * -- ZLib implementation
  * Public domain zlib decode v0.2 by Sean Barrett 2006-11-18
  * Modified and reformatted for DMLib by Matti 'ccr' Hamalainen
+ *
+ * For more information, refer to following RFCs:
+ * http://tools.ietf.org/html/rfc1950 - ZLIB compressed data format
+ * http://tools.ietf.org/html/rfc1951 - DEFLATE format
+ *
  */
 #include "dmzlib.h"
 
@@ -19,19 +24,25 @@
 {
     int i;
 
-    // use <= to match clearly with spec
+    // Use <= to match clearly with DEFLATE spec
+
+    // Literals 0  ..143:  8 bits, codes 00110000 .. 10111111
     for (i = 0; i <= 143; i++)
         dm_zdefault_length[i] = 8;
 
+    // Literals 144..255:  9 bits, codes 110010000 .. 111111111
     for (; i <= 255; i++)
         dm_zdefault_length[i] = 9;
 
+    // Literals 256..279:  7 bits, codes 0000000 .. 0010111
     for (; i <= 279; i++)
         dm_zdefault_length[i] = 7;
 
+    // Literals 280..287:  8 bits, codes 11000000 .. 11000111
     for (; i <= 287; i++)
         dm_zdefault_length[i] = 8;
 
+    // Default distances
     for (i = 0; i <= 31; i++)
         dm_zdefault_distance[i] = 5;
 }
@@ -39,6 +50,7 @@
 
 static inline int dmBitReverse16(int n)
 {
+    // "Reverse" a 16bit word through bitshifts
     n = ((n & 0xAAAA) >> 1) | ((n & 0x5555) << 1);
     n = ((n & 0xCCCC) >> 2) | ((n & 0x3333) << 2);
     n = ((n & 0xF0F0) >> 4) | ((n & 0x0F0F) << 4);
@@ -47,11 +59,11 @@
 }
 
 
-static inline int dmBitReverseN(int v, int bits)
+// To bit reverse N bits, reverse 16 and shift
+// e.g. 11 bits, bit reverse and shift away 5
+static inline int dmBitReverseN(int v, const int bits)
 {
     DMSTBI_ASSERT(bits <= 16);
-    // to bit reverse n bits, reverse 16 and shift
-    // e.g. 11 bits, bit reverse and shift away 5
     return dmBitReverse16(v) >> (16 - bits);
 }
 
@@ -61,7 +73,6 @@
     int i, k = 0;
     int code, next_code[16], sizes[17];
 
-    // DEFLATE spec for generating codes
     memset(sizes, 0, sizeof(sizes));
     memset(ctx->fast, 0, sizeof(ctx->fast));