Coverage Report

Created: 2024-05-04 12:45

/proc/self/cwd/external/libjpeg_turbo/jdmerge.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jdmerge.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1996, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2009, 2011, 2014-2015, 2020, D. R. Commander.
9
 * Copyright (C) 2013, Linaro Limited.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains code for merged upsampling/color conversion.
14
 *
15
 * This file combines functions from jdsample.c and jdcolor.c;
16
 * read those files first to understand what's going on.
17
 *
18
 * When the chroma components are to be upsampled by simple replication
19
 * (ie, box filtering), we can save some work in color conversion by
20
 * calculating all the output pixels corresponding to a pair of chroma
21
 * samples at one time.  In the conversion equations
22
 *      R = Y           + K1 * Cr
23
 *      G = Y + K2 * Cb + K3 * Cr
24
 *      B = Y + K4 * Cb
25
 * only the Y term varies among the group of pixels corresponding to a pair
26
 * of chroma samples, so the rest of the terms can be calculated just once.
27
 * At typical sampling ratios, this eliminates half or three-quarters of the
28
 * multiplications needed for color conversion.
29
 *
30
 * This file currently provides implementations for the following cases:
31
 *      YCbCr => RGB color conversion only.
32
 *      Sampling ratios of 2h1v or 2h2v.
33
 *      No scaling needed at upsample time.
34
 *      Corner-aligned (non-CCIR601) sampling alignment.
35
 * Other special cases could be added, but in most applications these are
36
 * the only common cases.  (For uncommon cases we fall back on the more
37
 * general code in jdsample.c and jdcolor.c.)
38
 */
39
40
#define JPEG_INTERNALS
41
#include "jinclude.h"
42
#include "jpeglib.h"
43
#include "jdmerge.h"
44
#include "jsimd.h"
45
#include "jconfigint.h"
46
47
#ifdef UPSAMPLE_MERGING_SUPPORTED
48
49
50
0
#define SCALEBITS       16      /* speediest right-shift on some machines */
51
0
#define ONE_HALF        ((JLONG)1 << (SCALEBITS - 1))
52
0
#define FIX(x)          ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
53
54
55
/* Include inline routines for colorspace extensions */
56
57
#include "jdmrgext.c"
58
#undef RGB_RED
59
#undef RGB_GREEN
60
#undef RGB_BLUE
61
#undef RGB_PIXELSIZE
62
63
0
#define RGB_RED  EXT_RGB_RED
64
0
#define RGB_GREEN  EXT_RGB_GREEN
65
0
#define RGB_BLUE  EXT_RGB_BLUE
66
0
#define RGB_PIXELSIZE  EXT_RGB_PIXELSIZE
67
#define h2v1_merged_upsample_internal  extrgb_h2v1_merged_upsample_internal
68
#define h2v2_merged_upsample_internal  extrgb_h2v2_merged_upsample_internal
69
#include "jdmrgext.c"
70
#undef RGB_RED
71
#undef RGB_GREEN
72
#undef RGB_BLUE
73
#undef RGB_PIXELSIZE
74
#undef h2v1_merged_upsample_internal
75
#undef h2v2_merged_upsample_internal
76
77
0
#define RGB_RED  EXT_RGBX_RED
78
0
#define RGB_GREEN  EXT_RGBX_GREEN
79
0
#define RGB_BLUE  EXT_RGBX_BLUE
80
0
#define RGB_ALPHA  3
81
0
#define RGB_PIXELSIZE  EXT_RGBX_PIXELSIZE
82
#define h2v1_merged_upsample_internal  extrgbx_h2v1_merged_upsample_internal
83
#define h2v2_merged_upsample_internal  extrgbx_h2v2_merged_upsample_internal
84
#include "jdmrgext.c"
85
#undef RGB_RED
86
#undef RGB_GREEN
87
#undef RGB_BLUE
88
#undef RGB_ALPHA
89
#undef RGB_PIXELSIZE
90
#undef h2v1_merged_upsample_internal
91
#undef h2v2_merged_upsample_internal
92
93
0
#define RGB_RED  EXT_BGR_RED
94
0
#define RGB_GREEN  EXT_BGR_GREEN
95
0
#define RGB_BLUE  EXT_BGR_BLUE
96
0
#define RGB_PIXELSIZE  EXT_BGR_PIXELSIZE
97
#define h2v1_merged_upsample_internal  extbgr_h2v1_merged_upsample_internal
98
#define h2v2_merged_upsample_internal  extbgr_h2v2_merged_upsample_internal
99
#include "jdmrgext.c"
100
#undef RGB_RED
101
#undef RGB_GREEN
102
#undef RGB_BLUE
103
#undef RGB_PIXELSIZE
104
#undef h2v1_merged_upsample_internal
105
#undef h2v2_merged_upsample_internal
106
107
0
#define RGB_RED  EXT_BGRX_RED
108
0
#define RGB_GREEN  EXT_BGRX_GREEN
109
0
#define RGB_BLUE  EXT_BGRX_BLUE
110
0
#define RGB_ALPHA  3
111
0
#define RGB_PIXELSIZE  EXT_BGRX_PIXELSIZE
112
#define h2v1_merged_upsample_internal  extbgrx_h2v1_merged_upsample_internal
113
#define h2v2_merged_upsample_internal  extbgrx_h2v2_merged_upsample_internal
114
#include "jdmrgext.c"
115
#undef RGB_RED
116
#undef RGB_GREEN
117
#undef RGB_BLUE
118
#undef RGB_ALPHA
119
#undef RGB_PIXELSIZE
120
#undef h2v1_merged_upsample_internal
121
#undef h2v2_merged_upsample_internal
122
123
0
#define RGB_RED  EXT_XBGR_RED
124
0
#define RGB_GREEN  EXT_XBGR_GREEN
125
0
#define RGB_BLUE  EXT_XBGR_BLUE
126
0
#define RGB_ALPHA  0
127
0
#define RGB_PIXELSIZE  EXT_XBGR_PIXELSIZE
128
#define h2v1_merged_upsample_internal  extxbgr_h2v1_merged_upsample_internal
129
#define h2v2_merged_upsample_internal  extxbgr_h2v2_merged_upsample_internal
130
#include "jdmrgext.c"
131
#undef RGB_RED
132
#undef RGB_GREEN
133
#undef RGB_BLUE
134
#undef RGB_ALPHA
135
#undef RGB_PIXELSIZE
136
#undef h2v1_merged_upsample_internal
137
#undef h2v2_merged_upsample_internal
138
139
0
#define RGB_RED  EXT_XRGB_RED
140
0
#define RGB_GREEN  EXT_XRGB_GREEN
141
0
#define RGB_BLUE  EXT_XRGB_BLUE
142
0
#define RGB_ALPHA  0
143
0
#define RGB_PIXELSIZE  EXT_XRGB_PIXELSIZE
144
#define h2v1_merged_upsample_internal  extxrgb_h2v1_merged_upsample_internal
145
#define h2v2_merged_upsample_internal  extxrgb_h2v2_merged_upsample_internal
146
#include "jdmrgext.c"
147
#undef RGB_RED
148
#undef RGB_GREEN
149
#undef RGB_BLUE
150
#undef RGB_ALPHA
151
#undef RGB_PIXELSIZE
152
#undef h2v1_merged_upsample_internal
153
#undef h2v2_merged_upsample_internal
154
155
156
/*
157
 * Initialize tables for YCC->RGB colorspace conversion.
158
 * This is taken directly from jdcolor.c; see that file for more info.
159
 */
160
161
LOCAL(void)
162
build_ycc_rgb_table(j_decompress_ptr cinfo)
163
0
{
164
0
  my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
165
0
  int i;
166
0
  JLONG x;
167
0
  SHIFT_TEMPS
168
169
0
  upsample->Cr_r_tab = (int *)
170
0
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
171
0
                                (MAXJSAMPLE + 1) * sizeof(int));
172
0
  upsample->Cb_b_tab = (int *)
173
0
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
174
0
                                (MAXJSAMPLE + 1) * sizeof(int));
175
0
  upsample->Cr_g_tab = (JLONG *)
