text
stringlengths
0
234
end if;
-- Huffman table selection
Get_Byte(image.buffer, b);
info_B(compo).ht_idx_AC:= Natural(b mod 16);
info_B(compo).ht_idx_DC:= Natural(b / 16);
end loop;
-- Parameters for progressive display format (SOF_2)
Get_Byte(image.buffer, start_spectral_selection);
Get_Byte(image.buffer, end_spectral_selection);
Get_Byte(image.buffer, successive_approximation);
--
-- End of SOS segment, image data follow.
--
mbsizex:= ssxmax * 8; -- pixels in a row of a macro-block
mbsizey:= ssymax * 8; -- pixels in a column of a macro-block
mbwidth := (image.width + mbsizex - 1) / mbsizex;
-- width in macro-blocks
mbheight:= (image.height + mbsizey - 1) / mbsizey;
-- height in macro-blocks
if some_trace then
Put_Line(" mbsizex = " & Integer'Image(mbsizex));
Put_Line(" mbsizey = " & Integer'Image(mbsizey));
Put_Line(" mbwidth = " & Integer'Image(mbwidth));
Put_Line(" mbheight = " & Integer'Image(mbheight));
end if;
for c in Component loop
if image.JPEG_stuff.components(c) then
info_B(c).width := (image.width * info_A(c).samples_hor + ssxmax - 1) / ssxmax;
info_B(c).height:= (image.height * info_A(c).samples_ver + ssymax - 1) / ssymax;
info_B(c).stride:= (mbwidth * mbsizex * info_A(c).samples_hor) / ssxmax;
if some_trace then
Put_Line(" Details for component " & Component'Image(c));
Put_Line(" samples in x " & Integer'Image(info_A(c).samples_hor));
Put_Line(" samples in y " & Integer'Image(info_A(c).samples_ver));
Put_Line(" width " & Integer'Image(info_B(c).width));
Put_Line(" height " & Integer'Image(info_B(c).height));
Put_Line(" stride " & Integer'Image(info_B(c).stride));
Put_Line(
" AC/DC table index " &
Integer'Image(info_B(compo).ht_idx_AC) & ", " &
Integer'Image(info_B(compo).ht_idx_DC)
);
end if;
if (info_B(c).width < 3 and info_A(c).samples_hor /= ssxmax) or
(info_B(c).height < 3 and info_A(c).samples_ver /= ssymax)
then
Raise_Exception(
error_in_image_data'Identity,
"JPEG: component " & Component'Image(c) &
": sample dimension mismatch"
);
end if;
end if;
end loop;
--
if image.interlaced then
Raise_Exception(
unsupported_image_subformat'Identity,
"JPEG: progressive format not yet functional"
);
end if;
declare
mb: Macro_block(Component, 1..ssxmax, 1..ssymax);
x0, y0: Integer:= 0;
begin
macro_blocks_loop:
loop
components_loop:
for c in Component loop
if image.JPEG_stuff.components(c) then
samples_y_loop:
for sby in 1..info_A(c).samples_ver loop
samples_x_loop:
for sbx in 1..info_A(c).samples_hor loop
Decode_Block(c, mb(c, sbx, sby));
end loop samples_x_loop;
end loop samples_y_loop;
end if;
end loop components_loop;
-- All components of the current macro-block are decoded.
-- Step 4, 5, 6 happen here: Upsampling, color transformation, output
Upsampling_and_output(mb, x0, y0);
--
mbx:= mbx + 1;
x0:= x0 + ssxmax * 8;
if mbx >= mbwidth then
mbx:= 0;
x0:= 0;
mby:= mby + 1;
y0:= y0 + ssymax * 8;
Feedback((100*mby)/mbheight);
exit macro_blocks_loop when mby >= mbheight;
end if;
if image.JPEG_stuff.restart_interval > 0 then
rstcount:= rstcount - 1;
if rstcount = 0 then
-- Here begins the restart.
bufbits:= Natural(U32(bufbits) and 16#F8#); -- byte alignment
-- Now the restart marker. We expect a
w:= U16(Get_bits(16));