text stringlengths 0 234 |
|---|
if Start > From then |
-- put_line(from'img & to'img & start'img); |
declare |
Copy_From : Lz_Buffer_Index_Type := Start; |
Copy : Lz_Buffer_Type (0 .. Slider_Max); |
begin |
for I in Copy'Range loop |
Copy (I) := Lz_Buffer (Copy_From); |
Copy_From := Copy_From + 1; -- Loops over (mod n) |
end loop; |
Initial_Hd := Build_Descriptors (Copy); |
Function Definition: procedure Encode is |
Function Body: X_Percent : Natural; |
Bytes_In : Natural; -- Count of input file bytes processed |
User_Aborting : Boolean; |
Pctdone : Natural; |
function Read_Byte return Byte is |
B : Byte; |
begin |
B := Inbuf (Inbufidx); |
Inbufidx := Inbufidx + 1; |
Zip.CRC.Update (CRC, (1 => B)); |
Bytes_In := Bytes_In + 1; |
if Feedback /= null then |
if Bytes_In = 1 then |
Feedback (0, User_Aborting); |
end if; |
if X_Percent > 0 |
and then ((Bytes_In - 1) mod X_Percent = 0 or Bytes_In = Integer (Input_Size)) |
then |
Pctdone := Integer ((100.0 * Float (Bytes_In)) / Float (Input_Size)); |
Feedback (Pctdone, User_Aborting); |
if User_Aborting then |
raise User_Abort; |
end if; |
end if; |
end if; |
return B; |
end Read_Byte; |
function More_Bytes return Boolean is |
begin |
if Inbufidx > Maxinbufidx then |
Read_Block; |
end if; |
return not Inputeof; |
end More_Bytes; |
-- LZ77 parameters |
Look_Ahead : constant Integer := 258; |
String_Buffer_Size : constant := 2**15; -- Required: 2**15 for Deflate, 2**16 for Deflate_e |
type Text_Buffer_Index is mod String_Buffer_Size; |
type Text_Buffer is array (Text_Buffer_Index) of Byte; |
Text_Buf : Text_Buffer; |
R : Text_Buffer_Index; |
-- If the DLE coding doesn't fit the format constraints, we need |
-- to decode it as a simple sequence of literals. The buffer used is |
-- called "Text" buffer by reference to "clear-text", but actually it |
-- is any binary data. |
procedure Lz77_Emits_Dl_Code (Distance, Length : Integer) is |
-- NB: no worry, all arithmetics in Text_buffer_index are modulo String_buffer_size |
B : Byte; |
Copy_Start : Text_Buffer_Index; |
Expand : Expanded_Data; |
Ie : Positive := 1; |
begin |
if Distance = |
String_Buffer_Size |
then -- Happens with 7-Zip, cannot happen with Info-Zip |
Copy_Start := R; |
else |
Copy_Start := R - Text_Buffer_Index (Distance); |
end if; |
-- Expand into the circular text buffer to have it up to date |
for K in 0 .. Text_Buffer_Index (Length - 1) loop |
B := Text_Buf (Copy_Start + K); |
Text_Buf (R) := B; |
R := R + 1; |
if Ie <= Max_Expand then -- Also memorize short sequences for LZ buffer |
Expand (Ie) := B; -- for the case a block needs to be stored in clear |
Ie := Ie + 1; |
end if; |
end loop; |
if Distance in Distance_Range and Length in Length_Range then |
Put_Or_Delay_Dl_Code (Distance, Length, Expand); |
else |
for K in 0 .. Text_Buffer_Index (Length - 1) loop |
Put_Or_Delay_Literal_Byte (Text_Buf (Copy_Start + K)); |
end loop; |
end if; |
end Lz77_Emits_Dl_Code; |
procedure Lz77_Emits_Literal_Byte (B : Byte) is |
begin |
Text_Buf (R) := B; |
R := R + 1; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.