text
stringlengths
0
234
-- Build huffman table from code lengths given by array b
procedure HufT_build (b : Length_array;
s : Integer;
d, e : Length_array;
tl : out p_Table_list;
m : in out Integer;
huft_incomplete : out Boolean)
is
use Interfaces;
b_max : constant := 16;
b_maxp1 : constant := b_max + 1;
-- bit length count table
count : array (0 .. b_maxp1) of Integer := (others => 0);
f : Integer; -- i repeats in table every f entries
g : Integer; -- max. code length
i, -- counter, current code
j : Integer; -- counter
kcc : Integer; -- number of bits in current code
c_idx, v_idx : Natural; -- array indices
current_table_ptr : p_HufT_table := null;
current_node_ptr : p_Table_list := null; -- curr. node for the curr. table
new_node_ptr : p_Table_list; -- new node for the new table
new_entry : HufT; -- table entry for structure assignment
u : array (0 .. b_max) of p_HufT_table; -- table stack
n_max : constant := 288;
-- values in order of bit length
v : array (0 .. n_max) of Integer := (others => 0);
el_v, el_v_m_s : Integer;
w : Natural := 0; -- bits before this table
offset, code_stack : array (0 .. b_maxp1) of Integer;
table_level : Integer := -1;
bits : array (Integer'(-1) .. b_maxp1) of Integer;
-- ^bits (table_level) = # bits in table of level table_level
y : Integer; -- number of dummy codes added
z : Natural := 0; -- number of entries in current table
el : Integer; -- length of eob code=code 256
no_copy_length_array : constant Boolean := d'Length = 0 or else e'Length = 0;
begin
if full_trace then
pragma Warnings (Off, "this code can never be executed and has been deleted");
Ada.Text_IO.Put ("[HufT_Build .. .");
pragma Warnings (On, "this code can never be executed and has been deleted");
end if;
tl := null;
if b'Length > 256 then -- set length of EOB code, if any
el := b (256);
else
el := b_max;
end if;
-- Generate counts for each bit length
for k in b'Range loop
if b (k) > b_max then
-- m := 0; -- GNAT 2005 doesn't like it (warning).
raise huft_error;
end if;
count (b (k)) := count (b (k)) + 1;
end loop;
if count (0) = b'Length then
m := 0;
huft_incomplete := False; -- spotted by Tucker Taft, 19 - Aug - 2004
return; -- complete
end if;
-- Find minimum and maximum length, bound m by those
j := 1;
while j <= b_max and then count (j) = 0 loop
j := j + 1;
end loop;
kcc := j;
if m < j then
m := j;
end if;
i := b_max;
while i > 0 and then count (i) = 0 loop
i := i - 1;
end loop;
g := i;
if m > i then
m := i;
end if;