Premultiplied utility methods added in the _BitmapImpl class
authorYoungki Ahn <ykahn@samsung.com>
Fri, 22 Mar 2013 01:57:08 +0000 (10:57 +0900)
committerYoungki Ahn <ykahn@samsung.com>
Fri, 22 Mar 2013 01:57:08 +0000 (10:57 +0900)
Change-Id: I26bad859e0779fc636dbd8292dd9cc915463f0c9
Signed-off-by: Youngki Ahn <ykahn@samsung.com>
src/graphics/FGrp_BitmapImpl.cpp [changed mode: 0644->0755]
src/graphics/inc/FGrp_BitmapImpl.h [changed mode: 0644->0755]
src/graphics/util/FGrp_UtilPixmap.cpp [changed mode: 0644->0755]
src/graphics/util/FGrp_UtilPixmap.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 05da8dc..996a93b
@@ -1645,7 +1645,7 @@ _BitmapImpl::SetAsImmutable(void)
 }
 
 bool
-_BitmapImpl::IsMutable(void)
+_BitmapImpl::IsMutable(void) const
 {
        SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, false, "This instance is not constructed yet.");
 
@@ -2241,6 +2241,66 @@ _BitmapImpl::HasNinePatchedBitmapTag(Tizen::Base::String fileName)
        return false;
 }
 
+void
+_BitmapImpl::SetAsPremultiplied(void)
+{
+       if (IS_INSTANCE_VALID)
+       {
+               this->_sharedItem->isMutable = false;
+               this->_sharedItem->nativeBitmap->__isPremultiplied = true;
+       }
+}
+
+void
+_BitmapImpl::SetAsNonpremultiplied(void)
+{
+       if (IS_INSTANCE_VALID)
+       {
+               this->_sharedItem->isMutable = true;
+               this->_sharedItem->nativeBitmap->__isPremultiplied = false;
+       }
+}
+
+result
+_BitmapImpl::ConvertToNonpremultiplied(Bitmap& bitmap, bool forceConversion)
+{
+       _BitmapImpl* pImpl = null;
+
+       // bitmap verification
+       {
+               SysTryReturn(NID_GRP, &bitmap, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given bitmap is invalid (null reference passed)");
+
+               pImpl = _BitmapImpl::GetInstance(bitmap);
+
+               SysTryReturn(NID_GRP, IS_BITMAPIMPL_VALID(pImpl), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The given bitmap is invalid");
+       }
+
+       if (!forceConversion)
+       {
+               SysTryReturn(NID_GRP, !pImpl->_sharedItem->isMutable, E_INVALID_CONDITION, E_INVALID_CONDITION, "[E_INVALID_CONDITION] The given bitmap is already non-premultipied");
+       }
+
+       {
+               BufferInfo bi;
+
+               if (pImpl->Lock(bi) == E_SUCCESS)
+               {
+                       _Util::Pixmap dstImage(bi.width, bi.height, bi.bitsPerPixel, (void*)bi.pPixels, bi.pitch);
+                       dstImage.isPremultiplied = true;
+                       dstImage.ConvertNonpremultiplied();
+
+                       pImpl->Unlock();
+               }
+
+               pImpl->_sharedItem->isMutable = true;
+               pImpl->_sharedItem->nativeBitmap->__isPremultiplied = false;
+
+               //?? this->_sharedItem->scaledNativeBitmap
+       }
+
+       return E_SUCCESS;
+}
+
 _BitmapImpl*&
 _BitmapImpl::_GetBitmapImpl(Bitmap* pBitmap)
 {
old mode 100644 (file)
new mode 100755 (executable)
index b4a0bde..e981a00
@@ -106,7 +106,10 @@ public:
        bool IsNinePatchedBitmap(void) const;
 
        void SetAsImmutable(void);
-       bool IsMutable(void);
+       bool IsMutable(void) const;
+
+       void SetAsPremultiplied(void);
+       void SetAsNonpremultiplied(void);
 
        result Lock(BufferInfo& info, long timeout = INFINITE);
        result Unlock(void);
@@ -210,6 +213,13 @@ public:
 
        static bool HasNinePatchedBitmapTag(Tizen::Base::String fileName);
 
+       /*
+        * @exception   E_SUCCESS            The method was successful.
+        * @exception   E_INVALID_ARG        The specified input parameter is invalid.
+        * @exception   E_INVALID_CONDITION  The specified bitmap is already non-premultipied.
+        */
+       static result ConvertToNonpremultiplied(Bitmap& bitmap, bool forceConversion = false);
+
        static _BitmapImpl* GetInstance(Bitmap& bitmap);
        static const _BitmapImpl* GetInstance(const Bitmap& bitmap);
 
old mode 100644 (file)
new mode 100755 (executable)
index c086cb1..1551f32
@@ -447,3 +447,49 @@ _Util::Pixmap::ConvertPremultiplied(void)
                p = reinterpret_cast<DestPixel*>(reinterpret_cast<unsigned char*>(p) + paddingBytes);
        }
 }
+
+void
+_Util::Pixmap::ConvertNonpremultiplied(void)
+{
+       if (this->pBitmap == null || this->depth != 32)
+               return;
+
+       if (!this->isPremultiplied)
+               return;
+
+       typedef unsigned long DestPixel;
+
+       DestPixel* p = reinterpret_cast<DestPixel*>(this->pBitmap);
+       long paddingBytes = this->bytesPerLine - this->width * this->depth / 8;
+
+       for (int y = 0; y < this->height; y++)
+       {
+               for (int x = 0; x < this->width; x++)
+               {
+                       DestPixel a = (*p >> 24);\r
+\r
+                       if (a > 0 && a < 254)\r
+                       {\r
+                               a += (a >> 7);\r
+\r
+                               DestPixel r = (*p >> 8) & 0x0000FF00;\r
+                               r = r / a;\r
+                               r = (r > 255) ? 255 : r;\r
+\r
+                               DestPixel g = (*p >> 0) & 0x0000FF00;\r
+                               g = g / a;\r
+                               g = (g > 255) ? 255 : g;\r
+\r
+                               DestPixel b = (*p << 8) & 0x0000FF00;\r
+                               b = b / a;\r
+                               b = (b > 255) ? 255 : b;\r
+\r
+                               *p = (*p & 0xFF000000) | (r << 16) | (g << 8) | b;\r
+                       }\r
+\r
+                       p++;\r
+               }
+
+               p = reinterpret_cast<DestPixel*>(reinterpret_cast<unsigned char*>(p) + paddingBytes);
+       }
+}
old mode 100644 (file)
new mode 100755 (executable)
index 6564f19..36eb5dd
@@ -69,6 +69,7 @@ struct Pixmap
        Pixmap* GetClone(unsigned long depth) const;
        Pixmap* GetPremultipliedPixmap(void) const;
        void ConvertPremultiplied(void);
+       void ConvertNonpremultiplied(void);
 };
 
 ////////////////////////////////////////////////////////////////////////////////