📄 jdmarker.pas
字号:
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sof := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
c := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
compptr^.h_samp_factor := (c shr 4) and 15;
compptr^.v_samp_factor := (c ) and 15;
{ Read a byte into variable compptr^.quant_tbl_no.
If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sof := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
compptr^.quant_tbl_no := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
TRACEMS4(j_common_ptr(cinfo), 1, JTRC_SOF_COMPONENT,
compptr^.component_id, compptr^.h_samp_factor,
compptr^.v_samp_factor, compptr^.quant_tbl_no);
Inc(compptr);
end;
cinfo^.marker^.saw_SOF := TRUE;
{ Unload the local copies --- do this only at a restart boundary }
datasrc^.next_input_byte := next_input_byte;
datasrc^.bytes_in_buffer := bytes_in_buffer;
get_sof := TRUE;
end; { get_sof }
{LOCAL}
function get_sos (cinfo : j_decompress_ptr) : boolean;
{ Process a SOS marker }
label
id_found;
var
length : INT32;
i, ci, n, c, cc : int;
compptr : jpeg_component_info_ptr;
{ Declare and initialize local copies of input pointer/count }
var
datasrc : jpeg_source_mgr_ptr;
next_input_byte : JOCTETptr; { Array[] of JOCTET; }
bytes_in_buffer : size_t;
begin
datasrc := cinfo^.src;
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
{}
if not cinfo^.marker^.saw_SOF then
ERREXIT(j_common_ptr(cinfo), JERR_SOS_NO_SOF);
{ Read two bytes interpreted as an unsigned 16-bit integer.
length should be declared unsigned int or perhaps INT32. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
length := (uint( GETJOCTET(next_input_byte^)) shl 8);
Inc( next_input_byte );
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
Inc( length, GETJOCTET( next_input_byte^));
Inc( next_input_byte );
{ Read a byte into variable n (Number of components).
If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
n := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
if ((length <> (n * 2 + 6)) or (n < 1) or (n > MAX_COMPS_IN_SCAN)) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
TRACEMS1(j_common_ptr(cinfo), 1, JTRC_SOS, n);
cinfo^.comps_in_scan := n;
{ Collect the component-spec parameters }
for i := 0 to Pred(n) do
begin
{ Read a byte into variable cc. If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
cc := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
{ Read a byte into variable c. If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
c := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
compptr := cinfo^.comp_info;
for ci := 0 to Pred(cinfo^.num_components) do
begin
if (cc = compptr^.component_id) then
goto id_found;
Inc(compptr);
end;
ERREXIT1(j_common_ptr(cinfo), JERR_BAD_COMPONENT_ID, cc);
id_found:
cinfo^.cur_comp_info[i] := compptr;
compptr^.dc_tbl_no := (c shr 4) and 15;
compptr^.ac_tbl_no := (c ) and 15;
TRACEMS3(j_common_ptr(cinfo), 1, JTRC_SOS_COMPONENT, cc,
compptr^.dc_tbl_no, compptr^.ac_tbl_no);
end;
{ Collect the additional scan parameters Ss, Se, Ah/Al. }
{ Read a byte into variable c. If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
c := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
cinfo^.Ss := c;
{ Read a byte into variable c. If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
c := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
cinfo^.Se := c;
{ Read a byte into variable c. If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_sos := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
c := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
cinfo^.Ah := (c shr 4) and 15;
cinfo^.Al := (c ) and 15;
TRACEMS4(j_common_ptr(cinfo), 1, JTRC_SOS_PARAMS, cinfo^.Ss, cinfo^.Se,
cinfo^.Ah, cinfo^.Al);
{ Prepare to scan data & restart markers }
cinfo^.marker^.next_restart_num := 0;
{ Count another SOS marker }
Inc( cinfo^.input_scan_number );
{ Unload the local copies --- do this only at a restart boundary }
datasrc^.next_input_byte := next_input_byte;
datasrc^.bytes_in_buffer := bytes_in_buffer;
get_sos := TRUE;
end; { get_sos }
{METHODDEF}
function get_app0 (cinfo : j_decompress_ptr) : boolean; far;
{ Process an APP0 marker }
const
JFIF_LEN = 14;
var
length : INT32;
b : Array[0..JFIF_LEN-1] of UINT8;
buffp : int;
var
datasrc : jpeg_source_mgr_ptr;
next_input_byte : JOCTETptr;
bytes_in_buffer : size_t;
begin
datasrc := cinfo^.src;
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
{ Read two bytes interpreted as an unsigned 16-bit integer.
length should be declared unsigned int or perhaps INT32. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_app0 := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
length := (uint( GETJOCTET(next_input_byte^)) shl 8);
Inc( next_input_byte );
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_app0 := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
Inc( length, GETJOCTET( next_input_byte^));
Inc( next_input_byte );
length := length - 2;
{ See if a JFIF APP0 marker is present }
if (length >= JFIF_LEN) then
begin
for buffp := 0 to Pred(JFIF_LEN) do
begin
{ Read a byte into variable b[buffp].
If must suspend, return FALSE. }
{ make a byte available.
Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
but we must reload the local copies after a successful fill. }
if (bytes_in_buffer = 0) then
begin
if (not datasrc^.fill_input_buffer(cinfo)) then
begin
get_app0 := FALSE;
exit;
end;
{ Reload the local copies }
next_input_byte := datasrc^.next_input_byte;
bytes_in_buffer := datasrc^.bytes_in_buffer;
end;
Dec( bytes_in_buffer );
b[buffp] := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
end;
length := length - JFIF_LEN;
if (b[0]=$4A) and (b[1]=$46) and (b[2]=$49)
and (b[3]=$46) and (b[4]=0) then
begin
{ Found JFIF APP0 marker: check version }
{ Major version must be 1, anything else signals an incompatible change.
We used to treat this as an error, but now it's a nonfatal warning,
because some bozo at Hijaak couldn't read the spec.
Minor version should be 0..2, but process anyway if newer. }
if (b[5] <> 1) then
WARNMS2(j_common_ptr(cinfo) , JWRN_JFIF_MAJOR, b[5], b[6])
else
if (b[6] > 2) then
TRACEMS2(j_common_ptr(cinfo), 1, JTRC_JFIF_MINOR, b[5], b[6]);
{ Save info }
cinfo^.saw_JFIF_marker := TRUE;
cinfo^.density_unit := b[7];
cinfo^.X_density := (b[8] shl 8) + b[9];
cinfo^.Y_density := (b[10] shl 8) + b[11];
TRACEMS3(j_common_ptr(cinfo), 1, JTRC_JFIF,
cinfo^.X_density, cinfo^.Y_density, cinfo^.density_unit);
if (b[12] or b[13]) <> 0 then
TRACEMS2(j_common_ptr(cinfo), 1, JTRC_JFIF_THUMBNAIL, b[12], b[13]);
if (length <> (INT32(b[12]) * INT32(b[13]) * INT32(3))) then
TRACEMS1(j_common_ptr(cinfo), 1, JTRC_JFIF_BADTHUMBNAILSIZE,
int(length));
end
else
begin
{ Start of APP0 does not match "JFIF" }
TRACEMS1(j_common_ptr(cinfo), 1, JTRC_APP0, int(length) + JFIF_LEN);
end;
end
else
begin
{ Too short to be JFIF marker }
TRACEMS1(j_common_ptr(cinfo), 1, JTRC_APP0, int(length));
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -