Init Tizen 2.2.1 submit/tizen_2.2/20131107.105112
authorSehong Na <sehong.na@samsung.com>
Thu, 7 Nov 2013 10:50:49 +0000 (19:50 +0900)
committerSehong Na <sehong.na@samsung.com>
Thu, 7 Nov 2013 10:50:49 +0000 (19:50 +0900)
inc/FMediaImageTypes.h
packaging/osp-image-core.spec
src/FMedia_ExifUtil.cpp [changed mode: 0644->0755]
src/FMedia_GifDecoder.cpp
src/FMedia_ImageUtil.cpp
src/FMedia_JpegDecoder.cpp
src/FMedia_MediaUtil.cpp
src/FMedia_PngEncoder.cpp
src/inc/FMedia_ImageUtil.h

index 958bdf7..5cecae0 100644 (file)
@@ -17,7 +17,7 @@
 
 /**
  * @file               FMediaImageTypes.h
- * @brief              This is the header file for the common types of the Image class.
+ * @brief              This is the header file for the common types in the %Image class.
  *
  * This header file contains the declarations of the enumerations of the Image class.
  */
@@ -38,39 +38,39 @@ namespace Tizen { namespace Media
 enum ImageFormat
 {
        IMG_FORMAT_NONE = -1,       /**< No image format type */
-       IMG_FORMAT_JPG = 0,         /**< The JPEG image format type*/
-       IMG_FORMAT_PNG,             /**< The PNG image format type*/
-       IMG_FORMAT_GIF,             /**< The GIF image format type*/
-       IMG_FORMAT_BMP,             /**< The BMP image format type*/
-       IMG_FORMAT_TIFF,            /**< The TIFF image format type*/
-       IMG_FORMAT_WBMP,            /**< The WBMP image format type*/
+       IMG_FORMAT_JPG = 0,         /**< The JPEG image format type */
+       IMG_FORMAT_PNG,             /**< The PNG image format type */
+       IMG_FORMAT_GIF,             /**< The GIF image format type */
+       IMG_FORMAT_BMP,             /**< The BMP image format type */
+       IMG_FORMAT_TIFF,            /**< The TIFF image format type */
+       IMG_FORMAT_WBMP,            /**< The WBMP image format type */
 };
 
 /**
  * @enum ImageRotationType
  *
- * Defines the types of rotation.
+ * Defines the types of rotations.
  *
  * @since      2.0
  */
 enum ImageRotationType
 {
-       IMAGE_ROTATION_0 = 0x00,    /**< The no-rotation */
-       IMAGE_ROTATION_90,          /**< The 90 degree rotation in clockwise direction */
-       IMAGE_ROTATION_180,         /**< The 180 degree rotation in clockwise direction */
-       IMAGE_ROTATION_270,         /**< The 270 degree rotation in clockwise direction */
+       IMAGE_ROTATION_0 = 0x00,    /**< No rotation type */
+       IMAGE_ROTATION_90,          /**< The 90 degree rotation in the clockwise direction */
+       IMAGE_ROTATION_180,         /**< The 180 degree rotation in the clockwise direction */
+       IMAGE_ROTATION_270,         /**< The 270 degree rotation in the clockwise direction */
 };
 
 /**
  * @enum ImageFlipType
  *
- * Defines the types of flip.
+ * Defines the types of flips.
  *
  * @since      2.0
  */
 enum ImageFlipType
 {
-       IMAGE_FLIP_NONE = 0x00,     /**< The no-flip type */
+       IMAGE_FLIP_NONE = 0x00,     /**< No flip type */
        IMAGE_FLIP_HORIZONTAL,      /**< The horizontal flip */
        IMAGE_FLIP_VERTICAL,        /**< The vertical flip */
 };
@@ -84,7 +84,7 @@ enum ImageFlipType
  */
 enum MediaPixelFormat
 {
-       MEDIA_PIXEL_FORMAT_NONE = 0x0000,     // The undefined pixel format
+       MEDIA_PIXEL_FORMAT_NONE = 0x0000,     /**< The undefined pixel format */
        MEDIA_PIXEL_FORMAT_RGB565LE = 0x0001, /**< The RGB565 little-endian format */
        MEDIA_PIXEL_FORMAT_RGB565BE,          /**< The RGB565 big-endian format */
        MEDIA_PIXEL_FORMAT_RGB888 = 0x0100,   /**< The RGB888 format */
@@ -104,7 +104,7 @@ enum MediaPixelFormat
 /**
  * @enum ImageScalingMethod
  *
- * Defines the image scaling method.
+ * Defines the image scaling methods.
  *
  * @since  2.1
  */
@@ -124,14 +124,14 @@ enum ImageScalingMethod
  */
 enum ExifOrientation
 {
-       EXIF_ORIENTATION_TOP_LEFT = 0x01,     /**< The row #0 is top, column #0 is left     */
-       EXIF_ORIENTATION_TOP_RIGHT,           /**< The row #0 is top, column #0 is right    */
-       EXIF_ORIENTATION_BOTTOM_RIGHT,        /**< The row #0 is bottom, column #0 is right */
-       EXIF_ORIENTATION_BOTTOM_LEFT,         /**< The row #0 is bottom, column #0 is left  */
-       EXIF_ORIENTATION_LEFT_TOP,            /**< The row #0 is left, column #0 is top     */
-       EXIF_ORIENTATION_RIGHT_TOP,           /**< The row #0 is right, column #0 is top    */
-       EXIF_ORIENTATION_RIGHT_BOTTOM,        /**< The row #0 is right, column #0 is bottom */
-       EXIF_ORIENTATION_LEFT_BOTTOM,         /**< The row #0 is left, column #0 is bottom  */
+       EXIF_ORIENTATION_TOP_LEFT = 0x01,     /**< The 0th row is on the top, the 0th column is to the left */
+       EXIF_ORIENTATION_TOP_RIGHT,           /**< The 0th row is on the top, the 0th column is to the right */
+       EXIF_ORIENTATION_BOTTOM_RIGHT,        /**< The 0th row is at the bottom, the 0th column is to the right */
+       EXIF_ORIENTATION_BOTTOM_LEFT,         /**< The 0th row is at the bottom, the 0th column is to the left */
+       EXIF_ORIENTATION_LEFT_TOP,            /**< The 0th row is to the left, the 0th column is at the top */
+       EXIF_ORIENTATION_RIGHT_TOP,           /**< The 0th row is to the right, the 0th column is at the top */
+       EXIF_ORIENTATION_RIGHT_BOTTOM,        /**< The 0th row is to the right, the 0th column is at the bottom */
+       EXIF_ORIENTATION_LEFT_BOTTOM,         /**< The 0th row is to the left, the 0th column is at the bottom */
 };
 
 };
index eb2ec64..042c01f 100755 (executable)
@@ -65,11 +65,24 @@ The Media Image Core library of OSP (DEV)
 %setup -q
 
 %build
+%if 0%{?tizen_build_binary_release_type_eng}
+CXXFLAGS="$CXXFLAGS -D_SECURE_LOG"
+%endif
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %ifarch %{ix86}
-CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=x86
+%if 0%{?simulator}
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=x86
+%else
+CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ " cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=x86
+%endif
 %else
+
+%if 0%{?tizen_build_binary_release_type_eng}
 CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=arm
+%else
+CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DOBS=1 -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DARCH=arm
+%endif
+
 %endif
 
 # Call make instruction with smp support
old mode 100644 (file)
new mode 100755 (executable)
index f0a7264..0ad53cb
@@ -139,9 +139,9 @@ void _ExifUtil::ForEachEntry(struct _ExifEntry *pEntry)
        switch ((int)pEntry->tag)
        {
        case EXIF_TAG_ORIENTATION:
-               if (pEntry->format == EXIF_FORMAT_SHORT && pEntry->size == 2)
+               if (pEntry->format == EXIF_FORMAT_SHORT && pEntry->size == 2 && __orientationExist != true)
                {
-                       __orientation = *(short*)(pEntry->data);
+                       __orientation = exif_get_short(pEntry->data, o);
                        __orientationExist = true;
                }
                break;
index c6c1a9e..e8b4e10 100644 (file)
@@ -121,6 +121,7 @@ _GifDecoder::ConstructBuffer(MediaPixelFormat pixelFormat)
        //                      "[%s] Propagated.", GetErrorMessage(GetLastResult()));
 
        __dstLength = __pDec->SWidth * __pDec->SHeight * __bpp;
+
        SysTryReturn(NID_MEDIA, __dstLength > 0, E_SYSTEM, E_SYSTEM, "invalid size:%d", __dstLength);
        __pDstByte.reset(new (std::nothrow) byte[__dstLength]);
        SysTryReturn(NID_MEDIA, __pDstByte.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
@@ -248,6 +249,8 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
        int col = 0;
        int width = 0;
        int height = 0;
+       int frameWidth = 0;
+       int frameHeight = 0;
        int count = 0;
        std::unique_ptr<byte[]> pLine;
        byte* pPalette = null;
@@ -258,19 +261,21 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
 
        row = __pDec->Image.Top; // Image Position relative to Screen.
        col = __pDec->Image.Left;
-       width = __pDec->Image.Width;
-       height = __pDec->Image.Height;
 
-       pLine.reset(new (std::nothrow) byte[width]);
-       SysTryReturn(NID_MEDIA, pLine.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
-               "[E_OUT_OF_MEMORY] Failed to allocate %d bytes for new pLine", width);
+       // If there is mismatch in screen dimensions and frame dimensions,
+       // use the smaller dimension to write to output buffer, but read using
+       // original dimensions, ie, use Image.Width to read a line from the decoder.
+       // But when writing to the output buffer, use only screen dimensions.
+
+       frameWidth = __pDec->Image.Width;
+       frameHeight = __pDec->Image.Height;
 
-       SysTryReturn(NID_MEDIA, __pDec->Image.Left + __pDec->Image.Width <= __pDec->SWidth &&
-               __pDec->Image.Top + __pDec->Image.Height <= __pDec->SHeight,
-               E_INVALID_DATA, E_INVALID_DATA,
-               "Image area exceeds it's frame size : (%d + %d) x (%d + %d) should be within (%d x %d)",
-               __pDec->Image.Left, __pDec->Image.Width, __pDec->Image.Top, __pDec->Image.Height,
-               __pDec->SWidth, __pDec->SHeight);
+       width = __pDec->Image.Width < __pDec->SWidth? __pDec->Image.Width : __pDec->SWidth;
+       height = __pDec->Image.Height < __pDec->SHeight? __pDec->Image.Height : __pDec->SHeight;
+
+       pLine.reset(new (std::nothrow) byte[frameWidth]);
+       SysTryReturn(NID_MEDIA, pLine.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+               "[E_OUT_OF_MEMORY] Failed to allocate %d bytes for new pLine", frameWidth);
 
        // Update Color map
        if (__pDec->Image.ColorMap != null)
@@ -305,7 +310,7 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                                for (j = row + _INTERLACED_OFFSET[loopIndex]; j < row + height; j += _INTERLACED_JUMPS[loopIndex])
                                {
                                        unsigned short* pBuf = (unsigned short*) pDstBuffer + __pDec->SWidth * (row + j) + col;
-                                       r = DGifGetLine(__pDec, pLine.get(), width);
+                                       r = DGifGetLine(__pDec, pLine.get(), frameWidth);
                                        SysTryReturn(NID_MEDIA, r != GIF_ERROR, E_INVALID_DATA, E_INVALID_DATA,
                                           "[E_INVALID_DATA] DGifGetLineByte failed with code %x", GifLastError());
 
@@ -341,7 +346,7 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                                for (j = row + _INTERLACED_OFFSET[loopIndex]; j < row + height; j += _INTERLACED_JUMPS[loopIndex])
                                {
                                        unsigned int* pBuf = (unsigned int*) pDstBuffer + __pDec->SWidth * (row + j) + col;
-                                       r = DGifGetLine(__pDec, pLine.get(), width);
+                                       r = DGifGetLine(__pDec, pLine.get(), frameWidth);
                                        SysTryReturn(NID_MEDIA, r != GIF_ERROR, E_INVALID_DATA, E_INVALID_DATA,
                                           "[E_INVALID_DATA] DGifGetLineByte failed with code %x", GifLastError());
                                        if (__transparent)
@@ -386,7 +391,7 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                        for (loopIndex = 0; loopIndex < height; loopIndex++)
                        {
                                unsigned short* pBuf = (unsigned short*) pDstBuffer + __pDec->SWidth * (row + loopIndex) + col;
-                               r = DGifGetLine(__pDec, pLine.get(), width);
+                               r = DGifGetLine(__pDec, pLine.get(), frameWidth);
                                SysTryReturn(NID_MEDIA, r != GIF_ERROR, E_INVALID_DATA, E_INVALID_DATA,
                                   "[E_INVALID_DATA] DGifGetLineByte failed with code %x", GifLastError());
                                for (k = 0; k < width; k++)
@@ -416,7 +421,7 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                        for (loopIndex = 0; loopIndex < height; loopIndex++)
                        {
                                unsigned int* pBuf = (unsigned int*) pDstBuffer + __pDec->SWidth * (row + loopIndex) + col;
-                               r = DGifGetLine(__pDec, pLine.get(), width);
+                               r = DGifGetLine(__pDec, pLine.get(), frameWidth);
                                SysTryReturn(NID_MEDIA, r != GIF_ERROR, E_INVALID_DATA, E_INVALID_DATA,
                                   "[E_INVALID_DATA] DGifGetLineByte failed with code %x", GifLastError());
                                if (__transparent)
index e2b10bb..b0bdb07 100644 (file)
@@ -46,8 +46,10 @@ namespace Tizen { namespace Media
        ((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_YUV444P) || (x == MEDIA_PIXEL_FORMAT_YUYV422)      \
-       || (x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_NV12) || (x == MEDIA_PIXEL_FORMAT_NV21))
+       || ( x == MEDIA_PIXEL_FORMAT_YUV444P)                                                                           \
+       || (x == MEDIA_PIXEL_FORMAT_YUYV422) || (x == MEDIA_PIXEL_FORMAT_UYVY422)               \
+       || (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())
@@ -429,8 +431,8 @@ _ImageUtil::ResizeYUV444(const byte* pDataIn, byte* pDataOut, int inWidth, int i
 }
 
 /*
-* Input is assumed to be YUYV422
-* pDataIn      => Input YUYV422 Buffer
+* Input is assumed to be either YUYV422 or UYVY422
+* pDataIn      => Input YUYV422 or UYVY422 Buffer
 * pDataOut     => Output buffer, allocated by caller
 * inWidth      => Input Width
 * inHeight     => Input Height
@@ -441,7 +443,7 @@ result
 _ImageUtil::ResizeYUYV422(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight)
 {
 
-       return ResizeRGB565(pDataIn, pDataOut, inWidth, inHeight, outWidth, outHeight);
+       return Resize8888(pDataIn, pDataOut, inWidth/2, inHeight, outWidth/2, outHeight);
 }
 
 /*
@@ -624,6 +626,7 @@ _ImageUtil::ResizeBuffer(const byte* pInBuf, MediaPixelFormat pixelFormat,
        {
 
                case MEDIA_PIXEL_FORMAT_RGBA8888:
+                       // fall through
                case MEDIA_PIXEL_FORMAT_BGRA8888:
                {
                         r = Resize8888(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
@@ -655,6 +658,8 @@ _ImageUtil::ResizeBuffer(const byte* pInBuf, MediaPixelFormat pixelFormat,
                break;
 
                case MEDIA_PIXEL_FORMAT_YUYV422:
+                       // fall through
+               case MEDIA_PIXEL_FORMAT_UYVY422:
                {
                        r = ResizeYUYV422(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
                }
@@ -667,6 +672,7 @@ _ImageUtil::ResizeBuffer(const byte* pInBuf, MediaPixelFormat pixelFormat,
                break;
 
                case MEDIA_PIXEL_FORMAT_NV12:
+                       // fall through
                case MEDIA_PIXEL_FORMAT_NV21:
                {
                        r = ResizeNV12(pInBuf, pOutBuf, srcWidth, srcHeight, dstWidth, dstHeight);
@@ -725,7 +731,9 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                outHeight = height;
        }
 
-       if (pixelFormat == MEDIA_PIXEL_FORMAT_GRAY)
+       switch(pixelFormat)
+       {
+       case MEDIA_PIXEL_FORMAT_GRAY:
        {
                int rowCount = 0;
                int colCount = 0;
@@ -786,7 +794,8 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
+       break;
+       case MEDIA_PIXEL_FORMAT_RGB888:
        {
                int rowCount = 0;
                int colCount = 0;
@@ -831,13 +840,13 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
 
                                for (colCount = 0; colCount < width / 2; colCount++)
                                {
-                                       pTmpOutCol -= 2;         // move to R bye of pixel
+                                       pTmpOutCol -= 2;         // move to R byte of pixel
                                        *pTmpOutCol++ = *pSrcBuf++; // copied R
                                        *pTmpOutCol++ = *pSrcBuf++; // copied G
                                        *pTmpOutCol = *pSrcBuf++;   // copied B
                                        pTmpOutCol -= 3; // move to  next pixel to get copied
 
-                                       pTmpOutCol -= 2;         // move to R bye of pixel
+                                       pTmpOutCol -= 2;         // move to R byte of pixel
                                        *pTmpOutCol++ = *pSrcBuf++; // copied R
                                        *pTmpOutCol++ = *pSrcBuf++; // copied G
                                        *pTmpOutCol = *pSrcBuf++;   // copied B
@@ -875,7 +884,8 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
+       break;
+       case MEDIA_PIXEL_FORMAT_RGB565LE:
        {
                switch (rotate)
                {
@@ -946,7 +956,10 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888 || pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+       break;
+       case MEDIA_PIXEL_FORMAT_RGBA8888:
+               // fall through
+       case MEDIA_PIXEL_FORMAT_BGRA8888:
        {
                switch (rotate)
                {
@@ -1017,7 +1030,8 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV420P)
+       break;
+       case MEDIA_PIXEL_FORMAT_YUV420P:
        {
                int rowCount = 0;
                int colCount = 0;
@@ -1127,8 +1141,10 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_NV12
-                       || pixelFormat == MEDIA_PIXEL_FORMAT_NV21)
+       break;
+       case MEDIA_PIXEL_FORMAT_NV12:
+               // fall through
+       case MEDIA_PIXEL_FORMAT_NV21:
        {
                int rowCount = 0;
                int colCount = 0;
@@ -1228,7 +1244,8 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV444P)
+       break;
+       case MEDIA_PIXEL_FORMAT_YUV444P:
        {
                int rowCount = 0;
                int colCount = 0;
@@ -1319,46 +1336,179 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUYV422)
+       break;
+       case MEDIA_PIXEL_FORMAT_YUYV422:
        {
                int rowCount = 0;
                int colCount = 0;
-               short* pSrcBuf = (short*)srcBuf;
-               short* pDstBuf = (short*)dstBuf;
-               short* pTmpOutCol = null;
+               byte* pSrcBuf = const_cast<byte*>(srcBuf);
+               byte* pDstBuf = dstBuf;
+               byte* pTmpOutCol = null;
+               byte* pTmpOut = null;
 
                switch (rotate)
                {
                case IMAGE_ROTATION_90:
                {
+                       pTmpOutCol = pDstBuf + (outWidth * 2);
                        // Copying from all source rows to destination columns.
-                       for (rowCount = 0; rowCount < height; rowCount++)
+                       for (rowCount = 0; rowCount < height; rowCount += 2)
                        {
                                // pTmpOutCol points to the top of the output column being filled.
-                               pTmpOutCol = pDstBuf + outWidth - 1 - rowCount;
+                               pTmpOutCol -= 4;
+                               pTmpOut = pTmpOutCol;
+                               pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
                                for (colCount = 0; colCount < width / 2 ; colCount++)
                                {
-                                       *pTmpOutCol = *pSrcBuf++; // copied Y0 U0
-                                       pTmpOutCol += outWidth;
-
-                                       *pTmpOutCol = *pSrcBuf++; // copied Y1 V0
-                                       pTmpOutCol += outWidth;
+                                       /*
+                                               y0 u0 y1 v1      y2 u2 y0 v1
+                                                                       ==>
+                                               y2 u2 y3 v3      y3 u2 y1 v1
+                                       */
+                                       pTmpOut[0] = pSrcBuf[(width * 2)];     // copied y2
+                                       pTmpOut[1] = pSrcBuf[(width * 2) + 1]; // copied u2
+                                       pTmpOut[2] = pSrcBuf[0];               // copied y0
+                                       pTmpOut[3] = pSrcBuf[3];          // copied v1
+                                       pTmpOut += outWidth * 2;
+
+                                       pTmpOut[0] = pSrcBuf[(width * 2) + 2]; // copied y3
+                                       pTmpOut[1] = pSrcBuf[(width * 2) + 1]; // copied u2
+                                       pTmpOut[2] = pSrcBuf[2];               // copied y1
+                                       pTmpOut[3] = pSrcBuf[3];               // copied v1
+                                       pTmpOut += outWidth * 2;
+
+                                       pSrcBuf += 4;
                                }
                        }
                }
                break;
                case IMAGE_ROTATION_180:
                {
-                       // Copying all source rows to destination columns.
+                       // Copying all source rows to destination rows in reverse.
+                       // pTmpOut points to the end of last row: u0y1 v1y0
+                       pTmpOut = pDstBuf + (outWidth * outHeight * 2) - 4;
                        for (rowCount = 0; rowCount < height; rowCount++)
                        {
+                               for (colCount = 0; colCount < width / 2; colCount++)
+                               {
+                                       /*
+                                               y0 u0 y1 v1 => y1 u1 y0 v0
+                                       */
+                                       pTmpOut[0] = pSrcBuf[2]; // copied y1
+                                       pTmpOut[1] = pSrcBuf[1]; // copied u0
+                                       pTmpOut[2] = pSrcBuf[0]; // copied y0
+                                       pTmpOut[3] = pSrcBuf[3]; // copied v1
+                                       pSrcBuf += 4;
+                                       pTmpOut -= 4;
+                               }
+                       }
+               }
+               break;
+               case IMAGE_ROTATION_270:
+               {
+                       // Copying all source rows to destination columns.
+                       pTmpOutCol = pDstBuf + (outWidth * (outHeight - 1) * 2);
+                       for (rowCount = 0; rowCount < height; rowCount += 2)
+                       {
+                               pTmpOut = pTmpOutCol;
+                               pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
                                // pTmpOutCol points to the bottom of the column being filled.
-                               pTmpOutCol = pDstBuf + ((outWidth * outHeight ) - 1) - (rowCount * outWidth);
+                               for (colCount = 0; colCount < width / 2; colCount++)
+                               {
+                                       /*
+                                               y0 u0 y1 v1      y1 u0 y3 v3
+                                                                       ==>
+                                               y2 u2 y3 v3      y0 u0 y2 v3
+                                       */
+                                       pTmpOut[0] = pSrcBuf[0];               // copied y0
+                                       pTmpOut[1] = pSrcBuf[1];               // copied u0
+                                       pTmpOut[2] = pSrcBuf[(width * 2) + 2]; // copied y3
+                                       pTmpOut[3] = pSrcBuf[(width * 2) + 3]; // copied v3
+                                       pTmpOut -= outWidth * 2;
+
+                                       pTmpOut[0] = pSrcBuf[2];               // copied y1
+                                       pTmpOut[1] = pSrcBuf[1];               // copied u0
+                                       pTmpOut[2] = pSrcBuf[(width * 2)];     // copied y2
+                                       pTmpOut[3] = pSrcBuf[(width * 2) + 3]; // copied v3
+                                       pTmpOut -= outWidth * 2;
+
+                                       pSrcBuf += 4;
+
+                               }
+                               pTmpOutCol += 4;
+                       }
+               }
+               break;
+               default:
+               break;
+               }
+       }
+       break;
+
+       case MEDIA_PIXEL_FORMAT_UYVY422:
+       {
+               int rowCount = 0;
+               int colCount = 0;
+               byte* pSrcBuf = const_cast<byte*>(srcBuf);
+               byte* pDstBuf = dstBuf;
+               byte* pTmpOutCol = null;
+               byte* pTmpOut = null;
 
+               switch (rotate)
+               {
+               case IMAGE_ROTATION_90:
+               {
+                       pTmpOutCol = pDstBuf + (outWidth * 2);
+                       // Copying from all source rows to destination columns.
+                       for (rowCount = 0; rowCount < height; rowCount += 2)
+                       {
+                               // pTmpOutCol points to the top of the output column being filled.
+                               pTmpOutCol -= 4;
+                               pTmpOut = pTmpOutCol;
+                               pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
+                               for (colCount = 0; colCount < width / 2 ; colCount++)
+                               {
+                                       /*
+                                               u0 y0 v1 y1      u2 y2 v1 y0
+                                                                       ==>
+                                               u2 y2 v3 y3      u2 y3 v1 y1
+                                       */
+
+                                       pTmpOut[0] = pSrcBuf[(width * 2)];     // copied u2
+                                       pTmpOut[1] = pSrcBuf[(width * 2) + 1]; // copied y2
+                                       pTmpOut[2] = pSrcBuf[2];               // copied v1
+                                       pTmpOut[3] = pSrcBuf[1];               // copied y0
+                                       pTmpOut += outWidth * 2;
+
+                                       pTmpOut[0] = pSrcBuf[(width * 2)];     // copied u2
+                                       pTmpOut[1] = pSrcBuf[(width * 2) + 3]; // copied y3
+                                       pTmpOut[2] = pSrcBuf[2];               // copied v1
+                                       pTmpOut[3] = pSrcBuf[3];               // copied y1
+                                       pTmpOut += outWidth * 2;
+
+                                       pSrcBuf += 4;
+                               }
+                       }
+               }
+               break;
+               case IMAGE_ROTATION_180:
+               {
+                       // Copying all source rows to destination rows in reverse.
+                       // pTmpOut points to the end of last row: u0y1 v1y0
+                       pTmpOut = pDstBuf + (outWidth * outHeight * 2) - 4;
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
                                for (colCount = 0; colCount < width / 2; colCount++)
                                {
-                                       *pTmpOutCol-- = *pSrcBuf++;   // copied Y0 U0
-                                       *pTmpOutCol-- = *pSrcBuf++;   // copied Y1 V0
+                                       /*
+                                               u0 y0 v1 y1 => u0 y1 v1 y0
+                                       */
+                                       pTmpOut[0] = pSrcBuf[0]; // copied u0
+                                       pTmpOut[1] = pSrcBuf[3]; // copied y1
+                                       pTmpOut[2] = pSrcBuf[2]; // copied v1
+                                       pTmpOut[3] = pSrcBuf[1]; // copied y0
+                                       pSrcBuf += 4;
+                                       pTmpOut -= 4;
                                }
                        }
                }
@@ -1366,18 +1516,36 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                case IMAGE_ROTATION_270:
                {
                        // Copying all source rows to destination columns.
-                       for (rowCount = 0; rowCount < height; rowCount++)
+                       pTmpOutCol = pDstBuf + (outWidth * (outHeight - 1) * 2);
+                       for (rowCount = 0; rowCount < height; rowCount += 2)
                        {
+                               pTmpOut = pTmpOutCol;
+                               pSrcBuf = const_cast<byte*>(srcBuf) + (width * 2 * rowCount);
                                // pTmpOutCol points to the bottom of the column being filled.
-                               pTmpOutCol = pDstBuf + (outWidth * (outHeight - 1)) + rowCount;
                                for (colCount = 0; colCount < width / 2; colCount++)
                                {
-                                       *pTmpOutCol = *pSrcBuf++;   // copied B
-                                       pTmpOutCol -= outWidth;
+                                       /*
+                                               u0 y0 v1 y1      u0 y1 v3 y3
+                                                                       ==>
+                                               u2 y2 v3 y3      u0 y0 v3 y2
+                                       */
+
+                                       pTmpOut[0] = pSrcBuf[0];               // copied u0
+                                       pTmpOut[1] = pSrcBuf[1];               // copied y0
+                                       pTmpOut[2] = pSrcBuf[(width * 2) + 2]; // copied v3
+                                       pTmpOut[3] = pSrcBuf[(width * 2) + 1]; // copied y2
+                                       pTmpOut -= outWidth * 2;
+
+                                       pTmpOut[0] = pSrcBuf[0];               // copied u0
+                                       pTmpOut[1] = pSrcBuf[3];               // copied y1
+                                       pTmpOut[2] = pSrcBuf[(width * 2) + 2]; // copied v3
+                                       pTmpOut[3] = pSrcBuf[(width * 2) + 3]; // copied y3
+                                       pTmpOut -= outWidth * 2;
+
+                                       pSrcBuf += 4;
 
-                                       *pTmpOutCol = *pSrcBuf++;   // copied B
-                                       pTmpOutCol -= outWidth;
                                }
+                               pTmpOutCol += 4;
                        }
                }
                break;
@@ -1385,7 +1553,8 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                break;
                }
        }
-       else
+       break;
+       default:
        {
 #ifdef USE_MM_UTIL
 
@@ -1410,6 +1579,8 @@ _ImageUtil::RotateBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                        "[E_SYSTEM] util_transform failed: %0x", ret);
 #endif
        }
+       break;
+       }
 
        return r;
 
