text stringlengths 0 234 |
|---|
-- here i is the huffman code of length k bits for value v(v_idx) |
while k > w + bits(table_level) loop |
w:= w + bits(table_level); -- Length of tables to this position |
table_level:= table_level+ 1; |
z:= g - w; -- Compute min size table <= m bits |
if z > m then |
z := m; |
end if; |
j := k - w; |
f := Integer(Shift_Left(Unsigned_32'(1), j)); -- f:= 2 ** j; |
if f > am1 + 2 then -- Try a k-w bit table |
f:= f - (am1 + 2); |
c_idx:= k; |
loop -- Try smaller tables up to z bits |
j:= j + 1; |
exit when j >= z; |
f := f * 2; |
c_idx:= c_idx + 1; |
exit when f - count(c_idx) <= 0; |
f:= f - count(c_idx); |
end loop; |
end if; |
if w + j > el and then w < el then |
j:= el - w; -- Make EOB code end at table |
end if; |
if w = 0 then |
j := m; -- Fix: main table always m bits! |
end if; |
z:= Integer(Shift_Left(Unsigned_32'(1), j)); -- z:= 2 ** j; |
bits(table_level) := j; |
-- Allocate and link new table |
begin |
current_table_ptr := new HufT_table ( 0..z ); |
new_node_ptr := new Table_list'( current_table_ptr, null ); |
exception |
when Storage_Error => |
raise huft_out_of_memory; |
Function Definition: procedure Big_endian is new Big_endian_number( U32 ); |
Function Body: use Ada.Exceptions; |
---------- |
-- Read -- |
---------- |
procedure Read (image: in out Image_descriptor; ch: out Chunk_head) is |
str4: String(1..4); |
b: U8; |
begin |
Big_endian(image.buffer, ch.length); |
for i in str4'Range loop |
Buffering.Get_Byte(image.buffer, b); |
str4(i):= Character'Val(b); |
end loop; |
begin |
ch.kind:= PNG_Chunk_tag'Value(str4); |
if some_trace then |
Ada.Text_IO.Put_Line( |
"Chunk [" & str4 & |
"], length:" & U32'Image(ch.length) |
); |
end if; |
exception |
when Constraint_Error => |
Raise_Exception( |
error_in_image_data'Identity, |
"PNG chunk unknown: " & |
Integer'Image(Character'Pos(str4(1))) & |
Integer'Image(Character'Pos(str4(2))) & |
Integer'Image(Character'Pos(str4(3))) & |
Integer'Image(Character'Pos(str4(4))) & |
" (" & str4 & ')' |
); |
Function Definition: procedure Prepare_table is |
Function Body: -- CRC-32 algorithm, ISO-3309 |
Seed: constant:= 16#EDB88320#; |
l: Unsigned_32; |
begin |
for i in CRC32_Table'Range loop |
l:= i; |
for bit in 0..7 loop |
if (l and 1) = 0 then |
l:= Shift_Right(l,1); |
else |
l:= Shift_Right(l,1) xor Seed; |
end if; |
end loop; |
CRC32_Table(i):= l; |
end loop; |
end Prepare_table; |
procedure Update( CRC: in out Unsigned_32; InBuf: Byte_array ) is |
local_CRC: Unsigned_32; |
begin |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.