File size: 33,645 Bytes
9375c9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - jdsample.c</title></head><body bgcolor='white'><pre>
<font color='#009900'>/*
 * jdsample.c
 *
 * Copyright (C) 1991-1996, Thomas G. Lane.
 * Modified 2002-2008 by Guido Vollbeding.
 * 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 upsampling routines.
 *
 * Upsampling input data is counted in "row groups".  A row group
 * is defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size)
 * sample rows of each component.  Upsampling will normally produce
 * max_v_samp_factor pixel rows from each row group (but this could vary
 * if the upsampler is applying a scale factor of its own).
 *
 * 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.
 */</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 upsample 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>, upsample1_ptr,
		<font face='Lucida Console'>(</font>j_decompress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
		 JSAMPARRAY input_data, JSAMPARRAY <font color='#5555FF'>*</font> output_data_ptr<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_upsampler pub;	<font color='#009900'>/* public fields */</font>

  <font color='#009900'>/* Color conversion buffer.  When using separate upsampling and color
   * conversion steps, this buffer holds one upsampled row group until it
   * has been color converted and output.
   * Note: we do not allocate any storage for component(s) which are full-size,
   * ie do not need rescaling.  The corresponding entry of color_buf[] is
   * simply set to point to the input data array, thereby avoiding copying.
   */</font>
  JSAMPARRAY color_buf[MAX_COMPONENTS];

  <font color='#009900'>/* Per-component upsampling method pointers */</font>
  upsample1_ptr methods[MAX_COMPONENTS];

  <font color='#0000FF'><u>int</u></font> next_row_out;		<font color='#009900'>/* counts rows emitted from color_buf */</font>
  JDIMENSION rows_to_go;	<font color='#009900'>/* counts rows remaining in image */</font>

  <font color='#009900'>/* Height of an input 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_expand need not
   * recompute them each time.  They are unused for other upsampling methods.
   */</font>
  UINT8 h_expand[MAX_COMPONENTS];
  UINT8 v_expand[MAX_COMPONENTS];
<b>}</b> my_upsampler;

<font color='#0000FF'>typedef</font> my_upsampler <font color='#5555FF'>*</font> my_upsample_ptr;


<font color='#009900'>/*
 * Initialize for an upsampling 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_upsample'></a>start_pass_upsample</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo<font face='Lucida Console'>)</font>
<b>{</b>
  my_upsample_ptr upsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>my_upsample_ptr<font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>upsample;

  <font color='#009900'>/* Mark the conversion buffer empty */</font>
  upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>next_row_out <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor;
  <font color='#009900'>/* Initialize total-height counter for detecting bottom of image */</font>
  upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rows_to_go <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>output_height;
<b>}</b>


<font color='#009900'>/*
 * Control routine to do upsampling (and color conversion).
 *
 * In this version we upsample each component independently.
 * We upsample one row group into the conversion buffer, then apply
 * color conversion a row at a time.
 */</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_upsample'></a>sep_upsample</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo,
	      JSAMPIMAGE input_buf, JDIMENSION <font color='#5555FF'>*</font>in_row_group_ctr,
	      JDIMENSION in_row_groups_avail,
	      JSAMPARRAY output_buf, JDIMENSION <font color='#5555FF'>*</font>out_row_ctr,
	      JDIMENSION out_rows_avail<font face='Lucida Console'>)</font>