@@ -1459,45 +1630,47 @@ _ImageUtil::FlipBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
        outWidth = width;
        outHeight = height;
 
-        if (pixelFormat == MEDIA_PIXEL_FORMAT_GRAY)
-        {
-                if (flip == IMAGE_FLIP_HORIZONTAL)
-                {
+       switch (pixelFormat)
+       {
+       case MEDIA_PIXEL_FORMAT_GRAY:
+       {
+               if (flip == IMAGE_FLIP_HORIZONTAL)
+               {
                        int rowCount = 0;
                        int colCount = 0;
-                        byte* pSrcBuf = (byte *)srcBuf;
-                        byte* pDstBuf = (byte *)dstBuf;
-                        // pTmpOutRow points to last column of first row of destination.
-                        byte* pTmpOutRow = pDstBuf + width - 1;
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width; colCount++)
-                                {
-                                        *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
-                                }
-                                pTmpOutRow += (2 * outWidth);
-                        }
+                       byte* pSrcBuf = (byte *)srcBuf;
+                       byte* pDstBuf = (byte *)dstBuf;
+                       // pTmpOutRow points to last column of first row of destination.
+                       byte* pTmpOutRow = pDstBuf + width - 1;
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
+                               }
+                               pTmpOutRow += (2 * outWidth);
+                       }
                }
                else
                {
                        int rowCount = 0;
-                        byte* pSrcBuf = (byte *)srcBuf;
-                        byte* pDstBuf = (byte *)dstBuf;
-                        // pTmpOutRow points to the start of last row in destination buffer.
-                        byte* pTmpOutRow = pDstBuf + (width * (height - 1));
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                // copy one row worth of data.
-                                memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * width);
-                                pTmpOutRow -= width; // go to one higher row.
-                                pSrcBuf += width; // go to next row.
-                        }
+                       byte* pSrcBuf = (byte *)srcBuf;
+                       byte* pDstBuf = (byte *)dstBuf;
+                       // pTmpOutRow points to the start of last row in destination buffer.
+                       byte* pTmpOutRow = pDstBuf + (width * (height - 1));
 
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               // copy one row worth of data.
+                               memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * width);
+                               pTmpOutRow -= width; // go to one higher row.
+                               pSrcBuf += width; // go to next row.
+                       }
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB565LE)
+       break;
+       case MEDIA_PIXEL_FORMAT_RGB565LE:
        {
                if (flip == IMAGE_FLIP_HORIZONTAL)
                {
@@ -1534,315 +1707,333 @@ _ImageUtil::FlipBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                        }
                }
        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGB888)
-        {
-                if (flip == IMAGE_FLIP_HORIZONTAL)
-                {
+       break;
+       case MEDIA_PIXEL_FORMAT_RGB888:
+       {
+               if (flip == IMAGE_FLIP_HORIZONTAL)
+               {
                        int rowCount = 0;
-                        int colCount = 0;
-                        byte* pSrcBuf = (byte *)srcBuf;
-                        byte* pDstBuf = (byte *)dstBuf;
-                        // pTmpOutRow points to last column of first row of destination.
-                        byte* pTmpOutRow = NULL;// pDstBuf + width * 3;
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
+                       int colCount = 0;
+                       byte* pSrcBuf = (byte *)srcBuf;
+                       byte* pDstBuf = (byte *)dstBuf;
+                       // pTmpOutRow points to last column of first row of destination.
+                       byte* pTmpOutRow = NULL;// pDstBuf + width * 3;
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
                                pTmpOutRow = pDstBuf + (rowCount + 1) * width * 3 - 3;
-                                for (colCount = 0; colCount < width; colCount++)
-                                {
-                                        *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
-                                        *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
-                                        *pTmpOutRow = *pSrcBuf++; // copy source row in reverse to destination.
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
+                                       *pTmpOutRow++ = *pSrcBuf++; // copy source row in reverse to destination.
+                                       *pTmpOutRow = *pSrcBuf++; // copy source row in reverse to destination.
                                        pTmpOutRow -= 5;
-                                }
-                        }
-                }
-                else
-                {
-                        int rowCount = 0;
-                        byte* pSrcBuf = (byte *)srcBuf;
-                        byte* pDstBuf = (byte *)dstBuf;
-                        // pTmpOutRow points to the start of last row in destination buffer.
-                        byte* pTmpOutRow = pDstBuf + (width * 3 * (height - 1));
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                // copy one row worth of data.
-                                memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * 3 * width);
-                                pTmpOutRow -= width*3; // go to one higher row.
-                                pSrcBuf += width*3; // go to next row.
-                        }
-                }
-        }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_RGBA8888 || pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+                               }
+                       }
+               }
+               else
+               {
+                       int rowCount = 0;
+                       byte* pSrcBuf = (byte *)srcBuf;
+                       byte* pDstBuf = (byte *)dstBuf;
+                       // pTmpOutRow points to the start of last row in destination buffer.
+                       byte* pTmpOutRow = pDstBuf + (width * 3 * (height - 1));
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               // copy one row worth of data.
+                               memcpy(pTmpOutRow, pSrcBuf, sizeof(byte) * 3 * width);
+                               pTmpOutRow -= width*3; // go to one higher row.
+                               pSrcBuf += width*3; // go to next row.
+                       }
+               }
+       }
+       break;
+       case MEDIA_PIXEL_FORMAT_RGBA8888:
+               // fall through
+       case MEDIA_PIXEL_FORMAT_BGRA8888:
        {
                if (flip == IMAGE_FLIP_HORIZONTAL)
-                {
-                        int rowCount = 0;
-                        int colCount = 0;
-                        unsigned int* pSrcBuf = (unsigned int *)srcBuf;
-                        unsigned int* pDstBuf = (unsigned int *)dstBuf;
-                        // pTmpOutRow points to last column of first row of destination.
-                        unsigned int* pTmpOutRow = pDstBuf + width - 1;
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width; colCount++)
-                                {
-                                        *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
-                                }
-                                pTmpOutRow += (2 * outWidth);
-                        }
-                }
-                else
-                {
-                        int rowCount = 0;
-                        unsigned int* pSrcBuf = (unsigned int *)srcBuf;
-                        unsigned int* pDstBuf = (unsigned int *)dstBuf;
-                        // pTmpOutRow points to the start of last row in destination buffer.
-                        unsigned int* pTmpOutRow = pDstBuf + (width * (height - 1));
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                // copy one row worth of data.
-                                memcpy(pTmpOutRow, pSrcBuf, sizeof(unsigned int) * width);
-                                pTmpOutRow -= width; // go to one higher row.
-                                pSrcBuf += width; // go to next row.
-                        }
-                }
-       }
-        else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV420P)
-        {
-                byte* pDstY = (byte *)dstBuf;
-                byte* pDstU = pDstY + width * height;
-                byte* pDstV = pDstU + (width / 2) * (height / 2);
-
-                byte* pSrcY = (byte *) srcBuf;
-                byte* pSrcU = pSrcY + width * height;
-                byte* pSrcV = pSrcU + (width /2) * ( height / 2);
-                byte* pTmpOutY = null;
-                byte* pTmpOutU = null;
-                byte* pTmpOutV = null;
+               {
+                       int rowCount = 0;
+                       int colCount = 0;
+                       unsigned int* pSrcBuf = (unsigned int *)srcBuf;
+                       unsigned int* pDstBuf = (unsigned int *)dstBuf;
+                       // pTmpOutRow points to last column of first row of destination.
+                       unsigned int* pTmpOutRow = pDstBuf + width - 1;
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutRow-- = *pSrcBuf++; // copy source row in reverse to destination.
+                               }
+                               pTmpOutRow += (2 * outWidth);
+                       }
+               }
+               else
+               {
+                       int rowCount = 0;
+                       unsigned int* pSrcBuf = (unsigned int *)srcBuf;
+                       unsigned int* pDstBuf = (unsigned int *)dstBuf;
+                       // pTmpOutRow points to the start of last row in destination buffer.
+                       unsigned int* pTmpOutRow = pDstBuf + (width * (height - 1));
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               // copy one row worth of data.
+                               memcpy(pTmpOutRow, pSrcBuf, sizeof(unsigned int) * width);
+                               pTmpOutRow -= width; // go to one higher row.
+                               pSrcBuf += width; // go to next row.
+                       }
+               }
+       }
+       break;
+       case MEDIA_PIXEL_FORMAT_YUV420P:
+       {
+               byte* pDstY = (byte *)dstBuf;
+               byte* pDstU = pDstY + width * height;
+               byte* pDstV = pDstU + (width / 2) * (height / 2);
+
+               byte* pSrcY = (byte *) srcBuf;
+               byte* pSrcU = pSrcY + width * height;
+               byte* pSrcV = pSrcU + (width / 2) * ( height / 2);
+               byte* pTmpOutY = null;
+               byte* pTmpOutU = null;
+               byte* pTmpOutV = null;
 
                if (flip == IMAGE_FLIP_HORIZONTAL)
-                {
-                       SysLog(NID_MEDIA,"$$$ MEDIA_PIXEL_FORMAT_YUV420 Flip: horizontal");
-                        int rowCount = 0;
-                        int colCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOutY = pDstY + width - 1;
-                        pTmpOutU = pDstU + width / 2 - 1;
-                        pTmpOutV = pDstV + width / 2 - 1;
-
-                        for (rowCount = 0; rowCount < height ; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width; colCount++)
-                                {
-                                        *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
-                                }
-                                pTmpOutY += (2 * width);
-                        }
-                        for (rowCount = 0; rowCount < height/2 ; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width/2; colCount++)
-                                {
-                                        *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
-                                        *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
-                                }
-                                pTmpOutU += (width);
-                                pTmpOutV += (width);
-                        }
-                }
-                else
-                {
+               {
                        int rowCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOutY = pDstY + (height - 1) * width;
-                        pTmpOutU = pDstU + (height / 2 - 1) * width / 2;
-                        pTmpOutV = pDstV + (height / 2 - 1) * width / 2;
+                       int colCount = 0;
+                       // pTmpOut* points to last column of first row of destination.
+                       pTmpOutY = pDstY + width - 1;
+                       pTmpOutU = pDstU + width / 2 - 1;
+                       pTmpOutV = pDstV + width / 2 - 1;
 
-                        for (rowCount = 0; rowCount < height / 2; rowCount++)
-                        {
+                       for (rowCount = 0; rowCount < height ; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
+                               }
+                               pTmpOutY += (2 * width);
+                       }
+                       for (rowCount = 0; rowCount < height/2 ; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width/2; colCount++)
+                               {
+                                       *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
+                                       *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
+                               }
+                               pTmpOutU += (width);
+                               pTmpOutV += (width);
+                       }
+               }
+               else
+               {
+                       int rowCount = 0;
+                       // pTmpOut* points to last column of first row of destination.
+                       pTmpOutY = pDstY + (height - 1) * width;
+                       pTmpOutU = pDstU + (height / 2 - 1) * width / 2;
+                       pTmpOutV = pDstV + (height / 2 - 1) * width / 2;
+
+                       for (rowCount = 0; rowCount < height / 2; rowCount++)
+                       {
                                memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
                                memcpy(pTmpOutU, pSrcU, sizeof(byte) * width / 2 );
                                memcpy(pTmpOutV, pSrcV, sizeof(byte) * width / 2 );
 
-                                pTmpOutY -=  width;
+                               pTmpOutY -=  width;
                                pSrcY += width;
-                                pTmpOutU -= (width / 2);
+                               pTmpOutU -= (width / 2);
                                pSrcU += (width / 2);
-                                pTmpOutV -= (width / 2);
+                               pTmpOutV -= (width / 2);
                                pSrcV += (width / 2);
-                        }
-                        for (rowCount = height / 2; rowCount < height; rowCount++)
-                        {
+                       }
+                       for (rowCount = height / 2; rowCount < height; rowCount++)
+                       {
                                memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
-                                pTmpOutY -= width;
+                               pTmpOutY -= width;
                                pSrcY += width;
-                        }
-                }
-       }
-        else if (pixelFormat == MEDIA_PIXEL_FORMAT_NV12
-                        || pixelFormat == MEDIA_PIXEL_FORMAT_NV21)
-        {
-                byte* pDstY = (byte *)dstBuf;
-                short* pDstUV = (short* )(pDstY + width * height);
-
-                byte* pSrcY = (byte* ) srcBuf;
-                short* pSrcUV = (short* )(pSrcY + width * height);
-                byte* pTmpOutY = null;
-                short* pTmpOutUV = null;
+                       }
+               }
+       }
+       break;
+       case MEDIA_PIXEL_FORMAT_NV12:
+               // fall through
+       case MEDIA_PIXEL_FORMAT_NV21:
+       {
+               byte* pDstY = (byte *)dstBuf;
+               short* pDstUV = (short* )(pDstY + width * height);
+
+               byte* pSrcY = (byte* ) srcBuf;
+               short* pSrcUV = (short* )(pSrcY + width * height);
+
+               byte* pTmpOutY = null;
+               short* pTmpOutUV = null;
+
                if (flip == IMAGE_FLIP_HORIZONTAL)
-                {
-                        int rowCount = 0;
-                        int colCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOutY = pDstY + width - 1;
-                        pTmpOutUV = pDstUV + width / 2 - 1;
-
-                        for (rowCount = 0; rowCount < height / 2; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width / 2; colCount++)
-                                {
-                                        *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
-                                        *pTmpOutUV-- = *pSrcUV++; // copy source row in reverse to destination.
-                                }
-                                for (colCount = width / 2; colCount < width; colCount++)
-                                {
-                                        *pTmpOutY-- = *pSrcY++;
-                                }
-                                pTmpOutY += (2 * width);
-                                pTmpOutUV += (width);
-                        }
-                        for (rowCount = height / 2; rowCount < height; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width; colCount++)
-                                {
-                                        *pTmpOutY-- = *pSrcY++;
-                                }
-                                pTmpOutY += (2 * width);
-                        }
-                }
+               {
+                       int rowCount = 0;
+                       int colCount = 0;
+                       // pTmpOut* points to last column of first row of destination.
+                       pTmpOutY = pDstY + width - 1;
+                       pTmpOutUV = pDstUV + width / 2 - 1;
+
+                       for (rowCount = 0; rowCount < height / 2; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width / 2; colCount++)
+                               {
+                                       *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
+                                       *pTmpOutUV-- = *pSrcUV++; // copy source row in reverse to destination.
+                               }
+                               for (colCount = width / 2; colCount < width; colCount++)
+                               {
+                                       *pTmpOutY-- = *pSrcY++;
+                               }
+                               pTmpOutY += (2 * width);
+                               pTmpOutUV += (width);
+                       }
+                       for (rowCount = height / 2; rowCount < height; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width; colCount++)
+                               {
+                                       *pTmpOutY-- = *pSrcY++;
+                               }
+                               pTmpOutY += (2 * width);
+                       }
+               }
                else
