1 : /*
2 : * jdmrgext.c
3 : *
4 : * Copyright (C) 1994-1996, Thomas G. Lane.
5 : * This file is part of the Independent JPEG Group's software.
6 : * For conditions of distribution and use, see the accompanying README file.
7 : *
8 : * This file contains code for merged upsampling/color conversion.
9 : */
10 :
11 :
12 : /* This file is included by jdmerge.c */
13 :
14 :
15 : /*
16 : * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
17 : */
18 :
19 : INLINE
20 : LOCAL(void)
21 0 : h2v1_merged_upsample_internal (j_decompress_ptr cinfo,
22 : JSAMPIMAGE input_buf,
23 : JDIMENSION in_row_group_ctr,
24 : JSAMPARRAY output_buf)
25 : {
26 0 : my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
27 : register int y, cred, cgreen, cblue;
28 : int cb, cr;
29 : register JSAMPROW outptr;
30 : JSAMPROW inptr0, inptr1, inptr2;
31 : JDIMENSION col;
32 : /* copy these pointers into registers if possible */
33 0 : register JSAMPLE * range_limit = cinfo->sample_range_limit;
34 0 : int * Crrtab = upsample->Cr_r_tab;
35 0 : int * Cbbtab = upsample->Cb_b_tab;
36 0 : INT32 * Crgtab = upsample->Cr_g_tab;
37 0 : INT32 * Cbgtab = upsample->Cb_g_tab;
38 : SHIFT_TEMPS
39 :
40 0 : inptr0 = input_buf[0][in_row_group_ctr];
41 0 : inptr1 = input_buf[1][in_row_group_ctr];
42 0 : inptr2 = input_buf[2][in_row_group_ctr];
43 0 : outptr = output_buf[0];
44 : /* Loop for each pair of output pixels */
45 0 : for (col = cinfo->output_width >> 1; col > 0; col--) {
46 : /* Do the chroma part of the calculation */
47 0 : cb = GETJSAMPLE(*inptr1++);
48 0 : cr = GETJSAMPLE(*inptr2++);
49 0 : cred = Crrtab[cr];
50 0 : cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
51 0 : cblue = Cbbtab[cb];
52 : /* Fetch 2 Y values and emit 2 pixels */
53 0 : y = GETJSAMPLE(*inptr0++);
54 0 : outptr[RGB_RED] = range_limit[y + cred];
55 0 : outptr[RGB_GREEN] = range_limit[y + cgreen];
56 0 : outptr[RGB_BLUE] = range_limit[y + cblue];
57 0 : outptr += RGB_PIXELSIZE;
58 0 : y = GETJSAMPLE(*inptr0++);
59 0 : outptr[RGB_RED] = range_limit[y + cred];
60 0 : outptr[RGB_GREEN] = range_limit[y + cgreen];
61 0 : outptr[RGB_BLUE] = range_limit[y + cblue];
62 0 : outptr += RGB_PIXELSIZE;
63 : }
64 : /* If image width is odd, do the last output column separately */
65 0 : if (cinfo->output_width & 1) {
66 0 : cb = GETJSAMPLE(*inptr1);
67 0 : cr = GETJSAMPLE(*inptr2);
68 0 : cred = Crrtab[cr];
69 0 : cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
70 0 : cblue = Cbbtab[cb];
71 0 : y = GETJSAMPLE(*inptr0);
72 0 : outptr[RGB_RED] = range_limit[y + cred];
73 0 : outptr[RGB_GREEN] = range_limit[y + cgreen];
74 0 : outptr[RGB_BLUE] = range_limit[y + cblue];
75 : }
76 0 : }
77 :
78 :
79 : /*
80 : * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
81 : */
82 :
83 : INLINE
84 : LOCAL(void)
85 0 : h2v2_merged_upsample_internal (j_decompress_ptr cinfo,
86 : JSAMPIMAGE input_buf,
87 : JDIMENSION in_row_group_ctr,
88 : JSAMPARRAY output_buf)
89 : {
90 0 : my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
91 : register int y, cred, cgreen, cblue;
92 : int cb, cr;
93 : register JSAMPROW outptr0, outptr1;
94 : JSAMPROW inptr00, inptr01, inptr1, inptr2;
95 : JDIMENSION col;
96 : /* copy these pointers into registers if possible */
97 0 : register JSAMPLE * range_limit = cinfo->sample_range_limit;
98 0 : int * Crrtab = upsample->Cr_r_tab;
99 0 : int * Cbbtab = upsample->Cb_b_tab;
100 0 : INT32 * Crgtab = upsample->Cr_g_tab;
101 0 : INT32 * Cbgtab = upsample->Cb_g_tab;
102 : SHIFT_TEMPS
103 :
104 0 : inptr00 = input_buf[0][in_row_group_ctr*2];
105 0 : inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
106 0 : inptr1 = input_buf[1][in_row_group_ctr];
107 0 : inptr2 = input_buf[2][in_row_group_ctr];
108 0 : outptr0 = output_buf[0];
109 0 : outptr1 = output_buf[1];
110 : /* Loop for each group of output pixels */
111 0 : for (col = cinfo->output_width >> 1; col > 0; col--) {
112 : /* Do the chroma part of the calculation */
113 0 : cb = GETJSAMPLE(*inptr1++);
114 0 : cr = GETJSAMPLE(*inptr2++);
115 0 : cred = Crrtab[cr];
116 0 : cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
117 0 : cblue = Cbbtab[cb];
118 : /* Fetch 4 Y values and emit 4 pixels */
119 0 : y = GETJSAMPLE(*inptr00++);
120 0 : outptr0[RGB_RED] = range_limit[y + cred];
121 0 : outptr0[RGB_GREEN] = range_limit[y + cgreen];
122 0 : outptr0[RGB_BLUE] = range_limit[y + cblue];
123 0 : outptr0 += RGB_PIXELSIZE;
124 0 : y = GETJSAMPLE(*inptr00++);
125 0 : outptr0[RGB_RED] = range_limit[y + cred];
126 0 : outptr0[RGB_GREEN] = range_limit[y + cgreen];
127 0 : outptr0[RGB_BLUE] = range_limit[y + cblue];
128 0 : outptr0 += RGB_PIXELSIZE;
129 0 : y = GETJSAMPLE(*inptr01++);
130 0 : outptr1[RGB_RED] = range_limit[y + cred];
131 0 : outptr1[RGB_GREEN] = range_limit[y + cgreen];
132 0 : outptr1[RGB_BLUE] = range_limit[y + cblue];
133 0 : outptr1 += RGB_PIXELSIZE;
134 0 : y = GETJSAMPLE(*inptr01++);
135 0 : outptr1[RGB_RED] = range_limit[y + cred];
136 0 : outptr1[RGB_GREEN] = range_limit[y + cgreen];
137 0 : outptr1[RGB_BLUE] = range_limit[y + cblue];
138 0 : outptr1 += RGB_PIXELSIZE;
139 : }
140 : /* If image width is odd, do the last output column separately */
141 0 : if (cinfo->output_width & 1) {
142 0 : cb = GETJSAMPLE(*inptr1);
143 0 : cr = GETJSAMPLE(*inptr2);
144 0 : cred = Crrtab[cr];
145 0 : cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
146 0 : cblue = Cbbtab[cb];
147 0 : y = GETJSAMPLE(*inptr00);
148 0 : outptr0[RGB_RED] = range_limit[y + cred];
149 0 : outptr0[RGB_GREEN] = range_limit[y + cgreen];
150 0 : outptr0[RGB_BLUE] = range_limit[y + cblue];
151 0 : y = GETJSAMPLE(*inptr01);
152 0 : outptr1[RGB_RED] = range_limit[y + cred];
153 0 : outptr1[RGB_GREEN] = range_limit[y + cgreen];
154 0 : outptr1[RGB_BLUE] = range_limit[y + cblue];
155 : }
156 0 : }
|