From b4c70b462bd21a496f061e0bc423f08778944df0 Mon Sep 17 00:00:00 2001 From: mamata pattanaik Date: Tue, 26 Mar 2013 12:51:44 +0530 Subject: [PATCH] Added transparency support in RGB565 bitmap outputs, for gif decoder. Change-Id: I0df348a2fd1b2dd2f2a19d10b0d652cacf7709d6 Signed-off-by: mamata pattanaik --- src/FMedia_GifDecoder.cpp | 102 +++++++++++++++++++++++++++++++---------- src/FMedia_ImageDecoder.cpp | 8 ++++ src/inc/FMedia_GifDecoder.h | 14 +++++- src/inc/FMedia_IImageDecoder.h | 15 ++++++ src/inc/FMedia_ImageDecoder.h | 10 ++++ 5 files changed, 123 insertions(+), 26 deletions(-) diff --git a/src/FMedia_GifDecoder.cpp b/src/FMedia_GifDecoder.cpp index f78f62a..536595b 100644 --- a/src/FMedia_GifDecoder.cpp +++ b/src/FMedia_GifDecoder.cpp @@ -22,6 +22,8 @@ #include #include +#include +#include #include #include #include @@ -50,6 +52,7 @@ _GifDecoder::_GifDecoder(void) __pDec = null; __bpp = 2; __transparent = false; + __chromaKey = BGRA8888(0xff, 0x00, 0xff, 0x00); __transColor = 0; __pixelFormat = MEDIA_PIXEL_FORMAT_RGB565LE; __firstFramePos = 0; @@ -292,6 +295,11 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length) // Need to perform 4 passes on the images: if (__bpp == 2) { + if (__transparent) + { + __chromaKey = ((unsigned int*) pPalette)[__transColor]; + } + for (count = 0, loopIndex = 0; loopIndex < 4; loopIndex++) { for (j = row + _INTERLACED_OFFSET[loopIndex]; j < row + height; j += _INTERLACED_JUMPS[loopIndex]) @@ -300,14 +308,7 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length) r = DGifGetLine(__pDec, pLine.get(), width); SysTryReturn(NID_MEDIA, r != GIF_ERROR, E_INVALID_DATA, E_INVALID_DATA, "[E_INVALID_DATA] DGifGetLineByte failed with code %x", GifLastError()); - if (__transparent) - { - for (k = 0; k < width; k++) - { - pBuf[k] = (pLine[k] == __transColor) ? pBuf[k] : ((unsigned short*) pPalette)[pLine[k]]; - } - } - else + { for (k = 0; k < width; k++) { @@ -319,6 +320,11 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length) } else if (__bpp == 4) { + if (__transparent) + { + __chromaKey = ((unsigned int*) pPalette)[__transColor]; + } + for (count = 0, loopIndex = 0; loopIndex < 4; loopIndex++) { for (j = row + _INTERLACED_OFFSET[loopIndex]; j < row + height; j += _INTERLACED_JUMPS[loopIndex]) @@ -331,7 +337,11 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length) { for (k = 0; k < width; k++) { - pBuf[k] = (pLine[k] == __transColor) ? BGRA8888(0, 0, 0, 0) : ((unsigned int*) pPalette)[pLine[k]]; + pBuf[k] = ((unsigned int*) pPalette)[pLine[k]]; + if (pLine[k] == __transColor) + { + pBuf[k] &= 0x00ffffff; + } } } else @@ -349,30 +359,30 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length) { if (__bpp == 2) { + if (__transparent) + { + __chromaKey = ((unsigned short*) pPalette)[__transColor]; + } + for (loopIndex = 0; loopIndex < height; loopIndex++) { unsigned short* pBuf = (unsigned short*) pDstBuffer + __pDec->SWidth * (row + loopIndex) + col; r = DGifGetLine(__pDec, pLine.get(), width); SysTryReturn(NID_MEDIA, r != GIF_ERROR, E_INVALID_DATA, E_INVALID_DATA, "[E_INVALID_DATA] DGifGetLineByte failed with code %x", GifLastError()); - if (__transparent) - { - for (k = 0; k < width; k++) - { - pBuf[k] = (pLine[k] == __transColor) ? pBuf[k] : ((unsigned short*) pPalette)[pLine[k]]; - } - } - else + for (k = 0; k < width; k++) { - for (k = 0; k < width; k++) - { - pBuf[k] = ((unsigned short*) pPalette)[pLine[k]]; - } + pBuf[k] = ((unsigned short*) pPalette)[pLine[k]]; } } } else if (__bpp == 4) { + if (__transparent) + { + __chromaKey = ((unsigned int*)pPalette)[__transColor]; + } + for (loopIndex = 0; loopIndex < height; loopIndex++) { unsigned int* pBuf = (unsigned int*) pDstBuffer + __pDec->SWidth * (row + loopIndex) + col; @@ -383,7 +393,11 @@ _GifDecoder::DecodeOneFrame(unsigned char* pDstBuffer, unsigned int length) { for (k = 0; k < width; k++) { - pBuf[k] = (pLine[k] == __transColor) ? BGRA8888(0, 0, 0, 0) : ((unsigned int*) pPalette)[pLine[k]]; + pBuf[k] = ((unsigned int*) pPalette)[pLine[k]]; + if (pLine[k] == __transColor) + { + pBuf[k] &= 0x00ffffff; + } } } else @@ -541,9 +555,47 @@ _GifDecoder::GetPixelFormat(void) return __pixelFormat; // MEDIA_PIXEL_FORMAT_RGB565LE; } -int -_GifDecoder::GetDuration(void) +result +_GifDecoder::GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value) { - return __duration; + result r = E_SUCCESS; + if (key.Equals(L"duration", false)) + { + Long *pLong = null; + pLong = dynamic_cast(&value); + + SysTryCatch(NID_MEDIA, pLong, r = E_INVALID_ARG, E_INVALID_ARG, + "value is not a Long"); + pLong->value = __duration; + } + else if (key.Equals(L"transparency", false)) + { + Boolean *pTransparent = null; + pTransparent = dynamic_cast(&value); + + SysTryCatch(NID_MEDIA, pTransparent, r = E_INVALID_ARG, E_INVALID_ARG, + "value is not a Boolean"); + + pTransparent->value = __transparent; + } + else if (key.Equals(L"chromaKey", false)) + { + Integer *pChromaKey = null; + + pChromaKey = dynamic_cast(&value); + + SysTryCatch(NID_MEDIA, pChromaKey, r = E_INVALID_ARG, E_INVALID_ARG, + "value is not an Integer"); + + pChromaKey->value = __chromaKey; + } + else + { + r = E_OBJ_NOT_FOUND; + } + +CATCH: + return r; } + }} // Tizen::Media diff --git a/src/FMedia_ImageDecoder.cpp b/src/FMedia_ImageDecoder.cpp index a6499bc..7b8b6d4 100644 --- a/src/FMedia_ImageDecoder.cpp +++ b/src/FMedia_ImageDecoder.cpp @@ -517,6 +517,14 @@ _ImageDecoder::GetPixelFormat(void) const } result +_ImageDecoder::GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value) +{ + SysTryReturnResult(NID_MEDIA, __pDec.get() != null, E_INVALID_STATE, "Not yet constructed"); + + return __pDec->GetValue(key, value); +} + +result _ImageDecoder::SetOutputDimension(int width, int height, bool keepAspectRatio) { if (width == 0 || height == 0 || __orgDim.width == 0 || diff --git a/src/inc/FMedia_GifDecoder.h b/src/inc/FMedia_GifDecoder.h index 21ff6e2..cf0d0d3 100644 --- a/src/inc/FMedia_GifDecoder.h +++ b/src/inc/FMedia_GifDecoder.h @@ -100,6 +100,18 @@ public: */ int GetDuration(void); + /** + * 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: static int BufferReadFuncStatic(struct GifFileType* gifFile, unsigned char* buf, int count); int BufferReadFunc(unsigned char* buf, int count); @@ -118,12 +130,12 @@ private: int __dstLength; int __firstFramePos; bool __transparent; + int __chromaKey; unsigned int __transColor; // Paramaters; int __srcWidth; int __srcHeight; int __frameIndex; -// int __requestedIndex; int __duration; int __totalFrames; _GifDecoder(const _GifDecoder& gifDecoder); diff --git a/src/inc/FMedia_IImageDecoder.h b/src/inc/FMedia_IImageDecoder.h index 4bb9b07..f38a368 100644 --- a/src/inc/FMedia_IImageDecoder.h +++ b/src/inc/FMedia_IImageDecoder.h @@ -88,6 +88,21 @@ public: * @return The output pixel format. */ virtual MediaPixelFormat GetPixelFormat(void) = 0; + + /** + * 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. + */ + virtual result GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value) + { + return E_UNSUPPORTED_OPERATION; + } }; // class _IImageDecoder }; diff --git a/src/inc/FMedia_ImageDecoder.h b/src/inc/FMedia_ImageDecoder.h index a9cff01..c06c56d 100644 --- a/src/inc/FMedia_ImageDecoder.h +++ b/src/inc/FMedia_ImageDecoder.h @@ -238,6 +238,16 @@ public: MediaPixelFormat GetPixelFormat(void) const; /** + * GetValue + * + * return result + * @exception E_SUCCESS The method is successful. + * @remark Used to get decoder specific values, such as duration, + * transparency etc for gif decoder. + */ + result GetValue(const Tizen::Base::String& key, Tizen::Base::Object &value); + + /** * Set demension of output * * return An error code -- 2.7.4