2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_Bitmap.cpp
20 * @brief This is the implementation file for _Bitmap class.
27 #include <unique_ptr.h>
29 #include <FGrpPoint.h>
30 #include <FGrpDimension.h>
31 #include <FGrpBufferInfo.h>
33 #include <FBaseSysLog.h>
35 #include "FGrp_BufferInfoImpl.h"
36 #include "FGrp_Bitmap.h"
37 #include "FGrp_Canvas.h"
38 #include "FGrp_CanvasPixman.h"
39 #include "FGrp_Screen.h"
40 #include "util/FGrp_UtilTemplate.h"
41 #include "effect/FGrp_Effect.h"
43 ////////////////////////////////////////////////////////////////////////////////
45 using namespace Tizen::Base;
46 using namespace Tizen::Graphics;
52 _CheckValidityOfRectangle(const Tizen::Graphics::Rectangle& rect)
54 return ((rect.width > 0) && (rect.height > 0));
58 _CheckValidity(const Tizen::Graphics::Rectangle& rtSrc, const Tizen::Graphics::Rectangle& rtDest)
60 // check 1. is width/height less or equal than 0?
61 if (rtSrc.width <= 0 || rtSrc.height <= 0 || rtDest.width <= 0 || rtDest.height <= 0)
63 return false; // "[E_OUT_OF_RANGE] The argument is out of range. (src(w:%d,h:%d), dst(w:%d,h:%d))\n", rtSrc.width, rtSrc.height, rtDest.width, rtDest.height);
66 // check 2. is src exiting outside of dest entirely?
67 if (rtSrc.x > rtDest.x + rtDest.width - 1 || rtSrc.x + rtSrc.width - 1 < rtDest.x)
69 return false; // "[E_OUT_OF_RANGE] The argument is out of range. (src(x:%d,y:%d,w:%d,h:%d), dst(x:%d,y:%d,w:%d,h:%d))\n", rtSrc.x, rtSrc.y, rtSrc.width, rtSrc.height, rtDest.x, rtDest.y, rtDest.width, rtDest.height);
72 if (rtSrc.y > rtDest.y + rtDest.height - 1 || rtSrc.y + rtSrc.height - 1 < rtDest.y)
74 return false; // "[E_OUT_OF_RANGE] The argument is out of range. (src(x:%d,y:%d,w:%d,h:%d), dst(x:%d,y:%d,w:%d,h:%d))\n", rtSrc.x, rtSrc.y, rtSrc.width, rtSrc.height, rtDest.x, rtDest.y, rtDest.width, rtDest.height);
81 _IsOpaqueAllOver(Tizen::Graphics::_Bitmap* pBitmap)
90 Tizen::Graphics::BufferInfo dstBufferInfo;
92 if (pBitmap->Lock(dstBufferInfo) == E_SUCCESS)
94 const Tizen::Graphics::_Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
95 ret = Tizen::Graphics::_Effect::IsOpaqueAllOver(dstImage);
103 typedef result (::Tizen::Graphics::_Bitmap::* _FnLock)(Tizen::Graphics::BufferInfo&, long);
104 typedef result (::Tizen::Graphics::_Bitmap::* _FnUnlock)(void);
107 _IsOpaqueAllOver(Tizen::Graphics::_Bitmap* pBitmap, _FnLock fnLock, _FnUnlock fnUnlock)
116 Tizen::Graphics::BufferInfo dstBufferInfo;
117 if ((pBitmap->*fnLock)(dstBufferInfo, INFINITE) == E_SUCCESS)
119 const Tizen::Graphics::_Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
120 ret = Tizen::Graphics::_Effect::IsOpaqueAllOver(dstImage);
122 (pBitmap->*fnUnlock)();
128 class _BitmapImplExHack
132 void SetOwnership(bool ownership)
134 this->_SetOwnership(ownership);
137 void ChangeBuffer(bool ownership, unsigned char* pBuffer)
139 this->_ChangeBuffer(ownership, pBuffer);
141 }; // _BitmapImplExHack
143 template<typename Pixel>
145 _CreateBitmapFromBufferInfo(_Bitmap* thiz, BufferInfo& sourBufferInfo, int x, int y, int width, int height)
147 std::unique_ptr<unsigned char[]> pDestBuffer(new (std::nothrow) unsigned char[width * height * sizeof(Pixel)]);
149 if (pDestBuffer == null)
151 return E_OUT_OF_MEMORY;
154 std::auto_ptr<_Util::ScratchPad<Pixel> > pSourScratchPadAuto(new (std::nothrow) _Util::ScratchPad<Pixel>((Pixel*) sourBufferInfo.pPixels, sourBufferInfo.width, sourBufferInfo.height, sourBufferInfo.pitch / sizeof(Pixel)));
155 std::auto_ptr<_Util::ScratchPad<Pixel> > pDestScratchPadAuto(new (std::nothrow) _Util::ScratchPad<Pixel>((Pixel*) pDestBuffer.get(), width, height, width));
157 _Util::ScratchPad<Pixel>* pSourScratchPad = pSourScratchPadAuto.get();
158 _Util::ScratchPad<Pixel>* pDestScratchPad = pDestScratchPadAuto.get();
160 if (pSourScratchPad == null || pDestScratchPad == null)
162 return E_OUT_OF_MEMORY;
165 pDestScratchPad->BitBlt(0, 0, pSourScratchPad, x, y, width, height);
167 result r = thiz->Construct((void*) pDestBuffer.get(), width, height, sizeof(Pixel) * 8);
174 pDestBuffer.release();
176 static_cast<_BitmapImplExHack*>(thiz)->SetOwnership(true);
181 template<typename Pixel>
183 _Resize(_Bitmap* thiz, _Util::ScratchPad<Pixel>*& pScratchPad, int width, int height, BitmapScalingQuality quality = BITMAP_SCALING_QUALITY_LOW)
185 std::unique_ptr<unsigned char[]> pDestBuffer(new (std::nothrow) unsigned char[width * height * sizeof(Pixel)]);
187 if (pDestBuffer == null)
189 return E_OUT_OF_MEMORY;
192 memset(pDestBuffer.get(), 0, width * height * sizeof(Pixel));
197 pScratchPad->GetBuffer(pAddr, pitch);
199 _Util::Pixmap srcImageEx(pScratchPad->GetWidth(), pScratchPad->GetHeight(), sizeof(Pixel) * 8, pAddr, pitch * sizeof(Pixel));
200 _Util::Pixmap dstImageEx(width, height, sizeof(Pixel) * 8, pDestBuffer.get(), width * sizeof(Pixel));
202 bool isDone = Tizen::Graphics::_Pixman::ResizePixmap(dstImageEx, srcImageEx, quality);
208 case BITMAP_SCALING_QUALITY_LOW:
209 isDone = Tizen::Graphics::_Effect::ScaleImage(dstImageEx, 0, 0, width, height, srcImageEx, Tizen::Graphics::_Effect::ROP_COPY);
211 case BITMAP_SCALING_QUALITY_MID:
212 isDone = Tizen::Graphics::_Effect::ScaleImageInterpolation(dstImageEx, 0, 0, width, height, srcImageEx, Tizen::Graphics::_Effect::DEFAULT_FILTER_GOOD);
214 case BITMAP_SCALING_QUALITY_HIGH:
215 isDone = Tizen::Graphics::_Effect::ScaleImageInterpolation(dstImageEx, 0, 0, width, height, srcImageEx, Tizen::Graphics::_Effect::DEFAULT_FILTER_BEST);
225 _Util::ScratchPad<Pixel>* pTempScratchPad = new (std::nothrow) _Util::ScratchPad<Pixel>((Pixel*) pDestBuffer.get(), width, height, width);
227 if (pTempScratchPad == null)
229 return E_OUT_OF_MEMORY;
234 pScratchPad = pTempScratchPad;
236 //?? need to be verified again for clearing
237 static_cast<_BitmapImplExHack*>(thiz)->ChangeBuffer(true, (unsigned char*) pDestBuffer.release());
242 template<typename DestPixel, typename SourPixel>
244 _MergeWithConversion(_Util::ScratchPad<DestPixel>* pDestScratchPad, int destX, int destY, _Util::ScratchPad<SourPixel>* pSourScratchPad, int srcX, int srcY, int srcWidth, int srcHeight)
246 _Util::Pixmap* pSrcImageEx = null;
249 _Util::ScratchPad<SourPixel>& srcScratchPad = *pSourScratchPad;
254 srcScratchPad.GetBuffer(pAddr, pitch);
257 _Util::Pixmap srcImageEx(srcScratchPad.GetWidth(), srcScratchPad.GetHeight(), sizeof(SourPixel) * 8, pAddr, pitch * sizeof(SourPixel));
259 pSrcImageEx = srcImageEx.GetClone(sizeof(DestPixel) * 8);
262 if (pSrcImageEx == null)
268 _Util::ScratchPad<DestPixel> srcScratchPad((DestPixel*) pSrcImageEx->pBitmap, pSrcImageEx->width, pSrcImageEx->height, pSrcImageEx->bytesPerLine / sizeof(DestPixel));
270 pDestScratchPad->BitBlt(destX, destY, &srcScratchPad, srcX, srcY, srcWidth, srcHeight);
279 namespace Tizen { namespace Graphics
282 bool _GetScreenShot(int depth, unsigned char*& pOutBuffer, int& screenWidth, int& screenHeight);
284 _Bitmap::_Bitmap(void)
287 , __isOpaqueAllOver(0)
288 , __hasOwnership(true)
290 , __isPremultiplied(false)
291 , __hasMaskingColor(false)
293 , __bitmapPixelFormat(BITMAP_PIXEL_FORMAT_MIN)
294 , __scalingQuality(BITMAP_SCALING_QUALITY_LOW)
295 , __pScratchPad32(null)
296 , __pScratchPad16(null)
297 , __pLockCallbackFunc(null)
298 , __pLockCallbackParam(null)
299 , __pUnlockCallbackFunc(null)
300 , __pUnlockCallbackParam(null)
304 _Bitmap::~_Bitmap(void)
306 delete __pScratchPad32;
307 delete __pScratchPad16;
316 _Bitmap::Construct(const Rectangle& rect)
318 //?? what do you do in the case of 16-bit?
319 const int systemBpp = _Screen::GetBytesPerPixel();
321 SysTryReturnResult(NID_GRP, (systemBpp == 32) || (systemBpp == 16), E_SYSTEM, "Screen depth is not available.");
325 int width = rect.width;
326 int height = rect.height;
329 size_t allocSize = width * height * systemBpp;
331 std::unique_ptr<unsigned char[]> pAllocated(new (std::nothrow) unsigned char[allocSize]);
333 SysTryReturnResult(NID_GRP, pAllocated, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The bitmap memory is insufficient");
335 result r = this->Construct((void*) pAllocated.get(), width, height, systemBpp);
337 SysTryReturnResult(NID_GRP, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
339 // copy contents from the current screen
341 unsigned char* pCapturedBuffer = null;
343 int bufferHeight = 0;
345 if (_GetScreenShot(systemBpp, pCapturedBuffer, bufferWidth, bufferHeight))
352 _Util::ScratchPad<unsigned long> capturedScratchPad((unsigned long*) pCapturedBuffer, bufferWidth, bufferHeight, bufferWidth);
353 __pScratchPad32->BitBlt(0, 0, &capturedScratchPad, x, y, width, height);
359 _Util::ScratchPad<unsigned short> capturedScratchPad((unsigned short*) pCapturedBuffer, bufferWidth, bufferHeight, bufferWidth);
360 __pScratchPad16->BitBlt(0, 0, &capturedScratchPad, x, y, width, height);
365 delete[] pCapturedBuffer;
369 this->__hasOwnership = true;
371 this->__isOpaqueAllOver = _IsOpaqueAllOver(this);
373 this->__bitmapPixelFormat = (systemBpp == 32) ? BITMAP_PIXEL_FORMAT_ARGB8888 : BITMAP_PIXEL_FORMAT_RGB565;
375 pAllocated.release();
382 _Bitmap::Construct(const Dimension& dim, BitmapPixelFormat pixelFormat)
384 int size = dim.width * dim.height;
385 int bytesPerPixel = 0;
389 case BITMAP_PIXEL_FORMAT_RGB565:
390 size *= sizeof(unsigned short);
391 bytesPerPixel = sizeof(unsigned short);
393 case BITMAP_PIXEL_FORMAT_ARGB8888:
394 case BITMAP_PIXEL_FORMAT_R8G8B8A8:
395 size *= sizeof(unsigned long);
396 bytesPerPixel = sizeof(unsigned long);
399 SysTryReturnResult(NID_GRP, 0, E_INVALID_ARG, "BitmapPixelFormat(%d) is invalid argument.\n", pixelFormat);
403 int width = dim.width;
404 int height = dim.height;
407 size_t allocSize = width * height * bytesPerPixel;
409 std::unique_ptr<unsigned char[]> pAllocated(new (std::nothrow) unsigned char[allocSize]);
411 SysTryReturnResult(NID_GRP, pAllocated, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The bitmap memory is insufficient");
413 result r = this->Construct((void*) pAllocated.get(), width, height, bytesPerPixel * 8);
415 SysTryReturnResult(NID_GRP, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
417 memset(pAllocated.get(), 0, allocSize);
419 this->__hasOwnership = true;
421 this->__isOpaqueAllOver = _IsOpaqueAllOver(this);
423 this->__bitmapPixelFormat = pixelFormat;
425 pAllocated.release();
432 _Bitmap::Construct(const _Canvas& canvas, const Rectangle& rect)
434 SysTryReturnResult(NID_GRP, canvas.IsValid(), E_INVALID_ARG, "A canvas is invalid.\n");
440 int width = rect.width;
441 int height = rect.height;
445 if (const_cast<_Canvas&>(canvas).Lock(sourBI) == E_SUCCESS)
447 switch (sourBI.bitsPerPixel)
450 r = _CreateBitmapFromBufferInfo<unsigned short>(this, sourBI, x, y, width, height);
454 r = _CreateBitmapFromBufferInfo<unsigned long>(this, sourBI, x, y, width, height);
461 const_cast<_Canvas&>(canvas).Unlock();
464 this->__isOpaqueAllOver = _IsOpaqueAllOver(this);
466 this->__bitmapPixelFormat = (sourBI.bitsPerPixel == 32) ? BITMAP_PIXEL_FORMAT_ARGB8888 : BITMAP_PIXEL_FORMAT_RGB565;
472 _Bitmap::Construct(const _Bitmap& bitmap, const Rectangle& rect)
478 int width = rect.width;
479 int height = rect.height;
483 if (const_cast<_Bitmap&>(bitmap).Lock(sourBI) == E_SUCCESS)
485 switch (bitmap.GetBitsPerPixel())
488 r = _CreateBitmapFromBufferInfo<unsigned short>(this, sourBI, x, y, width, height);
492 r = _CreateBitmapFromBufferInfo<unsigned long>(this, sourBI, x, y, width, height);
499 const_cast<_Bitmap&>(bitmap).Unlock();
502 this->__isOpaqueAllOver = _IsOpaqueAllOver(this);
504 //?? need to make a versioning for BITMAP_PIXEL_FORMAT_B8G8R8A8
505 this->__bitmapPixelFormat = (bitmap.GetBitsPerPixel() == 32) ? BITMAP_PIXEL_FORMAT_ARGB8888 : BITMAP_PIXEL_FORMAT_RGB565;
511 _Bitmap::Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat)
513 int bytesPerPixel = 0;
517 case BITMAP_PIXEL_FORMAT_RGB565:
520 case BITMAP_PIXEL_FORMAT_ARGB8888:
521 case BITMAP_PIXEL_FORMAT_R8G8B8A8:
528 // SysAssert(bytesPerPixel > 0);
530 int width = dim.width;
531 int height = dim.height;
534 size_t allocSize = width * height * bytesPerPixel;
536 std::unique_ptr<unsigned char[]> pAllocated(new (std::nothrow) unsigned char[allocSize]);
538 SysTryReturnResult(NID_GRP, pAllocated, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The bitmap memory is insufficient");
540 result r = this->Construct((void*) pAllocated.get(), width, height, bytesPerPixel * 8);
542 SysTryReturnResult(NID_GRP, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
544 memcpy(pAllocated.get(), buffer.GetPointer(), allocSize);
546 this->__hasOwnership = true;
548 this->__isOpaqueAllOver = _IsOpaqueAllOver(this);
550 this->__bitmapPixelFormat = pixelFormat;
552 pAllocated.release();
559 _Bitmap::Construct(const byte* pBuffer, int bufSize, const Dimension& dim, BitmapPixelFormat pixelFormat)
561 // already checks all parameters
563 // BitmapInterfaceCreator bitmapInterface(pBuffer, bufSize, dim.width, dim.height, pixelFormat);
564 // result r = bitmapInterface.Result();
565 // __pBitmapInterface = (r == E_SUCCESS) ? bitmapInterface.GetDuplicate() : null;
567 int bytesPerPixel = 0;
571 case BITMAP_PIXEL_FORMAT_RGB565:
574 case BITMAP_PIXEL_FORMAT_ARGB8888:
575 case BITMAP_PIXEL_FORMAT_R8G8B8A8:
582 // SysAssert(bytesPerPixel > 0);
584 int width = dim.width;
585 int height = dim.height;
588 result r = this->Construct((void*) pBuffer, width, height, bytesPerPixel * 8);
592 __hasOwnership = true;
595 this->__isOpaqueAllOver = _IsOpaqueAllOver(this);
597 this->__bitmapPixelFormat = pixelFormat;
604 _Bitmap::Construct(const void* pExtBuffer, int width, int height, int bitsPerPixel)
606 switch (bitsPerPixel)
610 typedef unsigned short Pixel;
612 __pScratchPad16 = new (std::nothrow) _Util::ScratchPad<Pixel>((Pixel*) pExtBuffer, width, height, width);
613 __pBuffer = (unsigned char*) pExtBuffer;
618 typedef unsigned long Pixel;
620 __pScratchPad32 = new (std::nothrow) _Util::ScratchPad<Pixel>((Pixel*) pExtBuffer, width, height, width);
621 __pBuffer = (unsigned char*) pExtBuffer;
628 SysTryReturnResult(NID_GRP, __pScratchPad16 || __pScratchPad32, E_OUT_OF_MEMORY, "The memory is insufficient");
630 this->__hasOwnership = false;
631 this->__isOpaqueAllOver = true;
633 this->__bitmapPixelFormat = (bitsPerPixel == 32) ? BITMAP_PIXEL_FORMAT_ARGB8888 : BITMAP_PIXEL_FORMAT_RGB565;
639 _Bitmap::IsValid(void) const
641 return (__pScratchPad16 || __pScratchPad32);
645 _Bitmap::_SetOwnership(bool ownership)
647 this->__hasOwnership = ownership;
651 _Bitmap::_ChangeBuffer(bool ownership, unsigned char* pBuffer)
653 if (this->__hasOwnership)
655 delete[] this->__pBuffer;
658 this->__hasOwnership = ownership;
659 this->__pBuffer = pBuffer;
663 _Bitmap::Scale(const Dimension& dim)
665 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
667 SysTryReturnResult(NID_GRP, dim.width > 0 && dim.height > 0, E_OUT_OF_RANGE, "Both of width(%d) and height(%d) MUST be greater than 0.\n", dim.width, dim.height);
669 switch (this->__scalingQuality)
671 case BITMAP_SCALING_QUALITY_MID:
672 case BITMAP_SCALING_QUALITY_HIGH:
673 return this->__ScaleEx(dim.width, dim.height, this->__scalingQuality);
675 return this->__Scale(dim.width, dim.height);
680 _Bitmap::ScaleEx(const Dimension& dim, BitmapScalingQuality quality)
682 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
684 SysTryReturnResult(NID_GRP, dim.width > 0 && dim.height > 0, E_OUT_OF_RANGE, "Both of width(%d) and height(%d) MUST be greater than 0.\n", dim.width, dim.height);
688 case BITMAP_SCALING_QUALITY_HIGH:
689 case BITMAP_SCALING_QUALITY_MID:
690 return this->__ScaleEx(dim.width, dim.height, quality);
691 case BITMAP_SCALING_QUALITY_LOW:
693 return this->__Scale(dim.width, dim.height);
698 _Bitmap::Merge(const Point& dest, const _Bitmap& src, const Rectangle& srcRect)
701 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
703 if ((srcRect.width == 0) || (srcRect.height == 0))
708 Rectangle rtBitmap(0, 0, src.GetWidth(), src.GetHeight());
710 if (!_CheckValidity(srcRect, rtBitmap))
715 // TODO, shkim, I'm not sure why it's E_OUT_OF_RANGE?
716 // TryReturnI(NID_GRP, srcRect.x >= 0 && srcRect.y >= 0, E_OUT_OF_RANGE, "the argument is out of range.\n");
718 SysTryReturnResult(NID_GRP, src.IsValid(), E_INVALID_ARG, "The specified source bitmap is invalid.\n");
720 result r = this->__Merge(dest.x, dest.y, src, srcRect.x, srcRect.y, srcRect.width, srcRect.height);
722 if (this->__isOpaqueAllOver != src.__isOpaqueAllOver)
724 this->__isOpaqueAllOver = _IsOpaqueAllOver(this, &_Bitmap::__Lock, &_Bitmap::__Unlock);
731 _Bitmap::GetHeight() const
733 SysTryReturn(NID_GRP, this->IsValid(), -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
737 return __pScratchPad16->GetHeight();
741 return __pScratchPad32->GetHeight();
746 _Bitmap::GetWidth() const
748 SysTryReturn(NID_GRP, this->IsValid(), -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
752 return __pScratchPad16->GetWidth();
756 return __pScratchPad32->GetWidth();
761 _Bitmap::GetBitsPerPixel() const
763 SysTryReturn(NID_GRP, this->IsValid(), -1, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
776 _Bitmap::GetPixelColorFormat() const
778 SysTryReturn(NID_GRP, this->IsValid(), BITMAP_PIXEL_FORMAT_MAX, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
780 return this->__bitmapPixelFormat;
784 _Bitmap::SetMaskingColor(const Color* pColor)
786 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
787 SysTryReturnResult(NID_GRP, this->GetPixelColorFormat() == BITMAP_PIXEL_FORMAT_RGB565, E_INVALID_ARG, "Only BitmapPixelFormat::BITMAP_PIXEL_FORMAT_RGB565 is supported\n");
791 __hasMaskingColor = true;
792 __maskingColor = pColor->GetRGB32();
796 __hasMaskingColor = false;
804 _Bitmap::GetMaskingColor(Color& color) const
806 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
807 SysTryReturnResult(NID_GRP, this->GetPixelColorFormat() == BITMAP_PIXEL_FORMAT_RGB565, E_INVALID_DATA, "Only BitmapPixelFormat::BITMAP_PIXEL_FORMAT_RGB565 is supported\n");
809 if (!__hasMaskingColor)
811 return E_INVALID_DATA;
814 color = Color(__maskingColor);
820 _Bitmap::SetAlphaConstant(int opacity)
832 this->__opacity = opacity;
836 _Bitmap::GetAlphaConstant(void) const
838 return this->__opacity;
842 _Bitmap::SetScalingQuality(BitmapScalingQuality quality)
846 case BITMAP_SCALING_QUALITY_LOW:
847 case BITMAP_SCALING_QUALITY_MID:
848 case BITMAP_SCALING_QUALITY_HIGH:
849 this->__scalingQuality = quality;
857 _Bitmap::GetScalingQuality(void) const
859 return this->__scalingQuality;
863 _Bitmap::IsNinePatchedBitmap(bool checkStrictly) const
865 SysTryReturn(NID_GRP, this->IsValid(), false, E_OPERATION_FAILED, "[E_OPERATION_FAILED] This instance is not constructed yet.\n");
867 BufferInfo dstBufferInfo;
870 if (const_cast<_Bitmap*>(this)->Lock(dstBufferInfo) == E_SUCCESS)
872 const Tizen::Graphics::_Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
874 ret = Tizen::Graphics::_Effect::IsNinePatchedBitmap(dstImage, checkStrictly);
876 const_cast<_Bitmap*>(this)->Unlock();
883 _Bitmap::Lock(BufferInfo& info, long timeout)
885 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
887 if (this->__pLockCallbackFunc)
889 this->__pLockCallbackFunc(this->__pLockCallbackParam);
892 return this->__Lock(info, timeout);
898 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
900 result r = this->__Unlock();
902 this->__isOpaqueAllOver = _IsOpaqueAllOver(this, &_Bitmap::__Lock, &_Bitmap::__Unlock);
904 if (this->__pUnlockCallbackFunc)
906 this->__pUnlockCallbackFunc(this->__pUnlockCallbackParam);
913 _Bitmap::LockFast(BufferInfo& info, long timeout)
915 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
917 if (this->__pLockCallbackFunc)
919 this->__pLockCallbackFunc(this->__pLockCallbackParam);
922 return this->__Lock(info, timeout);
926 _Bitmap::UnlockFast()
928 SysTryReturnResult(NID_GRP, this->IsValid(), E_OPERATION_FAILED, "This instance is not constructed yet.\n");
930 result r = this->__Unlock();
932 if (this->__pUnlockCallbackFunc)
934 this->__pUnlockCallbackFunc(this->__pUnlockCallbackParam);
941 _Bitmap::UpdateOpaqueInfo(void)
945 this->__isOpaqueAllOver = _IsOpaqueAllOver(this, &_Bitmap::__Lock, &_Bitmap::__Unlock);
950 _Bitmap::SetTimeStamp(unsigned long timeStamp)
952 __timeStamp = timeStamp;
956 _Bitmap::GetTimeStamp(void) const
962 _Bitmap::IsPremultiplied(void) const
964 return __isPremultiplied;
968 _Bitmap::AssignUserBuffer(unsigned char* pExtBuffer, int bytesPerLine)
970 if (this->__pScratchPad32)
972 typedef unsigned long Pixel;
974 _Util::ScratchPad<Pixel>* pBackupScratchPad32 = __pScratchPad32;
976 __pScratchPad32 = new (std::nothrow) _Util::ScratchPad<Pixel>((Pixel*) pExtBuffer, pBackupScratchPad32->GetWidth(), pBackupScratchPad32->GetHeight(), bytesPerLine / sizeof(Pixel));
978 if (__pScratchPad32 == null)
980 __pScratchPad32 = pBackupScratchPad32;
984 delete pBackupScratchPad32;
986 this->_ChangeBuffer(false, pExtBuffer);
988 else if (this->__pScratchPad16)
990 typedef unsigned short Pixel;
992 _Util::ScratchPad<Pixel>* pBackupScratchPad16 = __pScratchPad16;
994 __pScratchPad16 = new (std::nothrow) _Util::ScratchPad<Pixel>((Pixel*) pExtBuffer, pBackupScratchPad16->GetWidth(), pBackupScratchPad16->GetHeight(), bytesPerLine / sizeof(Pixel));
996 if (__pScratchPad16 == null)
998 __pScratchPad16 = pBackupScratchPad16;
1002 delete pBackupScratchPad16;
1004 this->_ChangeBuffer(false, pExtBuffer);
1009 _Bitmap::SetCallback(void (* LockCallback)(void*), void* pLockCallbackParam,
1010 void (* UnlockCallback)(void*), void* pUnlockCallbackParam)
1012 this->__pLockCallbackFunc = LockCallback;
1013 this->__pLockCallbackParam = pLockCallbackParam;
1015 this->__pUnlockCallbackFunc = UnlockCallback;
1016 this->__pUnlockCallbackParam = pUnlockCallbackParam;
1020 _Bitmap::__Scale(int width, int height)
1022 SysAssert(!(__pScratchPad16 == null && __pScratchPad32 == null));
1024 if (__pScratchPad16)
1026 return _Resize<unsigned short>(this, __pScratchPad16, width, height);
1030 //?? the alpha channel is applied twice in the 32-bit bitmap
1031 return _Resize<unsigned long>(this, __pScratchPad32, width, height);
1036 _Bitmap::__ScaleEx(int width, int height, BitmapScalingQuality quality)
1038 SysAssert(!(__pScratchPad16 == null && __pScratchPad32 == null));
1040 if (__pScratchPad16)
1042 return _Resize<unsigned short>(this, __pScratchPad16, width, height, quality);
1046 return _Resize<unsigned long>(this, __pScratchPad32, width, height, quality);
1051 _Bitmap::__Merge(int destX, int destY, const _Bitmap& src, int srcX, int srcY, int srcWidth, int srcHeight)
1053 SysAssert(!(__pScratchPad16 == null && __pScratchPad32 == null));
1055 const _Bitmap* pSrcBitmap = &src;
1057 if (pSrcBitmap == null)
1062 if (pSrcBitmap->__pScratchPad16 == null && pSrcBitmap->__pScratchPad32 == null)
1067 if (__pScratchPad16)
1069 if (pSrcBitmap->__pScratchPad16)
1071 __pScratchPad16->BitBlt(destX, destY, pSrcBitmap->__pScratchPad16, srcX, srcY, srcWidth, srcHeight);
1077 return _MergeWithConversion(__pScratchPad16, destX, destY, pSrcBitmap->__pScratchPad32, srcX, srcY, srcWidth, srcHeight);
1082 if (pSrcBitmap->__pScratchPad32)
1084 __pScratchPad32->BitBlt(destX, destY, pSrcBitmap->__pScratchPad32, srcX, srcY, srcWidth, srcHeight);
1090 return _MergeWithConversion(__pScratchPad32, destX, destY, pSrcBitmap->__pScratchPad16, srcX, srcY, srcWidth, srcHeight);
1096 _Bitmap::__Lock(BufferInfo& info, long timeout)
1098 SysAssert(!(__pScratchPad16 == null && __pScratchPad32 == null));
1100 if (this->__pBuffer == null)
1105 if (_BufferInfoImpl::GetInstance(info) != null)
1107 _BufferInfoImpl::GetInstance(info)->SetHandle(_BufferInfoImpl::HANDLE_TYPE_NONE, 0);
1110 if (__pScratchPad16)
1112 info.width = __pScratchPad16->GetWidth();
1113 info.height = __pScratchPad16->GetHeight();
1114 info.pitch = __pScratchPad16->GetWidth() * 2;
1115 info.bitsPerPixel = 16;
1116 info.pixelFormat = PIXEL_FORMAT_RGB565;
1117 info.pPixels = (void*) this->__pBuffer;
1118 //info.__handle = INVALID_HANDLE;
1122 info.width = __pScratchPad32->GetWidth();
1123 info.height = __pScratchPad32->GetHeight();
1124 info.pitch = __pScratchPad32->GetWidth() * 4;
1125 info.bitsPerPixel = 32;
1126 info.pixelFormat = PIXEL_FORMAT_ARGB8888;
1127 info.pPixels = (void*) this->__pBuffer;
1128 //info.__handle = INVALID_HANDLE;
1135 _Bitmap::__Unlock(void)
1140 }} // Tizen::Graphics