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 (C) 2011, 2015, 2020, 2022-2023, D. R. Commander.
8 * For conditions of distribution and use, see the accompanying README.ijg
11 * This file contains code for merged upsampling/color conversion.
15 /* This file is included by jdmerge.c */
19 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
24 h2v1_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
25 JDIMENSION in_row_group_ctr,
26 _JSAMPARRAY output_buf)
28 my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
29 register int y, cred, cgreen, cblue;
31 register _JSAMPROW outptr;
32 _JSAMPROW inptr0, inptr1, inptr2;
34 /* copy these pointers into registers if possible */
35 register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
36 int *Crrtab = upsample->Cr_r_tab;
37 int *Cbbtab = upsample->Cb_b_tab;
38 JLONG *Crgtab = upsample->Cr_g_tab;
39 JLONG *Cbgtab = upsample->Cb_g_tab;
42 inptr0 = input_buf[0][in_row_group_ctr];
43 inptr1 = input_buf[1][in_row_group_ctr];
44 inptr2 = input_buf[2][in_row_group_ctr];
45 outptr = output_buf[0];
46 /* Loop for each pair of output pixels */
47 for (col = cinfo->output_width >> 1; col > 0; col--) {
48 /* Do the chroma part of the calculation */
52 cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
54 /* Fetch 2 Y values and emit 2 pixels */
56 outptr[RGB_RED] = range_limit[y + cred];
57 outptr[RGB_GREEN] = range_limit[y + cgreen];
58 outptr[RGB_BLUE] = range_limit[y + cblue];
60 outptr[RGB_ALPHA] = _MAXJSAMPLE;
62 outptr += RGB_PIXELSIZE;
64 outptr[RGB_RED] = range_limit[y + cred];
65 outptr[RGB_GREEN] = range_limit[y + cgreen];
66 outptr[RGB_BLUE] = range_limit[y + cblue];
68 outptr[RGB_ALPHA] = _MAXJSAMPLE;
70 outptr += RGB_PIXELSIZE;
72 /* If image width is odd, do the last output column separately */
73 if (cinfo->output_width & 1) {
77 cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
80 outptr[RGB_RED] = range_limit[y + cred];
81 outptr[RGB_GREEN] = range_limit[y + cgreen];
82 outptr[RGB_BLUE] = range_limit[y + cblue];
84 outptr[RGB_ALPHA] = _MAXJSAMPLE;
91 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
96 h2v2_merged_upsample_internal(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
97 JDIMENSION in_row_group_ctr,
98 _JSAMPARRAY output_buf)
100 my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
101 register int y, cred, cgreen, cblue;
103 register _JSAMPROW outptr0, outptr1;
104 _JSAMPROW inptr00, inptr01, inptr1, inptr2;
106 /* copy these pointers into registers if possible */
107 register _JSAMPLE *range_limit = (_JSAMPLE *)cinfo->sample_range_limit;
108 int *Crrtab = upsample->Cr_r_tab;
109 int *Cbbtab = upsample->Cb_b_tab;
110 JLONG *Crgtab = upsample->Cr_g_tab;
111 JLONG *Cbgtab = upsample->Cb_g_tab;
114 inptr00 = input_buf[0][in_row_group_ctr * 2];
115 inptr01 = input_buf[0][in_row_group_ctr * 2 + 1];
116 inptr1 = input_buf[1][in_row_group_ctr];
117 inptr2 = input_buf[2][in_row_group_ctr];
118 outptr0 = output_buf[0];
119 outptr1 = output_buf[1];
120 /* Loop for each group of output pixels */
121 for (col = cinfo->output_width >> 1; col > 0; col--) {
122 /* Do the chroma part of the calculation */
126 cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
128 /* Fetch 4 Y values and emit 4 pixels */
130 outptr0[RGB_RED] = range_limit[y + cred];
131 outptr0[RGB_GREEN] = range_limit[y + cgreen];
132 outptr0[RGB_BLUE] = range_limit[y + cblue];
134 outptr0[RGB_ALPHA] = _MAXJSAMPLE;
136 outptr0 += RGB_PIXELSIZE;
138 outptr0[RGB_RED] = range_limit[y + cred];
139 outptr0[RGB_GREEN] = range_limit[y + cgreen];
140 outptr0[RGB_BLUE] = range_limit[y + cblue];
142 outptr0[RGB_ALPHA] = _MAXJSAMPLE;
144 outptr0 += RGB_PIXELSIZE;
146 outptr1[RGB_RED] = range_limit[y + cred];
147 outptr1[RGB_GREEN] = range_limit[y + cgreen];
148 outptr1[RGB_BLUE] = range_limit[y + cblue];
150 outptr1[RGB_ALPHA] = _MAXJSAMPLE;
152 outptr1 += RGB_PIXELSIZE;
154 outptr1[RGB_RED] = range_limit[y + cred];
155 outptr1[RGB_GREEN] = range_limit[y + cgreen];
156 outptr1[RGB_BLUE] = range_limit[y + cblue];
158 outptr1[RGB_ALPHA] = _MAXJSAMPLE;
160 outptr1 += RGB_PIXELSIZE;
162 /* If image width is odd, do the last output column separately */
163 if (cinfo->output_width & 1) {
167 cgreen = (int)RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
170 outptr0[RGB_RED] = range_limit[y + cred];
171 outptr0[RGB_GREEN] = range_limit[y + cgreen];
172 outptr0[RGB_BLUE] = range_limit[y + cblue];
174 outptr0[RGB_ALPHA] = _MAXJSAMPLE;
177 outptr1[RGB_RED] = range_limit[y + cred];
178 outptr1[RGB_GREEN] = range_limit[y + cgreen];
179 outptr1[RGB_BLUE] = range_limit[y + cblue];
181 outptr1[RGB_ALPHA] = _MAXJSAMPLE;