Added transparency support in RGB565 bitmap outputs, for gif decoder.
authormamata pattanaik <mamata.p@samsung.com>
Tue, 26 Mar 2013 07:22:42 +0000 (12:52 +0530)
committermamata pattanaik <mamata.p@samsung.com>
Tue, 26 Mar 2013 09:10:07 +0000 (14:40 +0530)
Change-Id: I94e7adbb175ed3fbb956290256a8d49d76a0a068
Signed-off-by: mamata pattanaik <mamata.p@samsung.com>
src/FMedia_GifDecoderImpl.cpp
src/FMedia_GifDecoderImpl.h
src/FMedia_ImageBufferImpl.cpp
src/FMedia_ImageImpl.cpp
src/inc/FMedia_ImageBufferImpl.h

index f953f20..51687c7 100644 (file)
@@ -135,7 +135,7 @@ _GifDecoderImpl::GetNextFrameN(long& duration)
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r));
        pBuf.get()->Flip();
 
-       r = GetValue(String("duration"), longValue);
+       r = __pGifDecoder->GetValue(L"duration", longValue);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r,
                           "[%s] dec.GetValue(duration)", GetErrorMessage(r));
        duration = longValue.ToLong();
@@ -170,22 +170,4 @@ _GifDecoderImpl::GetNextBitmapN(long& duration, Tizen::Graphics::BufferScaling b
        return pBitmap.release();
 }
 
-result
-_GifDecoderImpl::GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value)
-{
-       result r = E_SUCCESS;
-       if (key.Equals(L"duration", false))
-       {
-               Long *pLong = null;
-               pLong = dynamic_cast<Long*>(&value);
-
-               SysTryReturn(NID_MEDIA, pLong, E_INVALID_ARG, E_INVALID_ARG, "value is not a Long");
-               pLong->value = __pGifDecoder->GetDuration();
-       }
-       else
-       {
-               r = E_OBJ_NOT_FOUND;
-       }
-       return r;
-}
 }} // Tizen::Media
index 7126235..387c5df 100644 (file)
@@ -132,19 +132,6 @@ public:
         *                      The specific error code can be accessed using the GetLastResult() method.
         */
        Tizen::Graphics::Bitmap* GetNextBitmapN(long& duration, Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO);
-
-       /**
-        * Gets the value of given key.
-        *
-        * @return   An error code
-        * @param[in]  key                                        The key of the value.
-        * @param[out] value                                    The output value.
-        * @exception  E_SUCCESS                                The method is successful.
-        * @exception  E_INVALID_ARG                    The input parameter is invalid.
-        * @exception  E_UNSUPPORTED_OPERATION  This method is unsupported.
-        */
-       result GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value);
-
 private:
        _GifDecoderImpl(const _GifDecoderImpl& rhs);
        _GifDecoderImpl& operator =(const _GifDecoderImpl& rhs);
index 38f3016..6746310 100644 (file)
@@ -96,6 +96,8 @@ _ImageBufferImpl::_ImageBufferImpl(void)
        , __orientation(EXIF_ORIENTATION_TOP_LEFT)
        , __pixelFormat(MEDIA_PIXEL_FORMAT_NONE)
        , __isLocked(false)
+       , __transparent(false)
+       , __maskColor(0xf81f) // MAGENTA
 {
 }
 
@@ -197,6 +199,8 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
        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));
@@ -306,6 +310,29 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
                        __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)
                {
@@ -329,6 +356,30 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
                        __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
@@ -342,6 +393,30 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, const Ti
                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)
@@ -452,6 +527,8 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, int dest
        _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));
@@ -478,6 +555,30 @@ _ImageBufferImpl::Construct(const Tizen::Base::ByteBuffer &srcImageBuf, int dest
        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));
@@ -709,6 +810,38 @@ _ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, BufferScaling buffer
                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);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, pOutBitmap.release(), E_SUCCESS,
+                       "[%s] Could not set masking color.", GetErrorMessage(r));
+               delete pMaskingColor;
+       }
+
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated.",
                GetErrorMessage(r));
        return pOutBitmap.release();
