📄 jdcolor.pas
字号:
Inc(input_row);
Inc(JSAMPROW_PTR(output_buf));
end;
end;
{ Color conversion for grayscale: just copy the data.
This also works for YCbCr -> grayscale conversion, in which
we just copy the Y (luminance) component and ignore chrominance. }
{METHODDEF}
procedure grayscale_convert (cinfo : j_decompress_ptr;
input_buf : JSAMPIMAGE;
input_row : JDIMENSION;
output_buf : JSAMPARRAY;
num_rows : int); far;
begin
jcopy_sample_rows(input_buf^[0], int(input_row), output_buf, 0,
num_rows, cinfo^.output_width);
end;
{ Convert grayscale to RGB: just duplicate the graylevel three times.
This is provided to support applications that don't want to cope
with grayscale as a separate case. }
{METHODDEF}
procedure gray_rgb_convert (cinfo : j_decompress_ptr;
input_buf : JSAMPIMAGE;
input_row : JDIMENSION;
output_buf : JSAMPARRAY;
num_rows : int); far;
var
{register} inptr, outptr : JSAMPLE_PTR;
{register} col : JDIMENSION;
num_cols : JDIMENSION;
begin
num_cols := cinfo^.output_width;
while (num_rows > 0) do
begin
inptr := JSAMPLE_PTR(input_buf^[0]^[input_row]);
Inc(input_row);
outptr := JSAMPLE_PTR(@output_buf^[0]);
Inc(JSAMPROW_PTR(output_buf));
for col := 0 to pred(num_cols) do
begin
{ We can dispense with GETJSAMPLE() here }
JSAMPROW(outptr)^[RGB_RED] := inptr^;
JSAMPROW(outptr)^[RGB_GREEN] := inptr^;
JSAMPROW(outptr)^[RGB_BLUE] := inptr^;
Inc(inptr);
Inc(outptr, RGB_PIXELSIZE);
end;
Dec(num_rows);
end;
end;
{ Adobe-style YCCK -> CMYK conversion.
We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
conversion as above, while passing K (black) unchanged.
We assume build_ycc_rgb_table has been called. }
{METHODDEF}
procedure ycck_cmyk_convert (cinfo : j_decompress_ptr;
input_buf : JSAMPIMAGE;
input_row : JDIMENSION;
output_buf : JSAMPARRAY;
num_rows : int); far;
var
cconvert : my_cconvert_ptr;
{register} y, cb, cr : int;
{register} outptr : JSAMPROW;
{register} inptr0, inptr1, inptr2, inptr3 : JSAMPROW;
{register} col : JDIMENSION;
num_cols : JDIMENSION;
{ copy these pointers into registers if possible }
{register} range_limit : range_limit_table_ptr;
{register} Crrtab : int_table_ptr;
{register} Cbbtab : int_table_ptr;
{register} Crgtab : INT32_table_ptr;
{register} Cbgtab : INT32_table_ptr;
var
shift_temp : INT32;
begin
cconvert := my_cconvert_ptr (cinfo^.cconvert);
num_cols := cinfo^.output_width;
{ copy these pointers into registers if possible }
range_limit := cinfo^.sample_range_limit;
Crrtab := cconvert^.Cr_r_tab;
Cbbtab := cconvert^.Cb_b_tab;
Crgtab := cconvert^.Cr_g_tab;
Cbgtab := cconvert^.Cb_g_tab;
while (num_rows > 0) do
begin
Dec(num_rows);
inptr0 := input_buf^[0]^[input_row];
inptr1 := input_buf^[1]^[input_row];
inptr2 := input_buf^[2]^[input_row];
inptr3 := input_buf^[3]^[input_row];
Inc(input_row);
outptr := output_buf^[0];
Inc(JSAMPROW_PTR(output_buf));
for col := 0 to pred(num_cols) do
begin
y := GETJSAMPLE(inptr0^[col]);
cb := GETJSAMPLE(inptr1^[col]);
cr := GETJSAMPLE(inptr2^[col]);
{ Range-limiting is essential due to noise introduced by DCT losses. }
outptr^[0] := range_limit^[MAXJSAMPLE - (y + Crrtab^[cr])]; { red }
shift_temp := Cbgtab^[cb] + Crgtab^[cr];
if shift_temp < 0 then
outptr^[1] := range_limit^[MAXJSAMPLE - (y + int(
(shift_temp shr SCALEBITS) or ((not INT32(0)) shl (32-SCALEBITS))
) )]
else
outptr^[1] := range_limit^[MAXJSAMPLE - { green }
(y + int(shift_temp shr SCALEBITS) )];
outptr^[2] := range_limit^[MAXJSAMPLE - (y + Cbbtab^[cb])]; { blue }
{ K passes through unchanged }
outptr^[3] := inptr3^[col]; { don't need GETJSAMPLE here }
Inc(JSAMPLE_PTR(outptr), 4);
end;
end;
end;
{ Empty method for start_pass. }
{METHODDEF}
procedure start_pass_dcolor (cinfo : j_decompress_ptr); far;
begin
{ no work needed }
end;
{ Module initialization routine for output colorspace conversion. }
{GLOBAL}
procedure jinit_color_deconverter (cinfo : j_decompress_ptr);
var
cconvert : my_cconvert_ptr;
ci : int;
begin
cconvert := my_cconvert_ptr (
cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
SIZEOF(my_color_deconverter)) );
cinfo^.cconvert := jpeg_color_deconverter_ptr (cconvert);
cconvert^.pub.start_pass := start_pass_dcolor;
{ Make sure num_components agrees with jpeg_color_space }
case (cinfo^.jpeg_color_space) of
JCS_GRAYSCALE:
if (cinfo^.num_components <> 1) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
JCS_RGB,
JCS_YCbCr:
if (cinfo^.num_components <> 3) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
JCS_CMYK,
JCS_YCCK:
if (cinfo^.num_components <> 4) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
else { JCS_UNKNOWN can be anything }
if (cinfo^.num_components < 1) then
ERREXIT(j_common_ptr(cinfo), JERR_BAD_J_COLORSPACE);
end;
{ Set out_color_components and conversion method based on requested space.
Also clear the component_needed flags for any unused components,
so that earlier pipeline stages can avoid useless computation. }
case (cinfo^.out_color_space) of
JCS_GRAYSCALE:
begin
cinfo^.out_color_components := 1;
if (cinfo^.jpeg_color_space = JCS_GRAYSCALE)
or (cinfo^.jpeg_color_space = JCS_YCbCr) then
begin
cconvert^.pub.color_convert := grayscale_convert;
{ For color -> grayscale conversion, only the
Y (0) component is needed }
for ci := 1 to pred(cinfo^.num_components) do
cinfo^.comp_info^[ci].component_needed := FALSE;
end
else
ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
end;
JCS_RGB:
begin
cinfo^.out_color_components := RGB_PIXELSIZE;
if (cinfo^.jpeg_color_space = JCS_YCbCr) then
begin
cconvert^.pub.color_convert := ycc_rgb_convert;
build_ycc_rgb_table(cinfo);
end
else
if (cinfo^.jpeg_color_space = JCS_GRAYSCALE) then
begin
cconvert^.pub.color_convert := gray_rgb_convert;
end
else
if (cinfo^.jpeg_color_space = JCS_RGB) and (RGB_PIXELSIZE = 3) then
begin
cconvert^.pub.color_convert := null_convert;
end
else
ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
end;
JCS_CMYK:
begin
cinfo^.out_color_components := 4;
if (cinfo^.jpeg_color_space = JCS_YCCK) then
begin
cconvert^.pub.color_convert := ycck_cmyk_convert;
build_ycc_rgb_table(cinfo);
end
else
if (cinfo^.jpeg_color_space = JCS_CMYK) then
begin
cconvert^.pub.color_convert := null_convert;
end
else
ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
end;
else
begin { Permit null conversion to same output space }
if (cinfo^.out_color_space = cinfo^.jpeg_color_space) then
begin
cinfo^.out_color_components := cinfo^.num_components;
cconvert^.pub.color_convert := null_convert;
end
else { unsupported non-null conversion }
ERREXIT(j_common_ptr(cinfo), JERR_CONVERSION_NOTIMPL);
end;
end;
if (cinfo^.quantize_colors) then
cinfo^.output_components := 1 { single colormapped output component }
else
cinfo^.output_components := cinfo^.out_color_components;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -