summaryrefslogtreecommitdiff
path: root/NV12_resize.c (plain)
blob: 4fc0443b8901667eafd774cadc90c29657d70883
1#include "NV12_resize.h"
2#include "DebugUtils.h"
3
4//#define LOG_NDEBUG 0
5#define LOG_TAG "CAMHAL_NV12_resize "
6#define STRIDE 4096
7#include <utils/Log.h>
8
9/*==========================================================================
10* Function Name : VT_resizeFrame_Video_opt2_lp
11*
12* Description : Resize a yuv frame.
13*
14* Input(s) : input_img_ptr -> Input Image Structure
15* : output_img_ptr -> Output Image Structure
16* : cropout -> crop structure
17*
18* Value Returned : mmBool -> FALSE on error TRUE on success
19* NOTE:
20* Not tested for crop funtionallity.
21* faster version.
22============================================================================*/
23mmBool
24VT_resizeFrame_Video_opt2_lp
25(
26 structConvImage* i_img_ptr, /* Points to the input image */
27 structConvImage* o_img_ptr, /* Points to the output image */
28 IC_rect_type* cropout, /* how much to resize to in final image */
29 mmUint16 dummy /* Transparent pixel value */
30 )
31{
32 CAMHAL_LOGVA("VT_resizeFrame_Video_opt2_lp+");
33
34 mmUint16 row,col;
35 mmUint32 resizeFactorX;
36 mmUint32 resizeFactorY;
37
38
39 mmUint16 x, y;
40
41 mmUchar* ptr8;
42 mmUchar *ptr8Cb, *ptr8Cr;
43
44
45 mmUint16 xf, yf;
46 mmUchar* inImgPtrY;
47 mmUchar* inImgPtrU;
48 mmUchar* inImgPtrV;
49 mmUint32 cox, coy, codx, cody;
50 mmUint16 idx,idy, idxC;
51
52 if(i_img_ptr->uWidth == o_img_ptr->uWidth)
53 {
54 if(i_img_ptr->uHeight == o_img_ptr->uHeight)
55 {
56 CAMHAL_LOGVB("(i_img_ptr->uHeight == o_img_ptr->uHeight)\n"
57 "i_img_ptr->width = %d,i_img_ptr->uHeight = %d\n"
58 "o_img_ptr->width = %d,o_img_ptr->uHeight = %d\n",
59 i_img_ptr->uWidth, i_img_ptr->uHeight,
60 o_img_ptr->uWidth, o_img_ptr->uHeight);
61 }
62 }
63
64 if (!i_img_ptr || !i_img_ptr->imgPtr ||
65 !o_img_ptr || !o_img_ptr->imgPtr)
66 {
67 CAMHAL_LOGEA("Image Point NULL");
68 return FALSE;
69 }
70
71 inImgPtrY = (mmUchar *) i_img_ptr->imgPtr + i_img_ptr->uOffset;
72 inImgPtrU = (mmUchar *) i_img_ptr->clrPtr + i_img_ptr->uOffset/2;
73 inImgPtrV = (mmUchar*)inImgPtrU + 1;
74
75 if (cropout == NULL)
76 {
77 cox = 0;
78 coy = 0;
79 codx = o_img_ptr->uWidth;
80 cody = o_img_ptr->uHeight;
81 }
82 else
83 {
84 cox = cropout->x;
85 coy = cropout->y;
86 codx = cropout->uWidth;
87 cody = cropout->uHeight;
88 }
89 idx = i_img_ptr->uWidth;
90 idy = i_img_ptr->uHeight;
91
92 /* make sure valid input size */
93 if (idx < 1 || idy < 1 || i_img_ptr->uStride < 1)
94 {
95 CAMHAL_LOGEB("idx or idy less then 1 idx = %d idy = %d stride = %d", idx, idy, i_img_ptr->uStride);
96 return FALSE;
97 }
98
99 resizeFactorX = ((idx-1)<<9) / codx;
100 resizeFactorY = ((idy-1)<<9) / cody;
101
102 if(i_img_ptr->eFormat == IC_FORMAT_YCbCr420_lp &&
103 o_img_ptr->eFormat == IC_FORMAT_YCbCr420_lp)
104 {
105 ptr8 = (mmUchar*)o_img_ptr->imgPtr + cox + coy*o_img_ptr->uWidth;
106
107
108 ////////////////////////////for Y//////////////////////////
109 for (row=0; row < cody; row++)
110 {
111 mmUchar *pu8Yrow1 = NULL;
112 mmUchar *pu8Yrow2 = NULL;
113 y = (mmUint16) ((mmUint32) (row*resizeFactorY) >> 9);
114 yf = (mmUchar) ((mmUint32)((row*resizeFactorY) >> 6) & 0x7);
115 pu8Yrow1 = inImgPtrY + (y) * i_img_ptr->uStride;
116 pu8Yrow2 = pu8Yrow1 + i_img_ptr->uStride;
117
118 for (col=0; col < codx; col++)
119 {
120 mmUchar in11, in12, in21, in22;
121 mmUchar *pu8ptr1 = NULL;
122 mmUchar *pu8ptr2 = NULL;
123 mmUchar w;
124 mmUint16 accum_1;
125 //mmUint32 accum_W;
126
127
128
129 x = (mmUint16) ((mmUint32) (col*resizeFactorX) >> 9);
130 xf = (mmUchar) ((mmUint32) ((col*resizeFactorX) >> 6) & 0x7);
131
132
133 //accum_W = 0;
134 accum_1 = 0;
135
136 pu8ptr1 = pu8Yrow1 + (x);
137 pu8ptr2 = pu8Yrow2 + (x);
138
139 /* A pixel */
140 //in = *(inImgPtrY + (y)*idx + (x));
141 in11 = *(pu8ptr1);
142
143 w = bWeights[xf][yf][0];
144 accum_1 = (w * in11);
145 //accum_W += (w);
146
147 /* B pixel */
148 //in = *(inImgPtrY + (y)*idx + (x+1));
149 in12 = *(pu8ptr1+1);
150 w = bWeights[xf][yf][1];
151 accum_1 += (w * in12);
152 //accum_W += (w);
153
154 /* C pixel */
155 //in = *(inImgPtrY + (y+1)*idx + (x));
156 in21 = *(pu8ptr2);
157 w = bWeights[xf][yf][3];
158 accum_1 += (w * in21);
159 //accum_W += (w);
160
161 /* D pixel */
162 //in = *(inImgPtrY + (y+1)*idx + (x+1));
163 in22 = *(pu8ptr2+1);
164 w = bWeights[xf][yf][2];
165 accum_1 += (w * in22);
166 //accum_W += (w);
167
168 /* divide by sum of the weights */
169 //accum_1 /= (accum_W);
170 //accum_1 = (accum_1/64);
171 accum_1 = (accum_1>>6);
172 *ptr8 = (mmUchar)accum_1 ;
173
174
175 ptr8++;
176 }
177 ptr8 = ptr8 + (o_img_ptr->uStride - codx);
178 }
179 ////////////////////////////for Y//////////////////////////
180
181 ///////////////////////////////for Cb-Cr//////////////////////
182
183 ptr8Cb = (mmUchar*)o_img_ptr->clrPtr + cox + coy*o_img_ptr->uWidth;
184
185 ptr8Cr = (mmUchar*)(ptr8Cb+1);
186
187 idxC = (idx>>1);
188 for (row=0; row < (((cody)>>1)); row++)
189 {
190 mmUchar *pu8Cbr1 = NULL;
191 mmUchar *pu8Cbr2 = NULL;
192 mmUchar *pu8Crr1 = NULL;
193 mmUchar *pu8Crr2 = NULL;
194
195 y = (mmUint16) ((mmUint32) (row*resizeFactorY) >> 9);
196 yf = (mmUchar) ((mmUint32)((row*resizeFactorY) >> 6) & 0x7);
197
198 pu8Cbr1 = inImgPtrU + (y) * i_img_ptr->uStride;
199 pu8Cbr2 = pu8Cbr1 + i_img_ptr->uStride;
200 pu8Crr1 = inImgPtrV + (y) * i_img_ptr->uStride;
201 pu8Crr2 = pu8Crr1 + i_img_ptr->uStride;
202
203 for (col=0; col < (((codx)>>1)); col++)
204 {
205 mmUchar in11, in12, in21, in22;
206 mmUchar *pu8Cbc1 = NULL;
207 mmUchar *pu8Cbc2 = NULL;
208 mmUchar *pu8Crc1 = NULL;
209 mmUchar *pu8Crc2 = NULL;
210
211 mmUchar w;
212 mmUint16 accum_1Cb, accum_1Cr;
213 //mmUint32 accum_WCb, accum_WCr;
214
215
216 x = (mmUint16) ((mmUint32) (col*resizeFactorX) >> 9);
217 xf = (mmUchar) ((mmUint32) ((col*resizeFactorX) >> 6) & 0x7);
218
219
220 //accum_WCb = accum_WCr = 0;
221 accum_1Cb = accum_1Cr = 0;
222
223 pu8Cbc1 = pu8Cbr1 + (x*2);
224 pu8Cbc2 = pu8Cbr2 + (x*2);
225 pu8Crc1 = pu8Crr1 + (x*2);
226 pu8Crc2 = pu8Crr2 + (x*2);
227
228
229
230 /* A pixel */
231 w = bWeights[xf][yf][0];
232
233 in11 = *(pu8Cbc1);
234 accum_1Cb = (w * in11);
235 // accum_WCb += (w);
236
237 in11 = *(pu8Crc1);
238 accum_1Cr = (w * in11);
239 //accum_WCr += (w);
240
241 /* B pixel */
242 w = bWeights[xf][yf][1];
243
244 in12 = *(pu8Cbc1+2);
245 accum_1Cb += (w * in12);
246 //accum_WCb += (w);
247
248 in12 = *(pu8Crc1+2);
249 accum_1Cr += (w * in12);
250 //accum_WCr += (w);
251
252 /* C pixel */
253 w = bWeights[xf][yf][3];
254
255 in21 = *(pu8Cbc2);
256 accum_1Cb += (w * in21);
257 //accum_WCb += (w);
258
259 in21 = *(pu8Crc2);
260 accum_1Cr += (w * in21);
261 //accum_WCr += (w);
262
263 /* D pixel */
264 w = bWeights[xf][yf][2];
265
266 in22 = *(pu8Cbc2+2);
267 accum_1Cb += (w * in22);
268 //accum_WCb += (w);
269
270 in22 = *(pu8Crc2+2);
271 accum_1Cr += (w * in22);
272 //accum_WCr += (w);
273
274 /* divide by sum of the weights */
275 //accum_1Cb /= (accum_WCb);
276 accum_1Cb = (accum_1Cb>>6);
277 *ptr8Cb = (mmUchar)accum_1Cb ;
278
279
280 accum_1Cr = (accum_1Cr >> 6);
281 *ptr8Cr = (mmUchar)accum_1Cr ;
282
283 ptr8Cb++;
284 ptr8Cr++;
285
286 ptr8Cb++;
287 ptr8Cr++;
288 }
289 ptr8Cb = ptr8Cb + (o_img_ptr->uStride-codx);
290 ptr8Cr = ptr8Cr + (o_img_ptr->uStride-codx);
291 }
292 ///////////////////For Cb- Cr////////////////////////////////////////
293 }
294 else
295 {
296 CAMHAL_LOGEA("eFormat not supported");
297 return FALSE;
298 }
299 return TRUE;
300}
301