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