text
stringlengths
0
234
b := Read_byte;
block_size := Natural (b) - Character'Pos ('0');
tt := new Tcardinal_array (0 .. block_size * sub_block_size);
end Init;
function get_bits (n : Natural) return Unsigned_8 is
Result_get_bits : Unsigned_8;
data : Unsigned_8;
begin
if n > bits_available then
data := Read_byte;
Result_get_bits := Shift_Right (read_data, 8 - n) or Shift_Right (data, 8 - (n - bits_available));
read_data := Shift_Left (data, n - bits_available);
bits_available := bits_available + 8;
else
Result_get_bits := Shift_Right (read_data, 8 - n);
read_data := Shift_Left (read_data, n);
end if;
bits_available := bits_available - n;
return Result_get_bits;
end get_bits;
function get_bits_32 (n : Natural) return Unsigned_32 is
begin
return Unsigned_32 (get_bits (n));
end get_bits_32;
function get_boolean return Boolean is
begin
return Boolean'Val (get_bits (1));
end get_boolean;
function get_byte return Unsigned_8 is
begin
return get_bits (8);
end get_byte;
function get_cardinal24 return Unsigned_32 is
begin
return Shift_Left (get_bits_32 (8), 16) or Shift_Left (get_bits_32 (8), 8) or get_bits_32 (8);
end get_cardinal24;
function get_cardinal return Unsigned_32 is
begin
return Shift_Left (get_bits_32 (8), 24) or
Shift_Left (get_bits_32 (8), 16) or
Shift_Left (get_bits_32 (8), 8) or
get_bits_32 (8);
end get_cardinal;
-- Receive the mapping table. To save space, the inuse set is stored in pieces
-- of 16 bits. First 16 bits are stored which pieces of 16 bits are used, then
-- the pieces follow.
procedure receive_mapping_table is
inuse16 : array (0 .. 15) of Boolean;
--* inuse : array (0 .. 255) of Boolean; -- for dump purposes
begin
inuse16 := (others => False);
-- Receive the first 16 bits which tell which pieces are stored.
for i in 0 .. 15 loop
inuse16 (i) := get_boolean;
end loop;
-- Receive the used pieces.
--* inuse := (others => False);
inuse_count := 0;
for i in 0 .. 15 loop
if inuse16 (i) then
for j in 0 .. 15 loop
if get_boolean then
--* inuse (16*i + j) := True;
seq_to_unseq (inuse_count) := 16 * i + j;
inuse_count := inuse_count + 1;
end if;
end loop;
end if;
end loop;
end receive_mapping_table;
-- Receives the selectors.
procedure receive_selectors is
j : Unsigned_8;
begin
group_count := Natural (get_bits (3));
selector_count := Natural (Shift_Left (get_bits_32 (8), 7) or get_bits_32 (7));
for i in 0 .. selector_count - 1 loop
j := 0;
while get_boolean loop
j := j + 1;
if j > 5 then
raise data_error;
end if;
end loop;
selector_mtf (i) := j;
end loop;
end receive_selectors;
-- Undo the MTF values for the selectors.
procedure undo_mtf_values is
pos : array (0 .. max_groups) of Natural;
v, tmp : Natural;