@@ -761,6 +894,38 @@ _ImageBufferImpl::GetBitmapN(BitmapPixelFormat pixelFormat, const FloatDimension
                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);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, pOutBitmap.release(), E_SUCCESS,
+                       "[%s] Could not set masking color.", GetErrorMessage(r));
+               delete pMaskingColor;
+       }
+
        SysTryReturn(NID_MEDIA, pOutBitmap.get() != null, null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
        return pOutBitmap.release();
 }
@@ -821,6 +986,7 @@ _ImageBufferImpl::CloneN() const
        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));
@@ -833,6 +999,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);
@@ -849,6 +1021,7 @@ _ImageBufferImpl::ConvertPixelFormatN(MediaPixelFormat pixelFormat) const
        int length = 0;
        int dstLength = 0;
        MediaPixelFormat pixFmt = MEDIA_PIXEL_FORMAT_NONE;
+       _ImageBufferImpl* pConvertedImpl = null;
 
        SysTryReturn(NID_MEDIA, ISSUPPORTED(pixelFormat) == true, pImgBuffer.get(), E_INVALID_ARG,
                "[E_INVALID_ARG] Pixel format %d is not supported.", pixelFormat);
@@ -879,6 +1052,12 @@ _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
        {
@@ -904,6 +1083,7 @@ _ImageBufferImpl::ResizeN(int width, int height) const
        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,
                "[E_INVALID_ARG] Dimensions should be greater than zero: (%d x %d)", width, height);
@@ -937,6 +1117,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
        {
@@ -962,6 +1148,7 @@ _ImageBufferImpl::FlipN(ImageFlipType flipType) const
        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);
@@ -989,6 +1176,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
        {
@@ -1017,6 +1210,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);
@@ -1045,6 +1239,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
        {
@@ -1072,6 +1272,7 @@ _ImageBufferImpl::CropN(int x, int y, int width, int height) const
        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,
@@ -1121,6 +1322,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
        {
@@ -1172,7 +1379,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])
                {
@@ -1191,7 +1398,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,
index 28a1ba3..71f5090 100644 (file)
@@ -159,6 +159,41 @@ _ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::G
        r = pBmp->Construct(*pBuf.get(), outDim, pixelFormat, BUFFER_SCALING_AUTO);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r));
 
+       // Set transparency in case of rgb565 format
+       if (pixelFormat == BITMAP_PIXEL_FORMAT_RGB565)
+       {
+               short rgb565Chroma = 0;
+               Boolean transparency(false);
+               Short chromaKey(0);
+               byte red = 0;
+               byte green = 0;
+               byte blue = 0;
+               Color *pMaskingColor = null;
+
+               r = dec.GetValue(L"transparency", transparency);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS, "[%s] Propagated.", GetErrorMessage(r));
+               if (transparency.ToBool() == true)
+               {
+                       r = dec.GetValue(L"chromaKey", chromaKey);
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS, "[%s] Propagated.", GetErrorMessage(r));
+
+                       rgb565Chroma = chromaKey.ToShort();
+                       red = (rgb565Chroma & 0xf800) >> 8;
+                       red = red | (red >> 5);
+                       green = (rgb565Chroma & 0x07e0) >> 3;
+                       green = green | (green >> 6);
+                       blue = (rgb565Chroma & 0x001f) << 3;
+                       blue = blue | (blue >> 5);
+
+                       pMaskingColor = new Color(red, green, blue);
+                       SysTryReturn(NID_MEDIA, pMaskingColor != null, pBmp.release(), E_SUCCESS,
+                               "[%s] Could not apply masking color.", GetErrorMessage(r));
+                       r = pBmp->SetMaskingColor(pMaskingColor);
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS,
+                               "[%s] Could not set masking color.", GetErrorMessage(r));
+               }
+       }
+
        SetLastResult(E_SUCCESS);
        return pBmp.release();
 }
@@ -210,6 +245,41 @@ _ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::G
        r = pBmp->Construct(*pBuf.get(), outDim, pixelFormat, bufferScaling);
        SysTryReturn(NID_MEDIA, r == E_SUCCESS, null, r, "[%s] Propagated. ", GetErrorMessage(r));
 
+       // Set transparency in case of rgb565 format
+       if (pixelFormat == BITMAP_PIXEL_FORMAT_RGB565)
+       {
+               short rgb565Chroma = 0;
+               Boolean transparency(false);
+               Short chromaKey(0);
+               byte red = 0;
+               byte green = 0;
+               byte blue = 0;
+               Color *pMaskingColor = null;
+
+               r = dec.GetValue(L"transparency", transparency);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS, "[%s] Propagated.", GetErrorMessage(r));
+               if (transparency.ToBool() == true)
+               {
+                       r = dec.GetValue(L"chromaKey", chromaKey);
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS, "[%s] Propagated.", GetErrorMessage(r));
+
+                       rgb565Chroma = chromaKey.ToShort();
+                       red = (rgb565Chroma & 0xf800) >> 8;
+                       red = red | (red >> 5);
+                       green = (rgb565Chroma & 0x07e0) >> 3;
+                       green = green | (green >> 6);
+                       blue = (rgb565Chroma & 0x001f) << 3;
+                       blue = blue | (blue >> 5);
+
+                       pMaskingColor = new Color(red, green, blue);
+                       SysTryReturn(NID_MEDIA, pMaskingColor != null, pBmp.release(), E_SUCCESS,
+                               "[%s] Could not apply masking color.", GetErrorMessage(r));
+                       r = pBmp->SetMaskingColor(pMaskingColor);
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS,
+                               "[%s] Could not set masking color.", GetErrorMessage(r));
+               }
+       }
+
        SetLastResult(E_SUCCESS);
        return pBmp.release();
 }
@@ -253,6 +323,42 @@ _ImageImpl::DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::G
                           "[%s] new Bitmap", GetErrorMessage(GetLastResult()));
 
        pBmp.reset(_BitmapImpl::GetNonScaledBitmapN(*pBuf.get(), tmpDim, pixelFormat, destDim));
+
+       // Set transparency in case of rgb565 format
+       if (pixelFormat == BITMAP_PIXEL_FORMAT_RGB565)
+       {
+               short rgb565Chroma = 0;
+               Boolean transparency(false);
+               Short chromaKey(0);
+               byte red = 0;
+               byte green = 0;
+               byte blue = 0;
+               Color *pMaskingColor = null;
+
+               r = dec.GetValue(L"transparency", transparency);
+               SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS, "[%s] Propagated.", GetErrorMessage(r));
+               if (transparency.ToBool() == true)
+               {
+                       r = dec.GetValue(L"chromaKey", chromaKey);
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS, "[%s] Propagated.", GetErrorMessage(r));
+
+                       rgb565Chroma = chromaKey.ToShort();
+                       red = (rgb565Chroma & 0xf800) >> 8;
+                       red = red | (red >> 5);
+                       green = (rgb565Chroma & 0x07e0) >> 3;
+                       green = green | (green >> 6);
+                       blue = (rgb565Chroma & 0x001f) << 3;
+                       blue = blue | (blue >> 5);
+
+                       pMaskingColor = new Color(red, green, blue);
+                       SysTryReturn(NID_MEDIA, pMaskingColor != null, pBmp.release(), E_SUCCESS,
+                               "[%s] Could not apply masking color.", GetErrorMessage(r));
+                       r = pBmp->SetMaskingColor(pMaskingColor);
+                       SysTryReturn(NID_MEDIA, r == E_SUCCESS, pBmp.release(), E_SUCCESS,
+                               "[%s] Could not set masking color.", GetErrorMessage(r));
+               }
+       }
+
        SetLastResult(E_SUCCESS);
        return pBmp.release();
 }
index acecf30..ddb9d72 100644 (file)
@@ -222,6 +222,8 @@ private:
        ExifOrientation __orientation;
        MediaPixelFormat __pixelFormat;
        bool __isLocked;
+       bool __transparent;
+       int __maskColor;
 };
 
 }} // Tizen::Media