176
0
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
177
0
                                (MAXJSAMPLE + 1) * sizeof(JLONG));
178
0
  upsample->Cb_g_tab = (JLONG *)
179
0
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
180
0
                                (MAXJSAMPLE + 1) * sizeof(JLONG));
181
182
0
  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
183
    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
184
    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
185
    /* Cr=>R value is nearest int to 1.40200 * x */
186
0
    upsample->Cr_r_tab[i] = (int)
187
0
                    RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
188
    /* Cb=>B value is nearest int to 1.77200 * x */
189
0
    upsample->Cb_b_tab[i] = (int)
190
0
                    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
191
    /* Cr=>G value is scaled-up -0.71414 * x */
192
0
    upsample->Cr_g_tab[i] = (-FIX(0.71414)) * x;
193
    /* Cb=>G value is scaled-up -0.34414 * x */
194
    /* We also add in ONE_HALF so that need not do it in inner loop */
195
0
    upsample->Cb_g_tab[i] = (-FIX(0.34414)) * x + ONE_HALF;
196
0
  }
197
0
}
198
199
200
/*
201
 * Initialize for an upsampling pass.
202
 */
203
204
METHODDEF(void)
205
start_pass_merged_upsample(j_decompress_ptr cinfo)
206
0
{
207
0
  my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
208
209
  /* Mark the spare buffer empty */
210
0
  upsample->spare_full = FALSE;
211
  /* Initialize total-height counter for detecting bottom of image */
212
0
  upsample->rows_to_go = cinfo->output_height;
213
0
}
214
215
216
/*
217
 * Control routine to do upsampling (and color conversion).
218
 *
219
 * The control routine just handles the row buffering considerations.
220
 */
221
222
METHODDEF(void)
223
merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
224
                   JDIMENSION *in_row_group_ctr,
225
                   JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
226
                   JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
227
/* 2:1 vertical sampling case: may need a spare row. */
228
0
{
229
0
  my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
230
0
  JSAMPROW work_ptrs[2];
231
0
  JDIMENSION num_rows;          /* number of rows returned to caller */
232
233
0
  if (upsample->spare_full) {
234
    /* If we have a spare row saved from a previous cycle, just return it. */
235
0
    JDIMENSION size = upsample->out_row_width;
236
0
    if (cinfo->out_color_space == JCS_RGB565)
237
0
      size = cinfo->output_width * 2;
238
0
    jcopy_sample_rows(&upsample->spare_row, 0, output_buf + *out_row_ctr, 0, 1,
239
0
                      size);
240
0
    num_rows = 1;
241
0
    upsample->spare_full = FALSE;
242
0
  } else {
243
    /* Figure number of rows to return to caller. */
244
0
    num_rows = 2;
245
    /* Not more than the distance to the end of the image. */
246
0
    if (num_rows > upsample->rows_to_go)
247
0
      num_rows = upsample->rows_to_go;
248
    /* And not more than what the client can accept: */
249
0
    out_rows_avail -= *out_row_ctr;
250
0
    if (num_rows > out_rows_avail)
251
0
      num_rows = out_rows_avail;
252
    /* Create output pointer array for upsampler. */
253
0
    work_ptrs[0] = output_buf[*out_row_ctr];
254
0
    if (num_rows > 1) {
255
0
      work_ptrs[1] = output_buf[*out_row_ctr + 1];
256
0
    } else {
257
0
      work_ptrs[1] = upsample->spare_row;
258
0
      upsample->spare_full = TRUE;
259
0
    }
260
    /* Now do the upsampling. */
261
0
    (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
262
0
  }
263
264
  /* Adjust counts */
265
0
  *out_row_ctr += num_rows;
266
0
  upsample->rows_to_go -= num_rows;
267
  /* When the buffer is emptied, declare this input row group consumed */
268
0
  if (!upsample->spare_full)
269
0
    (*in_row_group_ctr)++;
270
0
}
271
272
273
METHODDEF(void)
274
merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
275
                   JDIMENSION *in_row_group_ctr,
276
                   JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
277
                   JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
278
/* 1:1 vertical sampling case: much easier, never need a spare row. */
279
0
{
280
0
  my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
281
282
  /* Just do the upsampling. */
283
0
  (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
284
0
                         output_buf + *out_row_ctr);
285
  /* Adjust counts */
286
0
  (*out_row_ctr)++;
287
0
  (*in_row_group_ctr)++;
288
0
}
289
290
291
/*
292
 * These are the routines invoked by the control routines to do
293
 * the actual upsampling/conversion.  One row group is processed per call.
294
 *
295
 * Note: since we may be writing directly into application-supplied buffers,
296
 * we have to be honest about the output width; we can't assume the buffer
297
 * has been rounded up to an even width.
298
 */
299
300
301
/*
302
 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
303
 */
304
305
METHODDEF(void)
306
h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
307
                     JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
308
0
{
309
0
  switch (cinfo->out_color_space) {
310
0
  case JCS_EXT_RGB:
311
0
    extrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
312
0
                                         output_buf);
313
0
    break;
314
0
  case JCS_EXT_RGBX:
315
0
  case JCS_EXT_RGBA:
316
0
    extrgbx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
317
0
                                          output_buf);
318
0
    break;
319
0
  case JCS_EXT_BGR:
320
0
    extbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
321
0
                                         output_buf);
