text
stringlengths
0
234
local_CRC:= CRC ;
for i in InBuf'Range loop
local_CRC :=
CRC32_Table( 16#FF# and ( local_CRC xor Unsigned_32( InBuf(i) ) ) )
xor
Shift_Right( local_CRC , 8 );
end loop;
CRC:= local_CRC;
end Update;
table_empty: Boolean:= True;
procedure Init( CRC: out Unsigned_32 ) is
begin
if table_empty then
Prepare_table;
table_empty:= False;
end if;
CRC:= 16#FFFF_FFFF#;
end Init;
function Final( CRC: Unsigned_32 ) return Unsigned_32 is
begin
return not CRC;
end Final;
end CRC32;
----------
-- Load --
----------
procedure Load (image: in out Image_descriptor) is
----------------------
-- Load_specialized --
----------------------
generic
-- These values are invariant through the whole picture,
-- so we can make them generic parameters. As a result, all
-- "if", "case", etc. using them at the center of the decoding
-- are optimized out at compile-time.
interlaced : Boolean;
bits_per_pixel : Positive;
bytes_to_unfilter : Positive;
-- ^ amount of bytes to unfilter at a time
-- = Integer'Max(1, bits_per_pixel / 8);
subformat_id : Natural;
procedure Load_specialized;
--
procedure Load_specialized is
use GID.Buffering;
subtype Mem_row_bytes_array is Byte_array(0..image.width*8);
--
mem_row_bytes: array(0..1) of Mem_row_bytes_array;
-- We need to memorize two image rows, for un-filtering
curr_row: Natural:= 1;
-- either current is 1 and old is 0, or the reverse
subtype X_range is Integer range -1..image.width-1;
subtype Y_range is Integer range 0..image.height-1;
-- X position -1 is for the row's filter methode code
x: X_range:= X_range'First;
y: Y_range:= Y_range'First;
x_max: X_range; -- for non-interlaced images: = X_range'Last
y_max: Y_range; -- for non-interlaced images: = Y_range'Last
pass: Positive range 1..7:= 1;
--------------------------
-- ** 9: Unfiltering ** --
--------------------------
-- http://www.w3.org/TR/PNG/#9Filters
type Filter_method_0 is (None, Sub, Up, Average, Paeth);
current_filter: Filter_method_0;
procedure Unfilter_bytes(
f: in Byte_array; -- filtered
u: out Byte_array -- unfiltered
)
is
pragma Inline(Unfilter_bytes);
-- Byte positions (f is the byte to be unfiltered):
--
-- c b
-- a f
a,b,c, p,pa,pb,pc,pr: Integer;
j: Integer:= 0;
begin
if full_trace and then x = 0 then
if y = 0 then
Ada.Text_IO.New_Line;
end if;