Fixed GifDecoder transparent issue
authorJungYumin <y_m.jung@samsung.com>
Tue, 18 Jun 2013 05:47:44 +0000 (14:47 +0900)
committerJungYumin <y_m.jung@samsung.com>
Tue, 18 Jun 2013 07:40:12 +0000 (16:40 +0900)
Change-Id: I62f5936c10ebaed949feee6b30195d77f7f27758
Signed-off-by: JungYumin <y_m.jung@samsung.com>
src/FMedia_GifDecoder.cpp
src/inc/FMedia_GifDecoder.h

index c730d47..762ec24 100644 (file)
@@ -54,7 +54,7 @@ _GifDecoder::_GifDecoder(void)
        __transparent = false;
        __chromaKey = BGRA8888(0xff, 0x00, 0xff, 0x00);
        __transColor = 0;
-       __pixelFormat = MEDIA_PIXEL_FORMAT_RGB565LE;
+       __pixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888;
        __firstFramePos = 0;
        __dstLength = 0;
        __srcWidth = 0;
@@ -62,6 +62,8 @@ _GifDecoder::_GifDecoder(void)
        __frameIndex = 0;
        __duration = 0;
        __totalFrames = 0;
+       __globalTransparent = false;
+       __globalChromaKey = __chromaKey;
 }
 
 _GifDecoder::~_GifDecoder(void)
@@ -314,7 +316,18 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                                        {
                                                for (k = 0; k < width; k++)
                                                {
-                                                       pBuf[k] = ((unsigned short*) pPalette)[pLine[k]];
+                                                       if (pLine[k] == __transColor && __frameIndex == 0)
+                                                       {
+                                                               pBuf[k] = ((unsigned short*) pPalette)[pLine[k]];
+                                                       }
+                                                       else if (pLine[k] == __transColor)
+                                                       {
+                                                               // use previous frame's color
+                                                       }
+                                                       else
+                                                       {
+                                                               pBuf[k] = ((unsigned short*) pPalette)[pLine[k]];
+                                                       }
                                                }
                                        }
                                }
@@ -339,11 +352,19 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                                        {
                                                for (k = 0; k < width; k++)
                                                {
-                                                       pBuf[k] = ((unsigned int*) pPalette)[pLine[k]];
-                                                       if (pLine[k] == __transColor) 
+                                                       if (pLine[k] == __transColor && __frameIndex == 0)
                                                        {
+                                                               pBuf[k] = ((unsigned int*) pPalette)[pLine[k]];
                                                                pBuf[k] &= 0x00ffffff;
                                                        }
+                                                       else if (pLine[k] == __transColor)
+                                                       {
+                                                               // use previous frame's color
+                                                       }
+                                                       else
+                                                       {
+                                                               pBuf[k] = ((unsigned int*) pPalette)[pLine[k]];
+                                                       }
                                                }
                                        }
                                        else
@@ -374,7 +395,18 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                                   "[E_INVALID_DATA] DGifGetLineByte failed with code %x", GifLastError());
                                for (k = 0; k < width; k++)
                                {
-                                       pBuf[k] = ((unsigned short*) pPalette)[pLine[k]];
+                                       if (pLine[k] == __transColor && __frameIndex == 0)
+                                       {
+                                               pBuf[k] = ((unsigned short*) pPalette)[pLine[k]];
+                                       }
+                                       else if (pLine[k] == __transColor)
+                                       {
+                                               // use previous frame's color
+                                       }
+                                       else
+                                       {
+                                               pBuf[k] = ((unsigned short*) pPalette)[pLine[k]];
+                                       }
                                }
                        }
                }
@@ -395,11 +427,19 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
                                {
                                        for (k = 0; k < width; k++)
                                        {
-                                               pBuf[k] = ((unsigned int*) pPalette)[pLine[k]];
-                                               if (pLine[k] == __transColor) 
+                                               if (pLine[k] == __transColor && __frameIndex == 0)
                                                {
+                                                       pBuf[k] = ((unsigned int*) pPalette)[pLine[k]];
                                                        pBuf[k] &= 0x00ffffff;
                                                }
+                                               else if (pLine[k] == __transColor)
+                                               {
+                                                       // use previous frame's color
+                                               }
+                                               else
+                                               {
+                                                       pBuf[k] = ((unsigned int*) pPalette)[pLine[k]];
+                                               }
                                        }
                                }
                                else
@@ -414,6 +454,14 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length)
        }
        length = __dstLength;
        r = E_SUCCESS;
+
+       if (__frameIndex == 0)
+       {
+               __globalTransparent = __transparent;
+               __globalChromaKey = __chromaKey;
+       }
+       __frameIndex++;
+
        return r;
 }
 
@@ -455,6 +503,7 @@ _GifDecoder::Construct(const byte* buffer, int length, MediaPixelFormat pixelFor
 
        r = ConstructBuffer(__pixelFormat);
 
+       __frameIndex = 0;
 CATCH:
        return r;
 }
@@ -578,7 +627,7 @@ _GifDecoder::GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value
                SysTryCatch(NID_MEDIA, pTransparent, r = E_INVALID_ARG, E_INVALID_ARG,
                        "value is not a Boolean");
 
-               pTransparent->value = __transparent;
+               pTransparent->value = __globalTransparent;
        }
        else if (key.Equals(L"chromaKey", false))
        {
@@ -589,7 +638,7 @@ _GifDecoder::GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value
                SysTryCatch(NID_MEDIA, pChromaKey, r = E_INVALID_ARG, E_INVALID_ARG,
                        "value is not an Integer");
 
-               pChromaKey->value = __chromaKey;
+               pChromaKey->value = __globalChromaKey;
        }
        else
        {
index cf0d0d3..566cd97 100644 (file)
@@ -131,6 +131,8 @@ private:
        int __firstFramePos;
        bool __transparent;
        int __chromaKey;
+       bool __globalTransparent;
+       int __globalChromaKey;
        unsigned int __transColor;
        // Paramaters;
        int __srcWidth;
@@ -140,7 +142,6 @@ private:
        int __totalFrames;
        _GifDecoder(const _GifDecoder& gifDecoder);
        _GifDecoder& operator =(const _GifDecoder& gifDecoder);
-
 }; // class _GifDecoder