Coverage Report

Created: 2026-01-10 06:48

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