📄 jdmarker.pas
字号:
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_dac := 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_dac := 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 );
Dec(length, 2);
while (length > 0) do
begin
{ Read a byte into variable index. 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_dac := 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 );
index := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
{ Read a byte into variable val. 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_dac := 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 );
val := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
Dec( length, 2);
{$IFDEF DEBUG}
TRACEMS2(j_common_ptr(cinfo), 1, JTRC_DAC, index, val);
{$ENDIF}
if (index < 0) or (index >= (2*NUM_ARITH_TBLS)) then
ERREXIT1(j_common_ptr(cinfo) , JERR_DAC_INDEX, index);
if (index >= NUM_ARITH_TBLS) then
begin { define AC table }
cinfo^.arith_ac_K[index-NUM_ARITH_TBLS] := UINT8(val);
end
else
begin { define DC table }
cinfo^.arith_dc_L[index] := UINT8(val and $0F);
cinfo^.arith_dc_U[index] := UINT8(val shr 4);
if (cinfo^.arith_dc_L[index] > cinfo^.arith_dc_U[index]) then
ERREXIT1(j_common_ptr(cinfo) , JERR_DAC_VALUE, val);
end;
end;
if (length <> 0) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
{ 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_dac := TRUE;
end; { get_dac }
{$ELSE}
{LOCAL}
function get_dac (cinfo : j_decompress_ptr) : boolean;
begin
get_dac := skip_variable(cinfo);
end;
{$ENDIF}
{LOCAL}
function get_dht (cinfo : j_decompress_ptr) : boolean;
{ Process a DHT marker }
var
length : INT32;
bits : Array[0..17-1] of UINT8;
huffval : Array[0..256-1] of UINT8;
i, index, count : int;
htblptr : ^JHUFF_TBL_PTR;
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_dht := 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_dht := 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 );
Dec(length, 2);
while (length > 16) do
begin
{ Read a byte into variable index. 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_dht := 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 );
index := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
{$IFDEF DEBUG}
TRACEMS1(j_common_ptr(cinfo), 1, JTRC_DHT, index);
{$ENDIF}
bits[0] := 0;
count := 0;
for i := 1 to 16 do
begin
{ Read a byte into variable bits[i]. 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_dht := 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 );
bits[i] := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
Inc( count, bits[i] );
end;
Dec( length, (1 + 16) );
{$IFDEF DEBUG}
TRACEMS8(j_common_ptr(cinfo), 2, JTRC_HUFFBITS,
bits[1], bits[2], bits[3], bits[4],
bits[5], bits[6], bits[7], bits[8]);
TRACEMS8(j_common_ptr(cinfo), 2, JTRC_HUFFBITS,
bits[9], bits[10], bits[11], bits[12],
bits[13], bits[14], bits[15], bits[16]);
{$ENDIF}
{ Here we just do minimal validation of the counts to avoid walking
off the end of our table space. jdhuff.c will check more carefully. }
if (count > 256) or (INT32(count) > length) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_HUFF_TABLE);
for i := 0 to Pred(count) do
begin
{ Read a byte into variable huffval[i]. 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_dht := 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 );
huffval[i] := GETJOCTET(next_input_byte^);
Inc(next_input_byte);
end;
Dec( length, count );
if (index and $10)<>0 then
begin { AC table definition }
Dec( index, $10 );
htblptr := @cinfo^.ac_huff_tbl_ptrs[index];
end
else
begin { DC table definition }
htblptr := @cinfo^.dc_huff_tbl_ptrs[index];
end;
if (index < 0) or (index >= NUM_HUFF_TBLS) then
ERREXIT1(j_common_ptr(cinfo), JERR_DHT_INDEX, index);
if (htblptr^ = NIL) then
htblptr^ := jpeg_alloc_huff_table(j_common_ptr(cinfo));
MEMCOPY(@(htblptr^)^.bits, @bits, SIZEOF((htblptr^)^.bits));
MEMCOPY(@(htblptr^)^.huffval, @huffval, SIZEOF((htblptr^)^.huffval));
end;
if (length <> 0) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
{ 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_dht := TRUE;
end; { get_dht }
{LOCAL}
function get_dqt (cinfo : j_decompress_ptr) : boolean;
{ Process a DQT marker }
var
length : INT32;
n, i, prec : int;
tmp : uint;
quant_ptr : JQUANT_TBL_PTR;
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_dqt := 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_dqt := 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 );
Dec( length, 2 );
while (length > 0) do
begin
{ Read a byte into variable n. 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_dqt := 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);
prec := n shr 4;
n := n and $0F;
{$IFDEF DEBUG}
TRACEMS2(j_common_ptr(cinfo), 1, JTRC_DQT, n, prec);
{$ENDIF}
if (n >= NUM_QUANT_TBLS) then
ERREXIT1(j_common_ptr(cinfo) , JERR_DQT_INDEX, n);
if (cinfo^.quant_tbl_ptrs[n] = NIL) then
cinfo^.quant_tbl_ptrs[n] := jpeg_alloc_quant_table(j_common_ptr(cinfo));
quant_ptr := cinfo^.quant_tbl_ptrs[n];
for i := 0 to Pred(DCTSIZE2) do
begin
if (prec <> 0) then
begin
{ Read two bytes interpreted as an unsigned 16-bit integer.
tmp 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_dqt := FALSE;
exit;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -