|
<html><head><title>dlib C++ Library - jcsample.c</title></head><body bgcolor='white'><pre> |
|
<font color='#009900'>/*
|
|
* jcsample.c
|
|
*
|
|
* Copyright (C) 1991-1996, Thomas G. Lane.
|
|
* This file is part of the Independent JPEG Group's software.
|
|
* For conditions of distribution and use, see the accompanying README file.
|
|
*
|
|
* This file contains downsampling routines.
|
|
*
|
|
* Downsampling input data is counted in "row groups". A row group
|
|
* is defined to be max_v_samp_factor pixel rows of each component,
|
|
* from which the downsampler produces v_samp_factor sample rows.
|
|
* A single row group is processed in each call to the downsampler module.
|
|
*
|
|
* The downsampler is responsible for edge-expansion of its output data
|
|
* to fill an integral number of DCT blocks horizontally. The source buffer
|
|
* may be modified if it is helpful for this purpose (the source buffer is
|
|
* allocated wide enough to correspond to the desired output width).
|
|
* The caller (the prep controller) is responsible for vertical padding.
|
|
*
|
|
* The downsampler may request "context rows" by setting need_context_rows
|
|
* during startup. In this case, the input arrays will contain at least
|
|
* one row group's worth of pixels above and below the passed-in data;
|
|
* the caller will create dummy rows at image top and bottom by replicating
|
|
* the first or last real pixel row.
|
|
*
|
|
* An excellent reference for image resampling is
|
|
* Digital Image Warping, George Wolberg, 1990.
|
|
* Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
|
|
*
|
|
* The downsampling algorithm used here is a simple average of the source
|
|
* pixels covered by the output pixel. The hi-falutin sampling literature
|
|
* refers to this as a "box filter". In general the characteristics of a box
|
|
* filter are not very good, but for the specific cases we normally use (1:1
|
|
* and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
|
|
* nearly so bad. If you intend to use other sampling ratios, you'd be well
|
|
* advised to improve this code.
|
|
*
|
|
* A simple input-smoothing capability is provided. This is mainly intended
|
|
* for cleaning up color-dithered GIF input files (if you find it inadequate,
|
|
* we suggest using an external filtering program such as pnmconvol). When
|
|
* enabled, each input pixel P is replaced by a weighted sum of itself and its
|
|
* eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF,
|
|
* where SF = (smoothing_factor / 1024).
|
|
* Currently, smoothing is only supported for 2h2v sampling factors.
|
|
*/</font>
|
|
|
|
<font color='#0000FF'>#define</font> JPEG_INTERNALS
|
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='jinclude.h.html'>jinclude.h</a>"
|
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='jpeglib.h.html'>jpeglib.h</a>"
|
|
|
|
|
|
<font color='#009900'>/* Pointer to routine to downsample a single component */</font>
|
|
<font color='#0000FF'>typedef</font> <b><a name='JMETHOD'></a>JMETHOD</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font>, downsample1_ptr,
|
|
<font face='Lucida Console'>(</font>j_compress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
|
|
JSAMPARRAY input_data, JSAMPARRAY output_data<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
|
|
|
|
<font color='#009900'>/* Private subobject */</font>
|
|
|
|
<font color='#0000FF'>typedef</font> <font color='#0000FF'>struct</font> <b>{</b>
|
|
<font color='#0000FF'>struct</font> jpeg_downsampler pub; <font color='#009900'>/* public fields */</font>
|
|
|
|
<font color='#009900'>/* Downsampling method pointers, one per component */</font>
|
|
downsample1_ptr methods[MAX_COMPONENTS];
|
|
|
|
<font color='#009900'>/* Height of an output row group for each component. */</font>
|
|
<font color='#0000FF'><u>int</u></font> rowgroup_height[MAX_COMPONENTS];
|
|
|
|
<font color='#009900'>/* These arrays save pixel expansion factors so that int_downsample need not
|
|
* recompute them each time. They are unused for other downsampling methods.
|
|
*/</font>
|
|
UINT8 h_expand[MAX_COMPONENTS];
|
|
UINT8 v_expand[MAX_COMPONENTS];
|
|
<b>}</b> my_downsampler;
|
|
|
|
<font color='#0000FF'>typedef</font> my_downsampler <font color='#5555FF'>*</font> my_downsample_ptr;
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Initialize for a downsampling pass.
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='start_pass_downsample'></a>start_pass_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
<font color='#009900'>/* no work for now */</font>
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Expand a component horizontally from width input_cols to width output_cols,
|
|
* by duplicating the rightmost samples.
|
|
*/</font>
|
|
|
|
<b><a name='LOCAL'></a>LOCAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='expand_right_edge'></a>expand_right_edge</b> <font face='Lucida Console'>(</font>JSAMPARRAY image_data, <font color='#0000FF'><u>int</u></font> num_rows,
|
|
JDIMENSION input_cols, JDIMENSION output_cols<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
<font color='#0000FF'>register</font> JSAMPROW ptr;
|
|
<font color='#0000FF'>register</font> JSAMPLE pixval;
|
|
<font color='#0000FF'>register</font> <font color='#0000FF'><u>int</u></font> count;
|
|
<font color='#0000FF'><u>int</u></font> row;
|
|
<font color='#0000FF'><u>int</u></font> numcols <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>output_cols <font color='#5555FF'>-</font> input_cols<font face='Lucida Console'>)</font>;
|
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>numcols <font color='#5555FF'>></font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>row <font color='#5555FF'>=</font> <font color='#979000'>0</font>; row <font color='#5555FF'><</font> num_rows; row<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
ptr <font color='#5555FF'>=</font> image_data[row] <font color='#5555FF'>+</font> input_cols;
|
|
pixval <font color='#5555FF'>=</font> ptr[<font color='#5555FF'>-</font><font color='#979000'>1</font>]; <font color='#009900'>/* don't need GETJSAMPLE() here */</font>
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>count <font color='#5555FF'>=</font> numcols; count <font color='#5555FF'>></font> <font color='#979000'>0</font>; count<font color='#5555FF'>-</font><font color='#5555FF'>-</font><font face='Lucida Console'>)</font>
|
|
<font color='#5555FF'>*</font>ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> pixval;
|
|
<b>}</b>
|
|
<b>}</b>
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Do downsampling for a whole row group (all components).
|
|
*
|
|
* In this version we simply downsample each component independently.
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='sep_downsample'></a>sep_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo,
|
|
JSAMPIMAGE input_buf, JDIMENSION in_row_index,
|
|
JSAMPIMAGE output_buf, JDIMENSION out_row_group_index<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
my_downsample_ptr downsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>my_downsample_ptr<font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>downsample;
|
|
<font color='#0000FF'><u>int</u></font> ci;
|
|
jpeg_component_info <font color='#5555FF'>*</font> compptr;
|
|
JSAMPARRAY in_ptr, out_ptr;
|
|
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>ci <font color='#5555FF'>=</font> <font color='#979000'>0</font>, compptr <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>comp_info; ci <font color='#5555FF'><</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>num_components;
|
|
ci<font color='#5555FF'>+</font><font color='#5555FF'>+</font>, compptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
in_ptr <font color='#5555FF'>=</font> input_buf[ci] <font color='#5555FF'>+</font> in_row_index;
|
|
out_ptr <font color='#5555FF'>=</font> output_buf[ci] <font color='#5555FF'>+</font>
|
|
<font face='Lucida Console'>(</font>out_row_group_index <font color='#5555FF'>*</font> downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>rowgroup_height[ci]<font face='Lucida Console'>)</font>;
|
|
<font face='Lucida Console'>(</font><font color='#5555FF'>*</font>downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>methods[ci]<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>cinfo, compptr, in_ptr, out_ptr<font face='Lucida Console'>)</font>;
|
|
<b>}</b>
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Downsample pixel values of a single component.
|
|
* One row group is processed per call.
|
|
* This version handles arbitrary integral sampling ratios, without smoothing.
|
|
* Note that this version is not actually used for customary sampling ratios.
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='int_downsample'></a>int_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
|
|
JSAMPARRAY input_data, JSAMPARRAY output_data<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
my_downsample_ptr downsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>my_downsample_ptr<font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>downsample;
|
|
<font color='#0000FF'><u>int</u></font> inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
|
|
JDIMENSION outcol, outcol_h; <font color='#009900'>/* outcol_h == outcol*h_expand */</font>
|
|
JDIMENSION output_cols <font color='#5555FF'>=</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>width_in_blocks <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_h_scaled_size;
|
|
JSAMPROW inptr, outptr;
|
|
INT32 outvalue;
|
|
|
|
h_expand <font color='#5555FF'>=</font> downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>h_expand[compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>component_index];
|
|
v_expand <font color='#5555FF'>=</font> downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>v_expand[compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>component_index];
|
|
numpix <font color='#5555FF'>=</font> h_expand <font color='#5555FF'>*</font> v_expand;
|
|
numpix2 <font color='#5555FF'>=</font> numpix<font color='#5555FF'>/</font><font color='#979000'>2</font>;
|
|
|
|
<font color='#009900'>/* Expand input data enough to let all the output samples be generated
|
|
* by the standard loop. Special-casing padded output would be more
|
|
* efficient.
|
|
*/</font>
|
|
<font color='#BB00BB'>expand_right_edge</font><font face='Lucida Console'>(</font>input_data, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor,
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>image_width, output_cols <font color='#5555FF'>*</font> h_expand<font face='Lucida Console'>)</font>;
|
|
|
|
inrow <font color='#5555FF'>=</font> outrow <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>inrow <font color='#5555FF'><</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor<font face='Lucida Console'>)</font> <b>{</b>
|
|
outptr <font color='#5555FF'>=</font> output_data[outrow];
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>outcol <font color='#5555FF'>=</font> <font color='#979000'>0</font>, outcol_h <font color='#5555FF'>=</font> <font color='#979000'>0</font>; outcol <font color='#5555FF'><</font> output_cols;
|
|
outcol<font color='#5555FF'>+</font><font color='#5555FF'>+</font>, outcol_h <font color='#5555FF'>+</font><font color='#5555FF'>=</font> h_expand<font face='Lucida Console'>)</font> <b>{</b>
|
|
outvalue <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>v <font color='#5555FF'>=</font> <font color='#979000'>0</font>; v <font color='#5555FF'><</font> v_expand; v<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
inptr <font color='#5555FF'>=</font> input_data[inrow<font color='#5555FF'>+</font>v] <font color='#5555FF'>+</font> outcol_h;
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>h <font color='#5555FF'>=</font> <font color='#979000'>0</font>; h <font color='#5555FF'><</font> h_expand; h<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
outvalue <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>INT32<font face='Lucida Console'>)</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>;
|
|
<b>}</b>
|
|
<b>}</b>
|
|
<font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>outvalue <font color='#5555FF'>+</font> numpix2<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> numpix<font face='Lucida Console'>)</font>;
|
|
<b>}</b>
|
|
inrow <font color='#5555FF'>+</font><font color='#5555FF'>=</font> v_expand;
|
|
outrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
|
|
<b>}</b>
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Downsample pixel values of a single component.
|
|
* This version handles the special case of a full-size component,
|
|
* without smoothing.
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='fullsize_downsample'></a>fullsize_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
|
|
JSAMPARRAY input_data, JSAMPARRAY output_data<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
<font color='#009900'>/* Copy the data */</font>
|
|
<font color='#BB00BB'>jcopy_sample_rows</font><font face='Lucida Console'>(</font>input_data, <font color='#979000'>0</font>, output_data, <font color='#979000'>0</font>,
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>image_width<font face='Lucida Console'>)</font>;
|
|
<font color='#009900'>/* Edge-expand */</font>
|
|
<font color='#BB00BB'>expand_right_edge</font><font face='Lucida Console'>(</font>output_data, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>image_width,
|
|
compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>width_in_blocks <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_h_scaled_size<font face='Lucida Console'>)</font>;
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Downsample pixel values of a single component.
|
|
* This version handles the common case of 2:1 horizontal and 1:1 vertical,
|
|
* without smoothing.
|
|
*
|
|
* A note about the "bias" calculations: when rounding fractional values to
|
|
* integer, we do not want to always round 0.5 up to the next integer.
|
|
* If we did that, we'd introduce a noticeable bias towards larger values.
|
|
* Instead, this code is arranged so that 0.5 will be rounded up or down at
|
|
* alternate pixel locations (a simple ordered dither pattern).
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='h2v1_downsample'></a>h2v1_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
|
|
JSAMPARRAY input_data, JSAMPARRAY output_data<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
<font color='#0000FF'><u>int</u></font> inrow;
|
|
JDIMENSION outcol;
|
|
JDIMENSION output_cols <font color='#5555FF'>=</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>width_in_blocks <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_h_scaled_size;
|
|
<font color='#0000FF'>register</font> JSAMPROW inptr, outptr;
|
|
<font color='#0000FF'>register</font> <font color='#0000FF'><u>int</u></font> bias;
|
|
|
|
<font color='#009900'>/* Expand input data enough to let all the output samples be generated
|
|
* by the standard loop. Special-casing padded output would be more
|
|
* efficient.
|
|
*/</font>
|
|
<font color='#BB00BB'>expand_right_edge</font><font face='Lucida Console'>(</font>input_data, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor,
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>image_width, output_cols <font color='#5555FF'>*</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>;
|
|
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>inrow <font color='#5555FF'>=</font> <font color='#979000'>0</font>; inrow <font color='#5555FF'><</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor; inrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
outptr <font color='#5555FF'>=</font> output_data[inrow];
|
|
inptr <font color='#5555FF'>=</font> input_data[inrow];
|
|
bias <font color='#5555FF'>=</font> <font color='#979000'>0</font>; <font color='#009900'>/* bias = 0,1,0,1,... for successive samples */</font>
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>outcol <font color='#5555FF'>=</font> <font color='#979000'>0</font>; outcol <font color='#5555FF'><</font> output_cols; outcol<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
<font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>
|
|
<font color='#5555FF'>+</font> bias<font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
|
|
bias ^<font color='#5555FF'>=</font> <font color='#979000'>1</font>; <font color='#009900'>/* 0=>1, 1=>0 */</font>
|
|
inptr <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;
|
|
<b>}</b>
|
|
<b>}</b>
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Downsample pixel values of a single component.
|
|
* This version handles the standard case of 2:1 horizontal and 2:1 vertical,
|
|
* without smoothing.
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='h2v2_downsample'></a>h2v2_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
|
|
JSAMPARRAY input_data, JSAMPARRAY output_data<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
<font color='#0000FF'><u>int</u></font> inrow, outrow;
|
|
JDIMENSION outcol;
|
|
JDIMENSION output_cols <font color='#5555FF'>=</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>width_in_blocks <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_h_scaled_size;
|
|
<font color='#0000FF'>register</font> JSAMPROW inptr0, inptr1, outptr;
|
|
<font color='#0000FF'>register</font> <font color='#0000FF'><u>int</u></font> bias;
|
|
|
|
<font color='#009900'>/* Expand input data enough to let all the output samples be generated
|
|
* by the standard loop. Special-casing padded output would be more
|
|
* efficient.
|
|
*/</font>
|
|
<font color='#BB00BB'>expand_right_edge</font><font face='Lucida Console'>(</font>input_data, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor,
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>image_width, output_cols <font color='#5555FF'>*</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>;
|
|
|
|
inrow <font color='#5555FF'>=</font> outrow <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>inrow <font color='#5555FF'><</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor<font face='Lucida Console'>)</font> <b>{</b>
|
|
outptr <font color='#5555FF'>=</font> output_data[outrow];
|
|
inptr0 <font color='#5555FF'>=</font> input_data[inrow];
|
|
inptr1 <font color='#5555FF'>=</font> input_data[inrow<font color='#5555FF'>+</font><font color='#979000'>1</font>];
|
|
bias <font color='#5555FF'>=</font> <font color='#979000'>1</font>; <font color='#009900'>/* bias = 1,2,1,2,... for successive samples */</font>
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>outcol <font color='#5555FF'>=</font> <font color='#979000'>0</font>; outcol <font color='#5555FF'><</font> output_cols; outcol<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
<font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr0<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>
|
|
<font color='#5555FF'>+</font> bias<font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>;
|
|
bias ^<font color='#5555FF'>=</font> <font color='#979000'>3</font>; <font color='#009900'>/* 1=>2, 2=>1 */</font>
|
|
inptr0 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; inptr1 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;
|
|
<b>}</b>
|
|
inrow <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;
|
|
outrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
|
|
<b>}</b>
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#0000FF'>#ifdef</font> INPUT_SMOOTHING_SUPPORTED
|
|
|
|
<font color='#009900'>/*
|
|
* Downsample pixel values of a single component.
|
|
* This version handles the standard case of 2:1 horizontal and 2:1 vertical,
|
|
* with smoothing. One row of context is required.
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='h2v2_smooth_downsample'></a>h2v2_smooth_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
|
|
JSAMPARRAY input_data, JSAMPARRAY output_data<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
<font color='#0000FF'><u>int</u></font> inrow, outrow;
|
|
JDIMENSION colctr;
|
|
JDIMENSION output_cols <font color='#5555FF'>=</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>width_in_blocks <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_h_scaled_size;
|
|
<font color='#0000FF'>register</font> JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
|
|
INT32 membersum, neighsum, memberscale, neighscale;
|
|
|
|
<font color='#009900'>/* Expand input data enough to let all the output samples be generated
|
|
* by the standard loop. Special-casing padded output would be more
|
|
* efficient.
|
|
*/</font>
|
|
<font color='#BB00BB'>expand_right_edge</font><font face='Lucida Console'>(</font>input_data <font color='#5555FF'>-</font> <font color='#979000'>1</font>, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor <font color='#5555FF'>+</font> <font color='#979000'>2</font>,
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>image_width, output_cols <font color='#5555FF'>*</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>;
|
|
|
|
<font color='#009900'>/* We don't bother to form the individual "smoothed" input pixel values;
|
|
* we can directly compute the output which is the average of the four
|
|
* smoothed values. Each of the four member pixels contributes a fraction
|
|
* (1-8*SF) to its own smoothed image and a fraction SF to each of the three
|
|
* other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
|
|
* output. The four corner-adjacent neighbor pixels contribute a fraction
|
|
* SF to just one smoothed pixel, or SF/4 to the final output; while the
|
|
* eight edge-adjacent neighbors contribute SF to each of two smoothed
|
|
* pixels, or SF/2 overall. In order to use integer arithmetic, these
|
|
* factors are scaled by 2^16 = 65536.
|
|
* Also recall that SF = smoothing_factor / 1024.
|
|
*/</font>
|
|
|
|
memberscale <font color='#5555FF'>=</font> <font color='#979000'>16384</font> <font color='#5555FF'>-</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>smoothing_factor <font color='#5555FF'>*</font> <font color='#979000'>80</font>; <font color='#009900'>/* scaled (1-5*SF)/4 */</font>
|
|
neighscale <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>smoothing_factor <font color='#5555FF'>*</font> <font color='#979000'>16</font>; <font color='#009900'>/* scaled SF/4 */</font>
|
|
|
|
inrow <font color='#5555FF'>=</font> outrow <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>inrow <font color='#5555FF'><</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor<font face='Lucida Console'>)</font> <b>{</b>
|
|
outptr <font color='#5555FF'>=</font> output_data[outrow];
|
|
inptr0 <font color='#5555FF'>=</font> input_data[inrow];
|
|
inptr1 <font color='#5555FF'>=</font> input_data[inrow<font color='#5555FF'>+</font><font color='#979000'>1</font>];
|
|
above_ptr <font color='#5555FF'>=</font> input_data[inrow<font color='#5555FF'>-</font><font color='#979000'>1</font>];
|
|
below_ptr <font color='#5555FF'>=</font> input_data[inrow<font color='#5555FF'>+</font><font color='#979000'>2</font>];
|
|
|
|
<font color='#009900'>/* Special case for first column: pretend column -1 is same as column 0 */</font>
|
|
membersum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr0<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
|
|
neighsum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>above_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>below_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr0<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
|
|
neighsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> neighsum;
|
|
neighsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>above_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>below_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
|
|
membersum <font color='#5555FF'>=</font> membersum <font color='#5555FF'>*</font> memberscale <font color='#5555FF'>+</font> neighsum <font color='#5555FF'>*</font> neighscale;
|
|
<font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>membersum <font color='#5555FF'>+</font> <font color='#979000'>32768</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>;
|
|
inptr0 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; inptr1 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; above_ptr <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; below_ptr <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;
|
|
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>colctr <font color='#5555FF'>=</font> output_cols <font color='#5555FF'>-</font> <font color='#979000'>2</font>; colctr <font color='#5555FF'>></font> <font color='#979000'>0</font>; colctr<font color='#5555FF'>-</font><font color='#5555FF'>-</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
<font color='#009900'>/* sum of pixels directly mapped to this output element */</font>
|
|
membersum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr0<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
|
|
<font color='#009900'>/* sum of edge-neighbor pixels */</font>
|
|
neighsum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>above_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>below_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
|
|
<font color='#009900'>/* The edge-neighbors count twice as much as corner-neighbors */</font>
|
|
neighsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> neighsum;
|
|
<font color='#009900'>/* Add in the corner-neighbors */</font>
|
|
neighsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
|
|
<font color='#009900'>/* form final output scaled up by 2^16 */</font>
|
|
membersum <font color='#5555FF'>=</font> membersum <font color='#5555FF'>*</font> memberscale <font color='#5555FF'>+</font> neighsum <font color='#5555FF'>*</font> neighscale;
|
|
<font color='#009900'>/* round, descale and output it */</font>
|
|
<font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>membersum <font color='#5555FF'>+</font> <font color='#979000'>32768</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>;
|
|
inptr0 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; inptr1 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; above_ptr <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; below_ptr <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;
|
|
<b>}</b>
|
|
|
|
<font color='#009900'>/* Special case for last column */</font>
|
|
membersum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr0<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
|
|
neighsum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>above_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>below_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr0[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>inptr1[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
|
|
neighsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> neighsum;
|
|
neighsum <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>above_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#5555FF'>-</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font>below_ptr[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
|
|
membersum <font color='#5555FF'>=</font> membersum <font color='#5555FF'>*</font> memberscale <font color='#5555FF'>+</font> neighsum <font color='#5555FF'>*</font> neighscale;
|
|
<font color='#5555FF'>*</font>outptr <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>membersum <font color='#5555FF'>+</font> <font color='#979000'>32768</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>;
|
|
|
|
inrow <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;
|
|
outrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
|
|
<b>}</b>
|
|
<b>}</b>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Downsample pixel values of a single component.
|
|
* This version handles the special case of a full-size component,
|
|
* with smoothing. One row of context is required.
|
|
*/</font>
|
|
|
|
<b><a name='METHODDEF'></a>METHODDEF</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='fullsize_smooth_downsample'></a>fullsize_smooth_downsample</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font>compptr,
|
|
JSAMPARRAY input_data, JSAMPARRAY output_data<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
<font color='#0000FF'><u>int</u></font> inrow;
|
|
JDIMENSION colctr;
|
|
JDIMENSION output_cols <font color='#5555FF'>=</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>width_in_blocks <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_h_scaled_size;
|
|
<font color='#0000FF'>register</font> JSAMPROW inptr, above_ptr, below_ptr, outptr;
|
|
INT32 membersum, neighsum, memberscale, neighscale;
|
|
<font color='#0000FF'><u>int</u></font> colsum, lastcolsum, nextcolsum;
|
|
|
|
<font color='#009900'>/* Expand input data enough to let all the output samples be generated
|
|
* by the standard loop. Special-casing padded output would be more
|
|
* efficient.
|
|
*/</font>
|
|
<font color='#BB00BB'>expand_right_edge</font><font face='Lucida Console'>(</font>input_data <font color='#5555FF'>-</font> <font color='#979000'>1</font>, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor <font color='#5555FF'>+</font> <font color='#979000'>2</font>,
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>image_width, output_cols<font face='Lucida Console'>)</font>;
|
|
|
|
<font color='#009900'>/* Each of the eight neighbor pixels contributes a fraction SF to the
|
|
* smoothed pixel, while the main pixel contributes (1-8*SF). In order
|
|
* to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
|
|
* Also recall that SF = smoothing_factor / 1024.
|
|
*/</font>
|
|
|
|
memberscale <font color='#5555FF'>=</font> <font color='#979000'>65536</font>L <font color='#5555FF'>-</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>smoothing_factor <font color='#5555FF'>*</font> <font color='#979000'>512</font>L; <font color='#009900'>/* scaled 1-8*SF */</font>
|
|
neighscale <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>smoothing_factor <font color='#5555FF'>*</font> <font color='#979000'>64</font>; <font color='#009900'>/* scaled SF */</font>
|
|
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>inrow <font color='#5555FF'>=</font> <font color='#979000'>0</font>; inrow <font color='#5555FF'><</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor; inrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
outptr <font color='#5555FF'>=</font> output_data[inrow];
|
|
inptr <font color='#5555FF'>=</font> input_data[inrow];
|
|
above_ptr <font color='#5555FF'>=</font> input_data[inrow<font color='#5555FF'>-</font><font color='#979000'>1</font>];
|
|
below_ptr <font color='#5555FF'>=</font> input_data[inrow<font color='#5555FF'>+</font><font color='#979000'>1</font>];
|
|
|
|
<font color='#009900'>/* Special case for first column */</font>
|
|
colsum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>above_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>below_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font face='Lucida Console'>)</font>;
|
|
membersum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>;
|
|
nextcolsum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>above_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>below_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font face='Lucida Console'>)</font>;
|
|
neighsum <font color='#5555FF'>=</font> colsum <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>colsum <font color='#5555FF'>-</font> membersum<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> nextcolsum;
|
|
membersum <font color='#5555FF'>=</font> membersum <font color='#5555FF'>*</font> memberscale <font color='#5555FF'>+</font> neighsum <font color='#5555FF'>*</font> neighscale;
|
|
<font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>membersum <font color='#5555FF'>+</font> <font color='#979000'>32768</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>;
|
|
lastcolsum <font color='#5555FF'>=</font> colsum; colsum <font color='#5555FF'>=</font> nextcolsum;
|
|
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>colctr <font color='#5555FF'>=</font> output_cols <font color='#5555FF'>-</font> <font color='#979000'>2</font>; colctr <font color='#5555FF'>></font> <font color='#979000'>0</font>; colctr<font color='#5555FF'>-</font><font color='#5555FF'>-</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
membersum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>;
|
|
above_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>; below_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
|
|
nextcolsum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>above_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>below_ptr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
|
|
<font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font face='Lucida Console'>)</font>;
|
|
neighsum <font color='#5555FF'>=</font> lastcolsum <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>colsum <font color='#5555FF'>-</font> membersum<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> nextcolsum;
|
|
membersum <font color='#5555FF'>=</font> membersum <font color='#5555FF'>*</font> memberscale <font color='#5555FF'>+</font> neighsum <font color='#5555FF'>*</font> neighscale;
|
|
<font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>membersum <font color='#5555FF'>+</font> <font color='#979000'>32768</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>;
|
|
lastcolsum <font color='#5555FF'>=</font> colsum; colsum <font color='#5555FF'>=</font> nextcolsum;
|
|
<b>}</b>
|
|
|
|
<font color='#009900'>/* Special case for last column */</font>
|
|
membersum <font color='#5555FF'>=</font> <font color='#BB00BB'>GETJSAMPLE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>inptr<font face='Lucida Console'>)</font>;
|
|
neighsum <font color='#5555FF'>=</font> lastcolsum <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>colsum <font color='#5555FF'>-</font> membersum<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> colsum;
|
|
membersum <font color='#5555FF'>=</font> membersum <font color='#5555FF'>*</font> memberscale <font color='#5555FF'>+</font> neighsum <font color='#5555FF'>*</font> neighscale;
|
|
<font color='#5555FF'>*</font>outptr <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JSAMPLE<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>membersum <font color='#5555FF'>+</font> <font color='#979000'>32768</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>;
|
|
|
|
<b>}</b>
|
|
<b>}</b>
|
|
|
|
<font color='#0000FF'>#endif</font> <font color='#009900'>/* INPUT_SMOOTHING_SUPPORTED */</font>
|
|
|
|
|
|
<font color='#009900'>/*
|
|
* Module initialization routine for downsampling.
|
|
* Note that we must select a routine for each component.
|
|
*/</font>
|
|
|
|
<b><a name='GLOBAL'></a>GLOBAL</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font>
|
|
<b><a name='jinit_downsampler'></a>jinit_downsampler</b> <font face='Lucida Console'>(</font>j_compress_ptr cinfo<font face='Lucida Console'>)</font>
|
|
<b>{</b>
|
|
my_downsample_ptr downsample;
|
|
<font color='#0000FF'><u>int</u></font> ci;
|
|
jpeg_component_info <font color='#5555FF'>*</font> compptr;
|
|
boolean smoothok <font color='#5555FF'>=</font> TRUE;
|
|
<font color='#0000FF'><u>int</u></font> h_in_group, v_in_group, h_out_group, v_out_group;
|
|
|
|
downsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>my_downsample_ptr<font face='Lucida Console'>)</font>
|
|
<font face='Lucida Console'>(</font><font color='#5555FF'>*</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>mem<font color='#5555FF'>-</font><font color='#5555FF'>></font>alloc_small<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>j_common_ptr<font face='Lucida Console'>)</font> cinfo, JPOOL_IMAGE,
|
|
<font color='#BB00BB'>SIZEOF</font><font face='Lucida Console'>(</font>my_downsampler<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>downsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'>struct</font> jpeg_downsampler <font color='#5555FF'>*</font><font face='Lucida Console'>)</font> downsample;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>pub.start_pass <font color='#5555FF'>=</font> start_pass_downsample;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>pub.downsample <font color='#5555FF'>=</font> sep_downsample;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>pub.need_context_rows <font color='#5555FF'>=</font> FALSE;
|
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>CCIR601_sampling<font face='Lucida Console'>)</font>
|
|
<font color='#BB00BB'>ERREXIT</font><font face='Lucida Console'>(</font>cinfo, JERR_CCIR601_NOTIMPL<font face='Lucida Console'>)</font>;
|
|
|
|
<font color='#009900'>/* Verify we can handle the sampling factors, and set up method pointers */</font>
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>ci <font color='#5555FF'>=</font> <font color='#979000'>0</font>, compptr <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>comp_info; ci <font color='#5555FF'><</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>num_components;
|
|
ci<font color='#5555FF'>+</font><font color='#5555FF'>+</font>, compptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
<font color='#009900'>/* Compute size of an "output group" for DCT scaling. This many samples
|
|
* are to be converted from max_h_samp_factor * max_v_samp_factor pixels.
|
|
*/</font>
|
|
h_out_group <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>h_samp_factor <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_h_scaled_size<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font>
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>min_DCT_h_scaled_size;
|
|
v_out_group <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>v_samp_factor <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>></font>DCT_v_scaled_size<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font>
|
|
cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>min_DCT_v_scaled_size;
|
|
h_in_group <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_h_samp_factor;
|
|
v_in_group <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>max_v_samp_factor;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>rowgroup_height[ci] <font color='#5555FF'>=</font> v_out_group; <font color='#009900'>/* save for use later */</font>
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>h_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> h_out_group <font color='#5555FF'>&</font><font color='#5555FF'>&</font> v_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> v_out_group<font face='Lucida Console'>)</font> <b>{</b>
|
|
<font color='#0000FF'>#ifdef</font> INPUT_SMOOTHING_SUPPORTED
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>smoothing_factor<font face='Lucida Console'>)</font> <b>{</b>
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>methods[ci] <font color='#5555FF'>=</font> fullsize_smooth_downsample;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>pub.need_context_rows <font color='#5555FF'>=</font> TRUE;
|
|
<b>}</b> <font color='#0000FF'>else</font>
|
|
<font color='#0000FF'>#endif</font>
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>methods[ci] <font color='#5555FF'>=</font> fullsize_downsample;
|
|
<b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>h_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> h_out_group <font color='#5555FF'>*</font> <font color='#979000'>2</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font>
|
|
v_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> v_out_group<font face='Lucida Console'>)</font> <b>{</b>
|
|
smoothok <font color='#5555FF'>=</font> FALSE;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>methods[ci] <font color='#5555FF'>=</font> h2v1_downsample;
|
|
<b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>h_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> h_out_group <font color='#5555FF'>*</font> <font color='#979000'>2</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font>
|
|
v_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> v_out_group <font color='#5555FF'>*</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
<font color='#0000FF'>#ifdef</font> INPUT_SMOOTHING_SUPPORTED
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>smoothing_factor<font face='Lucida Console'>)</font> <b>{</b>
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>methods[ci] <font color='#5555FF'>=</font> h2v2_smooth_downsample;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>pub.need_context_rows <font color='#5555FF'>=</font> TRUE;
|
|
<b>}</b> <font color='#0000FF'>else</font>
|
|
<font color='#0000FF'>#endif</font>
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>methods[ci] <font color='#5555FF'>=</font> h2v2_downsample;
|
|
<b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>h_in_group <font color='#5555FF'>%</font> h_out_group<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font>
|
|
<font face='Lucida Console'>(</font>v_in_group <font color='#5555FF'>%</font> v_out_group<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b>
|
|
smoothok <font color='#5555FF'>=</font> FALSE;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>methods[ci] <font color='#5555FF'>=</font> int_downsample;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>h_expand[ci] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>UINT8<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>h_in_group <font color='#5555FF'>/</font> h_out_group<font face='Lucida Console'>)</font>;
|
|
downsample<font color='#5555FF'>-</font><font color='#5555FF'>></font>v_expand[ci] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>UINT8<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>v_in_group <font color='#5555FF'>/</font> v_out_group<font face='Lucida Console'>)</font>;
|
|
<b>}</b> <font color='#0000FF'>else</font>
|
|
<font color='#BB00BB'>ERREXIT</font><font face='Lucida Console'>(</font>cinfo, JERR_FRACT_SAMPLE_NOTIMPL<font face='Lucida Console'>)</font>;
|
|
<b>}</b>
|
|
|
|
<font color='#0000FF'>#ifdef</font> INPUT_SMOOTHING_SUPPORTED
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>></font>smoothing_factor <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font color='#5555FF'>!</font>smoothok<font face='Lucida Console'>)</font>
|
|
<font color='#BB00BB'>TRACEMS</font><font face='Lucida Console'>(</font>cinfo, <font color='#979000'>0</font>, JTRC_SMOOTH_NOTIMPL<font face='Lucida Console'>)</font>;
|
|
<font color='#0000FF'>#endif</font>
|
|
<b>}</b>
|
|
|
|
</pre></body></html> |