322
0
    break;
323
0
  case JCS_EXT_BGRX:
324
0
  case JCS_EXT_BGRA:
325
0
    extbgrx_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
326
0
                                          output_buf);
327
0
    break;
328
0
  case JCS_EXT_XBGR:
329
0
  case JCS_EXT_ABGR:
330
0
    extxbgr_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
331
0
                                          output_buf);
332
0
    break;
333
0
  case JCS_EXT_XRGB:
334
0
  case JCS_EXT_ARGB:
335
0
    extxrgb_h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
336
0
                                          output_buf);
337
0
    break;
338
0
  default:
339
0
    h2v1_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
340
0
                                  output_buf);
341
0
    break;
342
0
  }
343
0
}
344
345
346
/*
347
 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
348
 */
349
350
METHODDEF(void)
351
h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
352
                     JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
353
0
{
354
0
  switch (cinfo->out_color_space) {
355
0
  case JCS_EXT_RGB:
356
0
    extrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
357
0
                                         output_buf);
358
0
    break;
359
0
  case JCS_EXT_RGBX:
360
0
  case JCS_EXT_RGBA:
361
0
    extrgbx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
362
0
                                          output_buf);
363
0
    break;
364
0
  case JCS_EXT_BGR:
365
0
    extbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
366
0
                                         output_buf);
367
0
    break;
368
0
  case JCS_EXT_BGRX:
369
0
  case JCS_EXT_BGRA:
370
0
    extbgrx_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
371
0
                                          output_buf);
372
0
    break;
373
0
  case JCS_EXT_XBGR:
374
0
  case JCS_EXT_ABGR:
375
0
    extxbgr_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
376
0
                                          output_buf);
377
0
    break;
378
0
  case JCS_EXT_XRGB:
379
0
  case JCS_EXT_ARGB:
380
0
    extxrgb_h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
381
0
                                          output_buf);
382
0
    break;
383
0
  default:
384
0
    h2v2_merged_upsample_internal(cinfo, input_buf, in_row_group_ctr,
385
0
                                  output_buf);
386
0
    break;
387
0
  }
388
0
}
389
390
391
/*
392
 * RGB565 conversion
393
 */
394
395
#define PACK_SHORT_565_LE(r, g, b) \
396
0
  ((((r) << 8) & 0xF800) | (((g) << 3) & 0x7E0) | ((b) >> 3))
397
#define PACK_SHORT_565_BE(r, g, b) \
398
0
  (((r) & 0xF8) | ((g) >> 5) | (((g) << 11) & 0xE000) | (((b) << 5) & 0x1F00))
399
400
0
#define PACK_TWO_PIXELS_LE(l, r)    ((r << 16) | l)
401
0
#define PACK_TWO_PIXELS_BE(l, r)    ((l << 16) | r)
402
403
0
#define WRITE_TWO_PIXELS_LE(addr, pixels) { \
404
0
  ((INT16 *)(addr))[0] = (INT16)(pixels); \
