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 FGrpBitmap.cpp
20 * @brief This is the implementation file for Bitmap class.
26 #include <FGrpBitmap.h>
28 #include <FBaseSysLog.h>
30 #include "FGrp_BitmapImpl.h"
31 #include "FGrp_BitmapUtil.h"
32 #include "util/FGrp_Util.h"
35 #define CHECK_INSTANCE \
36 SysTryReturnResult(NID_GRP, this->__pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.")
38 #define CHECK_INSTANCE_EX(_result) \
39 SysTryReturn(NID_GRP, this->__pImpl != null, _result, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.")
41 #define CHECK_INSTANCE_VOID \
42 SysTryReturnVoidResult(NID_GRP, this->__pImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Fails to allocate memory.")
45 #define CHECK_NOT_CONSTRUCTED \
47 SysAssertf(!this->__pImpl->IsConstructed(), \
48 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
50 #define CHECK_CONSTRUCTED \
51 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
52 "Not yet constructed. Construct() should be called before use.");
54 #define CHECK_CONSTRUCTED_EX(_result) \
55 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
56 "Not yet constructed. Construct() should be called before use.");
58 #define CHECK_CONSTRUCTED_VOID \
59 SysAssertf((this->__pImpl != null) && this->__pImpl->IsConstructed(), \
60 "Not yet constructed. Construct() should be called before use.");
63 namespace Tizen { namespace Graphics
67 : __pImpl(new (std::nothrow)_BitmapImpl)
77 Bitmap::Construct(const Rectangle& vc_rect)
79 CHECK_NOT_CONSTRUCTED;
81 result r = this->__pImpl->Construct(vc_rect);
83 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
89 Bitmap::Construct(const Dimension& vc_dim, BitmapPixelFormat pixelFormat)
91 CHECK_NOT_CONSTRUCTED;
93 result r = this->__pImpl->Construct(vc_dim, pixelFormat);
95 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
101 Bitmap::Construct(const Canvas& canvas, const Rectangle& vc_rect)
103 CHECK_NOT_CONSTRUCTED;
105 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&canvas), E_INVALID_ARG, "The source canvas is invalid.\n");
107 result r = this->__pImpl->Construct(*_CanvasImpl::GetInstance(canvas), vc_rect);
109 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
115 Bitmap::Construct(const Bitmap& bitmap, const Rectangle& vc_rect)
117 CHECK_NOT_CONSTRUCTED;
119 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&bitmap), E_INVALID_ARG, "The source bitmap is invalid.\n");
121 const Tizen::Graphics::_BitmapImpl& impl = *bitmap.__pImpl;
123 result r = this->__pImpl->Construct(impl, vc_rect);
125 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
131 Bitmap::Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& rq_dim, BitmapPixelFormat pixelFormat)
133 CHECK_NOT_CONSTRUCTED;
136 result r = this->Construct(buffer, rq_dim, pixelFormat, true);
138 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
144 Bitmap::Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& rq_dim, BitmapPixelFormat pixelFormat, bool autoScaling)
146 CHECK_NOT_CONSTRUCTED;
148 result r = this->__pImpl->Construct(buffer, rq_dim, pixelFormat, autoScaling);
150 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
156 Bitmap::Construct(const byte* pBuffer, int bufSize, const Dimension& rq_dim, BitmapPixelFormat pixelFormat, bool autoScaling)
158 CHECK_NOT_CONSTRUCTED;
160 result r = this->__pImpl->Construct(pBuffer, bufSize, rq_dim, pixelFormat, autoScaling);
162 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
168 Bitmap::Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& rq_dim, BitmapPixelFormat pixelFormat,
169 BufferScaling bufferScaling)
171 CHECK_NOT_CONSTRUCTED;
173 result r = this->__pImpl->Construct(buffer, rq_dim, pixelFormat, bufferScaling);
175 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
181 Bitmap::Scale(const Dimension& vc_dim)
185 result r = this->__pImpl->Scale(vc_dim);
187 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
193 Bitmap::Merge(const Point& vc_dest, const Bitmap& src, const Rectangle& vc_srcRect)
197 SysTryReturnResult(NID_GRP, _Util::CheckValidity(&src), E_INVALID_ARG, "The source bitmap is invalid.\n");
199 const Tizen::Graphics::_BitmapImpl& impl = *src.__pImpl;
201 result r = this->__pImpl->Merge(vc_dest, impl, vc_srcRect);
203 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
209 Bitmap::GetHeight() const
211 CHECK_CONSTRUCTED_EX(-1);
213 return this->__pImpl->GetHeight();
217 Bitmap::GetWidth() const
219 CHECK_CONSTRUCTED_EX(-1);
221 return this->__pImpl->GetWidth();
225 Bitmap::GetBitsPerPixel() const
227 CHECK_CONSTRUCTED_EX(-1);
229 return this->__pImpl->GetBitsPerPixel();
233 Bitmap::GetPixelColorFormat() const
235 CHECK_CONSTRUCTED_EX(BITMAP_PIXEL_FORMAT_MAX);
237 return this->__pImpl->GetPixelColorFormat();
241 Bitmap::SetScalingQuality(BitmapScalingQuality quality)
245 result r = this->__pImpl->SetScalingQuality(quality);
247 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r,"[%s] Propagating.", GetErrorMessage(r));
253 Bitmap::GetScalingQuality(void) const
255 CHECK_CONSTRUCTED_EX(BITMAP_SCALING_QUALITY_LOW);
257 return this->__pImpl->GetScalingQuality();
261 Bitmap::SetMaskingColor(const Color* pColor)
265 result r = this->__pImpl->SetMaskingColor(pColor);
267 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
273 Bitmap::GetMaskingColor(Color& color) const
277 result r = this->__pImpl->GetMaskingColor(color);
279 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
285 Bitmap::SetAlphaConstant(int opacity)
287 CHECK_CONSTRUCTED_VOID;
289 return this->__pImpl->SetAlphaConstant(opacity);
293 Bitmap::GetAlphaConstant(void) const
295 CHECK_CONSTRUCTED_EX(-1);
297 return this->__pImpl->GetAlphaConstant();
301 Bitmap::IsNinePatchedBitmap(void) const
303 CHECK_CONSTRUCTED_EX(false);
305 return this->__pImpl->IsNinePatchedBitmap();
309 Bitmap::Lock(BufferInfo& info, long timeout)
313 result r = this->__pImpl->Lock(info, timeout);
315 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
325 result r = this->__pImpl->Unlock();
327 SysTryReturn(NID_GRP, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
333 Bitmap::GetNonScaledBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat)
335 _BitmapImpl* pBitmapImpl = _BitmapImpl::GetNonScaledBitmapImplN(buffer, dim, pixelFormat);
337 if (pBitmapImpl == null)
342 Bitmap* pReturnBitmap = Tizen::Graphics::_BitmapUtil::CreateBitmapN(pBitmapImpl);
344 if (pReturnBitmap == null)
346 result r = GetLastResult();
348 SysTryReturn(NID_GRP, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
353 return pReturnBitmap;
356 }} // Tizen::Graphics