summaryrefslogtreecommitdiff
authorshanghai engineers <yuxi.sun@droid09.amlogic.com>2014-11-07 06:46:11 (GMT)
committer shanghai engineers <yuxi.sun@droid09.amlogic.com>2014-11-07 06:46:11 (GMT)
commitd307b582ebed38c8114577962c77cf451cddc958 (patch)
treed97352ecf7c45e253304cda159dcfb4116d4d12c
parent54dab6270b2c656909a92b2606dafd1ffda1a997 (diff)
downloadcamera-d307b582ebed38c8114577962c77cf451cddc958.zip
camera-d307b582ebed38c8114577962c77cf451cddc958.tar.gz
camera-d307b582ebed38c8114577962c77cf451cddc958.tar.bz2
Add NV12 resize function
Change-Id: I38e3dd74a15606b988fd3f720a80d832351547e7 Signed-off-by: shanghai engineers <yuxi.sun@droid09.amlogic.com>
Diffstat
-rwxr-xr-xv3/fake-pipeline2/NV12_resize.c300
-rwxr-xr-xv3/fake-pipeline2/NV12_resize.h148
2 files changed, 448 insertions, 0 deletions
diff --git a/v3/fake-pipeline2/NV12_resize.c b/v3/fake-pipeline2/NV12_resize.c
new file mode 100755
index 0000000..4fc0443
--- a/dev/null
+++ b/v3/fake-pipeline2/NV12_resize.c
@@ -0,0 +1,300 @@
+#include "NV12_resize.h"
+#include "DebugUtils.h"
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "CAMHAL_NV12_resize "
+#define STRIDE 4096
+#include <utils/Log.h>
+
+/*==========================================================================
+* Function Name : VT_resizeFrame_Video_opt2_lp
+*
+* Description : Resize a yuv frame.
+*
+* Input(s) : input_img_ptr -> Input Image Structure
+* : output_img_ptr -> Output Image Structure
+* : cropout -> crop structure
+*
+* Value Returned : mmBool -> FALSE on error TRUE on success
+* NOTE:
+* Not tested for crop funtionallity.
+* faster version.
+============================================================================*/
+mmBool
+VT_resizeFrame_Video_opt2_lp
+(
+ structConvImage* i_img_ptr, /* Points to the input image */
+ structConvImage* o_img_ptr, /* Points to the output image */
+ IC_rect_type* cropout, /* how much to resize to in final image */
+ mmUint16 dummy /* Transparent pixel value */
+ )
+{
+ CAMHAL_LOGVA("VT_resizeFrame_Video_opt2_lp+");
+
+ mmUint16 row,col;
+ mmUint32 resizeFactorX;
+ mmUint32 resizeFactorY;
+
+
+ mmUint16 x, y;
+
+ mmUchar* ptr8;
+ mmUchar *ptr8Cb, *ptr8Cr;
+
+
+ mmUint16 xf, yf;
+ mmUchar* inImgPtrY;
+ mmUchar* inImgPtrU;
+ mmUchar* inImgPtrV;
+ mmUint32 cox, coy, codx, cody;
+ mmUint16 idx,idy, idxC;
+
+ if(i_img_ptr->uWidth == o_img_ptr->uWidth)
+ {
+ if(i_img_ptr->uHeight == o_img_ptr->uHeight)
+ {
+ CAMHAL_LOGVB("(i_img_ptr->uHeight == o_img_ptr->uHeight)\n"
+ "i_img_ptr->width = %d,i_img_ptr->uHeight = %d\n"
+ "o_img_ptr->width = %d,o_img_ptr->uHeight = %d\n",
+ i_img_ptr->uWidth, i_img_ptr->uHeight,
+ o_img_ptr->uWidth, o_img_ptr->uHeight);
+ }
+ }
+
+ if (!i_img_ptr || !i_img_ptr->imgPtr ||
+ !o_img_ptr || !o_img_ptr->imgPtr)
+ {
+ CAMHAL_LOGEA("Image Point NULL");
+ return FALSE;
+ }
+
+ inImgPtrY = (mmUchar *) i_img_ptr->imgPtr + i_img_ptr->uOffset;
+ inImgPtrU = (mmUchar *) i_img_ptr->clrPtr + i_img_ptr->uOffset/2;
+ inImgPtrV = (mmUchar*)inImgPtrU + 1;
+
+ if (cropout == NULL)
+ {
+ cox = 0;
+ coy = 0;
+ codx = o_img_ptr->uWidth;
+ cody = o_img_ptr->uHeight;
+ }
+ else
+ {
+ cox = cropout->x;
+ coy = cropout->y;
+ codx = cropout->uWidth;
+ cody = cropout->uHeight;
+ }
+ idx = i_img_ptr->uWidth;
+ idy = i_img_ptr->uHeight;
+
+ /* make sure valid input size */
+ if (idx < 1 || idy < 1 || i_img_ptr->uStride < 1)
+ {
+ CAMHAL_LOGEB("idx or idy less then 1 idx = %d idy = %d stride = %d", idx, idy, i_img_ptr->uStride);
+ return FALSE;
+ }
+
+ resizeFactorX = ((idx-1)<<9) / codx;
+ resizeFactorY = ((idy-1)<<9) / cody;
+
+ if(i_img_ptr->eFormat == IC_FORMAT_YCbCr420_lp &&
+ o_img_ptr->eFormat == IC_FORMAT_YCbCr420_lp)
+ {
+ ptr8 = (mmUchar*)o_img_ptr->imgPtr + cox + coy*o_img_ptr->uWidth;
+
+
+ ////////////////////////////for Y//////////////////////////
+ for (row=0; row < cody; row++)
+ {
+ mmUchar *pu8Yrow1 = NULL;
+ mmUchar *pu8Yrow2 = NULL;
+ y = (mmUint16) ((mmUint32) (row*resizeFactorY) >> 9);
+ yf = (mmUchar) ((mmUint32)((row*resizeFactorY) >> 6) & 0x7);
+ pu8Yrow1 = inImgPtrY + (y) * i_img_ptr->uStride;
+ pu8Yrow2 = pu8Yrow1 + i_img_ptr->uStride;
+
+ for (col=0; col < codx; col++)
+ {
+ mmUchar in11, in12, in21, in22;
+ mmUchar *pu8ptr1 = NULL;
+ mmUchar *pu8ptr2 = NULL;
+ mmUchar w;
+ mmUint16 accum_1;
+ //mmUint32 accum_W;
+
+
+
+ x = (mmUint16) ((mmUint32) (col*resizeFactorX) >> 9);
+ xf = (mmUchar) ((mmUint32) ((col*resizeFactorX) >> 6) & 0x7);
+
+
+ //accum_W = 0;
+ accum_1 = 0;
+
+ pu8ptr1 = pu8Yrow1 + (x);
+ pu8ptr2 = pu8Yrow2 + (x);
+
+ /* A pixel */
+ //in = *(inImgPtrY + (y)*idx + (x));
+ in11 = *(pu8ptr1);
+
+ w = bWeights[xf][yf][0];
+ accum_1 = (w * in11);
+ //accum_W += (w);
+
+ /* B pixel */
+ //in = *(inImgPtrY + (y)*idx + (x+1));
+ in12 = *(pu8ptr1+1);
+ w = bWeights[xf][yf][1];
+ accum_1 += (w * in12);
+ //accum_W += (w);
+
+ /* C pixel */
+ //in = *(inImgPtrY + (y+1)*idx + (x));
+ in21 = *(pu8ptr2);
+ w = bWeights[xf][yf][3];
+ accum_1 += (w * in21);
+ //accum_W += (w);
+
+ /* D pixel */
+ //in = *(inImgPtrY + (y+1)*idx + (x+1));
+ in22 = *(pu8ptr2+1);
+ w = bWeights[xf][yf][2];
+ accum_1 += (w * in22);
+ //accum_W += (w);
+
+ /* divide by sum of the weights */
+ //accum_1 /= (accum_W);
+ //accum_1 = (accum_1/64);
+ accum_1 = (accum_1>>6);
+ *ptr8 = (mmUchar)accum_1 ;
+
+
+ ptr8++;
+ }
+ ptr8 = ptr8 + (o_img_ptr->uStride - codx);
+ }
+ ////////////////////////////for Y//////////////////////////
+
+ ///////////////////////////////for Cb-Cr//////////////////////
+
+ ptr8Cb = (mmUchar*)o_img_ptr->clrPtr + cox + coy*o_img_ptr->uWidth;
+
+ ptr8Cr = (mmUchar*)(ptr8Cb+1);
+
+ idxC = (idx>>1);
+ for (row=0; row < (((cody)>>1)); row++)
+ {
+ mmUchar *pu8Cbr1 = NULL;
+ mmUchar *pu8Cbr2 = NULL;
+ mmUchar *pu8Crr1 = NULL;
+ mmUchar *pu8Crr2 = NULL;
+
+ y = (mmUint16) ((mmUint32) (row*resizeFactorY) >> 9);
+ yf = (mmUchar) ((mmUint32)((row*resizeFactorY) >> 6) & 0x7);
+
+ pu8Cbr1 = inImgPtrU + (y) * i_img_ptr->uStride;
+ pu8Cbr2 = pu8Cbr1 + i_img_ptr->uStride;
+ pu8Crr1 = inImgPtrV + (y) * i_img_ptr->uStride;
+ pu8Crr2 = pu8Crr1 + i_img_ptr->uStride;
+
+ for (col=0; col < (((codx)>>1)); col++)
+ {
+ mmUchar in11, in12, in21, in22;
+ mmUchar *pu8Cbc1 = NULL;
+ mmUchar *pu8Cbc2 = NULL;
+ mmUchar *pu8Crc1 = NULL;
+ mmUchar *pu8Crc2 = NULL;
+
+ mmUchar w;
+ mmUint16 accum_1Cb, accum_1Cr;
+ //mmUint32 accum_WCb, accum_WCr;
+
+
+ x = (mmUint16) ((mmUint32) (col*resizeFactorX) >> 9);
+ xf = (mmUchar) ((mmUint32) ((col*resizeFactorX) >> 6) & 0x7);
+
+
+ //accum_WCb = accum_WCr = 0;
+ accum_1Cb = accum_1Cr = 0;
+
+ pu8Cbc1 = pu8Cbr1 + (x*2);
+ pu8Cbc2 = pu8Cbr2 + (x*2);
+ pu8Crc1 = pu8Crr1 + (x*2);
+ pu8Crc2 = pu8Crr2 + (x*2);
+
+
+
+ /* A pixel */
+ w = bWeights[xf][yf][0];
+
+ in11 = *(pu8Cbc1);
+ accum_1Cb = (w * in11);
+ // accum_WCb += (w);
+
+ in11 = *(pu8Crc1);
+ accum_1Cr = (w * in11);
+ //accum_WCr += (w);
+
+ /* B pixel */
+ w = bWeights[xf][yf][1];
+
+ in12 = *(pu8Cbc1+2);
+ accum_1Cb += (w * in12);
+ //accum_WCb += (w);
+
+ in12 = *(pu8Crc1+2);
+ accum_1Cr += (w * in12);
+ //accum_WCr += (w);
+
+ /* C pixel */
+ w = bWeights[xf][yf][3];
+
+ in21 = *(pu8Cbc2);
+ accum_1Cb += (w * in21);
+ //accum_WCb += (w);
+
+ in21 = *(pu8Crc2);
+ accum_1Cr += (w * in21);
+ //accum_WCr += (w);
+
+ /* D pixel */
+ w = bWeights[xf][yf][2];
+
+ in22 = *(pu8Cbc2+2);
+ accum_1Cb += (w * in22);
+ //accum_WCb += (w);
+
+ in22 = *(pu8Crc2+2);
+ accum_1Cr += (w * in22);
+ //accum_WCr += (w);
+
+ /* divide by sum of the weights */
+ //accum_1Cb /= (accum_WCb);
+ accum_1Cb = (accum_1Cb>>6);
+ *ptr8Cb = (mmUchar)accum_1Cb ;
+
+
+ accum_1Cr = (accum_1Cr >> 6);
+ *ptr8Cr = (mmUchar)accum_1Cr ;
+
+ ptr8Cb++;
+ ptr8Cr++;
+
+ ptr8Cb++;
+ ptr8Cr++;
+ }
+ ptr8Cb = ptr8Cb + (o_img_ptr->uStride-codx);
+ ptr8Cr = ptr8Cr + (o_img_ptr->uStride-codx);
+ }
+ ///////////////////For Cb- Cr////////////////////////////////////////
+ }
+ else
+ {
+ CAMHAL_LOGEA("eFormat not supported");
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/v3/fake-pipeline2/NV12_resize.h b/v3/fake-pipeline2/NV12_resize.h
new file mode 100755
index 0000000..927faf8
--- a/dev/null
+++ b/v3/fake-pipeline2/NV12_resize.h
@@ -0,0 +1,148 @@
+#ifndef NV12_RESIZE_H_
+#define NV12_RESIZE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned char mmBool;
+typedef unsigned char mmUchar;
+typedef unsigned char mmUint8;
+typedef unsigned char mmByte;
+typedef unsigned short mmUint16;
+typedef unsigned int mmUint32;
+typedef unsigned long mmUint64;
+typedef signed char mmInt8;
+typedef char mmChar;
+typedef signed short mmInt16;
+typedef signed int mmInt32;
+typedef signed long mmLong;
+typedef signed int mmHandle;
+typedef float mmFloat;
+typedef double mmDouble;
+typedef int HObj;
+typedef HObj HFile;
+typedef int HDir;
+typedef void* mmMutexHandle;
+typedef struct _fstat
+{
+ mmInt32 fileSize;
+}VE_FileAttribute;
+
+typedef struct
+{
+ mmInt32 second;
+ mmInt32 millisecond;
+}tsVE_Time;
+
+typedef struct
+{
+ mmInt32 year;
+ mmInt32 month;
+ mmInt32 day;
+ mmInt32 hour;
+ mmInt32 minute;
+ mmInt32 second;
+} TmDateTime;
+
+/*----------------------------------------------------------------------------
+ Define : TRUE/FALSE for boolean operations
+----------------------------------------------------------------------------*/
+
+#ifndef TRUE
+ #define TRUE 1
+#endif
+
+#ifndef FALSE
+ #define FALSE 0
+#endif
+
+#ifndef NULL
+ #define NULL 0
+#endif
+
+const mmUint8 bWeights[8][8][4] = {
+ {{64, 0, 0, 0}, {56, 0, 0, 8}, {48, 0, 0,16}, {40, 0, 0,24},
+ {32, 0, 0,32}, {24, 0, 0,40}, {16, 0, 0,48}, { 8, 0, 0,56}},
+
+ {{56, 8, 0, 0}, {49, 7, 1, 7}, {42, 6, 2,14}, {35, 5, 3,21},
+ {28, 4, 4,28}, {21, 3, 5,35}, {14, 2, 6,42}, { 7, 1, 7,49}},
+
+ {{48,16, 0, 0}, {42,14, 2, 6}, {36,12,4 ,12}, {30,10,6 ,18},
+ {24, 8, 8,24}, {18, 6,10,30}, {12,4 ,12,36}, { 6, 2,14,42}},
+
+ {{40,24,0 ,0 }, {35,21, 3, 5}, {30,18, 6,10}, {25,15, 9,15},
+ {20,12,12,20}, {15, 9,15,25}, {10, 6,18,30}, { 5, 3,21,35}},
+
+ {{32,32, 0,0 }, {28,28, 4, 4}, {24,24, 8, 8}, {20,20,12,12},
+ {16,16,16,16}, {12,12,20,20}, { 8, 8,24,24}, { 4, 4,28,28}},
+
+ {{24,40,0 ,0 }, {21,35, 5, 3}, {18,30,10, 6}, {15,25,15, 9},
+ {12,20,20,12}, { 9,15,25,15}, { 6,10,30,18}, { 3, 5,35,21}},
+
+ {{16,48, 0,0 }, {14,42, 6, 2}, {12,36,12, 4}, {10,30,18, 6},
+ {8 ,24,24,8 }, { 6,18,30,10}, { 4,12,36,12}, { 2, 6,42,14}},
+
+ {{ 8,56, 0,0 }, { 7,49, 7, 1}, { 6,42,14, 2}, { 5,35,21, 3},
+ { 4,28,28,4 }, { 3,21,35, 5}, { 2,14,42, 6}, { 1,7 ,49, 7}}
+};
+
+typedef enum
+{
+ IC_FORMAT_NONE,
+ IC_FORMAT_RGB565,
+ IC_FORMAT_RGB888,
+ IC_FORMAT_YCbCr420_lp,
+ IC_FORMAT_YCbCr,
+ IC_FORMAT_YCbCr420_FRAME_PK,
+ IC_FORMAT_MAX
+}enumImageFormat;
+
+/* This structure defines the format of an image */
+typedef struct
+{
+ mmInt32 uWidth;
+ mmInt32 uHeight;
+ mmInt32 uStride;
+ enumImageFormat eFormat;
+ mmByte *imgPtr;
+ mmByte *clrPtr;
+ mmInt32 uOffset;
+} structConvImage;
+
+typedef struct IC_crop_struct
+{
+ mmUint32 x; /* x pos of rectangle */
+ mmUint32 y; /* y pos of rectangle */
+ mmUint32 uWidth; /* dx of rectangle */
+ mmUint32 uHeight; /* dy of rectangle */
+} IC_rect_type;
+
+/*==========================================================================
+* Function Name : VT_resizeFrame_Video_opt2_lp
+*
+* Description : Resize a yuv frame.
+*
+* Input(s) : input_img_ptr -> Input Image Structure
+* : output_img_ptr -> Output Image Structure
+* : cropout -> crop structure
+*
+* Value Returned : mmBool -> FALSE on error TRUE on success
+* NOTE:
+* Not tested for crop funtionallity.
+* faster version.
+============================================================================*/
+mmBool
+VT_resizeFrame_Video_opt2_lp
+(
+ structConvImage* i_img_ptr, /* Points to the input image */
+ structConvImage* o_img_ptr, /* Points to the output image */
+ IC_rect_type* cropout, /* how much to resize to in final image */
+ mmUint16 dummy /* Transparent pixel value */
+ );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //#define NV12_RESIZE_H_