text
stringlengths
0
234
-- We consider length of contents, without the FFxx marker.
if some_trace then
Put_Line(
"Segment [" & JPEG_marker'Image(sh.kind) &
"], length:" & U16'Image(sh.length));
end if;
return;
end if;
end loop;
Raise_Exception(
error_in_image_data'Identity,
"JPEG: unknown marker here: FF, " & U8'Image(b)
);
end Read;
shift_arg: constant array(0..15) of Integer:=
(1 => 0, 2 => 1, 4 => 2, 8 => 3, others => -1);
-- SOF - Start Of Frame (the real header)
procedure Read_SOF(image: in out Image_descriptor; sh: Segment_head) is
use Bounded_255;
b, bits_pp_primary, id_base: U8;
w, h: U16;
compo: JPEG_defs.Component;
begin
case sh.kind is
when SOF_0 =>
image.detailed_format:= To_Bounded_String("JPEG, Baseline DCT (SOF_0)");
when SOF_2 =>
image.detailed_format:= To_Bounded_String("JPEG, Progressive DCT (SOF_2)");
image.interlaced:= True;
when others =>
Raise_Exception(
unsupported_image_subformat'Identity,
"JPEG: image type not yet supported: " & JPEG_marker'Image(sh.kind)
);
end case;
Get_Byte(image.buffer, bits_pp_primary);
if bits_pp_primary /= 8 then
Raise_Exception(
unsupported_image_subformat'Identity,
"Bits per primary color=" & U8'Image(bits_pp_primary)
);
end if;
image.bits_per_pixel:= 3 * Positive(bits_pp_primary);
Big_endian(image.buffer, h);
Big_endian(image.buffer, w);
image.width:= Natural(w);
image.height:= Natural(h);
-- Number of components:
Get_Byte(image.buffer, b);
image.subformat_id:= Integer(b);
--
image.JPEG_stuff.max_samples_hor:= 0;
image.JPEG_stuff.max_samples_ver:= 0;
id_base := 1;
-- For each component: 3 bytes information: ID, sampling factors, quantization table number
for i in 1..image.subformat_id loop
-- Component ID (1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q)
Get_Byte(image.buffer, b);
if b = 0 then
-- Workaround for a bug in some encoders, for instance Intel(R) JPEG Library,
-- version [2.0.18.50] as in some Photoshop versions : IDs are numbered 0, 1, 2.
id_base := 0;
end if;
if b - id_base > Component'Pos(Component'Last) then
Raise_Exception(error_in_image_data'Identity, "SOF: invalid component ID: " & U8'Image(b));
end if;
compo:= JPEG_defs.Component'Val(b - id_base);
image.JPEG_stuff.components(compo):= True;
declare
stuff: JPEG_stuff_type renames image.JPEG_stuff;
info: JPEG_defs.Info_per_component_A renames stuff.info(compo);
begin
-- Sampling factors (bit 0-3 vert., 4-7 hor.)
Get_Byte(image.buffer, b);
info.samples_ver:= Natural(b mod 16);
info.samples_hor:= Natural(b / 16);
stuff.max_samples_hor:=
Integer'Max(stuff.max_samples_hor, info.samples_hor);
stuff.max_samples_ver:=
Integer'Max(stuff.max_samples_ver, info.samples_ver);
-- Quantization table number
Get_Byte(image.buffer, b);
info.qt_assoc:= Natural(b);
Function Definition: procedure Color_transformation_and_output;
Function Body: --
procedure Color_transformation_and_output is
y_val, cb_val, cr_val, c_val, m_val, w_val: Integer;
y_val_8: U8;
begin
for ymb in flat'Range(3) loop
exit when y0+ymb >= image.height;
Set_X_Y(x0, image.height-1-(y0+ymb));
for xmb in flat'Range(2) loop
exit when x0+xmb >= image.width;
case color_space is
when YCbCr =>
y_val := flat(Y, xmb, ymb) * 256;