Fixed memory leak in ImageBuffer::ResizeN()
[platform/framework/native/image.git] / src / FMedia_ImageBufferImpl.cpp
index 00e8831..49f6f1d 100644 (file)
 #include "FMedia_ImageEncoder.h"
 #include "FMedia_ColorConverter.h"
 #include "FMedia_ExifUtil.h"
+#include "FUi_CoordinateSystemUtils.h"
+#include "FGrp_BitmapImpl.h"
 
 using namespace Tizen::Graphics;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Io;
 using namespace Tizen::App;
+using namespace Tizen::Ui;
 
 namespace Tizen { namespace Media
 {
 
-#define ISSUPPORTED(x)                                                                                                                 \
-    ((x == MEDIA_PIXEL_FORMAT_YUV420P) || (x == MEDIA_PIXEL_FORMAT_BGRA8888) ||        \
-       (x == MEDIA_PIXEL_FORMAT_RGB565LE) || (x == MEDIA_PIXEL_FORMAT_GRAY))
-
-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 */
-};
-
 typedef struct {
        ImageRotationType rotateType;
        ImageFlipType flipType;
@@ -79,19 +66,37 @@ static const _ImageExifInfo _IMAGE_ROTATE_FLIP_MAP[] = {
        { IMAGE_ROTATION_270, IMAGE_FLIP_NONE,       true  }  /* LEFT_BOTTOM  */
 };
 
+static const ExifOrientation _ORIENTATION_MAP[] ={
+       EXIF_ORIENTATION_TOP_LEFT,
+       EXIF_ORIENTATION_TOP_LEFT,
+       EXIF_ORIENTATION_TOP_RIGHT,
+       EXIF_ORIENTATION_BOTTOM_RIGHT,
+       EXIF_ORIENTATION_BOTTOM_LEFT,
+       EXIF_ORIENTATION_LEFT_TOP,
+       EXIF_ORIENTATION_RIGHT_TOP,
+       EXIF_ORIENTATION_RIGHT_BOTTOM,
+       EXIF_ORIENTATION_LEFT_BOTTOM
+};
+
 static const MediaPixelFormat _IMAGE_BUFFER_PIXEL_FORMATS[] =
 {
        MEDIA_PIXEL_FORMAT_RGB565LE,
        MEDIA_PIXEL_FORMAT_BGRA8888,
-       MEDIA_PIXEL_FORMAT_YUV420P
+       MEDIA_PIXEL_FORMAT_YUV420P,
+       MEDIA_PIXEL_FORMAT_NV12,
+       MEDIA_PIXEL_FORMAT_NV21,
+       MEDIA_PIXEL_FORMAT_GRAY
 };
 
 _ImageBufferImpl::_ImageBufferImpl(void)
        : __pBuffer(null)
        , __width(0)
        , __height(0)
+       , __orientation(EXIF_ORIENTATION_TOP_LEFT)
        , __pixelFormat(MEDIA_PIXEL_FORMAT_NONE)
        , __isLocked(false)
+       , __transparent(false)
+       , __maskColor(0xf81f) // MAGENTA
 {
 }
 
@@ -117,13 +122,11 @@ _ImageBufferImpl::Construct(int width, int height, MediaPixelFormat pixelFormat)
                "[E_INVALID_ARG] Check inputs: (%d x %d), pixel format (%d).",
                __width, __height, __pixelFormat);
 
-       __pBuffer.reset(new (std::nothrow) ByteBuffer);
+       __pBuffer.reset(new (std::nothrow) byte[length]);
        SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                "[E_OUT_OF_MEMORY] Construct instance failed.");
-
-       r = __pBuffer->Construct(length);
-       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r,
-               "[%s] Construct instance failed.", GetErrorMessage(r));
+       memset(__pBuffer.get(), 0, length);
+       __bufSize = length;
 
        return r;
 }
@@ -141,10 +144,9 @@ _ImageBufferImpl::Construct(int width, int height, MediaPixelFormat pixelFormat,
        SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), E_INVALID_ARG, E_INVALID_ARG,
                "[E_INVALID_ARG] Dimensions should be greater than zero : (%d x %d).", width, height);
 
-       SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, E_INVALID_ARG, E_INVALID_ARG,
-               "[E_INVALID_ARG] Pixelformat is not supported : %d.", pixelFormat);
-
        reqBufferSize = _ImageUtil::GetBufferSize(pixelFormat, width, height);
+       SysTryReturn(NID_MEDIA, reqBufferSize > 0, GetLastResult(), GetLastResult(),
+                       "[%s] Could not get output buffer size.", GetErrorMessage(GetLastResult()));
 
        if (pData != null)
        {
@@ -157,22 +159,20 @@ _ImageBufferImpl::Construct(int width, int height, MediaPixelFormat pixelFormat,
        __height = height;
        __pixelFormat = pixelFormat;
 
-       __pBuffer.reset(new (std::nothrow) ByteBuffer);
+       __pBuffer.reset(new (std::nothrow) byte[reqBufferSize]);
        SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                "[E_OUT_OF_MEMORY] Construct instance failed.");
 
-       r = __pBuffer->Construct(reqBufferSize);
-       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r,
-               "[%s] Construct instance failed.", GetErrorMessage(r));
+       __bufSize = reqBufferSize;
 
        if (pData != null)
        {
-               r = __pBuffer->SetArray(pData, 0, reqBufferSize);
-               SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r,
-                       "[%s] SetArray  for buffer %x of length %d failed.", GetErrorMessage(r),
-                       pData, reqBufferSize);
+               memcpy(__pBuffer.get(), pData, reqBufferSize);
+       }
+       else
+       {
+               memset(__pBuffer.get(), 0, reqBufferSize);
        }
-       __pBuffer->Flip();
        return r;
 }
 
@@ -193,13 +193,14 @@ _ImageBufferImpl::Construct(const Tizen::Base::String &srcImagePath, const Recta
 result
 _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Tizen::Graphics::Rectangle *pDecodingRegion, bool autoRotate)
 {
-
        result r = E_SUCCESS;
 
        _ImageDecoder dec;
-       std::unique_ptr<ByteBuffer> pDstBuf;
+       std::unique_ptr<byte[]> pDstBuf;
        Tizen::Graphics::Rectangle transformRegion;
        int orientationInfo = 0;
+       Boolean transparency(false);
+       Integer chromaKey;
 
        r = dec.Construct(srcImageBuf);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Decoder construct failed.", GetErrorMessage(r));
@@ -209,15 +210,13 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
        SysTryReturn(NID_MEDIA, __pixelFormat != MEDIA_PIXEL_FORMAT_NONE, r, r,
                "[%s] GetPixelFormat failed.", GetErrorMessage(r));
 
-       if(autoRotate == true)
-       {
-               _ExifUtil imgExif;
-               imgExif.Construct(srcImageBuf.GetPointer(), srcImageBuf.GetCapacity());
-               imgExif.GetValue(EXIF_TAG_IMAGE_ORIENTATION, orientationInfo);
-               // imgExif.GetValue() will return "r = E_OBJ_NOT_FOUND" if it could not be found exif infomation.
-               // However, the result should be decided by result of construct in this function.
-               SetLastResult(E_SUCCESS);
-       }
+       _ExifUtil imgExif;
+       imgExif.Construct(srcImageBuf.GetPointer(), srcImageBuf.GetCapacity());
+       imgExif.GetValue(EXIF_TAG_IMAGE_ORIENTATION, orientationInfo);
+       // imgExif.GetValue() will return "r = E_OBJ_NOT_FOUND" if it could not be found exif infomation.
+       // However, the result should be decided by result of construct in this function.
+       SetLastResult(E_SUCCESS);
+       __orientation = _ORIENTATION_MAP[orientationInfo];
 
        if (pDecodingRegion != null)
        {
@@ -240,7 +239,7 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
                }
                else
                {
-               SysTryReturn(NID_MEDIA, imgWidth >= (pDecodingRegion->x + pDecodingRegion->width)
+                       SysTryReturn(NID_MEDIA, imgWidth >= (pDecodingRegion->x + pDecodingRegion->width)
                                && imgHeight >= (pDecodingRegion->y + pDecodingRegion->height),
                                E_INVALID_ARG, E_INVALID_ARG,
                                "[E_INVALID_ARG] imageWidth = %d, imageHeight = %d, x = %d, y = %d, width = %d, height = %d",
@@ -308,30 +307,79 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
 
                if (r == E_SUCCESS)
                {
-                       __pBuffer.reset(dec.DecodeN());
-                       r = GetLastResult();
-                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.",
-                               GetErrorMessage(r));
+                       __pBuffer.reset(dec.DecodeN(__bufSize));
                        SysTryReturn(NID_MEDIA, __pBuffer.get() != null, r, r,
                                "[%s] DecodeN returned empty buffer.", GetErrorMessage(r));
+                       r = dec.GetValue("transparency", transparency);
+                       if (r != E_SUCCESS)
+                       {
+                               __transparent = false;
+                               r = E_SUCCESS;
+                       }
+                       else
+                       {
+                               __transparent = transparency.ToBool();
+                               if (__transparent == true)
+                               {
+                                       r = dec.GetValue(L"chromaKey", chromaKey);
+                                       if (r != E_SUCCESS)
+                                       {
+                                               __transparent = false;
+                                               r = E_SUCCESS;
+                                       }
+                                       else
+                                       {
+                                               __maskColor = chromaKey.ToInt();
+                                       }
+                               }
+                       }
                }
                else if (r == E_UNSUPPORTED_OPERATION)
                {
                        // crop image
-                       ByteBuffer *pTmpBuf = null;
+                       std::unique_ptr<byte[]> pTmpbyte;
 
-                       __pBuffer.reset(dec.DecodeN());
+                       pTmpbyte.reset(dec.DecodeN(__bufSize));
                        r = GetLastResult();
-                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated. ", GetErrorMessage(r));
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.", GetErrorMessage(r));
+                       SysTryReturn(NID_MEDIA, pTmpbyte.get() != null, r, r,
+                               "[%s] DecodeN returned empty buffer.", GetErrorMessage(r));
+
+                       __pBuffer.reset(_ImageUtil::CropN(pTmpbyte.get(), __pixelFormat, imgWidth, imgHeight,
+                               transformRegion.x, transformRegion.y, transformRegion.width, transformRegion.height));
 
-                       pTmpBuf = _ImageUtil::CropN(*__pBuffer.get(), __pixelFormat, imgWidth, imgHeight,
-                               transformRegion.x, transformRegion.y, transformRegion.width, transformRegion.height);
-                       SysTryReturn(NID_MEDIA, pTmpBuf != null, GetLastResult(), GetLastResult(),
-                               "[%s] Crop:%x %d %d %d %d %d %d %d", GetErrorMessage(GetLastResult()), __pBuffer->GetPointer(),
-                       __pixelFormat, imgWidth, imgHeight, pDecodingRegion->x, pDecodingRegion->y,
+                       SysTryReturn(NID_MEDIA, __pBuffer.get() != null, GetLastResult(), GetLastResult(),
+                               "[%s] Crop:%x %d %d %d %d %d %d %d", GetErrorMessage(GetLastResult()), pTmpbyte.get(),
+                               __pixelFormat, imgWidth, imgHeight, pDecodingRegion->x, pDecodingRegion->y,
                                pDecodingRegion->width, pDecodingRegion->height);
 
-                       __pBuffer.reset(pTmpBuf);
+                       __bufSize = _ImageUtil::GetBufferSize(__pixelFormat, pDecodingRegion->width, pDecodingRegion->height);
+                       SysTryReturn(NID_MEDIA, __bufSize > 0, GetLastResult(), GetLastResult(),
+                       "[%s] Could not get output buffer size.", GetErrorMessage(GetLastResult()));
+
+                       r = dec.GetValue("transparency", transparency);
+                       if (r != E_SUCCESS)
+                       {
+                               __transparent = false;
+                               r = E_SUCCESS;
+                       }
+                       else
+                       {
+                               __transparent = transparency.ToBool();
+                               if (__transparent == true)
+                               {
+                                       r = dec.GetValue(L"chromaKey", chromaKey);
+                                       if (r != E_SUCCESS)
+                                       {
+                                               __transparent = false;
+                                               r = E_SUCCESS;
+                                       }
+                                       else
+                                       {
+                                               __maskColor = chromaKey.ToInt();
+                                       }
+                               }
+                       }
                }
        }
        else
@@ -340,19 +388,43 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] GetDimension failed.",
                        GetErrorMessage(r));
 
-               __pBuffer.reset(dec.DecodeN());
+               __pBuffer.reset(dec.DecodeN(__bufSize));
                r = GetLastResult();
-               SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.",
-                       GetErrorMessage(r));
-               SysTryReturn(NID_MEDIA, __pBuffer.get() != null, r, r,
-                       "[%s] DecodeN returned empty buffer.", GetErrorMessage(r));
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.", GetErrorMessage(r));
+               SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+                       "[E_OUT_OF_MEMORY] Propagated.");
+
+               r = dec.GetValue("transparency", transparency);
+               if (r != E_SUCCESS)
+               {
+                       __transparent = false;
+                       r = E_SUCCESS;
+               }
+               else
+               {
+                       __transparent = transparency.ToBool();
+                       if (__transparent == true)
+                       {
+                               r = dec.GetValue(L"chromaKey", chromaKey);
+                               if (r != E_SUCCESS)
+                               {
+                                       __transparent = false;
+                                       r = E_SUCCESS;
+                               }
+                               else
+                               {
+                                       __maskColor = chromaKey.ToInt();
+                               }
+                       }
+               }
        }
 
        if (autoRotate == true)
        {
-               ByteBuffer *pTmpBuf = null;
-               int tempWidth = 0;
-               int length = 0;
+               int dstWidth = 0;
+               int dstHeight = 0;
+
+               __orientation = EXIF_ORIENTATION_TOP_LEFT;
 
                if (orientationInfo == EXIF_ORIENTATION_TOP_LEFT || orientationInfo == 0)
                {
@@ -364,33 +436,26 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
                        return E_SUCCESS;
                }
 
-               pDstBuf.reset(new (std::nothrow) ByteBuffer());
+               pDstBuf.reset(new (std::nothrow) byte[__bufSize]);
                SysTryReturn(NID_MEDIA, pDstBuf.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
 
-               length = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height);
-
-               pDstBuf->Construct(length);
-               pDstBuf->SetLimit(length);
-               pDstBuf->SetPosition(0);
-
                ImageRotationType rotateType = _IMAGE_ROTATE_FLIP_MAP[orientationInfo].rotateType;
                ImageFlipType flipType = _IMAGE_ROTATE_FLIP_MAP[orientationInfo].flipType;
 
-               r = _ImageUtil::Rotate(*__pBuffer.get(), __pixelFormat, __width, __height, *pDstBuf.get(), rotateType);
+               pDstBuf.reset(_ImageUtil::RotateN(__pBuffer.get(), __pixelFormat, __width, __height, rotateType, dstWidth, dstHeight));
+               r = GetLastResult();
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] _ImageUtil:Resize", GetErrorMessage(r));
-               if(_IMAGE_ROTATE_FLIP_MAP[orientationInfo].dimensionSwitch == true)
-               {
-                       tempWidth = __width;
-                       __width = __height;
-                       __height =  tempWidth;
-               }
 
