text
stringlengths
0
234
if ch.kind /= IDAT then
Raise_Exception(
error_in_image_data'Identity,
"PNG additional data chunk must be an IDAT"
);
end if;
end Jump_IDAT;
---------------------------------------------------------------------
-- ** 10: Decompression ** --
-- Excerpt and simplification from UnZip.Decompress (Inflate only) --
---------------------------------------------------------------------
-- http://www.w3.org/TR/PNG/#10Compression
-- Size of sliding dictionary and circular output buffer
wsize: constant:= 16#10000#;
--------------------------------------
-- Specifications of UnZ_* packages --
--------------------------------------
package UnZ_Glob is
-- I/O Buffers
-- > Sliding dictionary for unzipping, and output buffer as well
slide: Byte_array( 0..wsize );
slide_index: Integer:= 0; -- Current Position in slide
Zip_EOF : constant Boolean:= False;
crc32val : Unsigned_32; -- crc calculated from data
end UnZ_Glob;
package UnZ_IO is
procedure Init_Buffers;
procedure Read_raw_byte ( bt : out U8 );
pragma Inline(Read_raw_byte);
package Bit_buffer is
procedure Init;
-- Read at least n bits into the bit buffer, returns the n first bits
function Read ( n: Natural ) return Integer;
pragma Inline(Read);
function Read_U32 ( n: Natural ) return Unsigned_32;
pragma Inline(Read_U32);
-- Dump n bits no longer needed from the bit buffer
procedure Dump ( n: Natural );
pragma Inline(Dump);
procedure Dump_to_byte_boundary;
function Read_and_dump( n: Natural ) return Integer;
pragma Inline(Read_and_dump);
function Read_and_dump_U32( n: Natural ) return Unsigned_32;
pragma Inline(Read_and_dump_U32);
end Bit_buffer;
procedure Flush ( x: Natural ); -- directly from slide to output stream
procedure Flush_if_full(W: in out Integer);
pragma Inline(Flush_if_full);
procedure Copy(
distance, length: Natural;
index : in out Natural );
pragma Inline(Copy);
end UnZ_IO;
package UnZ_Meth is
deflate_e_mode: constant Boolean:= False;
procedure Inflate;
end UnZ_Meth;
------------------------------
-- Bodies of UnZ_* packages --
------------------------------
package body UnZ_IO is
procedure Init_Buffers is
begin
UnZ_Glob.slide_index := 0;
Bit_buffer.Init;
CRC32.Init( UnZ_Glob.crc32val );
end Init_Buffers;
procedure Read_raw_byte ( bt : out U8 ) is
begin
if ch.length = 0 then
-- We hit the end of a PNG 'IDAT' chunk, so we go to the next one
-- - in petto, it's strange design, but well...
-- This "feature" has taken some time (and nerves) to be addressed.
-- Incidentally, I have reprogrammed the whole Huffman
-- decoding, and looked at many other wrong places to solve
-- the mystery.
Jump_IDAT;
end if;
Buffering.Get_Byte(image.buffer, bt);
ch.length:= ch.length - 1;
end Read_raw_byte;
package body Bit_buffer is
B : Unsigned_32;