Added transparency support in RGB565 bitmap outputs, for gif decoder.
[platform/framework/native/image.git] / src / FMedia_ImageImpl.cpp
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();
 }