-               __pBuffer.swap(pDstBuf);
+               __width = dstWidth;
+               __height = dstHeight;
 
+               __pBuffer.swap(pDstBuf);
                if (flipType != IMAGE_FLIP_NONE)
                {
-                       r = _ImageUtil::Flip(*__pBuffer.get(), __pixelFormat, __width, __height, *pDstBuf, flipType);
+                       pDstBuf.reset(_ImageUtil::FlipN(__pBuffer.get(), __pixelFormat, __width, __height, flipType));
+                       r = GetLastResult();
                        SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] _ImageUtil:Flip", GetErrorMessage(r));
+
                        __pBuffer.swap(pDstBuf);
                }
        }
@@ -421,29 +486,110 @@ _ImageBufferImpl::Construct(const Bitmap &srcBitmap)
 
        __pixelFormat = _ImageUtilImpl::ToMediaPixelFormat(srcBitmap.GetPixelColorFormat());
 
-       __pBuffer.reset(new (std::nothrow) ByteBuffer);
-       SysTryCatch(NID_MEDIA, __pBuffer.get(), r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+       __pBuffer.reset(new (std::nothrow) byte[length]);
+       SysTryCatch(NID_MEDIA, __pBuffer.get() != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                "[E_OUT_OF_MEMORY] Construct instance failed.");
-
-       r = __pBuffer->Construct(length);
-       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r,
-               "[%s] Construct instance failed.", GetErrorMessage(r));
-       r = __pBuffer->SetArray((byte*)info.pPixels, 0, length);
-       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagated.", GetErrorMessage(r));
+       __bufSize = length;
+       memcpy(__pBuffer.get(), (byte*)info.pPixels, length);
 
        r = pTmpBmp->Unlock();
        SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] Bitmap.Unlock failed.", GetErrorMessage(r));
 
-       __pBuffer->Flip();
-
        return r;
-
 CATCH:
        pTmpBmp->Unlock();
 
        return r;
 }
 
+
+
+
+result
+_ImageBufferImpl::Construct(const Tizen::Base::String &srcImagePath, int destWidth, int destHeight, ImageScalingMethod scalingMethod)
+{
+       result r = E_SUCCESS;
+
+       std::unique_ptr<ByteBuffer> pBuf;
+       pBuf.reset(_MediaUtil::FileToBufferN(srcImagePath));
+       SysTryReturn(NID_MEDIA, pBuf.get() != null, GetLastResult(), GetLastResult(),
+                          "[%s] FileToBufferN %S", GetErrorMessage(GetLastResult()), srcImagePath.GetPointer());
+       r = Construct(*pBuf.get(), destWidth, destHeight, scalingMethod);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] ImageBuffer construct failed.", GetErrorMessage(r));
+       return r;
+}
+
+result
+_ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, int destWidth, int destHeight, ImageScalingMethod scalingMethod)
+{
+       result r = E_SUCCESS;
+       int orientationInfo = 0;
+       _ImageDecoder dec;
+       std::unique_ptr<byte[]> pDstBuf;
+       Tizen::Graphics::Rectangle transformRegion;
+       Boolean transparency(false);
+       Integer chromaKey;
+
+       r = dec.Construct(srcImageBuf);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Decoder construct failed.", GetErrorMessage(r));
+
+       __pixelFormat = dec.GetPixelFormat();
+       r = GetLastResult();
+       SysTryReturn(NID_MEDIA, __pixelFormat != MEDIA_PIXEL_FORMAT_NONE, r, r,
+               "[%s] GetPixelFormat failed.", GetErrorMessage(r));
+
+       _ExifUtil imgExif;
+       imgExif.Construct(srcImageBuf.GetPointer(), srcImageBuf.GetCapacity());
+       imgExif.GetValue(EXIF_TAG_IMAGE_ORIENTATION, orientationInfo);
+       // imgExif.GetValue() will return "r = E_OBJ_NOT_FOUND" if it could not be found exif infomation.
+       // However, the result should be decided by result of construct in this function.
+       SetLastResult(E_SUCCESS);
+
+       __orientation = _ORIENTATION_MAP[orientationInfo];
+
+       dec.SetOutputDimension(destWidth, destHeight, false);
+
+       __pBuffer.reset(dec.DecodeN(__bufSize, scalingMethod));
+       r = GetLastResult();
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] DecodeN failed.", GetErrorMessage(r));
+       SysTryReturn(NID_MEDIA, __pBuffer.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+               "[E_OUT_OF_MEMORY] Propagated.");
+
+       r = dec.GetValue("transparency", transparency);
+       if (r != E_SUCCESS)
+       {
+               __transparent = false;
+               r = E_SUCCESS;
+       }
+       else
+       {
+               __transparent = transparency.ToBool();
+               if (__transparent == true)
+               {
+                       r = dec.GetValue(L"chromaKey", chromaKey);
+                       if (r != E_SUCCESS)
+                       {
+                               __transparent = false;
+                               r = E_SUCCESS;
+                       }
+                       else
+                       {
+                               __maskColor = chromaKey.ToInt();
+                       }
+               }
+       }
+
+       r = dec.GetDimension(__width, __height);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] GetDimension failed.",
+               GetErrorMessage(r));
+
+       __bufSize = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height);
+       SysTryReturn(NID_MEDIA, __bufSize > 0, GetLastResult(), GetLastResult(),
+                       "[%s] Could not get output buffer size.", GetErrorMessage(GetLastResult()));
+       return r;
+}
+
+
 bool
 _ImageBufferImpl::Equals(ImageBuffer* pRhs) const
 {
@@ -492,7 +638,7 @@ _ImageBufferImpl::Equals(ImageBuffer* pRhs) const
                                        "[%s] Could not lock this ImageBuffer contents.", GetErrorMessage(r));
 
                                // Check if contents are equal.
-                               if ((__pixelFormat != pixFmtOther) || (__pBuffer->GetCapacity() != lengthOther))
+                               if ((__pixelFormat != pixFmtOther) || (__bufSize != lengthOther))
                                {
                                        out = false;
                                }
@@ -518,8 +664,12 @@ int
 _ImageBufferImpl::GetHashCode() const
 {
        int hashCode = 0;
+       int len = __bufSize / sizeof(len);
 
-       hashCode = __pBuffer->GetHashCode();
+       for (int i = 0; i < len; ++i)
+       {
+               hashCode = (hashCode << 5) - hashCode + static_cast <int>(__pBuffer[(i * sizeof(hashCode))]);
+       }
 
        hashCode = (hashCode ^ (__width * __height)) | (hashCode & __pixelFormat);
 
@@ -544,6 +694,12 @@ _ImageBufferImpl::GetPixelFormat() const
        return __pixelFormat;
 }
 
+ExifOrientation
+_ImageBufferImpl::GetExifOrientation(void) const
+{
+       return __orientation;
+}
+
 result
 _ImageBufferImpl::Lock(byte* &data, int &length, MediaPixelFormat &pixelFormat)
 {
@@ -552,7 +708,7 @@ _ImageBufferImpl::Lock(byte* &data, int &length, MediaPixelFormat &pixelFormat)
        SysTryReturn(NID_MEDIA, __isLocked != true, E_INVALID_STATE, E_INVALID_STATE,
                "[E_INVALID_STATE] Instance is locked. Unlock to use.");
 
-       data = const_cast<byte *>(__pBuffer->GetPointer());
+       data = const_cast<byte *>(__pBuffer.get());
        length = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height);
        pixelFormat = __pixelFormat;
 
@@ -585,7 +741,7 @@ _ImageBufferImpl::EncodeToBufferN(ImageFormat destImageFormat, int quality) cons
                "[E_INVALID_STATE] Instance is locked. Unlock to use.");
 
        inLength = _ImageUtil::GetBufferSize(__pixelFormat, __width, __height);
-       pBuf = _ImageEncoder::EncodeN(destImageFormat, (const byte*)__pBuffer->GetPointer(), inLength, __width, __height,
+       pBuf = _ImageEncoder::EncodeN(destImageFormat, (const byte*)__pBuffer.get(), inLength, __width, __height,
                __pixelFormat, quality);
        SysTryReturn(NID_MEDIA, pBuf != null, null, GetLastResult(), "[%s] Propagated. ", GetErrorMessage(GetLastResult()));
 
@@ -646,7 +802,44 @@ _ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, BufferScaling buffer
        }
        else
        {
-               r = pOutBitmap->Construct(*__pBuffer, Dimension(__width, __height), pixelFormat, bufferScaling);
+               std::unique_ptr<ByteBuffer> pTmpByteBuffer (new (std::nothrow) ByteBuffer());
+               r = pTmpByteBuffer->Construct(__pBuffer.get(), 0, __bufSize, __bufSize);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
+                       "[%s] Construct instance failed.", GetErrorMessage(r));
+
+               r = pOutBitmap->Construct(*pTmpByteBuffer.get(), Dimension(__width, __height), pixelFormat, bufferScaling);
+       }
+
+       if ((__transparent == true) && (pixelFormat == BITMAP_PIXEL_FORMAT_RGB565))
+       {
+               byte red = 0;
+               byte green = 0;
+               byte blue = 0;
+               Color *pMaskingColor = null;
+
+               if (__pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+               {
+                       blue = (__maskColor & 0x000000ff);
+                       green = (__maskColor & 0x0000ff00) >> 8;
+                       red = (__maskColor & 0x00ff0000) >> 16;
+               }
+               else
+               {
+                       red = (__maskColor & 0xf800) >> 8;
+                       red = red | (red >> 5);
+                       green = (__maskColor & 0x07e0) >> 3;
+                       green = green | (green >> 6);
+                       blue = (__maskColor & 0x001f) << 3;
+                       blue = blue | (blue >> 5);
+               }
+
+               pMaskingColor = new Color(red, green, blue);
+               SysTryReturn(NID_MEDIA, pMaskingColor != null, pOutBitmap.release(), E_SUCCESS,
+                       "[%s] Could not apply masking color.", GetErrorMessage(r));
+               r = pOutBitmap->SetMaskingColor(pMaskingColor);
+               delete pMaskingColor;
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, pOutBitmap.release(), E_SUCCESS,
+                       "[%s] Could not set masking color.", GetErrorMessage(r));
        }
 
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.",
@@ -654,6 +847,89 @@ _ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, BufferScaling buffer
        return pOutBitmap.release();
 }
 
+Bitmap*
+_ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, const FloatDimension &destDim) const
+{
+       result r = E_SUCCESS;
+       std::unique_ptr<Bitmap> pOutBitmap;
+       std::unique_ptr<ByteBuffer> pConverted;
+       MediaPixelFormat inPixelFormat = MEDIA_PIXEL_FORMAT_NONE;
+       Dimension convertDim;
+
+       SysTryReturn(NID_MEDIA, !__isLocked, null, E_INVALID_STATE,
+               "[E_INVALID_STATE] Instance is locked. Unlock to use.");
+
+       inPixelFormat = _ImageUtilImpl::ToMediaPixelFormat(pixelFormat);
+       SysTryReturn(NID_MEDIA, (inPixelFormat > MEDIA_PIXEL_FORMAT_NONE) && (inPixelFormat <= MEDIA_PIXEL_FORMAT_GRAY),
+                                null, E_INVALID_ARG, "[E_INVALID_ARG] Pixel format is invalid.", inPixelFormat);
+
+       pOutBitmap.reset(new (std::nothrow) Bitmap);
+       SysTryReturn(NID_MEDIA, pOutBitmap.get() != null, null, E_OUT_OF_MEMORY,
+               "[E_OUT_OF_MEMORY] Propagated.");
+
+       convertDim.width = _CoordinateSystemUtils::ConvertToInteger(destDim.width);
+       convertDim.height = _CoordinateSystemUtils::ConvertToInteger(destDim.height);
+
+       std::unique_ptr<ByteBuffer> pTmpByteBuffer (new (std::nothrow) ByteBuffer());
+       r = pTmpByteBuffer->Construct(__pBuffer.get(), 0, __bufSize, __bufSize);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
+                               "[%s] Construct instance failed.", GetErrorMessage(r));
+
+       if (inPixelFormat == __pixelFormat && convertDim.width == __width && convertDim.height == __height)
+       {
+               pOutBitmap.reset(_BitmapImpl::GetNonScaledBitmapN(*pTmpByteBuffer.get(), convertDim, pixelFormat, destDim));
+       }
+       else
+       {
+               std::unique_ptr<ByteBuffer> pOutBuf;
+               _ColorConverter cvt;
+
+               r = cvt.Construct(__pixelFormat, __width, __height, inPixelFormat, convertDim.width, convertDim.height);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r));
+
+               pOutBuf.reset(cvt.ConvertN(*pTmpByteBuffer));
+               r = GetLastResult();
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r));
+
+               pOutBitmap.reset(_BitmapImpl::GetNonScaledBitmapN(*pOutBuf.get(), convertDim, pixelFormat, destDim));
+       }
+
+       if ((__transparent == true) && (pixelFormat == BITMAP_PIXEL_FORMAT_RGB565))
+       {
+               byte red = 0;
+               byte green = 0;
+               byte blue = 0;
+               Color *pMaskingColor = null;
+
+               if (__pixelFormat == MEDIA_PIXEL_FORMAT_BGRA8888)
+               {
+                       blue = (__maskColor & 0x000000ff);
+                       green = (__maskColor & 0x0000ff00) >> 8;
+                       red = (__maskColor & 0x00ff0000) >> 16;
+               }
+               else
+               {
+                       red = (__maskColor & 0xf800) >> 8;
+                       red = red | (red >> 5);
+                       green = (__maskColor & 0x07e0) >> 3;
+                       green = green | (green >> 6);
+                       blue = (__maskColor & 0x001f) << 3;
+                       blue = blue | (blue >> 5);
+               }
+
+               pMaskingColor = new Color(red, green, blue);
+               SysTryReturn(NID_MEDIA, pMaskingColor != null, pOutBitmap.release(), E_SUCCESS,
+                       "[%s] Could not apply masking color.", GetErrorMessage(r));
+               r = pOutBitmap->SetMaskingColor(pMaskingColor);
+               delete pMaskingColor;
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, pOutBitmap.release(), E_SUCCESS,
+                       "[%s] Could not set masking color.", GetErrorMessage(r));
+       }
+
+       SysTryReturn(NID_MEDIA, pOutBitmap.get() != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
+       return pOutBitmap.release();
+}
+
 ByteBuffer*
 _ImageBufferImpl::GetByteBufferN(MediaPixelFormat inPixelFormat) const
 {
@@ -663,12 +939,14 @@ _ImageBufferImpl::GetByteBufferN(MediaPixelFormat inPixelFormat) const
        SysTryReturn(NID_MEDIA, !__isLocked, null, E_INVALID_STATE,
                "[E_INVALID_STATE] Instance is locked. Unlock to use.");
 
-       SysTryReturn(NID_MEDIA, (inPixelFormat > MEDIA_PIXEL_FORMAT_NONE) && (inPixelFormat <= MEDIA_PIXEL_FORMAT_YUYV422),
-               null, E_INVALID_ARG, "[E_INVALID_ARG] Pixel format is invalid.", inPixelFormat);
-
        SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(inPixelFormat) == true , null, E_UNSUPPORTED_FORMAT,
                "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.")
 
+       std::unique_ptr<ByteBuffer> pTmpByteBuffer (new (std::nothrow) ByteBuffer());
+       r = pTmpByteBuffer->Construct(__pBuffer.get(), 0, __bufSize, __bufSize);
+       SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
+                       "[%s] Construct instance failed.", GetErrorMessage(r));
+
        if (inPixelFormat != __pixelFormat)
        {
                // Convert raw data to the required pixel format.
@@ -678,7 +956,7 @@ _ImageBufferImpl::GetByteBufferN(MediaPixelFormat inPixelFormat) const
                        inPixelFormat, __width, __height);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r));
 
-               pOutBuf.reset(cvt.ConvertN(*__pBuffer));
+               pOutBuf.reset(cvt.ConvertN(*pTmpByteBuffer));
                r = GetLastResult();
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.", GetErrorMessage(r));
        }
@@ -688,7 +966,7 @@ _ImageBufferImpl::GetByteBufferN(MediaPixelFormat inPixelFormat) const
                SysTryReturn(NID_MEDIA, pOutBuf.get() != null, null, E_OUT_OF_MEMORY,
                        "[E_OUT_OF_MEMORY] Propagated.");
 
-               r = pOutBuf->Construct(*__pBuffer);
+               r = pOutBuf->Construct(*pTmpByteBuffer);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                        "[%s] Propagated.", GetErrorMessage(r));
        }
@@ -701,11 +979,11 @@ ImageBuffer*
 _ImageBufferImpl::CloneN() const
 {
        std::unique_ptr<ImageBuffer> pImgBuffer;
-       _ImageBufferImpl* pImgBufferImpl = null;
        result r = E_SUCCESS;
        byte* pData = null;
        int length = 0;
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+       _ImageBufferImpl* pClonedImpl = null;
 
        r = const_cast<_ImageBufferImpl *>(this)->Lock(pData, length, pixFmt);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, pImgBuffer.get(), r, "[%s] Propagated.", GetErrorMessage(r));
@@ -718,6 +996,12 @@ _ImageBufferImpl::CloneN() const
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                "[%s] Failed to construct the cloned ImageBuffer.", GetErrorMessage(r));
 
+       pClonedImpl = GetInstance(*pImgBuffer);
+       SysTryReturn(NID_MEDIA, pClonedImpl != null, null, r,
+               "[%s] Failed to GetInstance.", GetErrorMessage(r));
+       pClonedImpl->__maskColor = __maskColor;
+       pClonedImpl->__transparent = __transparent;
+
        const_cast<_ImageBufferImpl *>(this)->Unlock();
 
        SetLastResult(r);
@@ -728,16 +1012,19 @@ ImageBuffer*
 _ImageBufferImpl::ConvertPixelFormatN(MediaPixelFormat pixelFormat) const
 {
        std::unique_ptr<ImageBuffer> pImgBuffer;
-       _ImageBufferImpl* pImgBufferImpl = null;
        result r = E_SUCCESS;
        byte* pData = null;
        std::unique_ptr<byte[]> pDataConvert;
        int length = 0;
        int dstLength = 0;
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+       _ImageBufferImpl* pConvertedImpl = null;
+
+       SysTryReturn(NID_MEDIA, IsSupportedPixelFormat(pixelFormat) == true , null, E_UNSUPPORTED_FORMAT,
+               "[E_UNSUPPORTED_FORMAT] The specified pixelFormat is not supported.")
 
-       SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, pImgBuffer.get(), E_INVALID_ARG,
-               "[E_INVALID_ARG] Pixel format %d is not supported.", pixelFormat);
+       SysTryReturn(NID_MEDIA, _ImageUtil::IsValidDimension(pixelFormat, __width, __height) == true, null, E_INVALID_ARG,
+               "[E_INVALID_ARG] Dimensions should be even for this pixel format: (%d x %d)", __width, __height);
 
        if (pixelFormat != __pixelFormat)
        {
@@ -765,6 +1052,13 @@ _ImageBufferImpl::ConvertPixelFormatN(MediaPixelFormat pixelFormat) const
                r = pImgBuffer->Construct(__width, __height, pixelFormat, pDataConvert.get(), dstLength);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                        "[%s] Failed to construct the converted ImageBuffer.", GetErrorMessage(r));
+
+               pConvertedImpl = GetInstance(*pImgBuffer);
+               SysTryReturn(NID_MEDIA, pConvertedImpl != null, null, r,
+                       "[%s] Failed to GetInstance.", GetErrorMessage(r));
+               pConvertedImpl->__maskColor = __maskColor;
+               pConvertedImpl->__transparent = __transparent;
+
        }
        else
        {
@@ -784,17 +1078,20 @@ ImageBuffer*
 _ImageBufferImpl::ResizeN(int width, int height) const
 {
        std::unique_ptr<ImageBuffer> pImgBuffer;
-       _ImageBufferImpl* pImgBufferImpl = null;
        result r = E_SUCCESS;
        byte* pData = null;
        std::unique_ptr<byte[]> pDataResized;
        int length = 0;
        int dstLength = 0;
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+       _ImageBufferImpl* pResizedImpl = null;
 
-       SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), pImgBuffer.get(), E_INVALID_ARG,
+       SysTryReturn(NID_MEDIA, (width > 0) && (height > 0), null, E_INVALID_ARG,
                "[E_INVALID_ARG] Dimensions should be greater than zero: (%d x %d)", width, height);
 
+       SysTryReturn(NID_MEDIA, _ImageUtil::IsValidDimension(__pixelFormat, width, height) == true, null, E_INVALID_ARG,
+               "[E_INVALID_ARG] Dimensions should be even for this pixel format: (%d x %d)", width, height);
+
        if ((width != __width) && (height != __height))
        {
                dstLength = _ImageUtil::GetBufferSize(__pixelFormat, width, height);
@@ -824,6 +1121,12 @@ _ImageBufferImpl::ResizeN(int width, int height) const
                r = pImgBuffer->Construct(width, height, __pixelFormat, pDataResized.get(), dstLength);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                        "[%s] Failed to construct the resized ImageBuffer.", GetErrorMessage(r));
+
+               pResizedImpl = GetInstance(*pImgBuffer);
+               SysTryReturn(NID_MEDIA, pResizedImpl != null, null, r,
+                       "[%s] Failed to GetInstance.", GetErrorMessage(r));
+               pResizedImpl->__maskColor = __maskColor;
+               pResizedImpl->__transparent = __transparent;
        }
        else
        {
@@ -844,12 +1147,12 @@ ImageBuffer*
 _ImageBufferImpl::FlipN(ImageFlipType flipType) const
 {
        std::unique_ptr<ImageBuffer> pImgBuffer;
-       _ImageBufferImpl* pImgBufferImpl = null;
        result r = E_SUCCESS;
        byte* pData = null;
        std::unique_ptr<byte[]> pDataFlip;
        int length = 0;
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+       _ImageBufferImpl* pFlippedImpl = null;
 
        SysTryReturn(NID_MEDIA, (flipType >= IMAGE_FLIP_NONE) && (flipType <= IMAGE_FLIP_VERTICAL),
                pImgBuffer.get(), E_INVALID_ARG, "[E_INVALID_ARG] Flip type is not valid: %d.", flipType);
@@ -877,6 +1180,12 @@ _ImageBufferImpl::FlipN(ImageFlipType flipType) const
                r = pImgBuffer->Construct(__width, __height, __pixelFormat, pDataFlip.get(), length);
                SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r,
                        "[%s] Failed to construct the fliped ImageBuffer.", GetErrorMessage(r));
+
+               pFlippedImpl = GetInstance(*pImgBuffer);
+               SysTryReturn(NID_MEDIA, pFlippedImpl != null, null, r,
+                       "[%s] Failed to GetInstance.", GetErrorMessage(r));
+               pFlippedImpl->__maskColor = __maskColor;
+               pFlippedImpl->__transparent = __transparent;
        }
        else
        {
@@ -898,7 +1207,6 @@ ImageBuffer*
 _ImageBufferImpl::RotateN(ImageRotationType rotationType) const
 {
        std::unique_ptr<ImageBuffer> pImgBuffer;
-       _ImageBufferImpl* pImgBufferImpl = null;
        result r = E_SUCCESS;
        byte* pData = null;
        std::unique_ptr<byte[]> pDataRotate;
@@ -906,6 +1214,7 @@ _ImageBufferImpl::RotateN(ImageRotationType rotationType) const
        int rotatedWidth= 0;
        int rotatedHeight = 0;
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+       _ImageBufferImpl* pRotatedImpl = null;
 
        SysTryReturn(NID_MEDIA, (rotationType >= IMAGE_ROTATION_0) && (rotationType <= IMAGE_ROTATION_270),
                pImgBuffer.get(), E_INVALID_ARG, "[E_INVALID_ARG] Rotation type is not valid: %d.", rotationType);
@@ -934,6 +1243,12 @@ _ImageBufferImpl::RotateN(ImageRotationType rotationType) const
                r = pImgBuffer->Construct(rotatedWidth, rotatedHeight, __pixelFormat, pDataRotate.get(), length);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                        "[%s] Failed to construct the rotated ImageBuffer.", GetErrorMessage(r));
+
+               pRotatedImpl = GetInstance(*pImgBuffer);
+               SysTryReturn(NID_MEDIA, pRotatedImpl != null, null, r,
+                       "[%s] Failed to GetInstance.", GetErrorMessage(r));
+               pRotatedImpl->__maskColor = __maskColor;
+               pRotatedImpl->__transparent = __transparent;
        }
        else
        {
@@ -955,13 +1270,13 @@ ImageBuffer*
 _ImageBufferImpl::CropN(int x, int y, int width, int height) const
 {
        std::unique_ptr<ImageBuffer> pImgBuffer;
-       _ImageBufferImpl* pImgBufferImpl = null;
        result r = E_SUCCESS;
        byte* pData = null;
        std::unique_ptr<byte[]> pDataCropped;
        int length = 0;
        int dstLength = 0;
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+       _ImageBufferImpl *pCroppedImpl = null;
 
        SysTryReturn(NID_MEDIA, (x >= 0) && (y >= 0) && (x <= __width) && (y <= __height),
                pImgBuffer.get(), E_INVALID_ARG,
@@ -1011,6 +1326,12 @@ _ImageBufferImpl::CropN(int x, int y, int width, int height) const
                r = pImgBuffer->Construct(width, height, __pixelFormat, pDataCropped.get(), dstLength);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                        "[%s] Failed to construct the croped ImageBuffer.", GetErrorMessage(r));
+
+               pCroppedImpl = GetInstance(*pImgBuffer);
+               SysTryReturn(NID_MEDIA, pCroppedImpl != null, null, r,
+                       "[%s] Failed to GetInstance.", GetErrorMessage(r));
+               pCroppedImpl->__maskColor = __maskColor;
+               pCroppedImpl->__transparent = __transparent;
        }
        else
        {
@@ -1062,7 +1383,7 @@ _ImageBufferImpl::GetImageInfo(const ByteBuffer& srcImageBuf, ImageFormat& image
 bool
 _ImageBufferImpl::IsSupportedPixelFormat(MediaPixelFormat pixelFormat)
 {
-       for (int i = 0; i < sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]) ; i++)
+       for (unsigned int i = 0; i < sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]) ; i++)
        {
                if(pixelFormat == _IMAGE_BUFFER_PIXEL_FORMATS[i])
                {
@@ -1081,7 +1402,7 @@ _ImageBufferImpl::GetSupportedPixelFormatListN()
                "[E_OUT_OF_MEMORY] Could not allocate memory for output.");
 
        // TODO update list later for supported color formats in color converter?.
-       for (int i=0; i<sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]); i++)
+       for (unsigned int i=0; i<sizeof(_IMAGE_BUFFER_PIXEL_FORMATS)/sizeof(_IMAGE_BUFFER_PIXEL_FORMATS[0]); i++)
        {
                r = pList->Add(_IMAGE_BUFFER_PIXEL_FORMATS[i]);
                SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,