<b>{</b>
  my_upsample_ptr upsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>my_upsample_ptr<font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>upsample;
  <font color='#0000FF'><u>int</u></font> ci;
  jpeg_component_info <font color='#5555FF'>*</font> compptr;
  JDIMENSION num_rows;

  <font color='#009900'>/* Fill the conversion buffer, if it's empty */</font>
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>next_row_out <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor<font face='Lucida Console'>)</font> <b>{</b>
    <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'>&gt;</font>comp_info; ci <font color='#5555FF'>&lt;</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</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'>/* Invoke per-component upsample method.  Notice we pass a POINTER
       * to color_buf[ci], so that fullsize_upsample can change it.
       */</font>
      <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>methods[ci]<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>cinfo, compptr,
	input_buf[ci] <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>in_row_group_ctr <font color='#5555FF'>*</font> upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rowgroup_height[ci]<font face='Lucida Console'>)</font>,
	upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_buf <font color='#5555FF'>+</font> ci<font face='Lucida Console'>)</font>;
    <b>}</b>
    upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>next_row_out <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
  <b>}</b>

  <font color='#009900'>/* Color-convert and emit rows */</font>

  <font color='#009900'>/* How many we have in the buffer: */</font>
  num_rows <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>JDIMENSION<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor <font color='#5555FF'>-</font> upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>next_row_out<font face='Lucida Console'>)</font>;
  <font color='#009900'>/* Not more than the distance to the end of the image.  Need this test
   * in case the image height is not a multiple of max_v_samp_factor:
   */</font>
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num_rows <font color='#5555FF'>&gt;</font> upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rows_to_go<font face='Lucida Console'>)</font> 
    num_rows <font color='#5555FF'>=</font> upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rows_to_go;
  <font color='#009900'>/* And not more than what the client can accept: */</font>
  out_rows_avail <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#5555FF'>*</font>out_row_ctr;
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num_rows <font color='#5555FF'>&gt;</font> out_rows_avail<font face='Lucida Console'>)</font>
    num_rows <font color='#5555FF'>=</font> out_rows_avail;

  <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>cconvert<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_convert<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>cinfo, upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_buf,
				     <font face='Lucida Console'>(</font>JDIMENSION<font face='Lucida Console'>)</font> upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>next_row_out,
				     output_buf <font color='#5555FF'>+</font> <font color='#5555FF'>*</font>out_row_ctr,
				     <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font> num_rows<font face='Lucida Console'>)</font>;

  <font color='#009900'>/* Adjust counts */</font>
  <font color='#5555FF'>*</font>out_row_ctr <font color='#5555FF'>+</font><font color='#5555FF'>=</font> num_rows;
  upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rows_to_go <font color='#5555FF'>-</font><font color='#5555FF'>=</font> num_rows;
  upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>next_row_out <font color='#5555FF'>+</font><font color='#5555FF'>=</font> num_rows;
  <font color='#009900'>/* When the buffer is emptied, declare this input row group consumed */</font>
  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>next_row_out <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>in_row_group_ctr<font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
<b>}</b>


<font color='#009900'>/*
 * These are the routines invoked by sep_upsample to upsample pixel values
 * of a single component.  One row group is processed per call.
 */</font>


<font color='#009900'>/*
 * For full-size components, we just make color_buf[ci] point at the
 * input buffer, and thus avoid copying any data.  Note that this is
 * safe only because sep_upsample doesn't declare the input row group
 * "consumed" until we are done color converting and emitting it.
 */</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_upsample'></a>fullsize_upsample</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
		   JSAMPARRAY input_data, JSAMPARRAY <font color='#5555FF'>*</font> output_data_ptr<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#5555FF'>*</font>output_data_ptr <font color='#5555FF'>=</font> input_data;
<b>}</b>


<font color='#009900'>/*
 * This is a no-op version used for "uninteresting" components.
 * These components will not be referenced by color conversion.
 */</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='noop_upsample'></a>noop_upsample</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
	       JSAMPARRAY input_data, JSAMPARRAY <font color='#5555FF'>*</font> output_data_ptr<font face='Lucida Console'>)</font>
<b>{</b>
  <font color='#5555FF'>*</font>output_data_ptr <font color='#5555FF'>=</font> NULL;	<font color='#009900'>/* safety check */</font>
<b>}</b>


<font color='#009900'>/*
 * This version handles any integral sampling ratios.
 * This is not used for typical JPEG files, so it need not be fast.
 * Nor, for that matter, is it particularly accurate: the algorithm is
 * simple replication of the input pixel onto the corresponding output
 * pixels.  The hi-falutin sampling literature refers to this as a
 * "box filter".  A box filter tends to introduce visible artifacts,
 * so if you are actually going to use 3:1 or 4:1 sampling ratios
 * you would be well advised to improve this code.
 */</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_upsample'></a>int_upsample</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
	      JSAMPARRAY input_data, JSAMPARRAY <font color='#5555FF'>*</font> output_data_ptr<font face='Lucida Console'>)</font>
