text stringlengths 0 234 |
|---|
Put_Or_Delay_Literal_Byte (B); |
end Lz77_Emits_Literal_Byte; |
Lz77_Choice : constant array (Deflation_Method) of Lz77.Method_Type := |
(Deflate_Fixed => Lz77.Iz_4, |
Deflate_1 => Lz77.Iz_6, -- Level 6 is the default in Info-Zip's zip.exe |
Deflate_2 => Lz77.Iz_8, |
Deflate_3 => Lz77.Iz_10); |
procedure My_Lz77 is new Lz77.Encode |
(String_Buffer_Size => String_Buffer_Size, |
Look_Ahead => Look_Ahead, |
Threshold => 2, -- From a string match length > 2, a DL code is sent |
Method => Lz77_Choice (Method), |
Read_Byte => Read_Byte, |
More_Bytes => More_Bytes, |
Write_Literal => Lz77_Emits_Literal_Byte, |
Write_Dl_Code => Lz77_Emits_Dl_Code); |
begin |
Read_Block; |
R := Text_Buffer_Index (String_Buffer_Size - Look_Ahead); |
Bytes_In := 0; |
X_Percent := Integer (Input_Size / 40); |
case Method is |
when Deflate_Fixed => -- "Fixed" (predefined) compression structure |
-- We have only one compressed data block, then it is already the last one. |
Put_Code (Code => 1, Code_Size => 1); -- Signals last block |
Put_Code (Code => 1, Code_Size => 2); -- Signals a "fixed" block |
when Taillaule_Deflation_Method => |
null; -- No start data sent, all is delayed |
end case; |
-- The whole compression is happening in the following line: |
My_Lz77; |
-- Done. Send the code signaling the end of compressed data block: |
case Method is |
when Deflate_Fixed => |
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block)); |
when Taillaule_Deflation_Method => |
if Lz_Buffer_Index * 2 = 0 then -- Already flushed at latest Push, or empty data |
if Block_To_Finish and then Last_Block_Type in Fixed .. Dynamic then |
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block)); |
end if; |
else |
Flush_Half_Buffer (Last_Flush => True); |
if Last_Block_Type in Fixed .. Dynamic then |
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block)); |
end if; |
end if; |
if not Last_Block_Marked then |
-- Add a fake fixed block, just to have a final block... |
Put_Code (Code => 1, Code_Size => 1); -- Signals last block |
Put_Code (Code => 1, Code_Size => 2); -- Signals a "fixed" block |
Curr_Descr := Deflate_Fixed_Descriptors; |
Put_Huffman_Code (Curr_Descr.Lit_Len (End_Of_Block)); |
end if; |
end case; |
end Encode; |
begin |
-- Allocate input and output buffers |
Inbuf := new Byte_Buffer |
(1 .. Integer'Min (Integer'Max (8, Integer (Input_Size)), Default_Buffer_Size)); |
Outbuf := new Byte_Buffer (1 .. Default_Buffer_Size); |
Output_Size := 0; |
Lz_Buffer := new Full_Range_Lz_Buffer_Type; |
begin |
Encode; |
Compression_Ok := True; |
Flush_Bit_Buffer; |
Flush_Byte_Buffer; |
exception |
when Compression_Inefficient => |
-- Escaped from Encode |
Compression_Ok := False; |
Function Definition: function Intel_Nb is new Intel_X86_Number (Unsigned_16); |
Function Body: function Intel_Nb is new Intel_X86_Number (Unsigned_32); |
-- Put numbers with correct endianess as bytes |
generic |
type Number is mod <>; -- range <> in Ada83 version (fake Interfaces) |
Size : Stream_Element_Count; |
function Intel_X86_Buffer (N : Number) return Stream_Element_Array; |
function Intel_X86_Buffer (N : Number) return Stream_Element_Array is |
B : Stream_Element_Array (1 .. Size); |
M : Number := N; |
begin |
for I in B'Range loop |
B (I) := Stream_Element (M and 255); |
M := M / 256; |
end loop; |
return B; |
end Intel_X86_Buffer; |
function Intel_Bf is new Intel_X86_Buffer (Unsigned_16, 2); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.