-                {
-                        int rowCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOutY = pDstY + (height - 1) * width;
-                        pTmpOutUV = pDstUV + (height / 2 - 1) * width / 2;
-
-                        for (rowCount = 0; rowCount < height / 2; rowCount++)
-                        {
-                                memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
-                                memcpy(pTmpOutUV, pSrcUV, sizeof(short) * width / 2 );
-
-                                pTmpOutY -= width;
-                                pSrcY += width;
+               {
+                       int rowCount = 0;
+                       // pTmpOut* points to last column of first row of destination.
+                       pTmpOutY = pDstY + (height - 1) * width;
+                       pTmpOutUV = pDstUV + (height / 2 - 1) * width / 2;
+
+                       for (rowCount = 0; rowCount < height / 2; rowCount++)
+                       {
+                               memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
+                               memcpy(pTmpOutUV, pSrcUV, sizeof(short) * width / 2 );
+
+                               pTmpOutY -= width;
+                               pSrcY += width;
                                pTmpOutUV -=  width / 2;
                                pSrcUV += width / 2;
-                        }
-                        for (rowCount = height / 2; rowCount < height; rowCount++)
-                        {
-                                memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
-                                pTmpOutY -=  width;
+                       }
+                       for (rowCount = height / 2; rowCount < height; rowCount++)
+                       {
+                               memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
+                               pTmpOutY -=  width;
                                pSrcY += width;
-                        }
-                }
-       }
-       else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUV444P)
-        {
-                byte* pDstY = (byte *)dstBuf;
-                byte* pDstU = pDstY + width * height;
-                byte* pDstV = pDstU + width * height;
-
-                byte* pSrcY = (byte *) srcBuf;
-                byte* pSrcU = pSrcY + width * height;
-                byte* pSrcV = pSrcU + width * height;
-                byte* pTmpOutY = null;
-                byte* pTmpOutU = null;
-                byte* pTmpOutV = null;
+                       }
+               }
+       }
+       break;
+       case MEDIA_PIXEL_FORMAT_YUV444P:
+       {
+               byte* pDstY = (byte *)dstBuf;
+               byte* pDstU = pDstY + width * height;
+               byte* pDstV = pDstU + width * height;
+
+               byte* pSrcY = (byte *) srcBuf;
+               byte* pSrcU = pSrcY + width * height;
+               byte* pSrcV = pSrcU + width * height;
+               byte* pTmpOutY = null;
+               byte* pTmpOutU = null;
+               byte* pTmpOutV = null;
                if (flip == IMAGE_FLIP_HORIZONTAL)
-                {
-                        int rowCount = 0;
-                        int colCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOutY = pDstY + width - 1;
-                        pTmpOutU = pDstU + width - 1;
-                        pTmpOutV = pDstV + width - 1;
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width ; colCount++)
-                                {
-                                        *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
-                                        *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
-                                        *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
-                                }
-                                pTmpOutY += (2 * width);
-                                pTmpOutU += (2 * width);
-                                pTmpOutV += (2 * width);
-                        }
-                }
+               {
+                       int rowCount = 0;
+                       int colCount = 0;
+                       // pTmpOut* points to last column of first row of destination.
+                       pTmpOutY = pDstY + width - 1;
+                       pTmpOutU = pDstU + width - 1;
+                       pTmpOutV = pDstV + width - 1;
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width ; colCount++)
+                               {
+                                       *pTmpOutY-- = *pSrcY++; // copy source row in reverse to destination.
+                                       *pTmpOutU-- = *pSrcU++; // copy source row in reverse to destination.
+                                       *pTmpOutV-- = *pSrcV++; // copy source row in reverse to destination.
+                               }
+                               pTmpOutY += (2 * width);
+                               pTmpOutU += (2 * width);
+                               pTmpOutV += (2 * width);
+                       }
+               }
                else
-                {
-                        int rowCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOutY = pDstY + (height - 1) * width;
-                        pTmpOutU = pDstU + (height - 1) * width;
-                        pTmpOutV = pDstV + (height - 1) * width;
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
-                                memcpy(pTmpOutU, pSrcU, sizeof(byte) * width);
-                                memcpy(pTmpOutV, pSrcV, sizeof(byte) * width);
-
-                                pTmpOutY -=  width;
+               {
+                       int rowCount = 0;
+                       // pTmpOut* points to last column of first row of destination.
+                       pTmpOutY = pDstY + (height - 1) * width;
+                       pTmpOutU = pDstU + (height - 1) * width;
+                       pTmpOutV = pDstV + (height - 1) * width;
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               memcpy(pTmpOutY, pSrcY, sizeof(byte) * width);
+                               memcpy(pTmpOutU, pSrcU, sizeof(byte) * width);
+                               memcpy(pTmpOutV, pSrcV, sizeof(byte) * width);
+
+                               pTmpOutY -=  width;
                                pSrcY += width;
-                                pTmpOutU -=  width;
+                               pTmpOutU -=  width;
                                pSrcU += width;
-                                pTmpOutV -= width;
+                               pTmpOutV -= width;
                                pSrcV += width;
-                        }
-                }
+                       }
+               }
        }
-        else if (pixelFormat == MEDIA_PIXEL_FORMAT_YUYV422)
-        {
-                short* pSrcBuf = (short*)srcBuf;
-                short* pDstBuf = (short*)dstBuf;
-                short* pTmpOut = null;
+       break;
+       case MEDIA_PIXEL_FORMAT_YUYV422:
+               // fall through
+       case MEDIA_PIXEL_FORMAT_UYVY422:
+       {
+               byte* pSrcBuf = const_cast<byte*>(srcBuf);
+               byte* pDstBuf = dstBuf;
+               byte* pTmpOut = null;
 
                if (flip == IMAGE_FLIP_HORIZONTAL)
-                {
-                        int rowCount = 0;
-                        int colCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOut = pDstBuf + width - 1;
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                                for (colCount = 0; colCount < width / 2; colCount++)
-                                {
-                                        *pTmpOut-- = *pSrcBuf++; // copied YO U0.
-                                        *pTmpOut-- = *pSrcBuf++; // copied Y1 U1
-                                }
-                                pTmpOut += 2 * width;
-                        }
-                }
+               {
+                       int rowCount = 0;
+                       int colCount = 0;
+                       // pTmpOut points to last column of first row of destination.
+                       pTmpOut = pDstBuf + (width * 2) - 4;
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               for (colCount = 0; colCount < width / 2; colCount++)
+                               {
+                                       pTmpOut[0] = pSrcBuf[0]; // u0
+                                       pTmpOut[1] = pSrcBuf[3]; // y1
+                                       pTmpOut[2] = pSrcBuf[2]; // v1
+                                       pTmpOut[3] = pSrcBuf[1]; // y0
+
+                                       pTmpOut -= 4;
+                                       pSrcBuf += 4;
+                               }
+                               pTmpOut += 4 * width;
+                       }
+               }
                else