<b>{</b>
  my_upsample_ptr upsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>my_upsample_ptr<font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>upsample;
  JSAMPARRAY output_data <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>output_data_ptr;
  <font color='#0000FF'>register</font> JSAMPROW inptr, outptr;
  <font color='#0000FF'>register</font> JSAMPLE invalue;
  <font color='#0000FF'>register</font> <font color='#0000FF'><u>int</u></font> h;
  JSAMPROW outend;
  <font color='#0000FF'><u>int</u></font> h_expand, v_expand;
  <font color='#0000FF'><u>int</u></font> inrow, outrow;

  h_expand <font color='#5555FF'>=</font> upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>h_expand[compptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>component_index];
  v_expand <font color='#5555FF'>=</font> upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>v_expand[compptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>component_index];

  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>outrow <font color='#5555FF'>&lt;</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor<font face='Lucida Console'>)</font> <b>{</b>
    <font color='#009900'>/* Generate one output row with proper horizontal expansion */</font>
    inptr <font color='#5555FF'>=</font> input_data[inrow];
    outptr <font color='#5555FF'>=</font> output_data[outrow];
    outend <font color='#5555FF'>=</font> outptr <font color='#5555FF'>+</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>output_width;
    <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>outptr <font color='#5555FF'>&lt;</font> outend<font face='Lucida Console'>)</font> <b>{</b>
      invalue <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>inptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;	<font color='#009900'>/* don't need GETJSAMPLE() here */</font>
      <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>h <font color='#5555FF'>=</font> h_expand; h <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font>; h<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> invalue;
      <b>}</b>
    <b>}</b>
    <font color='#009900'>/* Generate any additional output rows by duplicating the first one */</font>
    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>v_expand <font color='#5555FF'>&gt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <b>{</b>
      <font color='#BB00BB'>jcopy_sample_rows</font><font face='Lucida Console'>(</font>output_data, outrow, output_data, outrow<font color='#5555FF'>+</font><font color='#979000'>1</font>,
			v_expand<font color='#5555FF'>-</font><font color='#979000'>1</font>, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>output_width<font face='Lucida Console'>)</font>;
    <b>}</b>
    inrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
    outrow <font color='#5555FF'>+</font><font color='#5555FF'>=</font> v_expand;
  <b>}</b>
<b>}</b>


<font color='#009900'>/*
 * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
 * It's still a box filter.
 */</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_upsample'></a>h2v1_upsample</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
	       JSAMPARRAY input_data, JSAMPARRAY <font color='#5555FF'>*</font> output_data_ptr<font face='Lucida Console'>)</font>
<b>{</b>
  JSAMPARRAY output_data <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>output_data_ptr;
  <font color='#0000FF'>register</font> JSAMPROW inptr, outptr;
  <font color='#0000FF'>register</font> JSAMPLE invalue;
  JSAMPROW outend;
  <font color='#0000FF'><u>int</u></font> outrow;

  <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>outrow <font color='#5555FF'>=</font> <font color='#979000'>0</font>; outrow <font color='#5555FF'>&lt;</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor; outrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <b>{</b>
    inptr <font color='#5555FF'>=</font> input_data[outrow];
    outptr <font color='#5555FF'>=</font> output_data[outrow];
    outend <font color='#5555FF'>=</font> outptr <font color='#5555FF'>+</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>output_width;
    <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>outptr <font color='#5555FF'>&lt;</font> outend<font face='Lucida Console'>)</font> <b>{</b>
      invalue <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>inptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;	<font color='#009900'>/* don't need GETJSAMPLE() here */</font>
      <font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> invalue;
      <font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> invalue;
    <b>}</b>
  <b>}</b>
<b>}</b>


<font color='#009900'>/*
 * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
 * It's still a box filter.
 */</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_upsample'></a>h2v2_upsample</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo, jpeg_component_info <font color='#5555FF'>*</font> compptr,
	       JSAMPARRAY input_data, JSAMPARRAY <font color='#5555FF'>*</font> output_data_ptr<font face='Lucida Console'>)</font>
<b>{</b>
  JSAMPARRAY output_data <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>output_data_ptr;
  <font color='#0000FF'>register</font> JSAMPROW inptr, outptr;
  <font color='#0000FF'>register</font> JSAMPLE invalue;
  JSAMPROW outend;
  <font color='#0000FF'><u>int</u></font> inrow, outrow;

  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>outrow <font color='#5555FF'>&lt;</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor<font face='Lucida Console'>)</font> <b>{</b>
    inptr <font color='#5555FF'>=</font> input_data[inrow];
    outptr <font color='#5555FF'>=</font> output_data[outrow];
    outend <font color='#5555FF'>=</font> outptr <font color='#5555FF'>+</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>output_width;
    <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>outptr <font color='#5555FF'>&lt;</font> outend<font face='Lucida Console'>)</font> <b>{</b>
      invalue <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>inptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;	<font color='#009900'>/* don't need GETJSAMPLE() here */</font>
      <font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> invalue;
      <font color='#5555FF'>*</font>outptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> invalue;
    <b>}</b>
    <font color='#BB00BB'>jcopy_sample_rows</font><font face='Lucida Console'>(</font>output_data, outrow, output_data, outrow<font color='#5555FF'>+</font><font color='#979000'>1</font>,
		      <font color='#979000'>1</font>, cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>output_width<font face='Lucida Console'>)</font>;
    inrow<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
    outrow <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>;
  <b>}</b>
<b>}</b>


<font color='#009900'>/*
 * Module initialization routine for upsampling.
 */</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_upsampler'></a>jinit_upsampler</b> <font face='Lucida Console'>(</font>j_decompress_ptr cinfo<font face='Lucida Console'>)</font>
