image_intensities 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/ext/image_intensities/Makefile +73 -4
  3. data/ext/image_intensities/turbojpeg/cderror.h +137 -0
  4. data/ext/image_intensities/turbojpeg/cdjpeg.h +157 -0
  5. data/ext/image_intensities/turbojpeg/cmyk.h +61 -0
  6. data/ext/image_intensities/turbojpeg/jaricom.c +157 -0
  7. data/ext/image_intensities/turbojpeg/jcapimin.c +295 -0
  8. data/ext/image_intensities/turbojpeg/jcapistd.c +162 -0
  9. data/ext/image_intensities/turbojpeg/jcarith.c +932 -0
  10. data/ext/image_intensities/turbojpeg/jccoefct.c +449 -0
  11. data/ext/image_intensities/turbojpeg/jccolext.c +144 -0
  12. data/ext/image_intensities/turbojpeg/jccolor.c +710 -0
  13. data/ext/image_intensities/turbojpeg/jcdctmgr.c +721 -0
  14. data/ext/image_intensities/turbojpeg/jchuff.c +1096 -0
  15. data/ext/image_intensities/turbojpeg/jchuff.h +42 -0
  16. data/ext/image_intensities/turbojpeg/jcicc.c +105 -0
  17. data/ext/image_intensities/turbojpeg/jcinit.c +77 -0
  18. data/ext/image_intensities/turbojpeg/jcmainct.c +162 -0
  19. data/ext/image_intensities/turbojpeg/jcmarker.c +664 -0
  20. data/ext/image_intensities/turbojpeg/jcmaster.c +640 -0
  21. data/ext/image_intensities/turbojpeg/jcomapi.c +109 -0
  22. data/ext/image_intensities/turbojpeg/jconfig.h +73 -0
  23. data/ext/image_intensities/turbojpeg/jconfigint.h +31 -0
  24. data/ext/image_intensities/turbojpeg/jcparam.c +541 -0
  25. data/ext/image_intensities/turbojpeg/jcphuff.c +1105 -0
  26. data/ext/image_intensities/turbojpeg/jcprepct.c +351 -0
  27. data/ext/image_intensities/turbojpeg/jcsample.c +539 -0
  28. data/ext/image_intensities/turbojpeg/jctrans.c +400 -0
  29. data/ext/image_intensities/turbojpeg/jdapimin.c +407 -0
  30. data/ext/image_intensities/turbojpeg/jdapistd.c +639 -0
  31. data/ext/image_intensities/turbojpeg/jdarith.c +773 -0
  32. data/ext/image_intensities/turbojpeg/jdatadst-tj.c +203 -0
  33. data/ext/image_intensities/turbojpeg/jdatadst.c +293 -0
  34. data/ext/image_intensities/turbojpeg/jdatasrc-tj.c +194 -0
  35. data/ext/image_intensities/turbojpeg/jdatasrc.c +295 -0
  36. data/ext/image_intensities/turbojpeg/jdcoefct.c +692 -0
  37. data/ext/image_intensities/turbojpeg/jdcoefct.h +82 -0
  38. data/ext/image_intensities/turbojpeg/jdcol565.c +384 -0
  39. data/ext/image_intensities/turbojpeg/jdcolext.c +143 -0
  40. data/ext/image_intensities/turbojpeg/jdcolor.c +883 -0
  41. data/ext/image_intensities/turbojpeg/jdct.h +208 -0
  42. data/ext/image_intensities/turbojpeg/jddctmgr.c +352 -0
  43. data/ext/image_intensities/turbojpeg/jdhuff.c +831 -0
  44. data/ext/image_intensities/turbojpeg/jdhuff.h +238 -0
  45. data/ext/image_intensities/turbojpeg/jdicc.c +171 -0
  46. data/ext/image_intensities/turbojpeg/jdinput.c +408 -0
  47. data/ext/image_intensities/turbojpeg/jdmainct.c +460 -0
  48. data/ext/image_intensities/turbojpeg/jdmainct.h +71 -0
  49. data/ext/image_intensities/turbojpeg/jdmarker.c +1377 -0
  50. data/ext/image_intensities/turbojpeg/jdmaster.c +737 -0
  51. data/ext/image_intensities/turbojpeg/jdmaster.h +28 -0
  52. data/ext/image_intensities/turbojpeg/jdmerge.c +617 -0
  53. data/ext/image_intensities/turbojpeg/jdmrg565.c +354 -0
  54. data/ext/image_intensities/turbojpeg/jdmrgext.c +184 -0
  55. data/ext/image_intensities/turbojpeg/jdphuff.c +687 -0
  56. data/ext/image_intensities/turbojpeg/jdpostct.c +294 -0
  57. data/ext/image_intensities/turbojpeg/jdsample.c +518 -0
  58. data/ext/image_intensities/turbojpeg/jdsample.h +50 -0
  59. data/ext/image_intensities/turbojpeg/jdtrans.c +155 -0
  60. data/ext/image_intensities/turbojpeg/jerror.c +251 -0
  61. data/ext/image_intensities/turbojpeg/jfdctflt.c +169 -0
  62. data/ext/image_intensities/turbojpeg/jfdctfst.c +227 -0
  63. data/ext/image_intensities/turbojpeg/jfdctint.c +288 -0
  64. data/ext/image_intensities/turbojpeg/jidctflt.c +240 -0
  65. data/ext/image_intensities/turbojpeg/jidctfst.c +371 -0
  66. data/ext/image_intensities/turbojpeg/jidctint.c +2627 -0
  67. data/ext/image_intensities/turbojpeg/jidctred.c +409 -0
  68. data/ext/image_intensities/turbojpeg/jinclude.h +88 -0
  69. data/ext/image_intensities/turbojpeg/jmemmgr.c +1179 -0
  70. data/ext/image_intensities/turbojpeg/jmemnobs.c +115 -0
  71. data/ext/image_intensities/turbojpeg/jmemsys.h +178 -0
  72. data/ext/image_intensities/turbojpeg/jpeg_nbits_table.h +4098 -0
  73. data/ext/image_intensities/turbojpeg/jpegcomp.h +31 -0
  74. data/ext/image_intensities/turbojpeg/jquant1.c +859 -0
  75. data/ext/image_intensities/turbojpeg/jquant2.c +1285 -0
  76. data/ext/image_intensities/turbojpeg/jsimd.h +117 -0
  77. data/ext/image_intensities/turbojpeg/jsimd_none.c +418 -0
  78. data/ext/image_intensities/turbojpeg/jsimddct.h +70 -0
  79. data/ext/image_intensities/turbojpeg/jstdhuff.c +143 -0
  80. data/ext/image_intensities/turbojpeg/jutils.c +133 -0
  81. data/ext/image_intensities/turbojpeg/jversion.h +52 -0
  82. data/ext/image_intensities/turbojpeg/libturbojpeg.a +0 -0
  83. data/ext/image_intensities/turbojpeg/rdbmp.c +689 -0
  84. data/ext/image_intensities/turbojpeg/rdppm.c +766 -0
  85. data/ext/image_intensities/turbojpeg/tjutil.h +47 -0
  86. data/ext/image_intensities/turbojpeg/transupp.c +1628 -0
  87. data/ext/image_intensities/turbojpeg/transupp.h +210 -0
  88. data/ext/image_intensities/turbojpeg/turbojpeg.c +2150 -0
  89. data/ext/image_intensities/turbojpeg/wrbmp.c +558 -0
  90. data/ext/image_intensities/turbojpeg/wrppm.c +365 -0
  91. data/image_intensities.gemspec +1 -1
  92. data/lib/image_intensities/version.rb +1 -1
  93. metadata +91 -3
