}
bool
-_BitmapImpl::IsMutable(void)
+_BitmapImpl::IsMutable(void) const
{
SysTryReturnResult(NID_GRP, INSTANCE_IS_VALID, false, "This instance is not constructed yet.");
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)
{
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);
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);
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);
+ }
+}
Pixmap* GetClone(unsigned long depth) const;
Pixmap* GetPremultipliedPixmap(void) const;
void ConvertPremultiplied(void);
+ void ConvertNonpremultiplied(void);
};
////////////////////////////////////////////////////////////////////////////////