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_BitmapUtil.cpp
20 * @brief This is the cpp file for internal util class.
27 #include <FGrpCanvas.h>
29 #include <FBaseSysLog.h>
31 #include "FGrp_BitmapUtil.h"
32 #include "FGrp_Bitmap.h"
33 #include "FGrp_ResUtil.h"
34 #include "util/FGrp_UtilTemplate.h"
37 namespace Tizen { namespace Graphics
40 unsigned long _GetBitmapTimeStamp(const Tizen::Graphics::_BitmapImpl& bitmap);
41 unsigned long _UpdateBitmapTimeStamp(Tizen::Graphics::_BitmapImpl& bitmap);
43 BitmapTemp::BitmapTemp(Canvas& canvas)
47 BufferInfo canvasDesc;
48 result r = canvas.Lock(canvasDesc);
56 int pixelPerLine = canvasDesc.pitch / (canvasDesc.bitsPerPixel / 8);
58 // 'pitch' can be a negative value
59 pixelPerLine = (pixelPerLine >= 0) ? pixelPerLine : -pixelPerLine;
61 // new width = max(pixelPerLine, canvasDesc.width)
62 canvasDesc.width = (pixelPerLine > canvasDesc.width) ? pixelPerLine : canvasDesc.width;
65 this->_sharedItem->nativeBitmap->Construct((void*) canvasDesc.pPixels, canvasDesc.width, canvasDesc.height,
66 canvasDesc.bitsPerPixel);
68 Dimension pc_dim(canvasDesc.width, canvasDesc.height);
69 Dimension vc_dim(canvas.GetBounds().width, canvas.GetBounds().height);
71 _ResUtil::Rect vc_rect(0, 0, vc_dim.width, vc_dim.height);
72 _ResUtil::Rect pc_rect(0, 0, pc_dim.width, pc_dim.height);
74 this->_sharedItem->coordHolder->bitmapSize.required = vc_rect;
75 this->_sharedItem->coordHolder->bitmapSize.phyCoord = pc_rect;
76 this->_sharedItem->coordHolder->bitmapSize.virCoord = vc_rect;
84 BitmapTemp::BitmapTemp(void* pBuffer, int width, int height, int depth)
88 if (pBuffer == null || width <= 0 || height <= 0 || !(depth == 16 || depth == 32))
93 result r = this->_sharedItem->nativeBitmap->Construct((void*) pBuffer, width, height, depth);
100 Dimension pc_dim(width, height);
101 Dimension vc_dim = _ResUtil::ConvertToVirCoord(pc_dim);
103 _ResUtil::Rect vc_rect(0, 0, vc_dim.width, vc_dim.height);
104 _ResUtil::Rect pc_rect(0, 0, pc_dim.width, pc_dim.height);
106 this->_sharedItem->coordHolder->bitmapSize.required = vc_rect;
107 this->_sharedItem->coordHolder->bitmapSize.phyCoord = pc_rect;
108 this->_sharedItem->coordHolder->bitmapSize.virCoord = vc_rect;
113 BitmapTemp::BitmapTemp(Dimension physicalSize, int depth)
117 if (physicalSize.width <= 0 || physicalSize.height <= 0 || !(depth == 16 || depth == 32))
122 result r = this->_sharedItem->nativeBitmap->Construct(physicalSize, (depth == 32) ? BITMAP_PIXEL_FORMAT_ARGB8888 : BITMAP_PIXEL_FORMAT_RGB565);
129 Dimension pcDim(physicalSize.width, physicalSize.height);
130 Dimension vcDim = _ResUtil::ConvertToVirCoord(pcDim);
132 _ResUtil::Rect vcRect(0, 0, vcDim.width, vcDim.height);
133 _ResUtil::Rect pcRect(0, 0, pcDim.width, pcDim.height);
135 this->_sharedItem->coordHolder->bitmapSize.required = vcRect;
136 this->_sharedItem->coordHolder->bitmapSize.phyCoord = pcRect;
137 this->_sharedItem->coordHolder->bitmapSize.virCoord = vcRect;
142 BitmapTemp::~BitmapTemp()
147 BitmapTemp::IsValid(void)
152 ////////////////////////////////////////////////////////////////////////////////
155 Tizen::Graphics::_BitmapUtil::GetTimeStamp(const Tizen::Graphics::Bitmap& bitmap)
157 const Tizen::Graphics::_BitmapImpl* pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(bitmap);
161 return _GetBitmapTimeStamp(*pBitmapImpl);
168 Tizen::Graphics::_BitmapUtil::UpdateTimeStamp(Tizen::Graphics::Bitmap& bitmap)
170 Tizen::Graphics::_BitmapImpl* pBitmapImpl = Tizen::Graphics::_BitmapImpl::GetInstance(bitmap);
174 return _UpdateBitmapTimeStamp(*pBitmapImpl);
180 Tizen::Graphics::Bitmap*
181 Tizen::Graphics::_BitmapUtil::CreateBitmapN(_BitmapImpl* pBitmapImpl)
183 if (pBitmapImpl == null)
188 std::auto_ptr <Tizen::Graphics::Bitmap> bitmap(new (std::nothrow) Tizen::Graphics::Bitmap);
190 SysTryReturn(NID_GRP, bitmap.get() != 0, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
192 // change the implentation instance of Bitmap class
194 // exception of ICLS-CLSIF-03
195 class _BitmapImplHack
199 static _BitmapImpl*& GetBitmapImplRef(Bitmap* pBitmap)
201 return _BitmapImpl::_GetBitmapImpl(pBitmap);
203 }; // _BitmapImplHack
205 Tizen::Graphics::_BitmapImpl*& pRefBitmapImpl = _BitmapImplHack::GetBitmapImplRef(bitmap.get());
207 delete pRefBitmapImpl;
208 pRefBitmapImpl = pBitmapImpl;
211 return bitmap.release();
214 Tizen::Graphics::Bitmap*
215 Tizen::Graphics::_BitmapUtil::CreateBitmapN(void* pBuffer, int width, int height, int depth)
217 std::auto_ptr <Tizen::Graphics::BitmapTemp> bitmapTemp(new (std::nothrow) Tizen::Graphics::BitmapTemp(pBuffer, width, height,
220 SysTryReturn(NID_GRP, bitmapTemp.get() && bitmapTemp->IsValid(), 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
222 Tizen::Graphics::Bitmap* pBitmap = Tizen::Graphics::_BitmapUtil::CreateBitmapN(bitmapTemp.get());
227 bitmapTemp.release();
233 Tizen::Graphics::Bitmap*
234 Tizen::Graphics::_BitmapUtil::CreateBitmapN(Dimension physicalSize, int depth)
236 std::auto_ptr <Tizen::Graphics::BitmapTemp> bitmapTemp(new (std::nothrow) Tizen::Graphics::BitmapTemp(physicalSize, depth));
238 SysTryReturn(NID_GRP, bitmapTemp.get() && bitmapTemp->IsValid(), 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
240 Tizen::Graphics::Bitmap* pBitmap = Tizen::Graphics::_BitmapUtil::CreateBitmapN(bitmapTemp.get());
245 bitmapTemp.release();
252 Tizen::Graphics::_BitmapUtil::ChangeBuffer(Tizen::Graphics::Bitmap& srcBitmap, void* pBuffer, long bytesPerLine, void (* DestroyCallback)(void*), void* pCallbackParam)
254 if (_BitmapImpl::GetInstance(srcBitmap) == null)
259 _Bitmap* pNativeBitmap = GetBitmapEx(srcBitmap);
261 if (pNativeBitmap == null)
266 if (!SetCallback(srcBitmap, DestroyCallback, pCallbackParam, null, null, null, null))
271 pNativeBitmap->AssignUserBuffer((unsigned char*) pBuffer, bytesPerLine);
277 Tizen::Graphics::_BitmapUtil::SetCallback(Tizen::Graphics::Bitmap& bitmap,
278 void (* DestroyCallback)(void*), void* pCallbackParam,
279 void (* LockCallback)(void*), void* pLockParam,
280 void (* UnlockCallback)(void*), void* pUnlockParam)
282 Tizen::Graphics::_BitmapImpl* pBitmapImpl = _BitmapImpl::GetInstance(bitmap);
284 _BitmapImplHack* pBitmapImplHack = static_cast <_BitmapImplHack*>(pBitmapImpl);
286 return (pBitmapImplHack) ? pBitmapImplHack->SetCallback(DestroyCallback, pCallbackParam, LockCallback, pLockParam, UnlockCallback, pUnlockParam) : false;
290 Tizen::Graphics::_BitmapUtil::ResetCallback(Tizen::Graphics::Bitmap& bitmap)
292 Tizen::Graphics::_BitmapImpl* pBitmapImpl = _BitmapImpl::GetInstance(bitmap);
294 _BitmapImplHack* pBitmapImplHack = static_cast <_BitmapImplHack*>(pBitmapImpl);
298 pBitmapImplHack->ResetCallback();
302 }} // Tizen::Graphics