@@ -0,0 +1,518 @@
1
+ /*
2
+ * jdsample.c
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1991-1996, Thomas G. Lane.
6
+ * libjpeg-turbo Modifications:
7
+ * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
+ * Copyright (C) 2010, 2015-2016, D. R. Commander.
9
+ * Copyright (C) 2014, MIPS Technologies, Inc., California.
10
+ * Copyright (C) 2015, Google, Inc.
11
+ * Copyright (C) 2019, Arm Limited.
12
+ * For conditions of distribution and use, see the accompanying README.ijg
13
+ * file.
14
+ *
15
+ * This file contains upsampling routines.
16
+ *
17
+ * Upsampling input data is counted in "row groups". A row group
18
+ * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
19
+ * sample rows of each component. Upsampling will normally produce
20
+ * max_v_samp_factor pixel rows from each row group (but this could vary
21
+ * if the upsampler is applying a scale factor of its own).
22
+ *
23
+ * An excellent reference for image resampling is
24
+ * Digital Image Warping, George Wolberg, 1990.
25
+ * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
26
+ */
27
+
28
+ #include "jinclude.h"
29
+ #include "jdsample.h"
30
+ #include "jsimd.h"
31
+ #include "jpegcomp.h"
32
+
33
+
34
+
35
+ /*
36
+ * Initialize for an upsampling pass.
37
+ */
38
+
39
+ METHODDEF(void)
40
+ start_pass_upsample(j_decompress_ptr cinfo)
41
+ {
42
+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
43
+
44
+ /* Mark the conversion buffer empty */
45
+ upsample->next_row_out = cinfo->max_v_samp_factor;
46
+ /* Initialize total-height counter for detecting bottom of image */
47
+ upsample->rows_to_go = cinfo->output_height;
48
+ }
49
+
50
+
51
+ /*
52
+ * Control routine to do upsampling (and color conversion).
53
+ *
54
+ * In this version we upsample each component independently.
55
+ * We upsample one row group into the conversion buffer, then apply
56
+ * color conversion a row at a time.
57
+ */
58
+
59
+ METHODDEF(void)
60
+ sep_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
61
+ JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
62
+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
63
+ JDIMENSION out_rows_avail)
64
+ {
65
+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
66
+ int ci;
67
+ jpeg_component_info *compptr;
68
+ JDIMENSION num_rows;
69
+
70
+ /* Fill the conversion buffer, if it's empty */
71
+ if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
72
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
73
+ ci++, compptr++) {
74
+ /* Invoke per-component upsample method. Notice we pass a POINTER
75
+ * to color_buf[ci], so that fullsize_upsample can change it.
76
+ */
77
+ (*upsample->methods[ci]) (cinfo, compptr,
78
+ input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
79
+ upsample->color_buf + ci);
80
+ }
81
+ upsample->next_row_out = 0;
82
+ }
83
+
84
+ /* Color-convert and emit rows */
85
+
86
+ /* How many we have in the buffer: */
87
+ num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
88
+ /* Not more than the distance to the end of the image. Need this test
89
+ * in case the image height is not a multiple of max_v_samp_factor:
90
+ */
91
+ if (num_rows > upsample->rows_to_go)
92
+ num_rows = upsample->rows_to_go;
93
+ /* And not more than what the client can accept: */
94
+ out_rows_avail -= *out_row_ctr;
95
+ if (num_rows > out_rows_avail)
96
+ num_rows = out_rows_avail;
97
+
98
+ (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
99
+ (JDIMENSION)upsample->next_row_out,
100
+ output_buf + *out_row_ctr, (int)num_rows);
101
+
102
+ /* Adjust counts */
103
+ *out_row_ctr += num_rows;
104
+ upsample->rows_to_go -= num_rows;
105
+ upsample->next_row_out += num_rows;
106
+ /* When the buffer is emptied, declare this input row group consumed */
107
+ if (upsample->next_row_out >= cinfo->max_v_samp_factor)
108
+ (*in_row_group_ctr)++;
109
+ }
110
+
111
+
112
+ /*
113
+ * These are the routines invoked by sep_upsample to upsample pixel values
114
+ * of a single component. One row group is processed per call.
115
+ */
116
+
117
+
118
+ /*
119
+ * For full-size components, we just make color_buf[ci] point at the
120
+ * input buffer, and thus avoid copying any data. Note that this is
121
+ * safe only because sep_upsample doesn't declare the input row group
122
+ * "consumed" until we are done color converting and emitting it.
123
+ */
124
+
125
+ METHODDEF(void)
126
+ fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
127
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
128
+ {
129
+ *output_data_ptr = input_data;
130
+ }
131
+
132
+
133
+ /*
134
+ * This is a no-op version used for "uninteresting" components.
135
+ * These components will not be referenced by color conversion.
136
+ */
137
+
138
+ METHODDEF(void)
139
+ noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
140
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
141
+ {
142
+ *output_data_ptr = NULL; /* safety check */
143
+ }
144
+
145
+
146
+ /*
147
+ * This version handles any integral sampling ratios.
148
+ * This is not used for typical JPEG files, so it need not be fast.
149
+ * Nor, for that matter, is it particularly accurate: the algorithm is
150
+ * simple replication of the input pixel onto the corresponding output
151
+ * pixels. The hi-falutin sampling literature refers to this as a
152
+ * "box filter". A box filter tends to introduce visible artifacts,
153
+ * so if you are actually going to use 3:1 or 4:1 sampling ratios
154
+ * you would be well advised to improve this code.
155
+ */
156
+
157
+ METHODDEF(void)
158
+ int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
159
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
160
+ {
161
+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
162
+ JSAMPARRAY output_data = *output_data_ptr;
163
+ register JSAMPROW inptr, outptr;
164
+ register JSAMPLE invalue;
165
+ register int h;
166
+ JSAMPROW outend;
167
+ int h_expand, v_expand;
168
+ int inrow, outrow;
169
+
170
+ h_expand = upsample->h_expand[compptr->component_index];
171
+ v_expand = upsample->v_expand[compptr->component_index];
172
+
173
+ inrow = outrow = 0;
174
+ while (outrow < cinfo->max_v_samp_factor) {
175
+ /* Generate one output row with proper horizontal expansion */
176
+ inptr = input_data[inrow];
177
+ outptr = output_data[outrow];
178
+ outend = outptr + cinfo->output_width;
179
+ while (outptr < outend) {
180
+ invalue = *inptr++; /* don't need GETJSAMPLE() here */
181
+ for (h = h_expand; h > 0; h--) {
182
+ *outptr++ = invalue;
183
+ }
184
+ }
185
+ /* Generate any additional output rows by duplicating the first one */
186
+ if (v_expand > 1) {
187
+ jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
188
+ v_expand - 1, cinfo->output_width);
189
+ }
190
+ inrow++;
191
+ outrow += v_expand;
192
+ }
193
+ }
194
+
195
+
196
+ /*
197
+ * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
198
+ * It's still a box filter.
199
+ */
200
+
201
+ METHODDEF(void)
202
+ h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
203
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
204
+ {
205
+ JSAMPARRAY output_data = *output_data_ptr;
206
+ register JSAMPROW inptr, outptr;
207
+ register JSAMPLE invalue;
208
+ JSAMPROW outend;
209
+ int inrow;
210
+
211
+ for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
212
+ inptr = input_data[inrow];
213
+ outptr = output_data[inrow];
214
+ outend = outptr + cinfo->output_width;
215
+ while (outptr < outend) {
216
+ invalue = *inptr++; /* don't need GETJSAMPLE() here */
217
+ *outptr++ = invalue;
218
+ *outptr++ = invalue;
219
+ }
220
+ }
221
+ }
222
+
223
+
224
+ /*
225
+ * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
226
+ * It's still a box filter.
227
+ */
228
+
229
+ METHODDEF(void)
230
+ h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
231
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
232
+ {
233
+ JSAMPARRAY output_data = *output_data_ptr;
234
+ register JSAMPROW inptr, outptr;
235
+ register JSAMPLE invalue;
236
+ JSAMPROW outend;
237
+ int inrow, outrow;
238
+
239
+ inrow = outrow = 0;
240
+ while (outrow < cinfo->max_v_samp_factor) {
241
+ inptr = input_data[inrow];
242
+ outptr = output_data[outrow];
243
+ outend = outptr + cinfo->output_width;
244
+ while (outptr < outend) {
245
+ invalue = *inptr++; /* don't need GETJSAMPLE() here */
246
+ *outptr++ = invalue;
247
+ *outptr++ = invalue;
248
+ }
249
+ jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
250
+ cinfo->output_width);
251
+ inrow++;
252
+ outrow += 2;
253
+ }
254
+ }
255
+
256
+
257
+ /*
258
+ * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
259
+ *
260
+ * The upsampling algorithm is linear interpolation between pixel centers,
261
+ * also known as a "triangle filter". This is a good compromise between
262
+ * speed and visual quality. The centers of the output pixels are 1/4 and 3/4
263
+ * of the way between input pixel centers.
264
+ *
265
+ * A note about the "bias" calculations: when rounding fractional values to
266
+ * integer, we do not want to always round 0.5 up to the next integer.
267
+ * If we did that, we'd introduce a noticeable bias towards larger values.
268
+ * Instead, this code is arranged so that 0.5 will be rounded up or down at
269
+ * alternate pixel locations (a simple ordered dither pattern).
270
+ */
271
+
272
+ METHODDEF(void)
273
+ h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
274
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
275
+ {
276
+ JSAMPARRAY output_data = *output_data_ptr;
277
+ register JSAMPROW inptr, outptr;
278
+ register int invalue;
279
+ register JDIMENSION colctr;
280
+ int inrow;
281
+
282
+ for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
283
+ inptr = input_data[inrow];
284
+ outptr = output_data[inrow];
285
+ /* Special case for first column */
286
+ invalue = GETJSAMPLE(*inptr++);
287
+ *outptr++ = (JSAMPLE)invalue;
288
+ *outptr++ = (JSAMPLE)((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
289
+
290
+ for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
291
+ /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
292
+ invalue = GETJSAMPLE(*inptr++) * 3;
293
+ *outptr++ = (JSAMPLE)((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
294
+ *outptr++ = (JSAMPLE)((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
295
+ }
296
+
297
+ /* Special case for last column */
298
+ invalue = GETJSAMPLE(*inptr);
299
+ *outptr++ = (JSAMPLE)((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
300
+ *outptr++ = (JSAMPLE)invalue;
301
+ }
302
+ }
303
+
304
+
305
+ /*
306
+ * Fancy processing for 1:1 horizontal and 2:1 vertical (4:4:0 subsampling).
307
+ *
308
+ * This is a less common case, but it can be encountered when losslessly
309
+ * rotating/transposing a JPEG file that uses 4:2:2 chroma subsampling.
310
+ */
311
+
312
+ METHODDEF(void)
313
+ h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
314
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
315
+ {
316
+ JSAMPARRAY output_data = *output_data_ptr;
317
+ JSAMPROW inptr0, inptr1, outptr;
318
+ #if BITS_IN_JSAMPLE == 8
319
+ int thiscolsum, bias;
320
+ #else
321
+ JLONG thiscolsum, bias;
322
+ #endif
323
+ JDIMENSION colctr;
324
+ int inrow, outrow, v;
325
+
326
+ inrow = outrow = 0;
327
+ while (outrow < cinfo->max_v_samp_factor) {
328
+ for (v = 0; v < 2; v++) {
329
+ /* inptr0 points to nearest input row, inptr1 points to next nearest */
330
+ inptr0 = input_data[inrow];
331
+ if (v == 0) { /* next nearest is row above */
332
+ inptr1 = input_data[inrow - 1];
333
+ bias = 1;
334
+ } else { /* next nearest is row below */
335
+ inptr1 = input_data[inrow + 1];
336
+ bias = 2;
337
+ }
338
+ outptr = output_data[outrow++];
339
+
340
+ for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
341
+ thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
342
+ *outptr++ = (JSAMPLE)((thiscolsum + bias) >> 2);
343
+ }
344
+ }
345
+ inrow++;
346
+ }
347
+ }
348
+
349
+
350
+ /*
351
+ * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
352
+ * Again a triangle filter; see comments for h2v1 case, above.
353
+ *
354
+ * It is OK for us to reference the adjacent input rows because we demanded
355
+ * context from the main buffer controller (see initialization code).
356
+ */
357
+
358
+ METHODDEF(void)
359
+ h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
360
+ JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
361
+ {
362
+ JSAMPARRAY output_data = *output_data_ptr;
363
+ register JSAMPROW inptr0, inptr1, outptr;
364
+ #if BITS_IN_JSAMPLE == 8
365
+ register int thiscolsum, lastcolsum, nextcolsum;
366
+ #else
367
+ register JLONG thiscolsum, lastcolsum, nextcolsum;
368
+ #endif
369
+ register JDIMENSION colctr;
370
+ int inrow, outrow, v;
371
+
372
+ inrow = outrow = 0;
373
+ while (outrow < cinfo->max_v_samp_factor) {
374
+ for (v = 0; v < 2; v++) {
375
+ /* inptr0 points to nearest input row, inptr1 points to next nearest */
376
+ inptr0 = input_data[inrow];
377
+ if (v == 0) /* next nearest is row above */
378
+ inptr1 = input_data[inrow - 1];
379
+ else /* next nearest is row below */
380
+ inptr1 = input_data[inrow + 1];
381
+ outptr = output_data[outrow++];
382
+
383
+ /* Special case for first column */
384
+ thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
385
+ nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
386
+ *outptr++ = (JSAMPLE)((thiscolsum * 4 + 8) >> 4);
387
+ *outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
388
+ lastcolsum = thiscolsum; thiscolsum = nextcolsum;
389
+
390
+ for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
391
+ /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
392
+ /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
393
+ nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
394
+ *outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
395
+ *outptr++ = (JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
396
+ lastcolsum = thiscolsum; thiscolsum = nextcolsum;
397
+ }
398
+
399
+ /* Special case for last column */
400
+ *outptr++ = (JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
401
+ *outptr++ = (JSAMPLE)((thiscolsum * 4 + 7) >> 4);
402
+ }
403
+ inrow++;
404
+ }
405
+ }
406
+
407
+
408
+ /*
409
+ * Module initialization routine for upsampling.
410
+ */
411
+
412
+ GLOBAL(void)
413
+ jinit_upsampler(j_decompress_ptr cinfo)
414
+ {
415
+ my_upsample_ptr upsample;
416
+ int ci;
417
+ jpeg_component_info *compptr;
418
+ boolean need_buffer, do_fancy;
419
+ int h_in_group, v_in_group, h_out_group, v_out_group;
420
+
421
+ if (!cinfo->master->jinit_upsampler_no_alloc) {
422
+ upsample = (my_upsample_ptr)
423
+ (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
424
+ sizeof(my_upsampler));
425
+ cinfo->upsample = (struct jpeg_upsampler *)upsample;
426
+ upsample->pub.start_pass = start_pass_upsample;
427
+ upsample->pub.upsample = sep_upsample;
428
+ upsample->pub.need_context_rows = FALSE; /* until we find out differently */
429
+ } else
430
+ upsample = (my_upsample_ptr)cinfo->upsample;
431
+
432
+ if (cinfo->CCIR601_sampling) /* this isn't supported */
433
+ ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
434
+
435
+ /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
436
+ * so don't ask for it.
437
+ */
438
+ do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
439
+
440
+ /* Verify we can handle the sampling factors, select per-component methods,
441
+ * and create storage as needed.
442
+ */
443
+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
444
+ ci++, compptr++) {
445
+ /* Compute size of an "input group" after IDCT scaling. This many samples
446
+ * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
447
+ */
448
+ h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
449
+ cinfo->_min_DCT_scaled_size;
450
+ v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
451
+ cinfo->_min_DCT_scaled_size;
452
+ h_out_group = cinfo->max_h_samp_factor;
453
+ v_out_group = cinfo->max_v_samp_factor;
454
+ upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
455
+ need_buffer = TRUE;
456
+ if (!compptr->component_needed) {
457
+ /* Don't bother to upsample an uninteresting component. */
458
+ upsample->methods[ci] = noop_upsample;
459
+ need_buffer = FALSE;
460
+ } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
461
+ /* Fullsize components can be processed without any work. */
462
+ upsample->methods[ci] = fullsize_upsample;
463
+ need_buffer = FALSE;
464
+ } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
465
+ /* Special cases for 2h1v upsampling */
466
+ if (do_fancy && compptr->downsampled_width > 2) {
467
+ if (jsimd_can_h2v1_fancy_upsample())
468
+ upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
469
+ else
470
+ upsample->methods[ci] = h2v1_fancy_upsample;
471
+ } else {
472
+ if (jsimd_can_h2v1_upsample())
473
+ upsample->methods[ci] = jsimd_h2v1_upsample;
474
+ else
475
+ upsample->methods[ci] = h2v1_upsample;
476
+ }
477
+ } else if (h_in_group == h_out_group &&
478
+ v_in_group * 2 == v_out_group && do_fancy) {
479
+ /* Non-fancy upsampling is handled by the generic method */
480
+ upsample->methods[ci] = h1v2_fancy_upsample;
481
+ upsample->pub.need_context_rows = TRUE;
482
+ } else if (h_in_group * 2 == h_out_group &&
483
+ v_in_group * 2 == v_out_group) {
484
+ /* Special cases for 2h2v upsampling */
485
+ if (do_fancy && compptr->downsampled_width > 2) {
486
+ if (jsimd_can_h2v2_fancy_upsample())
487
+ upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
488
+ else
489
+ upsample->methods[ci] = h2v2_fancy_upsample;
490
+ upsample->pub.need_context_rows = TRUE;
491
+ } else {
492
+ if (jsimd_can_h2v2_upsample())
493
+ upsample->methods[ci] = jsimd_h2v2_upsample;
494
+ else
495
+ upsample->methods[ci] = h2v2_upsample;
496
+ }
497
+ } else if ((h_out_group % h_in_group) == 0 &&
498
+ (v_out_group % v_in_group) == 0) {
499
+ /* Generic integral-factors upsampling method */
500
+ #if defined(__mips__)
501
+ if (jsimd_can_int_upsample())
502
+ upsample->methods[ci] = jsimd_int_upsample;
503
+ else
504
+ #endif
505
+ upsample->methods[ci] = int_upsample;
506
+ upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
507
+ upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
508
+ } else
509
+ ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
510
+ if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
511
+ upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
512
+ ((j_common_ptr)cinfo, JPOOL_IMAGE,
513
+ (JDIMENSION)jround_up((long)cinfo->output_width,
514
+ (long)cinfo->max_h_samp_factor),
515
+ (JDIMENSION)cinfo->max_v_samp_factor);
516
+ }
517
+ }
518
+ }
@@ -0,0 +1,50 @@
1
+ /*
2
+ * jdsample.h
3
+ *
4
+ * This file was part of the Independent JPEG Group's software:
5
+ * Copyright (C) 1991-1996, Thomas G. Lane.
6
+ * For conditions of distribution and use, see the accompanying README.ijg
7
+ * file.
8
+ */
9
+
10
+ #define JPEG_INTERNALS
11
+ #include "jpeglib.h"
12
+
13
+
14
+ /* Pointer to routine to upsample a single component */
15
+ typedef void (*upsample1_ptr) (j_decompress_ptr cinfo,
16
+ jpeg_component_info *compptr,
17
+ JSAMPARRAY input_data,
18
+ JSAMPARRAY *output_data_ptr);
19
+
20
+ /* Private subobject */
21
+
22
+ typedef struct {
23
+ struct jpeg_upsampler pub; /* public fields */
24
+
25
+ /* Color conversion buffer. When using separate upsampling and color
26
+ * conversion steps, this buffer holds one upsampled row group until it
27
+ * has been color converted and output.
28
+ * Note: we do not allocate any storage for component(s) which are full-size,
29
+ * ie do not need rescaling. The corresponding entry of color_buf[] is
30
+ * simply set to point to the input data array, thereby avoiding copying.
31
+ */
32
+ JSAMPARRAY color_buf[MAX_COMPONENTS];
33
+
34
+ /* Per-component upsampling method pointers */
35
+ upsample1_ptr methods[MAX_COMPONENTS];
36
+
37
+ int next_row_out; /* counts rows emitted from color_buf */
38
+ JDIMENSION rows_to_go; /* counts rows remaining in image */
39
+
40
+ /* Height of an input row group for each component. */
41
+ int rowgroup_height[MAX_COMPONENTS];
42
+
43
+ /* These arrays save pixel expansion factors so that int_expand need not
44
+ * recompute them each time. They are unused for other upsampling methods.
45
+ */
46
+ UINT8 h_expand[MAX_COMPONENTS];
47
+ UINT8 v_expand[MAX_COMPONENTS];
48
+ } my_upsampler;
49
+
50
+ typedef my_upsampler *my_upsample_ptr;