405
0
  ((INT16 *)(addr))[1] = (INT16)((pixels) >> 16); \
406
0
}
407
0
#define WRITE_TWO_PIXELS_BE(addr, pixels) { \
408
0
  ((INT16 *)(addr))[1] = (INT16)(pixels); \
409
0
  ((INT16 *)(addr))[0] = (INT16)((pixels) >> 16); \
410
0
}
411
412
0
#define DITHER_565_R(r, dither)  ((r) + ((dither) & 0xFF))
413
0
#define DITHER_565_G(g, dither)  ((g) + (((dither) & 0xFF) >> 1))
414
0
#define DITHER_565_B(b, dither)  ((b) + ((dither) & 0xFF))
415
416
417
/* Declarations for ordered dithering
418
 *
419
 * We use a 4x4 ordered dither array packed into 32 bits.  This array is
420
 * sufficient for dithering RGB888 to RGB565.
421
 */
422
423
0
#define DITHER_MASK       0x3
424
0
#define DITHER_ROTATE(x)  ((((x) & 0xFF) << 24) | (((x) >> 8) & 0x00FFFFFF))
425
static const JLONG dither_matrix[4] = {
426
  0x0008020A,
427
  0x0C040E06,
428
  0x030B0109,
429
  0x0F070D05
430
};
431
432
433
/* Include inline routines for RGB565 conversion */
434
435
0
#define PACK_SHORT_565  PACK_SHORT_565_LE
436
0
#define PACK_TWO_PIXELS  PACK_TWO_PIXELS_LE
437
0
#define WRITE_TWO_PIXELS  WRITE_TWO_PIXELS_LE
438
#define h2v1_merged_upsample_565_internal  h2v1_merged_upsample_565_le
439
#define h2v1_merged_upsample_565D_internal  h2v1_merged_upsample_565D_le
440
#define h2v2_merged_upsample_565_internal  h2v2_merged_upsample_565_le
441
#define h2v2_merged_upsample_565D_internal  h2v2_merged_upsample_565D_le
442
#include "jdmrg565.c"
443
#undef PACK_SHORT_565
444
#undef PACK_TWO_PIXELS
445
#undef WRITE_TWO_PIXELS
446
#undef h2v1_merged_upsample_565_internal
447
#undef h2v1_merged_upsample_565D_internal
448
#undef h2v2_merged_upsample_565_internal
449
#undef h2v2_merged_upsample_565D_internal
450
451
0
#define PACK_SHORT_565  PACK_SHORT_565_BE
452
0
#define PACK_TWO_PIXELS  PACK_TWO_PIXELS_BE
453
0
#define WRITE_TWO_PIXELS  WRITE_TWO_PIXELS_BE
454
#define h2v1_merged_upsample_565_internal  h2v1_merged_upsample_565_be
455
#define h2v1_merged_upsample_565D_internal  h2v1_merged_upsample_565D_be
456
#define h2v2_merged_upsample_565_internal  h2v2_merged_upsample_565_be
457
#define h2v2_merged_upsample_565D_internal  h2v2_merged_upsample_565D_be
458
#include "jdmrg565.c"
459
#undef PACK_SHORT_565
460
#undef PACK_TWO_PIXELS
461
#undef WRITE_TWO_PIXELS
462
#undef h2v1_merged_upsample_565_internal
463
#undef h2v1_merged_upsample_565D_internal
464
#undef h2v2_merged_upsample_565_internal
465
#undef h2v2_merged_upsample_565D_internal
466
467
468
static INLINE boolean is_big_endian(void)
469
0
{
470
0
  int test_value = 1;
471
0
  if (*(char *)&test_value != 1)
472
0
    return TRUE;
473
0
  return FALSE;
474
0
}
475
476
477
METHODDEF(void)
478
h2v1_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
479
                         JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
480
0
{
481
0
  if (is_big_endian())
482
0
    h2v1_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
483
0
                                output_buf);
484
0
  else