<b>{</b>
  my_upsample_ptr upsample;
  <font color='#0000FF'><u>int</u></font> ci;
  jpeg_component_info <font color='#5555FF'>*</font> compptr;
  boolean need_buffer;
  <font color='#0000FF'><u>int</u></font> h_in_group, v_in_group, h_out_group, v_out_group;

  upsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>my_upsample_ptr<font face='Lucida Console'>)</font>
    <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mem<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</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_upsampler<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
  cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>upsample <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'>struct</font> jpeg_upsampler <font color='#5555FF'>*</font><font face='Lucida Console'>)</font> upsample;
  upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pub.start_pass <font color='#5555FF'>=</font> start_pass_upsample;
  upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pub.upsample <font color='#5555FF'>=</font> sep_upsample;
  upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pub.need_context_rows <font color='#5555FF'>=</font> FALSE; <font color='#009900'>/* until we find out differently */</font>

  <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>CCIR601_sampling<font face='Lucida Console'>)</font>	<font color='#009900'>/* this isn't supported */</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, select per-component methods,
   * and create storage as needed.
   */</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'>&gt;</font>comp_info; ci <font color='#5555FF'>&lt;</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</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 "input group" after IDCT scaling.  This many samples
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
     */</font>
    h_in_group <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>compptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>h_samp_factor <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>DCT_h_scaled_size<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font>
		 cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>min_DCT_h_scaled_size;
    v_in_group <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>compptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>v_samp_factor <font color='#5555FF'>*</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>DCT_v_scaled_size<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font>
		 cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>min_DCT_v_scaled_size;
    h_out_group <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_h_samp_factor;
    v_out_group <font color='#5555FF'>=</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor;
    upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rowgroup_height[ci] <font color='#5555FF'>=</font> v_in_group; <font color='#009900'>/* save for use later */</font>
    need_buffer <font color='#5555FF'>=</font> TRUE;
    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font> compptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>component_needed<font face='Lucida Console'>)</font> <b>{</b>
      <font color='#009900'>/* Don't bother to upsample an uninteresting component. */</font>
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>methods[ci] <font color='#5555FF'>=</font> noop_upsample;
      need_buffer <font color='#5555FF'>=</font> FALSE;
    <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'>&amp;</font><font color='#5555FF'>&amp;</font> v_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> v_out_group<font face='Lucida Console'>)</font> <b>{</b>
      <font color='#009900'>/* Fullsize components can be processed without any work. */</font>
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>methods[ci] <font color='#5555FF'>=</font> fullsize_upsample;
      need_buffer <font color='#5555FF'>=</font> FALSE;
    <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='#979000'>2</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> h_out_group <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
	       v_in_group <font color='#5555FF'>=</font><font color='#5555FF'>=</font> v_out_group<font face='Lucida Console'>)</font> <b>{</b>
      <font color='#009900'>/* Special case for 2h1v upsampling */</font>
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>methods[ci] <font color='#5555FF'>=</font> h2v1_upsample;
    <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='#979000'>2</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> h_out_group <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
	       v_in_group <font color='#5555FF'>*</font> <font color='#979000'>2</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> v_out_group<font face='Lucida Console'>)</font> <b>{</b>
      <font color='#009900'>/* Special case for 2h2v upsampling */</font>
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>methods[ci] <font color='#5555FF'>=</font> h2v2_upsample;
    <b>}</b> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>h_out_group <font color='#5555FF'>%</font> h_in_group<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
	       <font face='Lucida Console'>(</font>v_out_group <font color='#5555FF'>%</font> v_in_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>
      <font color='#009900'>/* Generic integral-factors upsampling method */</font>
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>methods[ci] <font color='#5555FF'>=</font> int_upsample;
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</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_out_group <font color='#5555FF'>/</font> h_in_group<font face='Lucida Console'>)</font>;
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</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_out_group <font color='#5555FF'>/</font> v_in_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>;
    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>need_buffer<font face='Lucida Console'>)</font> <b>{</b>
      upsample<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_buf[ci] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mem<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>alloc_sarray<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 face='Lucida Console'>(</font>JDIMENSION<font face='Lucida Console'>)</font> <font color='#BB00BB'>jround_up</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>output_width,
				<font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_h_samp_factor<font face='Lucida Console'>)</font>,
	 <font face='Lucida Console'>(</font>JDIMENSION<font face='Lucida Console'>)</font> cinfo<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>max_v_samp_factor<font face='Lucida Console'>)</font>;
    <b>}</b>
  <b>}</b>
<b>}</b>

</pre></body></html>