-                {
-                        int rowCount = 0;
-                        // pTmpOutRow points to last column of first row of destination.
-                        pTmpOut = pDstBuf + (height - 1) * (width);
-
-                        for (rowCount = 0; rowCount < height; rowCount++)
-                        {
-                               memcpy(pTmpOut, pSrcBuf, sizeof(short) * width);
-                                pTmpOut -= width;
-                               pSrcBuf += width;
-                        }
-                }
+               {
+                       int rowCount = 0;
+                       // pTmpOut points to last column of first row of destination.
+                       pTmpOut = pDstBuf + ((height - 1) * width * 2);
+
+                       for (rowCount = 0; rowCount < height; rowCount++)
+                       {
+                               memcpy(pTmpOut, pSrcBuf, 2 * width);
+                               pTmpOut -= width * 2;
+                               pSrcBuf += width * 2;
+                       }
+               }
        }
-       else
+       break;
+       default:
        {
 #ifdef USE_MM_UTIL
 
@@ -1864,6 +2055,7 @@ _ImageUtil::FlipBuffer(const byte* srcBuf, MediaPixelFormat pixelFormat,
                        "util_transform failed with error code: %0x", ret);
 #endif
        }
+       }
 
 CATCH:
        return r;
@@ -2187,7 +2379,7 @@ _ImageUtil::Rotate(const ByteBuffer& srcBuf,
                outHeight = height;
        }
 
-       return  RotateBuffer((byte *)srcBuf.GetPointer(), pixelFormat, width, height,
+       return RotateBuffer((byte *)srcBuf.GetPointer(), pixelFormat, width, height,
                        (byte *)dstBuf.GetPointer(), outWidth, outHeight, rotate);
 CATCH:
        return r;
@@ -2324,7 +2516,7 @@ _ImageUtil::GetImageFormat(const Tizen::Base::ByteBuffer& srcBuf)
                        break;
                }
        }
-       if ((fmt == IMG_FORMAT_WBMP) && (pBuf[2] == 1 || pBuf[2] == 2) && pBuf[3] == 0 )
+       if ((fmt == IMG_FORMAT_WBMP) && (pBuf[2] == 0 || pBuf[2] == 1 || pBuf[2] == 2) && pBuf[3] == 0 )
        {
                fmt = IMG_FORMAT_NONE;
        }
@@ -2478,7 +2670,7 @@ _ImageUtil::Crop(const Tizen::Base::ByteBuffer &srcBuf,
 {
        result r = E_SUCCESS;
 
-    r = CropBuffer(srcBuf.GetPointer(), pixelFormat, srcWidth, srcHeight,
+       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));
@@ -2523,6 +2715,10 @@ _ImageUtil::CropBuffer(const byte* srcBuf,
                r = E_INVALID_ARG, E_INVALID_ARG,
                "[E_INVALID_ARG] Dimensions should be even (%d x %d).", dstWidth, dstHeight);
 
+       SysTryCatch(NID_MEDIA, IsValidCoordinate(pixelFormat, dstX, dstY),
+               r = E_INVALID_ARG, E_INVALID_ARG,
+               "[E_INVALID_ARG] Source location must be even (%d, %d).", dstX, dstY);
+
        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);
@@ -2566,6 +2762,7 @@ _ImageUtil::CropBuffer(const byte* srcBuf,
                }
                break;
                case MEDIA_PIXEL_FORMAT_RGB888:
+                       // fall through
                case MEDIA_PIXEL_FORMAT_BGR888:
                {
                        bpp = 3;
@@ -2582,6 +2779,7 @@ _ImageUtil::CropBuffer(const byte* srcBuf,
                }
                break;
                case MEDIA_PIXEL_FORMAT_RGBA8888:
+                       // fall through
                case MEDIA_PIXEL_FORMAT_BGRA8888:
                {
                        bpp = 4;
@@ -2615,17 +2813,22 @@ _ImageUtil::CropBuffer(const byte* srcBuf,
                }
                break;
                case MEDIA_PIXEL_FORMAT_YUYV422:
+                       // fall through
+               case MEDIA_PIXEL_FORMAT_UYVY422:
                {
                        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++)
+                       if ((dstX % 2) == 0)
                        {
-                               memcpy(pOutBuffer, pInBuffer, copyRowWidth);
-                               pOutBuffer += copyRowWidth;
-                               pInBuffer += srcRowWidth;
+                               for (int i = dstY; i < dstY + dstHeight; i++)
+                               {
+                                       memcpy(pOutBuffer, pInBuffer, copyRowWidth);
+                                       pOutBuffer += copyRowWidth;
+                                       pInBuffer += srcRowWidth;
+                               }
                        }
                }
                break;
@@ -2657,6 +2860,7 @@ _ImageUtil::CropBuffer(const byte* srcBuf,
                }
                break;
                case MEDIA_PIXEL_FORMAT_NV12:
+                       // fall through
                case MEDIA_PIXEL_FORMAT_NV21:
                {
                        bpp = 1;
@@ -2823,6 +3027,7 @@ _ImageUtil::GetBufferSize(MediaPixelFormat pixelFormat, int width, int height)
                { MEDIA_PIXEL_FORMAT_NV21, {3, 2}},
                { MEDIA_PIXEL_FORMAT_YUV444P, {3, 1}},
                { MEDIA_PIXEL_FORMAT_YUYV422, {2, 1}},
+               { MEDIA_PIXEL_FORMAT_UYVY422, {2, 1}},
                { MEDIA_PIXEL_FORMAT_BGR888, {3,1}},
                { MEDIA_PIXEL_FORMAT_RGB888, {3,1}},
        };
@@ -2859,6 +3064,7 @@ _ImageUtil::IsValidDimension(MediaPixelFormat pixelFormat, int width, int height
                MEDIA_PIXEL_FORMAT_NV12,
                MEDIA_PIXEL_FORMAT_NV21,
                MEDIA_PIXEL_FORMAT_YUYV422,
+               MEDIA_PIXEL_FORMAT_UYVY422,
        };
 
        for (unsigned int i = 0; i < sizeof(fmt)/sizeof(fmt[0]); i++)
@@ -2876,6 +3082,33 @@ _ImageUtil::IsValidDimension(MediaPixelFormat pixelFormat, int width, int height
        return true;
 }
 
+bool
+_ImageUtil::IsValidCoordinate(MediaPixelFormat pixelFormat, int XLoc, int YLoc)
+{
+       if ((MEDIA_PIXEL_FORMAT_YUV420P == pixelFormat) ||
+               (MEDIA_PIXEL_FORMAT_NV12 == pixelFormat) ||
+               (MEDIA_PIXEL_FORMAT_NV21 == pixelFormat))
+       {
+               if ((XLoc & 0x01) || (YLoc & 0x01))
+               {
+                       return false;
+               }
+               return true;
+       }
+
+       if ((MEDIA_PIXEL_FORMAT_YUYV422 == pixelFormat) ||
+               (MEDIA_PIXEL_FORMAT_UYVY422 == pixelFormat))
+       {
+               if ((XLoc & 0x01))
+               {
+                       return false;
+               }
+               return true;
+       }
+       // return true for other pixel formats
+       return true;
+}
+
 int
 _ImageUtil::ToFfmpegPixelFormat(MediaPixelFormat pixelFmt)
 {
index db4ee53..70c312f 100644 (file)
@@ -167,6 +167,10 @@ _JpegDecoder::DecodeN(int& length)
        {
                __pDec->out_color_space = JCS_GRAYSCALE;
        }
+       else if (__pDec->jpeg_color_space == JCS_YCCK) // YCCK
+       {
+               __pDec->out_color_space = JCS_YCCK;
+       }
        else // YUV444
        {
                __pDec->out_color_space = JCS_YCbCr;
@@ -243,7 +247,77 @@ _JpegDecoder::DecodeN(int& length)
                        }
                }
        }
-       else
+       else if (__pDec->output_components == 4) // YCCK. Need to handle CMYK also.
+       {
+               if (__isDecodeRegionEnabled == true)
+               {
+                       buffSize = __decodingRectWidth * __decodingRectHeight * 3;
+                       planarSize = (__decodingRectWidth * __decodingRectHeight);
+                       length = buffSize;
+                       int row_stride = __pDec->output_width * __pDec->output_components;
+                       JSAMPARRAY buffer = (*__pDec->mem->alloc_sarray)((struct jpeg_common_struct *) __pDec, JPOOL_IMAGE, row_stride, 1);
+
+                       pReturnBuf = new (std::nothrow) byte[buffSize];
+                       SysTryCatch(NID_MEDIA, pReturnBuf != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                          "[E_OUT_OF_MEMORY] Could not allocate %d bytes for output.", buffSize);
+
+                       memset(pReturnBuf, 0, buffSize);
+                       outBuf = pReturnBuf;
+
+                       while (__pDec->output_scanline < (__decodingRectY + __decodingRectHeight))
+                       {
+                               jpeg_read_scanlines(__pDec, buffer, 1);
+                               if (h >= __decodingRectY)
+                               {
+                                       outX = 0;
+                                       for (int x = __decodingRectX; x < __decodingRectX + __decodingRectWidth; x++)
+                                       {
+                                               JSAMPLE* p = buffer[0] + (__pDec->output_components * x);
+
+                                               // YCCK -> YUV444p
+                                               pReturnBuf[(__decodingRectWidth * outY) + outX] = 255 - p[0];                                   // Y
+                                               pReturnBuf[(__decodingRectWidth * outY) + planarSize + outX] = 255 - p[1];              // Cb
+                                               pReturnBuf[(__decodingRectWidth * outY) + (planarSize * 2) + outX] = 255 - p[2];// Cr
+                                               outX++;
+                                       }
+                                       outY++;
+                               }
+                               h++;
+                       }
+               }
+               else
+               {
+                       buffSize = __pDec->output_width * __pDec->output_height * 3;
+                       planarSize = __pDec->output_width * __pDec->output_height;
+                       length = buffSize;
+                       int row_stride = __pDec->output_width * __pDec->output_components;
+                       JSAMPARRAY buffer = (*__pDec->mem->alloc_sarray)((struct jpeg_common_struct *) __pDec, JPOOL_IMAGE, row_stride, 1);
+
+                       pReturnBuf = new (std::nothrow) byte[buffSize];
+                       SysTryCatch(NID_MEDIA, pReturnBuf != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                          "[E_OUT_OF_MEMORY] Could not allocate %d bytes for output.", buffSize);
+
+                       memset(pReturnBuf, 0, buffSize);
+                       outBuf = pReturnBuf;
+
+                       while (__pDec->output_scanline < __pDec->output_height)
+                       {
+                               jpeg_read_scanlines(__pDec, buffer, 1);
+
+                               for (unsigned int x = 0; x < __pDec->output_width; x++)
+                               {
+                                       JSAMPLE* p = buffer[0] + (__pDec->output_components * x);
+
+                                       // YCCK -> YUV444p
+                                       pReturnBuf[(__pDec->output_width * h) + x] = 255 - p[0];                                                // Y
+                                       pReturnBuf[(__pDec->output_width * h) + planarSize + x] = 255 - p[1];                   // Cb
+                                       pReturnBuf[(__pDec->output_width * h) + (planarSize * 2) + x] = 255 - p[2];             // Cr
+                               }
+                               h++;
+                       }
+               }
+       }
+       else // (__pDec->output_components == 3) YUV444
        {
                if (__isDecodeRegionEnabled == true)
                {
index e0e78e2..28bd88b 100644 (file)
@@ -138,6 +138,10 @@ _MediaUtil::BufferToFile(const Tizen::Base::ByteBuffer &srcBuf,
        SysSecureTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated. Temp File.Write failed for %ls",
                                          GetErrorMessage(r), tmpPath.GetPointer());
 
+       r = file.Flush();
+       SysSecureTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Propagated. Temp File.Flush failed for %ls",
+                                         GetErrorMessage(r), tmpPath.GetPointer());
+
        if (File::IsFileExist(dstPath))
        {
                r = File::Remove(dstPath);
index aaab638..b5833f3 100644 (file)
@@ -131,6 +131,9 @@ _PngEncoder::EncodeN(const byte* srcBuf, int srcLength)
        int bytePerPixel = 4;      // Fixed. Source format is always RGBA8888 through ColorConverter.
        std::unique_ptr<ByteBuffer> pRetBuf;
 
+       SysTryCatch(NID_MEDIA, srcBuf != null, r = E_INVALID_ARG, E_INVALID_ARG,
+               "[E_INVALID_ARG] Input data pointer is null.");
+
        pRetBuf.reset(new (std::nothrow) ByteBuffer());
        SysTryCatch(NID_MEDIA, pRetBuf.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                "[E_OUT_OF_MEMORY] Failed to create new ByteBuffer");
index ebd731b..612b42c 100644 (file)
@@ -132,6 +132,8 @@ public:
 
        static bool IsValidDimension(MediaPixelFormat pixelFormat, int width, int height);
 
+       static bool IsValidCoordinate(MediaPixelFormat pixelFormat, int XLoc, int YLoc);
+
        static int ToFfmpegPixelFormat(MediaPixelFormat pixelFmt);
 
        static MediaPixelFormat ToMediaPixelFormatFromFfmpeg(int pixelFormat);