text
stringlengths
0
234
-- message buffer for starting the copy) shall be 33, plus the value given
-- by the 4 extra bits (between 0 and 15).
case Distance is
when 1 .. 4 => -- Codes 0..3, with no extra bit
Put_Huffman_Code (Curr_Descr.Dis (Distance - 1));
when 5 .. 8 => -- Codes 4..5, with 1 extra bit
Put_Huffman_Code (Curr_Descr.Dis (4 + (Distance - 5) / 2));
Put_Code (U32 ((Distance - 5) mod 2), 1);
when 9 .. 16 => -- Codes 6..7, with 2 extra bits
Put_Huffman_Code (Curr_Descr.Dis (6 + (Distance - 9) / 4));
Put_Code (U32 ((Distance - 9) mod 4), 2);
when 17 .. 32 => -- Codes 8..9, with 3 extra bits
Put_Huffman_Code (Curr_Descr.Dis (8 + (Distance - 17) / 8));
Put_Code (U32 ((Distance - 17) mod 8), 3);
when 33 .. 64 => -- Codes 10..11, with 4 extra bits
Put_Huffman_Code (Curr_Descr.Dis (10 + (Distance - 33) / 16));
Put_Code (U32 ((Distance - 33) mod 16), 4);
when 65 .. 128 => -- Codes 12..13, with 5 extra bits
Put_Huffman_Code (Curr_Descr.Dis (12 + (Distance - 65) / 32));
Put_Code (U32 ((Distance - 65) mod 32), 5);
when 129 .. 256 => -- Codes 14..15, with 6 extra bits
Put_Huffman_Code (Curr_Descr.Dis (14 + (Distance - 129) / 64));
Put_Code (U32 ((Distance - 129) mod 64), 6);
when 257 .. 512 => -- Codes 16..17, with 7 extra bits
Put_Huffman_Code (Curr_Descr.Dis (16 + (Distance - 257) / 128));
Put_Code (U32 ((Distance - 257) mod 128), 7);
when 513 .. 1024 => -- Codes 18..19, with 8 extra bits
Put_Huffman_Code (Curr_Descr.Dis (18 + (Distance - 513) / 256));
Put_Code (U32 ((Distance - 513) mod 256), 8);
when 1025 .. 2048 => -- Codes 20..21, with 9 extra bits
Put_Huffman_Code (Curr_Descr.Dis (20 + (Distance - 1025) / 512));
Put_Code (U32 ((Distance - 1025) mod 512), 9);
when 2049 .. 4096 => -- Codes 22..23, with 10 extra bits
Put_Huffman_Code (Curr_Descr.Dis (22 + (Distance - 2049) / 1024));
Put_Code (U32 ((Distance - 2049) mod 1024), 10);
when 4097 .. 8192 => -- Codes 24..25, with 11 extra bits
Put_Huffman_Code (Curr_Descr.Dis (24 + (Distance - 4097) / 2048));
Put_Code (U32 ((Distance - 4097) mod 2048), 11);
when 8193 .. 16384 => -- Codes 26..27, with 12 extra bits
Put_Huffman_Code (Curr_Descr.Dis (26 + (Distance - 8193) / 4096));
Put_Code (U32 ((Distance - 8193) mod 4096), 12);
when 16385 .. 32768 => -- Codes 28..29, with 13 extra bits
Put_Huffman_Code (Curr_Descr.Dis (28 + (Distance - 16385) / 8192));
Put_Code (U32 ((Distance - 16385) mod 8192), 13);
end case;
end Put_Dl_Code;
function Deflate_Code_For_Lz_Distance (Distance : Distance_Range) return Natural is
begin
case Distance is
when 1 .. 4 => -- Codes 0..3, with no extra bit
return Distance - 1;
when 5 .. 8 => -- Codes 4..5, with 1 extra bit
return 4 + (Distance - 5) / 2;
when 9 .. 16 => -- Codes 6..7, with 2 extra bits
return 6 + (Distance - 9) / 4;
when 17 .. 32 => -- Codes 8..9, with 3 extra bits
return 8 + (Distance - 17) / 8;
when 33 .. 64 => -- Codes 10..11, with 4 extra bits
return 10 + (Distance - 33) / 16;
when 65 .. 128 => -- Codes 12..13, with 5 extra bits
return 12 + (Distance - 65) / 32;
when 129 .. 256 => -- Codes 14..15, with 6 extra bits
return 14 + (Distance - 129) / 64;
when 257 .. 512 => -- Codes 16..17, with 7 extra bits
return 16 + (Distance - 257) / 128;
when 513 .. 1024 => -- Codes 18..19, with 8 extra bits
return 18 + (Distance - 513) / 256;
when 1025 .. 2048 => -- Codes 20..21, with 9 extra bits
return 20 + (Distance - 1025) / 512;
when 2049 .. 4096 => -- Codes 22..23, with 10 extra bits
return 22 + (Distance - 2049) / 1024;
when 4097 .. 8192 => -- Codes 24..25, with 11 extra bits
return 24 + (Distance - 4097) / 2048;
when 8193 .. 16384 => -- Codes 26..27, with 12 extra bits
return 26 + (Distance - 8193) / 4096;
when 16385 .. 32768 => -- Codes 28..29, with 13 extra bits
return 28 + (Distance - 16385) / 8192;
end case;
end Deflate_Code_For_Lz_Distance;
-----------------
-- LZ Buffer --
-----------------
-- We buffer the LZ codes (plain, or distance/length) in order to
-- analyse them and try to do smart things.
Max_Expand : constant := 14;
-- *Tuned* Sometimes it is better to store data and expand short strings
Code_For_Max_Expand : constant := 266;
subtype Expanded_Data is Byte_Buffer (1 .. Max_Expand);
type Lz_Atom_Kind is (Plain_Byte, Distance_Length);
type Lz_Atom is record
Kind : Lz_Atom_Kind;
Plain : Byte;
Lz_Distance : Natural;
Lz_Length : Natural;