📄 jdmerge.pas
字号:
upsample := my_upsample_ptr (cinfo^.upsample);
{ Just do the upsampling. }
upsample^.upmethod (cinfo, input_buf, in_row_group_ctr,
JSAMPARRAY(@ output_buf^[out_row_ctr]));
{ Adjust counts }
Inc(out_row_ctr);
Inc(in_row_group_ctr);
end;
{ These are the routines invoked by the control routines to do
the actual upsampling/conversion. One row group is processed per call.
Note: since we may be writing directly into application-supplied buffers,
we have to be honest about the output width; we can't assume the buffer
has been rounded up to an even width. }
{ Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical. }
{METHODDEF}
procedure h2v1_merged_upsample (cinfo : j_decompress_ptr;
input_buf : JSAMPIMAGE;
in_row_group_ctr : JDIMENSION;
output_buf : JSAMPARRAY); far;
var
upsample : my_upsample_ptr;
{register} y, cred, cgreen, cblue : int;
cb, cr : int;
{register} outptr : JSAMPROW;
inptr0, inptr1, inptr2 : JSAMPLE_PTR;
col : JDIMENSION;
{ copy these pointers into registers if possible }
{register} range_limit : range_limit_table_ptr;
Crrtab : int_CConvertPtr;
Cbbtab : int_CConvertPtr;
Crgtab : INT32_CConvertPtr;
Cbgtab : INT32_CConvertPtr;
var
shift_temp : INT32;
begin
upsample := my_upsample_ptr (cinfo^.upsample);
range_limit := cinfo^.sample_range_limit;
Crrtab := upsample^.Cr_r_tab;
Cbbtab := upsample^.Cb_b_tab;
Crgtab := upsample^.Cr_g_tab;
Cbgtab := upsample^.Cb_g_tab;
inptr0 := JSAMPLE_PTR(input_buf^[0]^[in_row_group_ctr]);
inptr1 := JSAMPLE_PTR(input_buf^[1]^[in_row_group_ctr]);
inptr2 := JSAMPLE_PTR(input_buf^[2]^[in_row_group_ctr]);
outptr := output_buf^[0];
{ Loop for each pair of output pixels }
for col := pred(cinfo^.output_width shr 1) downto 0 do
begin
{ Do the chroma part of the calculation }
cb := GETJSAMPLE(inptr1^);
Inc(inptr1);
cr := GETJSAMPLE(inptr2^);
Inc(inptr2);
cred := Crrtab^[cr];
{cgreen := int( RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS) );}
shift_temp := Cbgtab^[cb] + Crgtab^[cr];
if shift_temp < 0 then { SHIFT arithmetic RIGHT }
cgreen := int((shift_temp shr SCALEBITS)
or ( (not INT32(0)) shl (32-SCALEBITS)))
else
cgreen := int(shift_temp shr SCALEBITS);
cblue := Cbbtab^[cb];
{ Fetch 2 Y values and emit 2 pixels }
y := GETJSAMPLE(inptr0^);
Inc(inptr0);
outptr^[RGB_RED] := range_limit^[y + cred];
outptr^[RGB_GREEN] := range_limit^[y + cgreen];
outptr^[RGB_BLUE] := range_limit^[y + cblue];
Inc(JSAMPLE_PTR(outptr), RGB_PIXELSIZE);
y := GETJSAMPLE(inptr0^);
Inc(inptr0);
outptr^[RGB_RED] := range_limit^[y + cred];
outptr^[RGB_GREEN] := range_limit^[y + cgreen];
outptr^[RGB_BLUE] := range_limit^[y + cblue];
Inc(JSAMPLE_PTR(outptr), RGB_PIXELSIZE);
end;
{ If image width is odd, do the last output column separately }
if Odd(cinfo^.output_width) then
begin
cb := GETJSAMPLE(inptr1^);
cr := GETJSAMPLE(inptr2^);
cred := Crrtab^[cr];
{cgreen := int ( RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS) );}
shift_temp := Cbgtab^[cb] + Crgtab^[cr];
if shift_temp < 0 then { SHIFT arithmetic RIGHT }
cgreen := int((shift_temp shr SCALEBITS)
or ( (not INT32(0)) shl (32-SCALEBITS)))
else
cgreen := int(shift_temp shr SCALEBITS);
cblue := Cbbtab^[cb];
y := GETJSAMPLE(inptr0^);
outptr^[RGB_RED] := range_limit^[y + cred];
outptr^[RGB_GREEN] := range_limit^[y + cgreen];
outptr^[RGB_BLUE] := range_limit^[y + cblue];
end;
end;
{ Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical. }
{METHODDEF}
procedure h2v2_merged_upsample (cinfo : j_decompress_ptr;
input_buf : JSAMPIMAGE;
in_row_group_ctr : JDIMENSION;
output_buf : JSAMPARRAY); far;
var
upsample : my_upsample_ptr;
{register} y, cred, cgreen, cblue : int;
cb, cr : int;
{register} outptr0, outptr1 : JSAMPROW;
inptr00, inptr01, inptr1, inptr2 : JSAMPLE_PTR;
col : JDIMENSION;
{ copy these pointers into registers if possible }
{register} range_limit : range_limit_table_ptr;
Crrtab : int_CConvertPtr;
Cbbtab : int_CConvertPtr;
Crgtab : INT32_CConvertPtr;
Cbgtab : INT32_CConvertPtr;
var
shift_temp : INT32;
begin
upsample := my_upsample_ptr (cinfo^.upsample);
range_limit := cinfo^.sample_range_limit;
Crrtab := upsample^.Cr_r_tab;
Cbbtab := upsample^.Cb_b_tab;
Crgtab := upsample^.Cr_g_tab;
Cbgtab := upsample^.Cb_g_tab;
inptr00 := JSAMPLE_PTR(input_buf^[0]^[in_row_group_ctr*2]);
inptr01 := JSAMPLE_PTR(input_buf^[0]^[in_row_group_ctr*2 + 1]);
inptr1 := JSAMPLE_PTR(input_buf^[1]^[in_row_group_ctr]);
inptr2 := JSAMPLE_PTR(input_buf^[2]^[in_row_group_ctr]);
outptr0 := output_buf^[0];
outptr1 := output_buf^[1];
{ Loop for each group of output pixels }
for col := pred(cinfo^.output_width shr 1) downto 0 do
begin
{ Do the chroma part of the calculation }
cb := GETJSAMPLE(inptr1^);
Inc(inptr1);
cr := GETJSAMPLE(inptr2^);
Inc(inptr2);
cred := Crrtab^[cr];
{cgreen := int( RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS) );}
shift_temp := Cbgtab^[cb] + Crgtab^[cr];
if shift_temp < 0 then { SHIFT arithmetic RIGHT }
cgreen := int((shift_temp shr SCALEBITS)
or ( (not INT32(0)) shl (32-SCALEBITS)))
else
cgreen := int(shift_temp shr SCALEBITS);
cblue := Cbbtab^[cb];
{ Fetch 4 Y values and emit 4 pixels }
y := GETJSAMPLE(inptr00^);
Inc(inptr00);
outptr0^[RGB_RED] := range_limit^[y + cred];
outptr0^[RGB_GREEN] := range_limit^[y + cgreen];
outptr0^[RGB_BLUE] := range_limit^[y + cblue];
Inc(JSAMPLE_PTR(outptr0), RGB_PIXELSIZE);
y := GETJSAMPLE(inptr00^);
Inc(inptr00);
outptr0^[RGB_RED] := range_limit^[y + cred];
outptr0^[RGB_GREEN] := range_limit^[y + cgreen];
outptr0^[RGB_BLUE] := range_limit^[y + cblue];
Inc(JSAMPLE_PTR(outptr0), RGB_PIXELSIZE);
y := GETJSAMPLE(inptr01^);
Inc(inptr01);
outptr1^[RGB_RED] := range_limit^[y + cred];
outptr1^[RGB_GREEN] := range_limit^[y + cgreen];
outptr1^[RGB_BLUE] := range_limit^[y + cblue];
Inc(JSAMPLE_PTR(outptr1), RGB_PIXELSIZE);
y := GETJSAMPLE(inptr01^);
Inc(inptr01);
outptr1^[RGB_RED] := range_limit^[y + cred];
outptr1^[RGB_GREEN] := range_limit^[y + cgreen];
outptr1^[RGB_BLUE] := range_limit^[y + cblue];
Inc(JSAMPLE_PTR(outptr1), RGB_PIXELSIZE);
end;
{ If image width is odd, do the last output column separately }
if Odd(cinfo^.output_width) then
begin
cb := GETJSAMPLE(inptr1^);
cr := GETJSAMPLE(inptr2^);
cred := Crrtab^[cr];
{cgreen := int (RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS));}
shift_temp := Cbgtab^[cb] + Crgtab^[cr];
if shift_temp < 0 then { SHIFT arithmetic RIGHT }
cgreen := int((shift_temp shr SCALEBITS)
or ( (not INT32(0)) shl (32-SCALEBITS)))
else
cgreen := int(shift_temp shr SCALEBITS);
cblue := Cbbtab^[cb];
y := GETJSAMPLE(inptr00^);
outptr0^[RGB_RED] := range_limit^[y + cred];
outptr0^[RGB_GREEN] := range_limit^[y + cgreen];
outptr0^[RGB_BLUE] := range_limit^[y + cblue];
y := GETJSAMPLE(inptr01^);
outptr1^[RGB_RED] := range_limit^[y + cred];
outptr1^[RGB_GREEN] := range_limit^[y + cgreen];
outptr1^[RGB_BLUE] := range_limit^[y + cblue];
end;
end;
{ Module initialization routine for merged upsampling/color conversion.
NB: this is called under the conditions determined by use_merged_upsample()
in jdmaster.c. That routine MUST correspond to the actual capabilities
of this module; no safety checks are made here. }
{GLOBAL}
procedure jinit_merged_upsampler (cinfo : j_decompress_ptr);
var
upsample : my_upsample_ptr;
begin
upsample := my_upsample_ptr (
cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
SIZEOF(my_upsampler)) );
cinfo^.upsample := jpeg_upsampler_ptr (upsample);
upsample^.pub.start_pass := start_pass_merged_upsample;
upsample^.pub.need_context_rows := FALSE;
upsample^.out_row_width := cinfo^.output_width * cinfo^.out_color_components;
if (cinfo^.max_v_samp_factor = 2) then
begin
upsample^.pub.upsample := merged_2v_upsample;
upsample^.upmethod := h2v2_merged_upsample;
{ Allocate a spare row buffer }
upsample^.spare_row := JSAMPROW(
cinfo^.mem^.alloc_large ( j_common_ptr(cinfo), JPOOL_IMAGE,
size_t (upsample^.out_row_width * SIZEOF(JSAMPLE))) );
end
else
begin
upsample^.pub.upsample := merged_1v_upsample;
upsample^.upmethod := h2v1_merged_upsample;
{ No spare row needed }
upsample^.spare_row := NIL;
end;
build_ycc_rgb_table(cinfo);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -