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.
17 #include <FBaseErrors.h>
18 #include <FGrpBitmap.h>
19 #include <FBaseSysLog.h>
20 #include <FGrp_Effect.h>
21 #include <FGrp_BitmapImpl.h>
22 #include <../util/FGrp_Util.h>
24 #include "FUiCtrl_GalleryBitmap.h"
27 using namespace Tizen::Graphics;
29 namespace Tizen { namespace Ui { namespace Controls {
31 _GalleryBitmap::_GalleryBitmap(void)
33 , __rotation(GALLERY_INTERNAL_IMAGE_ROTATION_0)
34 , __bitmapSizeAndRotateAdjusted(false)
39 _GalleryBitmap::~_GalleryBitmap(void)
45 _GalleryBitmap::CloneN(_GalleryBitmap* pBitmap)
47 Bitmap* pInternalBitmap = null;
48 _GalleryBitmap* pCloneBitmap = new(std::nothrow) _GalleryBitmap();
49 SysTryCatch(NID_UI_CTRL, pCloneBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
51 pInternalBitmap = _BitmapImpl::CloneN(*pBitmap->GetInternalBitmap());
52 SysTryCatch(NID_UI_CTRL, pInternalBitmap != null, , GetLastResult(), "[%s] Propagating", GetErrorMessage(GetLastResult()));
54 pCloneBitmap->SetInternalBitmap(pInternalBitmap);
56 pCloneBitmap->SetAdjustBitmapFlag(pBitmap->IsInitialize());
58 pCloneBitmap->SetBitmapRotation(pBitmap->GetBitmapRotation());
60 SetLastResult(E_SUCCESS);
71 _GalleryBitmap::CreateGalleryBitmapN(Bitmap* pBitmap)
73 Bitmap* pInternalBitmap = null;
74 _GalleryBitmap* pCloneBitmap = new(std::nothrow) _GalleryBitmap();
75 SysTryCatch(NID_UI_CTRL, pCloneBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
77 pInternalBitmap = _BitmapImpl::CloneN(*pBitmap);
78 SysTryCatch(NID_UI_CTRL, pInternalBitmap != null, , GetLastResult(), "[%s] Propagating", GetErrorMessage(GetLastResult()));
80 pCloneBitmap->SetInternalBitmap(pInternalBitmap);
82 SetLastResult(E_SUCCESS);
93 _GalleryBitmap::SetSize(const Dimension& size)
95 if (size.width == GetSize().width && size.height == GetSize().height)
100 Dimension scaledSize = size;
101 float width = GetSize().width;
102 float height = GetSize().height;
104 float widthFactor = (float)size.width / width;
105 float heightFactor = (float)size.height / height;
107 if (widthFactor > heightFactor)
109 scaledSize.width = width * heightFactor + 0.5f;
113 scaledSize.height = height * widthFactor + 0.5f;
116 result r = __pBitmap->Scale(scaledSize);
117 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
123 _GalleryBitmap::GetSize(void) const
126 dim.width = __pBitmap->GetWidth();
127 dim.height = __pBitmap->GetHeight();
133 _GalleryBitmap::Initialize(const Dimension& size, _GalleryFittingType fittingType)
135 if (IsInitialize() == false)
137 result r = AdjustBitmapRotate();
138 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
140 r = AdjustBitmapSize(size, fittingType);
141 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
143 SetAdjustBitmapFlag(true);
150 _GalleryBitmap::AdjustBitmapSize(const Dimension& size, _GalleryFittingType fittingType)
152 Dimension scaledSize = size;
153 if (fittingType == GALLERY_FITTING_TYPE_NONE)
158 if (fittingType != GALLERY_FITTING_TYPE_FIT_XY)
160 float width = GetSize().width;
161 float height = GetSize().height;
163 float widthFactor = (float)size.width / width;
164 float heightFactor = (float)size.height / height;
166 if (fittingType == GALLERY_FITTING_TYPE_STRECTABLE)
168 if (widthFactor < 1.0f && heightFactor < 1.0f)
173 else if (fittingType == GALLERY_FITTING_TYPE_SHRINKABLE)
175 if (widthFactor > 1.0f && heightFactor > 1.0f)
181 if (widthFactor > heightFactor)
183 scaledSize.width = width * heightFactor + 0.5f;
187 scaledSize.height = height * widthFactor + 0.5f;
191 result r = __pBitmap->Scale(scaledSize);
192 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
198 _GalleryBitmap::AdjustBitmapRotate(void)
200 Bitmap* pImage = null;
201 _Util::LockManager* pSrcLock = null;
202 _Util::LockManager* pDstLock = null;
203 Bitmap* pBitmap = null;
204 result r = E_SUCCESS;
210 case GALLERY_INTERNAL_IMAGE_ROTATION_0:
211 dim.SetSize(__pBitmap->GetWidth(), __pBitmap->GetHeight());
213 case GALLERY_INTERNAL_IMAGE_ROTATION_90:
215 dim.SetSize(__pBitmap->GetHeight(), __pBitmap->GetWidth());
217 case GALLERY_INTERNAL_IMAGE_ROTATION_180:
219 dim.SetSize(__pBitmap->GetWidth(), __pBitmap->GetHeight());
221 case GALLERY_INTERNAL_IMAGE_ROTATION_270:
223 dim.SetSize(__pBitmap->GetHeight(), __pBitmap->GetWidth());
230 if (__rotation != GALLERY_INTERNAL_IMAGE_ROTATION_0)
232 pImage = new(std::nothrow) Bitmap();
233 SysTryReturn(NID_UI_CTRL, pImage != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
235 r = pImage->Construct(dim, __pBitmap->GetPixelColorFormat());
236 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
238 pSrcLock = new (std::nothrow) _Util::LockManager(*_BitmapImpl::GetInstance(*__pBitmap));
239 SysTryCatch(NID_UI_CTRL, pSrcLock != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
241 pDstLock = new (std::nothrow) _Util::LockManager(*_BitmapImpl::GetInstance(*pImage));
242 SysTryCatch(NID_UI_CTRL, pDstLock != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
245 const BufferInfo& srcBufferInfo = pSrcLock->GetBufferInfo();
246 const BufferInfo& dstBufferInfo = pDstLock->GetBufferInfo();
248 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
249 _Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
251 _Effect::RotateDesc rotateDesc = { degree, __pBitmap->GetWidth() >> 1 , __pBitmap->GetHeight() >> 1}; //???
252 bool pass = _Effect::RotateImage(dstImage, dim.width >> 1, dim.height >> 1, srcImage, rotateDesc, 255);
253 //bool pass = _Effect::RotateImage(dstImage, dstBufferInfo.width >> 1, dstBufferInfo.height >> 1, srcImage, rotateDesc, 255);
256 pBitmap = new (std::nothrow) Bitmap();
257 SysTryCatch(NID_UI_CTRL, pBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
259 Rectangle rect(0, 0, dim.width, dim.height);
260 r = pBitmap->Construct(*pImage, rect);
261 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
288 _GalleryBitmap::IsInitialize(void) const
290 return __bitmapSizeAndRotateAdjusted;
294 _GalleryBitmap::SetBitmapRotation(_GalleryImageRotation rotation)
296 __rotation = rotation;
299 _GalleryImageRotation
300 _GalleryBitmap::GetBitmapRotation(void) const
306 _GalleryBitmap::GetInternalBitmap(void) const
312 _GalleryBitmap::SetAdjustBitmapFlag(bool initialize)
314 __bitmapSizeAndRotateAdjusted = initialize;
318 _GalleryBitmap::SetInternalBitmap(Bitmap* pBitmap)
323 }}} // Tizen::Ui::Controls