text
stringlengths
0
234
-- literal/length and distance code lengths
Ll: Length_array( 0 .. 288+32-1 ):= (others=> 0);
huft_incomplete : Boolean;
procedure Repeat_length_code( amount: Natural ) is
begin
if defined + amount > number_of_lengths then
raise error_in_image_data;
end if;
for c in reverse 1..amount loop
Ll ( defined ) := Natural_M32(current_length);
defined:= defined + 1;
end loop;
end Repeat_length_code;
begin
if full_trace then
Ada.Text_IO.Put_Line("Begin Inflate_dynamic_block");
end if;
-- Read in table lengths
Nl := 257 + UnZ_IO.Bit_buffer.Read_and_dump(5);
Nd := 1 + UnZ_IO.Bit_buffer.Read_and_dump(5);
Nb := 4 + UnZ_IO.Bit_buffer.Read_and_dump(4);
if Nl > 288 or else Nd > 32 then
raise error_in_image_data;
end if;
-- Read in bit-length-code lengths.
-- The rest, Ll( Bit_Order( Nb .. 18 ) ), is already = 0
for J in 0 .. Nb - 1 loop
Ll ( bit_order( J ) ) := Natural_M32(UnZ_IO.Bit_buffer.Read_and_dump(3));
end loop;
-- Build decoding table for trees--single level, 7 bit lookup
Bl := 7;
begin
HufT_build (
Ll( 0..18 ), 19, empty, empty, Tl, Bl, huft_incomplete
);
if huft_incomplete then
HufT_free(Tl);
raise error_in_image_data;
end if;
exception
when others =>
raise error_in_image_data;
Function Definition: procedure Inflate is
Function Body: is_last_block: Boolean;
blocks: Positive:= 1;
begin
if deflate_e_mode then
copy_lengths_literal(28):= 3; -- instead of 258
extra_bits_literal(28):= 16; -- instead of 0
max_dist:= 31;
end if;
loop
Inflate_Block ( is_last_block );
exit when is_last_block;
blocks:= blocks+1;
end loop;
UnZ_IO.Flush( UnZ_Glob.slide_index );
UnZ_Glob.slide_index:= 0;
if some_trace then
Ada.Text_IO.Put("# blocks:" & Integer'Image(blocks));
end if;
UnZ_Glob.crc32val := CRC32.Final( UnZ_Glob.crc32val );
end Inflate;
end UnZ_Meth;
--------------------------------------------------------------------
-- End of the Decompression part, and of UnZip.Decompress excerpt --
--------------------------------------------------------------------
b: U8;
z_crc, dummy: U32;
begin -- Load_specialized
--
-- For optimization reasons, bytes_to_unfilter is passed as a
-- generic parameter but should be always as below right to "/=" :
--
if bytes_to_unfilter /= Integer'Max(1, bits_per_pixel / 8) then
raise Program_Error;
end if;
if interlaced then
x_max:= (image.width+7)/8 - 1;
y_max:= (image.height+7)/8 - 1;
else
x_max:= X_range'Last;
y_max:= Y_range'Last;
end if;
main_chunk_loop:
loop
loop
Read(image, ch);