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, 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_upsample_ptr upsample
= (my_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
= 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 */
49 cb
= GETJSAMPLE(*inptr1
++);
50 cr
= GETJSAMPLE(*inptr2
++);
52 cgreen
= (int)RIGHT_SHIFT(Cbgtab
[cb
] + Crgtab
[cr
], SCALEBITS
);
54 /* Fetch 2 Y values and emit 2 pixels */
55 y
= GETJSAMPLE(*inptr0
++);
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
] = 0xFF;
62 outptr
+= RGB_PIXELSIZE
;
63 y
= GETJSAMPLE(*inptr0
++);
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
] = 0xFF;
70 outptr
+= RGB_PIXELSIZE
;
72 /* If image width is odd, do the last output column separately */
73 if (cinfo
->output_width
& 1) {
74 cb
= GETJSAMPLE(*inptr1
);
75 cr
= GETJSAMPLE(*inptr2
);
77 cgreen
= (int)RIGHT_SHIFT(Cbgtab
[cb
] + Crgtab
[cr
], SCALEBITS
);
79 y
= GETJSAMPLE(*inptr0
);
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
] = 0xFF;
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_upsample_ptr upsample
= (my_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
= 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 */
123 cb
= GETJSAMPLE(*inptr1
++);
124 cr
= GETJSAMPLE(*inptr2
++);
126 cgreen
= (int)RIGHT_SHIFT(Cbgtab
[cb
] + Crgtab
[cr
], SCALEBITS
);
128 /* Fetch 4 Y values and emit 4 pixels */
129 y
= GETJSAMPLE(*inptr00
++);
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
] = 0xFF;
136 outptr0
+= RGB_PIXELSIZE
;
137 y
= GETJSAMPLE(*inptr00
++);
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
] = 0xFF;
144 outptr0
+= RGB_PIXELSIZE
;
145 y
= GETJSAMPLE(*inptr01
++);
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
] = 0xFF;
152 outptr1
+= RGB_PIXELSIZE
;
153 y
= GETJSAMPLE(*inptr01
++);
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
] = 0xFF;
160 outptr1
+= RGB_PIXELSIZE
;
162 /* If image width is odd, do the last output column separately */
163 if (cinfo
->output_width
& 1) {
164 cb
= GETJSAMPLE(*inptr1
);
165 cr
= GETJSAMPLE(*inptr2
);
167 cgreen
= (int)RIGHT_SHIFT(Cbgtab
[cb
] + Crgtab
[cr
], SCALEBITS
);
169 y
= GETJSAMPLE(*inptr00
);
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
] = 0xFF;
176 y
= GETJSAMPLE(*inptr01
);
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
] = 0xFF;