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 <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, const Rectangle& partialBounds, const Dimension& imageSize) const
53 SysTryReturn(NID_UI_CTRL, index >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The index argument is negative value.");
54 SysTryReturn(NID_UI_CTRL, index < __galleryModel.GetItemCount(), null, E_OUT_OF_RANGE,
55 "[E_OUT_OF_RANGE] The index argument is out of range");
57 if (__currentLoadBitmapIndex != index || __currentLoadBitmapSize != imageSize)
59 const_cast<_GalleryImageReader*>(this)->LoadPartialImageFromFile(index, imageSize);
62 _GalleryBitmap* pPartialGalleryBitmap = null;
63 Bitmap* pPartialBitmap = new(std::nothrow) Bitmap();
64 SysTryReturn(NID_UI_CTRL, pPartialBitmap != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
66 result r = pPartialBitmap->Construct(*__pTmpFileBitmap, partialBounds);
67 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
69 pPartialGalleryBitmap = _GalleryBitmap::CreateGalleryBitmapN(pPartialBitmap);
70 SysTryCatch(NID_UI_CTRL, pPartialGalleryBitmap != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
72 SetLastResult(E_SUCCESS);
73 delete pPartialBitmap;
75 return pPartialGalleryBitmap;
78 //delete pPartialGalleryBitmap;
79 delete pPartialBitmap;
85 _GalleryImageReader::GetItemImage(int index) const
87 SysTryReturn(NID_UI_CTRL, index >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] The index argument is negative value.");
88 SysTryReturn(NID_UI_CTRL, index < __galleryModel.GetItemCount(), null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index argument is out of range.");
90 _GalleryItem* pItem = __galleryModel.GetItem(index);
91 SysTryReturn(NID_UI_CTRL, pItem != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
93 return pItem->GetGalleryItemImage();
97 _GalleryImageReader::LoadPartialImageFromFile(int index, const Dimension& imageSize)
99 _GalleryBitmap* pPartialGalleryBitmap = null;
100 Dimension bitmapSize;
101 ByteBuffer* pBuffer = null;
102 MediaPixelFormat mediaPixelFormat = MEDIA_PIXEL_FORMAT_NONE;
103 result r = E_SUCCESS;
105 _GalleryItem* pItem = __galleryModel.GetItem(index);
106 SysTryCatch(NID_UI_CTRL, pItem != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
108 if (pItem->GetGalleryItemImage() == null)
110 SysTryCatch(NID_UI_CTRL, false, , E_SYSTEM, "[E_SYSTEM] The gallery bitmap not exist.");
113 switch (pItem->GetGalleryItemImage()->GetInternalBitmap()->GetPixelColorFormat())
115 case BITMAP_PIXEL_FORMAT_RGB565:
116 mediaPixelFormat = MEDIA_PIXEL_FORMAT_RGB565LE;
118 case BITMAP_PIXEL_FORMAT_ARGB8888:
119 mediaPixelFormat = MEDIA_PIXEL_FORMAT_BGRA8888;
121 case BITMAP_PIXEL_FORMAT_R8G8B8A8:
122 mediaPixelFormat = MEDIA_PIXEL_FORMAT_RGBA8888;
129 pBuffer = _ImageDecoder::DecodeToBufferN(pItem->GetGalleryItemFilePath(), mediaPixelFormat, bitmapSize.width, bitmapSize.height);
131 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
133 delete __pTmpFileBitmap;
134 __pTmpFileBitmap = new (std::nothrow) Bitmap();
135 SysTryCatch(NID_UI_CTRL, __pTmpFileBitmap != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
137 r = __pTmpFileBitmap->Construct(*pBuffer, bitmapSize, pItem->GetGalleryItemImage()->GetInternalBitmap()->GetPixelColorFormat());
138 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
140 pPartialGalleryBitmap = _GalleryBitmap::CreateGalleryBitmapN(__pTmpFileBitmap);
141 SysTryCatch(NID_UI_CTRL, pPartialGalleryBitmap != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
143 pPartialGalleryBitmap->SetBitmapRotation(pItem->GetGalleryRotation());
145 r = pPartialGalleryBitmap->Initialize(imageSize, GALLERY_FITTING_TYPE_FIT);
146 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
148 r = pPartialGalleryBitmap->SetSize(imageSize);
149 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
151 delete __pTmpFileBitmap;
152 __pTmpFileBitmap = _BitmapImpl::CloneN(*pPartialGalleryBitmap->GetInternalBitmap());
153 SysTryCatch(NID_UI_CTRL, __pTmpFileBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
155 SetLastResult(E_SUCCESS);
157 __currentLoadBitmapIndex = index;
158 __currentLoadBitmapSize = imageSize;
161 delete pPartialGalleryBitmap;
166 delete __pTmpFileBitmap;
167 __pTmpFileBitmap = null;
168 delete pPartialGalleryBitmap;
171 }}} // Tizen::Ui::Controls