text
stringlengths
0
234
Put_Byte (B2);
Put_Byte (not B1);
Put_Byte (not B2);
for I in Lzb'Range loop
case Lzb (I).Kind is
when Plain_Byte =>
Put_Byte (Lzb (I).Plain);
when Distance_Length =>
for J in 1 .. Lzb (I).Lz_Length loop
Put_Byte (Lzb (I).Lz_Expanded (J));
end loop;
end case;
end loop;
end Expand_Lz_Buffer;
-- Extra bits that need to be sent after various Deflate codes
Extra_Bits_For_Lz_Length_Code : constant array (257 .. 285) of Natural :=
(257 .. 264 => 0,
265 .. 268 => 1,
269 .. 272 => 2,
273 .. 276 => 3,
277 .. 280 => 4,
281 .. 284 => 5,
285 => 0);
Extra_Bits_For_Lz_Distance_Code : constant array (0 .. 29) of Natural :=
(0 .. 3 => 0,
4 .. 5 => 1,
6 .. 7 => 2,
8 .. 9 => 3,
10 .. 11 => 4,
12 .. 13 => 5,
14 .. 15 => 6,
16 .. 17 => 7,
18 .. 19 => 8,
20 .. 21 => 9,
22 .. 23 => 10,
24 .. 25 => 11,
26 .. 27 => 12,
28 .. 29 => 13);
subtype Long_Length_Codes is
Alphabet_Lit_Len range Code_For_Max_Expand + 1 .. Alphabet_Lit_Len'Last;
Zero_Bl_Long_Lengths : constant Stats_Type (Long_Length_Codes) := (others => 0);
-- Send_as_block.
--
-- lzb (can be a slice of the principal buffer) will be sent as:
-- * a new "dynamic" block, preceded by a compression structure header
-- or * the continuation of previous "dynamic" block
-- or * a new "fixed" block, if lz data's Huffman descriptor is close enough to "fixed"
-- or * a new "stored" block, if lz data are too random
procedure Send_As_Block (Lzb : Lz_Buffer_Type; Last_Block : Boolean) is
New_Descr, New_Descr_2 : Deflate_Huff_Descriptors;
procedure Send_Fixed_Block is
begin
if Last_Block_Type = Fixed then
-- Cool, we don't need to mark a block boundary: the Huffman codes are already
-- the expected ones. We can just continue sending the LZ atoms.
null;
else
Mark_New_Block (Last_Block_For_Stream => Last_Block);
Curr_Descr := Deflate_Fixed_Descriptors;
Put_Code (Code => 1, Code_Size => 2); -- Signals a "fixed" block
Last_Block_Type := Fixed;
end if;
Put_Lz_Buffer (Lzb);
end Send_Fixed_Block;
Stats_Lit_Len, Stats_Lit_Len_2 : Stats_Lit_Len_Type;
Stats_Dis, Stats_Dis_2 : Stats_Dis_Type;
procedure Send_Dynamic_Block (Dyn : Deflate_Huff_Descriptors) is
Dummy : Count_Type := 0;
begin
Mark_New_Block (Last_Block_For_Stream => Last_Block);
Curr_Descr := Prepare_Huffman_Codes (Dyn);
Put_Code (Code => 2, Code_Size => 2); -- Signals a "dynamic" block
Put_Compression_Structure (Curr_Descr, Cost_Analysis => False, Bits => Dummy);
Put_Lz_Buffer (Lzb);
Last_Block_Type := Dynamic;
end Send_Dynamic_Block;
-- The following variables will contain the *exact* number of bits taken
-- by the block to be sent, using different Huffman encodings, or stored.
Stored_Format_Bits, -- Block is stored (no compression)
Fixed_Format_Bits, -- Fixed (preset) Huffman codes
Dynamic_Format_Bits, -- Dynamic Huffman codes using block's statistics
Dynamic_Format_Bits_2, -- Dynamic Huffman codes after Tweak_for_better_RLE
Recycled_Format_Bits : Count_Type :=
0; -- Continue previous block, use current Huffman codes
Stored_Format_Possible : Boolean; -- Can we store (needs expansion of DL codes) ?
Recycling_Possible : Boolean; -- Can we recycle current Huffman codes ?
procedure Compute_Sizes_Of_Variants is
C : Count_Type;
Extra : Natural;
begin