2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 FloatDimension& 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 SetAdjustBitmapFlag(true);
147 _GalleryBitmap::AdjustBitmapRotate(void)
149 // TODO : need _Effect::RotateImageF()
150 Bitmap* pImage = null;
151 _Util::LockManager* pSrcLock = null;
152 _Util::LockManager* pDstLock = null;
153 Bitmap* pBitmap = null;
154 result r = E_SUCCESS;
160 case GALLERY_INTERNAL_IMAGE_ROTATION_0:
161 dim.SetSize(__pBitmap->GetWidth(), __pBitmap->GetHeight());
163 case GALLERY_INTERNAL_IMAGE_ROTATION_90:
165 dim.SetSize(__pBitmap->GetHeight(), __pBitmap->GetWidth());
167 case GALLERY_INTERNAL_IMAGE_ROTATION_180:
169 dim.SetSize(__pBitmap->GetWidth(), __pBitmap->GetHeight());
171 case GALLERY_INTERNAL_IMAGE_ROTATION_270:
173 dim.SetSize(__pBitmap->GetHeight(), __pBitmap->GetWidth());
180 if (__rotation != GALLERY_INTERNAL_IMAGE_ROTATION_0)
182 pImage = new(std::nothrow) Bitmap();
183 SysTryReturn(NID_UI_CTRL, pImage != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
185 r = pImage->Construct(dim, __pBitmap->GetPixelColorFormat());
186 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
188 pSrcLock = new (std::nothrow) _Util::LockManager(*_BitmapImpl::GetInstance(*__pBitmap));
189 SysTryCatch(NID_UI_CTRL, pSrcLock != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
191 pDstLock = new (std::nothrow) _Util::LockManager(*_BitmapImpl::GetInstance(*pImage));
192 SysTryCatch(NID_UI_CTRL, pDstLock != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
195 const BufferInfo& srcBufferInfo = pSrcLock->GetBufferInfo();
196 const BufferInfo& dstBufferInfo = pDstLock->GetBufferInfo();
198 _Util::Pixmap srcImage(srcBufferInfo.width, srcBufferInfo.height, srcBufferInfo.bitsPerPixel, srcBufferInfo.pPixels, srcBufferInfo.pitch);
199 _Util::Pixmap dstImage(dstBufferInfo.width, dstBufferInfo.height, dstBufferInfo.bitsPerPixel, dstBufferInfo.pPixels, dstBufferInfo.pitch);
201 _Effect::RotateDesc rotateDesc = { degree, __pBitmap->GetWidth() >> 1 , __pBitmap->GetHeight() >> 1}; //???
202 bool pass = _Effect::RotateImage(dstImage, dim.width >> 1, dim.height >> 1, srcImage, rotateDesc, 255);
203 //bool pass = _Effect::RotateImage(dstImage, dstBufferInfo.width >> 1, dstBufferInfo.height >> 1, srcImage, rotateDesc, 255);
206 pBitmap = new (std::nothrow) Bitmap();
207 SysTryCatch(NID_UI_CTRL, pBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
209 Rectangle rect(0, 0, dim.width, dim.height);
210 r = pBitmap->Construct(*pImage, rect);
211 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
238 _GalleryBitmap::IsInitialize(void) const
240 return __bitmapSizeAndRotateAdjusted;
244 _GalleryBitmap::SetBitmapRotation(_GalleryImageRotation rotation)
246 __rotation = rotation;
249 _GalleryImageRotation
250 _GalleryBitmap::GetBitmapRotation(void) const
256 _GalleryBitmap::GetInternalBitmap(void) const
262 _GalleryBitmap::SetAdjustBitmapFlag(bool initialize)
264 __bitmapSizeAndRotateAdjusted = initialize;
268 _GalleryBitmap::SetInternalBitmap(Bitmap* pBitmap)
273 }}} // Tizen::Ui::Controls