485
0
    h2v1_merged_upsample_565_le(cinfo, input_buf, in_row_group_ctr,
486
0
                                output_buf);
487
0
}
488
489
490
METHODDEF(void)
491
h2v1_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
492
                          JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
493
0
{
494
0
  if (is_big_endian())
495
0
    h2v1_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
496
0
                                 output_buf);
497
0
  else
498
0
    h2v1_merged_upsample_565D_le(cinfo, input_buf, in_row_group_ctr,
499
0
                                 output_buf);
500
0
}
501
502
503
METHODDEF(void)
504
h2v2_merged_upsample_565(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
505
                         JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
506
0
{
507
0
  if (is_big_endian())
508
0
    h2v2_merged_upsample_565_be(cinfo, input_buf, in_row_group_ctr,
509
0
                                output_buf);
510
0
  else
511
0
    h2v2_merged_upsample_565_le(cinfo, input_buf, in_row_group_ctr,
512
0
                                output_buf);
513
0
}
514
515
516
METHODDEF(void)
517
h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
518
                          JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
519
0
{
520
0
  if (is_big_endian())
521
0
    h2v2_merged_upsample_565D_be(cinfo, input_buf, in_row_group_ctr,
522
0
                                 output_buf);
523
0
  else
524
0
    h2v2_merged_upsample_565D_le(cinfo, input_buf, in_row_group_ctr,
525
0
                                 output_buf);
526
0
}
527
528
529
/*
530
 * Module initialization routine for merged upsampling/color conversion.
531
 *
532
 * NB: this is called under the conditions determined by use_merged_upsample()
533
 * in jdmaster.c.  That routine MUST correspond to the actual capabilities
534
 * of this module; no safety checks are made here.
535
 */
536
537
GLOBAL(void)
538
jinit_merged_upsampler(j_decompress_ptr cinfo)
539
0
{
540
0
  my_merged_upsample_ptr upsample;
541
542
0
  upsample = (my_merged_upsample_ptr)
543
0
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
544
0
                                sizeof(my_merged_upsampler));
545
0
  cinfo->upsample = (struct jpeg_upsampler *)upsample;
546
0
  upsample->pub.start_pass = start_pass_merged_upsample;
547
0
  upsample->pub.need_context_rows = FALSE;
548
549
0
  upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
550
551
0
  if (cinfo->max_v_samp_factor == 2) {
552
0
    upsample->pub.upsample = merged_2v_upsample;
553
0
    if (jsimd_can_h2v2_merged_upsample())
554
0
      upsample->upmethod = jsimd_h2v2_merged_upsample;
555
0
    else
556
0
      upsample->upmethod = h2v2_merged_upsample;
557
0
    if (cinfo->out_color_space == JCS_RGB565) {
558
0
      if (cinfo->dither_mode != JDITHER_NONE) {
559
0
        upsample->upmethod = h2v2_merged_upsample_565D;
560
0
      } else {
561
0
        upsample->upmethod = h2v2_merged_upsample_565;
562
0
      }
563
0
    }
564
    /* Allocate a spare row buffer */
565
0
    upsample->spare_row = (JSAMPROW)
566
0
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
567
0
                (size_t)(upsample->out_row_width * sizeof(JSAMPLE)));
568
0
  } else {
569
0
    upsample->pub.upsample = merged_1v_upsample;
570
0
    if (jsimd_can_h2v1_merged_upsample())
571
0
      upsample->upmethod = jsimd_h2v1_merged_upsample;
572
0
    else
573
0
      upsample->upmethod = h2v1_merged_upsample;
574
0
    if (cinfo->out_color_space == JCS_RGB565) {
575
0
      if (cinfo->dither_mode != JDITHER_NONE) {
576
0
        upsample->upmethod = h2v1_merged_upsample_565D;
577
0
      } else {
578
0
        upsample->upmethod = h2v1_merged_upsample_565;
579
0
      }
580
0
    }
581
    /* No spare row needed */
582
0
    upsample->spare_row = NULL;
583
0
  }
584
585
0
  build_ycc_rgb_table(cinfo);
586
0
}
587
588
#endif /* UPSAMPLE_MERGING_SUPPORTED */