Coverage Report

Created: 2025-12-14 06:14

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