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 <FBaseBuffer.h>
19 #include <FGrpBitmap.h>
20 #include <FMediaImageTypes.h>
21 #include <FBaseSysLog.h>
22 #include <FGrp_BitmapImpl.h>
23 #include <FMedia_ImageDecoder.h>
24 #include "FUiCtrl_GalleryImageReader.h"
25 #include "FUiCtrl_GalleryBitmap.h"
26 #include "FUiCtrl_GalleryModel.h"
27 #include "FUiCtrl_GalleryItem.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Media;
34 namespace Tizen { namespace Ui { namespace Controls {
36 _GalleryImageReader::_GalleryImageReader(_GalleryModel& galleryModel)
37 : __galleryModel(galleryModel)
38 , __pTmpFileBitmap(null)
39 , __currentLoadBitmapIndex(-1)
40 , __currentLoadBitmapSize(0, 0)
45 _GalleryImageReader::~_GalleryImageReader(void)
47 delete __pTmpFileBitmap;
51 _GalleryImageReader::GetPartialImageFromFileN(int index,
52 const FloatRectangle& partialBounds, const FloatDimension& imageSize) const
54 SysTryReturn(NID_UI_CTRL, index >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The index argument is negative value.");
55 SysTryReturn(NID_UI_CTRL, index < __galleryModel.GetItemCount(), null, E_OUT_OF_RANGE,
56 "[E_OUT_OF_RANGE] The index argument is out of range");
58 if (__currentLoadBitmapIndex != index || __currentLoadBitmapSize != imageSize)
60 const_cast<_GalleryImageReader*>(this)->LoadPartialImageFromFile(index, imageSize);
63 _GalleryBitmap* pPartialGalleryBitmap = null;
64 Bitmap* pPartialBitmap = new(std::nothrow) Bitmap();
65 SysTryReturn(NID_UI_CTRL, pPartialBitmap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
67 result r = pPartialBitmap->Construct(*__pTmpFileBitmap, partialBounds);
68 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
70 pPartialGalleryBitmap = _GalleryBitmap::CreateGalleryBitmapN(pPartialBitmap);
71 SysTryCatch(NID_UI_CTRL, pPartialGalleryBitmap != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
73 SetLastResult(E_SUCCESS);
74 delete pPartialBitmap;
76 return pPartialGalleryBitmap;
79 //delete pPartialGalleryBitmap;
80 delete pPartialBitmap;
86 _GalleryImageReader::GetItemImage(int index) const
88 SysTryReturn(NID_UI_CTRL, index >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The index argument is negative value.");
89 SysTryReturn(NID_UI_CTRL, index < __galleryModel.GetItemCount(), null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index argument is out of range.");
91 _GalleryItem* pItem = __galleryModel.GetItem(index);
92 SysTryReturn(NID_UI_CTRL, pItem != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
94 return pItem->GetGalleryItemImage();
98 _GalleryImageReader::LoadPartialImageFromFile(int index, const FloatDimension& imageSize)
100 _GalleryBitmap* pPartialGalleryBitmap = null;
101 Dimension bitmapSize;
102 ByteBuffer* pBuffer = null;
103 MediaPixelFormat mediaPixelFormat = MEDIA_PIXEL_FORMAT_NONE;
104 result r = E_SUCCESS;
106 _GalleryItem* pItem = __galleryModel.GetItem(index);
107 SysTryCatch(NID_UI_CTRL, pItem != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
109 if (pItem->GetGalleryItemImage() == null)
111 SysTryCatch(NID_UI_CTRL, false, , E_SYSTEM, "[E_SYSTEM] The gallery bitmap not exist.");
114 switch (pItem->GetGalleryItemImage()->GetInternalBitmap()->GetPixelColorFormat())
116 case BITMAP_PIXEL_FORMAT_RGB565:
117 mediaPixelFormat = MEDIA_PIXEL_FORMAT_RGB565LE;
119 case BITMAP_PIXEL_FORMAT_ARGB8888:
120 mediaPixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888;
122 case BITMAP_PIXEL_FORMAT_R8G8B8A8:
123 mediaPixelFormat = MEDIA_PIXEL_FORMAT_RGBA8888;
130 pBuffer = _ImageDecoder::DecodeToBufferN(pItem->GetGalleryItemFilePath(), mediaPixelFormat, bitmapSize.width, bitmapSize.height, true);
132 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
134 delete __pTmpFileBitmap;
135 __pTmpFileBitmap = new (std::nothrow) Bitmap();
136 SysTryCatch(NID_UI_CTRL, __pTmpFileBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
138 // TODO : need Bitmap::ConstructF(ByteBuffer, )
139 //FloatDimension bitmapSizeF(bitmapSize.width, bitmapSize.height);
140 r = __pTmpFileBitmap->Construct(*pBuffer, bitmapSize, pItem->GetGalleryItemImage()->GetInternalBitmap()->GetPixelColorFormat());
141 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
143 r = __pTmpFileBitmap->Scale(imageSize);
144 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
146 pPartialGalleryBitmap = _GalleryBitmap::CreateGalleryBitmapN(__pTmpFileBitmap);
147 SysTryCatch(NID_UI_CTRL, pPartialGalleryBitmap != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
149 pPartialGalleryBitmap->SetBitmapRotation(pItem->GetGalleryRotation());
151 r = pPartialGalleryBitmap->Initialize(imageSize, GALLERY_FITTING_TYPE_FIT);
152 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
154 delete __pTmpFileBitmap;
155 __pTmpFileBitmap = _BitmapImpl::CloneN(*pPartialGalleryBitmap->GetInternalBitmap());
156 SysTryCatch(NID_UI_CTRL, __pTmpFileBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
158 SetLastResult(E_SUCCESS);
160 __currentLoadBitmapIndex = index;
161 __currentLoadBitmapSize = imageSize;
164 delete pPartialGalleryBitmap;
169 delete __pTmpFileBitmap;
170 __pTmpFileBitmap = null;
171 delete pPartialGalleryBitmap;
175 _GalleryImageReader::ResetLoadedPartialImageIndex(void)
177 __currentLoadBitmapIndex = -1;
180 }}} // Tizen::Ui::Controls