Adding image utilities for nv12, nv21 and gray format.
authormamata pattanaik <mamata.p@samsung.com>
Tue, 2 Apr 2013 05:55:15 +0000 (11:25 +0530)
committermamata pattanaik <mamata.p@samsung.com>
Tue, 2 Apr 2013 06:05:11 +0000 (11:35 +0530)
Change-Id: I0dd3930ead59f709a81751e1a69660bf140b9b5b
Signed-off-by: mamata pattanaik <mamata.p@samsung.com>
src/FMedia_ImageUtil.cpp
src/FMedia_SlpUtil.cpp
src/inc/FMedia_ImageUtil.h

index 438158f..0c8f1c7 100644 (file)
@@ -42,12 +42,12 @@ using namespace Tizen::Io;
 namespace Tizen { namespace Media
 {
 
-#define IS_VALID_PIXEL(x)                                                                                                                      \
-       ((x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_NV12)            \
-       || (x == MEDIA_PIXEL_FORMAT_YUYV422) || (x == MEDIA_PIXEL_FORMAT_RGB565LE)      \
+#define IS_VALID_PIXEL(x)                                                                                                              \
+       ((x == MEDIA_PIXEL_FORMAT_RGB565LE)     || ( x == MEDIA_PIXEL_FORMAT_GRAY)              \
        || (x == MEDIA_PIXEL_FORMAT_BGRA8888) || (x == MEDIA_PIXEL_FORMAT_RGBA8888)     \
        || (x == MEDIA_PIXEL_FORMAT_BGR888) || (x == MEDIA_PIXEL_FORMAT_RGB888)         \
-       || (x == MEDIA_PIXEL_FORMAT_NV21) || ( x == MEDIA_PIXEL_FORMAT_YUV444P))
+       || ( x == MEDIA_PIXEL_FORMAT_YUV444P) || (x == MEDIA_PIXEL_FORMAT_YUYV422)      \
+       || (x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_NV12) || (x == MEDIA_PIXEL_FORMAT_NV21))
 
 #define IS_VALID_BUF(buf, format, w, h)                                                                 \
        (_ImageUtil::GetBufferSize(format, w, h) <= buf.GetCapacity())
@@ -73,7 +73,8 @@ static const _PixelFormatMap _PIXEL_FORMAT_MAP[] =
        { MEDIA_PIXEL_FORMAT_UYVY422, PIX_FMT_UYVY422, 2 },
        { MEDIA_PIXEL_FORMAT_NV12, PIX_FMT_NV12, 1.5 },
        { MEDIA_PIXEL_FORMAT_NV12_TILE, PIX_FMT_NV12, 1.5 },
-       { MEDIA_PIXEL_FORMAT_NV21, PIX_FMT_NV21, 1.5 }
+       { MEDIA_PIXEL_FORMAT_NV21, PIX_FMT_NV21, 1.5 },
+       { MEDIA_PIXEL_FORMAT_GRAY, PIX_FMT_GRAY8, 1 }
 };
 
 static const int _BPP_RGB565 = 2;
@@ -285,6 +286,71 @@ _ImageUtil::ResizeRGB565(const byte* pDataIn, byte* pDataOut, int inWidth, int i
 }
 
 /*
+* Input is assumed to be GRAY8
+* pDataIn      => Input GRAY8 Buffer
+* pDataOut     => Output GRAY8 Buffer (memory is assumed to be already allocated)
+* inWidth      => Input Width
+* inHeight     => Input Height
+* outWidth     => Output Width
+* outHeight    => Output Height
+*/
+result
+_ImageUtil::ResizeGray(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight)
+{
+       int scaleX = 0;
+       int scaleY = 0;
+       int i = 0;
+       int j = 0;
+
+       int iRow = 0;
+       int iIndex = 0;
+
+       byte* pOutput = pDataOut;
+       byte* pOut = pDataOut;
+       const byte* pIn = null;
+
+       std::unique_ptr<int []> pColLUT (new (std::nothrow) int[sizeof(int) * outWidth]);
+       SysTryReturn(NID_MEDIA, pColLUT.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+               "[E_OUT_OF_MEMORY] Could not allocate memory.");
+
+       /* Calculate X Scale factor */
+       scaleX = inWidth * 256 / outWidth;
+
+       /* Calculate Y Scale factor, aspect ratio is not maintained */
+       scaleY = inHeight * 256 / outHeight;
+
+       for (j = 0; j < outWidth; j++)
+       {
+               /* Get input index based on column scale factor */
+
+               /* To get more optimization, this is calculated once and
+               * is placed in a LUT and used for indexing
+               */
+               pColLUT [j] = ((j * scaleX) >> 8);
+       }
+
+       pOut = pOutput;
+
+       for (i = 0; i < outHeight; i++)
+       {
+               /* Get input row index based on row scale factor */
+               iRow = (i * scaleY >> 8) * inWidth;
+
+               /* Loop could be unrolled for more optimization */
+               for (j = 0; j < (outWidth); j++)
+               {
+                       /* Get input index based on column scale factor */
+                       iIndex = iRow + pColLUT [j];
+
+                       pIn = pDataIn + iIndex;
+                       *pOut++ = *pIn++;
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+/*
 * Input is assumed to be YUV444
 * pDataIn      => Input YUV444 Buffer
 * pDataOut     => Output buffer, allocated by caller
@@ -576,6 +642,12 @@ _ImageUtil::ResizeBuffer(const byte* pInBuf, MediaPixelFormat pixelFormat,
                }
                break;
 
+               case MEDIA_PIXEL_FORMAT_GRAY:
+               {
+                       r = ResizeGray(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
+               }
+               break;
+
                case MEDIA_PIXEL_FORMAT_YUV444P:
                {
                        r = ResizeYUV444(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
@@ -595,6 +667,7 @@ _ImageUtil::ResizeBuffer(const byte* pInBuf, MediaPixelFormat pixelFormat,
                break;
 
                case MEDIA_PIXEL_FORMAT_NV12:
+               case MEDIA_PIXEL_FORMAT_NV21:
                {
                        r = ResizeNV12(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
                }
@@ -652,8 +725,69 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                outHeight = height;
        }
 
-       if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
-        {
+       if (pixelFormat == MEDIA_PIXEL_FORMAT_GRAY)
+       {
+               int rowCount = 0;
+               int colCount = 0;
+               byte* pSrcBuf = (byte *)srcBuf;
+               byte* pDstBuf = (byte *)dstBuf;
+               byte* pTmpOutCol = null;
+
+               switch (rotate)
+               {
+               case IMAGE_ROTATION_90:
+               {
+                       // Copying from all source rows to destination columns.
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               // pTmpOutCol points to the top of the output column being filled.
+                               pTmpOutCol = pDstBuf + (outWidth - 1) - rowCount;
+
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutCol = *pSrcBuf++;
+                                       pTmpOutCol += outWidth;
+                               }
+                       }
+               }
+               break;
+               case IMAGE_ROTATION_180:
+               {
+                       // Copying all source rows to destination columns.
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               // pTmpOutCol points to the bottom of the column being filled.
+                               pTmpOutCol = pDstBuf + ((outWidth * outHeight) - 1) - (rowCount * outWidth);
+
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutCol-- = *pSrcBuf++;
+                               }
+                       }
+               }
+               break;
+               case IMAGE_ROTATION_270:
+               {
+                       // Copying all source rows to destination columns.
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               // pTmpOutCol points to the bottom of the column being filled.
+                               pTmpOutCol = pDstBuf + (outWidth *  (outHeight - 1)) + rowCount;
+
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutCol = *pSrcBuf++;
+                                       pTmpOutCol -= outWidth;
+                               }
+                       }
+               }
+               break;
+               default:
+               break;
+               }
+       }
+       else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
+       {
                int rowCount = 0;
                int colCount = 0;
                byte* pSrcBuf = (byte *)srcBuf;
@@ -741,7 +875,6 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-
        else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
        {
                switch (rotate)
@@ -905,7 +1038,7 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                        // Copying from all source rows to destination columns of Y plane.
                        for (rowCount = 0; rowCount < height / 2; rowCount++)
                        {
-                                // pTmpOutCol points to the top of the output column being filled.
+                               // pTmpOutCol points to the top of the output column being filled.
                                pTmpOutColU = pDstU + (outWidth / 2)  - 1 - rowCount;
                                pTmpOutColV = pDstV + (outWidth / 2)  - 1 - rowCount;
                                pTmpOutColY = pDstY + outWidth - 1 - rowCount;
@@ -923,7 +1056,7 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                                        *pTmpOutColY = *pSrcY++;
                                        pTmpOutColY += outWidth;
                                }
-                        }
+                       }
                        for (rowCount = height / 2; rowCount < height; rowCount++)
                        {
                                pTmpOutColY = pDstY + outWidth - 1 - rowCount;
@@ -958,7 +1091,7 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
 
                        // Copying from all source rows to destination columns of Y plane.
                        for (rowCount = 0; rowCount < height / 2; rowCount++)
-                        {
+                       {
                                // pTmpOutCol points to the top of the output column being filled.
                                pTmpOutColY = pDstY + (outWidth *  (outHeight - 1)) + rowCount;
                                pTmpOutColU = pDstU + (outWidth / 2) * (outHeight / 2 - 1) + rowCount;
@@ -971,15 +1104,15 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                                        pTmpOutColU -= outWidth / 2;
                                        *pTmpOutColV = *pSrcV++;
                                        pTmpOutColV -= outWidth / 2;
-                                }
+                               }
                                for (colCount = width / 2; colCount < width; colCount++)
                                {
                                        *pTmpOutColY = *pSrcY++;
                                        pTmpOutColY -= outWidth;
                                }
-                        }
+                       }
                        for (rowCount = height / 2; rowCount < height; rowCount++)
-                        {
+                       {
                                pTmpOutColY = pDstY + (outWidth *  (outHeight - 1)) + rowCount;
                                // pTmpOutCol points to the top of the output column being filled.
                                for (colCount = 0; colCount < width; colCount++)
@@ -988,7 +1121,7 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                                        pTmpOutColY -= outWidth;
                                }
                        }
-                }
+               }
                break;
                default:
                break;
@@ -1057,7 +1190,7 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                                *pTmpOutColY-- = *pSrcY++;
                        }
                }
-                break;
+               break;
                case IMAGE_ROTATION_270:
                {
                        // Copying from all source rows to destination columns of Y plane.
@@ -1124,14 +1257,14 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                                for (colCount = 0; colCount < width / 2; colCount++)
                                {
                                        *pTmpOutColU = *pSrcU++;
-                                        pTmpOutColU += outWidth;
+                                       pTmpOutColU += outWidth;
                                        *pTmpOutColV = *pSrcV++;
                                        pTmpOutColV += outWidth;
                                        *pTmpOutColY = *pSrcY++;
                                        pTmpOutColY += outWidth;
 
                                        *pTmpOutColU = *pSrcU++;
-                                        pTmpOutColU += outWidth;
+                                       pTmpOutColU += outWidth;
                                        *pTmpOutColV = *pSrcV++;
                                        pTmpOutColV += outWidth;
                                        *pTmpOutColY = *pSrcY++;
@@ -1198,24 +1331,24 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                {
                case IMAGE_ROTATION_90:
                {
-                        // Copying from all source rows to destination columns.
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                // pTmpOutCol points to the top of the output column being filled.
-                                pTmpOutCol = pDstBuf + outWidth - 1 - rowCount;
-                                for (colCount = 0; colCount < width / 2 ; colCount++)
-                                {
+                       // Copying from all source rows to destination columns.
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               // pTmpOutCol points to the top of the output column being filled.
+                               pTmpOutCol = pDstBuf + outWidth - 1 - rowCount;
+                               for (colCount = 0; colCount < width / 2 ; colCount++)
+                               {
                                        *pTmpOutCol = *pSrcBuf++; // copied Y0 U0
                                        pTmpOutCol += outWidth;
 
                                        *pTmpOutCol = *pSrcBuf++; // copied Y1 V0
                                        pTmpOutCol += outWidth;
-                                }
-                        }
-                }
-                break;
+                               }
+                       }
+               }
+               break;
                case IMAGE_ROTATION_180:
-                {
+               {
                        // Copying all source rows to destination columns.
                        for (rowCount = 0; rowCount < height; rowCount++)
                        {
@@ -1672,20 +1805,8 @@ _ImageUtil::Rotate(const ByteBuffer& srcBuf,
                                        ImageRotationType rotate)
 {
        result r = E_SUCCESS;
-       int ret = 0;
-#ifdef USE_MM_UTIL
-       mm_util_img_format colorFormat = MM_UTIL_IMG_FMT_NUM;
-       mm_util_img_rotate_type rotation = MM_UTIL_ROTATE_NUM;
-
-       unsigned int outWidth = 0;
-       unsigned int outHeight = 0;
-#else
-       image_util_colorspace_e colorFormat = IMAGE_UTIL_COLORSPACE_RGB565;
-       image_util_rotation_e rotation = IMAGE_UTIL_ROTATION_NONE;
        int outWidth = 0;
        int outHeight = 0;
-#endif
-
 
        SysTryCatch(NID_MEDIA, IS_VALID_BUF(srcBuf, pixelFormat, width, height),
                r = E_INVALID_ARG, E_INVALID_ARG,
@@ -1719,7 +1840,8 @@ _ImageUtil::Rotate(const ByteBuffer& srcBuf,
                outHeight = height;
        }
 
-       return  RotateBuffer( (byte *)srcBuf.GetPointer(), pixelFormat, width, height, (byte *)dstBuf.GetPointer(), (int &)outWidth, (int &)outHeight, rotate);
+       return  RotateBuffer((byte *)srcBuf.GetPointer(), pixelFormat, width, height,
+                       (byte *)dstBuf.GetPointer(), outWidth, outHeight, rotate);
 CATCH:
        return r;
 }
@@ -2101,81 +2223,15 @@ _ImageUtil::Crop(const Tizen::Base::ByteBuffer &srcBuf,
                                 int dstX, int dstY, int dstWidth, int dstHeight)
 {
        result r = E_SUCCESS;
-       byte* pInBuffer = null;
-       byte* pOutBuffer = null;
-       int copyRowWidth = 0;
-       int srcRowWidth = 0;
-       int bpp = 0;
-
-       SysTryCatch(NID_MEDIA, srcWidth > 0 && srcHeight > 0, r = E_INVALID_ARG, E_INVALID_ARG,
-               "[E_INVALID_ARG] Invalid src dimension: Should be greater than zero (%d x %d)", srcWidth, srcHeight);
-       SysTryCatch(NID_MEDIA, dstWidth > 0 && dstHeight > 0, r = E_INVALID_ARG, E_INVALID_ARG,
-               "[E_INVALID_ARG] Invalid dst dimension: Should be greater than zero (%d x %d)", dstWidth, dstHeight);
-       SysTryCatch(NID_MEDIA, dstX >= 0 && dstY >= 0, r = E_INVALID_ARG, E_INVALID_ARG,
-               "[E_INVALID_ARG] Invalid offset dimension: Should be greater than zero (%d x %d)", dstX, dstY);
-
-       SysTryCatch(NID_MEDIA, (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE) ||
-               (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888) ||
-               (pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888),
-               r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
-               "Unsupported pixelFormat: %d", pixelFormat);
-
-       SysTryCatch(NID_MEDIA, IsValidDimension(pixelFormat, srcWidth, srcHeight),
-               r = E_INVALID_ARG, E_INVALID_ARG,
-               "[E_INVALID_ARG] Dimensions should be even (%d x %d).", srcWidth, srcHeight);
-
-       SysTryCatch(NID_MEDIA, IS_VALID_BUF(srcBuf, pixelFormat, srcWidth, srcHeight),
-               r = E_INVALID_ARG, E_INVALID_ARG,
-               "Invalid buffer size (%d) for format (%d), width (%d), height (%d)",
-               srcBuf.GetLimit(), pixelFormat, srcWidth, srcHeight);
-
-       SysTryCatch(NID_MEDIA, IsValidDimension(pixelFormat, dstWidth, dstHeight),
-               r = E_INVALID_ARG, E_INVALID_ARG,
-               "[E_INVALID_ARG] Dimensions should be even (%d x %d).", dstWidth, dstHeight);
-
-       SysTryCatch(NID_MEDIA, IS_VALID_BUF(dstBuf, pixelFormat, dstWidth, dstHeight),
-               r = E_INVALID_ARG, E_INVALID_ARG,
-               "Invalid buffer size (%d) for format (%d), width (%d), height (%d)",
-               dstBuf.GetLimit(), pixelFormat, dstWidth, dstHeight);
-
-       SysTryCatch(NID_MEDIA, dstWidth + dstX <= srcWidth , r = E_INVALID_ARG, E_INVALID_ARG,
-               "Invalid Clip Area : destination \"x\" (%d) exceeds image width (%d).",
-               dstWidth + dstX, srcWidth);
-
-       SysTryCatch(NID_MEDIA, dstHeight + dstY <= srcHeight , r = E_INVALID_ARG, E_INVALID_ARG,
-               "Invalid Clip Area  : destination \"y\" (%d) exceeds image height (%d).",
-               dstHeight + dstY, srcHeight);
-
-       pOutBuffer = (byte *)dstBuf.GetPointer();
-
-       if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
-       {
-               bpp = 2;
-               // pInBuffer points to the start of the region to be copied to destination.
-               pInBuffer = (byte *)srcBuf.GetPointer() + (dstY * srcWidth * bpp) + (dstX * bpp);
-               copyRowWidth = dstWidth * bpp;
-               srcRowWidth = srcWidth * bpp;
-       }
-       else
-       {
-               bpp = 4;
-               // pInBuffer points to the start of the region to be copied to destination.
-               pInBuffer = (byte *)srcBuf.GetPointer() + (dstY * srcWidth * bpp) + (dstX * bpp);
-               copyRowWidth = dstWidth * bpp; // BGRA and RGBA are 4 bytes each.
-               srcRowWidth = srcWidth * bpp;
-       }
 
-       for (int i = dstY; i < dstY + dstHeight; i++)
-       {
-               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
-               pOutBuffer += copyRowWidth;
-               pInBuffer += srcRowWidth;
-       }
+    r = CropBuffer(srcBuf.GetPointer(), pixelFormat, srcWidth, srcHeight,
+               const_cast<byte*>(dstBuf.GetPointer()), dstX, dstY, dstWidth, dstHeight);
+       SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] _ImageUtil::CropBuffer failed.",
+               GetErrorMessage(r));
 
        r = dstBuf.SetLimit(_ImageUtil::GetBufferSize(pixelFormat, dstWidth, dstHeight));
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] ByteBuffer.SetLimit to %d failed.",
                GetErrorMessage(r), _ImageUtil::GetBufferSize(pixelFormat, dstWidth, dstHeight));
-       return r;
 
 CATCH:
        return r;
@@ -2202,11 +2258,8 @@ _ImageUtil::CropBuffer(const byte* srcBuf,
        SysTryCatch(NID_MEDIA, dstX >= 0 && dstY >= 0, r = E_INVALID_ARG, E_INVALID_ARG,
                "[E_INVALID_ARG] Invalid offset dimension: Should be greater than zero (%d x %d)", dstX, dstY);
 
-       SysTryCatch(NID_MEDIA, (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE) ||
-               (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888) ||
-               (pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888),
-               r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
-               "Unsupported pixelFormat: %d", pixelFormat);
+       SysTryCatch(NID_MEDIA, IS_VALID_PIXEL(pixelFormat), r = E_UNSUPPORTED_FORMAT, E_UNSUPPORTED_FORMAT,
+               "[E_UNSUPPORTED_FORMAT] Unsupported pixelFormat: %d", pixelFormat);
 
        SysTryCatch(NID_MEDIA, IsValidDimension(pixelFormat, srcWidth, srcHeight),
                r = E_INVALID_ARG, E_INVALID_ARG,
@@ -2226,28 +2279,154 @@ _ImageUtil::CropBuffer(const byte* srcBuf,
 
        pOutBuffer = dstBuf;
 
-       if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
+       switch(pixelFormat)
        {
-               bpp = 2;
-               // pInBuffer points to the start of the region to be copied to destination.
-               pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
-               copyRowWidth = dstWidth * bpp;
-               srcRowWidth = srcWidth * bpp;
-       }
-       else
-       {
-               bpp = 4;
-               // pInBuffer points to the start of the region to be copied to destination.
-               pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
-               copyRowWidth = dstWidth * bpp; // BGRA and RGBA are 4 bytes each.
-               srcRowWidth = srcWidth * bpp;
-       }
+               case MEDIA_PIXEL_FORMAT_GRAY:
+               {
+                       bpp = 1;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp;
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               case MEDIA_PIXEL_FORMAT_RGB565LE:
+               {
+                       bpp = 2;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp;
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               case MEDIA_PIXEL_FORMAT_RGB888:
+               case MEDIA_PIXEL_FORMAT_BGR888:
+               {
+                       bpp = 3;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp;
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               case MEDIA_PIXEL_FORMAT_RGBA8888:
+               case MEDIA_PIXEL_FORMAT_BGRA8888:
+               {
+                       bpp = 4;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp; // BGRA and RGBA are 4 bytes each.
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               case MEDIA_PIXEL_FORMAT_YUV444P:
+               {
+                       bpp = 1;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp;
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               memcpy(pOutBuffer + (dstWidth * dstHeight), pInBuffer + (srcWidth * srcHeight), copyRowWidth);
+                               memcpy(pOutBuffer + (2 * dstWidth * dstHeight), pInBuffer + (2 * srcWidth * srcHeight), copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               case MEDIA_PIXEL_FORMAT_YUYV422:
+               {
+                       bpp = 2;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp;
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               case MEDIA_PIXEL_FORMAT_YUV420P:
+               {
+                       bpp = 1;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp;
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
 
-       for (int i = dstY; i < dstY + dstHeight; i++)
-       {
-               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
-               pOutBuffer += copyRowWidth;
-               pInBuffer += srcRowWidth;
+                       pOutBuffer = dstBuf + (dstWidth * dstHeight);
+                       pInBuffer = const_cast<byte*>(srcBuf) + (srcWidth * srcHeight) + (dstY/2 * srcWidth/2) + (dstX/2);
+                       copyRowWidth /= 2;
+                       srcRowWidth /= 2;
+                       for (int i = 0; i < dstHeight/2; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               memcpy(pOutBuffer + (dstWidth * dstHeight)/4, pInBuffer + (srcWidth * srcHeight)/4, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               case MEDIA_PIXEL_FORMAT_NV12:
+               case MEDIA_PIXEL_FORMAT_NV21:
+               {
+                       bpp = 1;
+                       // pInBuffer points to the start of the region to be copied to destination.
+                       pInBuffer = const_cast<byte*>(srcBuf) + (dstY * srcWidth * bpp) + (dstX * bpp);
+                       copyRowWidth = dstWidth * bpp;
+                       srcRowWidth = srcWidth * bpp;
+                       for (int i = dstY; i < dstY + (dstHeight)/2; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               memcpy(pOutBuffer + (dstWidth * dstHeight), pInBuffer + (srcWidth * srcHeight), copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+                       for (int i = dstY + (dstHeight + 1)/2; i < dstY + dstHeight; i++)
+                       {
+                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                               pOutBuffer += copyRowWidth;
+                               pInBuffer += srcRowWidth;
+                       }
+               }
+               break;
+               default:
+                       r = E_UNSUPPORTED_FORMAT;
        }
 
 CATCH:
@@ -2385,6 +2564,7 @@ _ImageUtil::GetBufferSize(MediaPixelFormat pixelFormat, int width, int height)
                { MEDIA_PIXEL_FORMAT_RGBA8888, {4, 1}},
                { MEDIA_PIXEL_FORMAT_BGRA8888, {4, 1}},
                { MEDIA_PIXEL_FORMAT_YUV420P, {3, 2}},
+               { MEDIA_PIXEL_FORMAT_GRAY, {1, 1}},
                { MEDIA_PIXEL_FORMAT_NV12, {3, 2}},
                { MEDIA_PIXEL_FORMAT_NV21, {3, 2}},
                { MEDIA_PIXEL_FORMAT_YUV444P, {3, 1}},
@@ -2410,6 +2590,7 @@ _ImageUtil::GetBufferSize(MediaPixelFormat pixelFormat, int width, int height)
                "Could not find details for pixelformat %d.", pixelFormat);
 
        SetLastResult(E_SUCCESS);
+
        return width * height * ret.num / ret.den;
 
 CATCH:
@@ -2422,6 +2603,7 @@ _ImageUtil::IsValidDimension(MediaPixelFormat pixelFormat, int width, int height
        MediaPixelFormat fmt[] = {
                MEDIA_PIXEL_FORMAT_YUV420P,
                MEDIA_PIXEL_FORMAT_NV12,
+               MEDIA_PIXEL_FORMAT_NV21,
                MEDIA_PIXEL_FORMAT_YUYV422,
        };
 
index ec32eb9..aff3f76 100644 (file)
@@ -70,6 +70,7 @@ _SlpUtil::ToColorspace(MediaPixelFormat pixelFormat)
        { MEDIA_PIXEL_FORMAT_YUV420P, IMAGE_UTIL_COLORSPACE_YV12 },
        { MEDIA_PIXEL_FORMAT_YUYV422, IMAGE_UTIL_COLORSPACE_YUYV },
        { MEDIA_PIXEL_FORMAT_NV12, IMAGE_UTIL_COLORSPACE_NV12 },
+       { MEDIA_PIXEL_FORMAT_NV21, IMAGE_UTIL_COLORSPACE_NV12 },
        };
        image_util_colorspace_e ret = (image_util_colorspace_e)0xff;
 
@@ -149,6 +150,7 @@ _SlpUtil::ToMmUtilImgFormat(Tizen::Media::MediaPixelFormat pixelFormat)
        { MEDIA_PIXEL_FORMAT_YUV420P,  MM_UTIL_IMG_FMT_YUV420 },
        { MEDIA_PIXEL_FORMAT_YUYV422,  MM_UTIL_IMG_FMT_YUYV },
        { MEDIA_PIXEL_FORMAT_NV12,       MM_UTIL_IMG_FMT_NV12 },
+       { MEDIA_PIXEL_FORMAT_NV21,       MM_UTIL_IMG_FMT_NV12 },
        };
        mm_util_img_format ret = MM_UTIL_IMG_FMT_RGB565;
 
index e9bd8a8..e06e1c2 100644 (file)
@@ -164,6 +164,8 @@ private:
 
        static result ResizeRGB565(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
 
+       static result ResizeGray(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
+
        static result ResizeYUV444(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
 
        static result ResizeYUYV422(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);