Added EventThreadCallback class & BitmapLoader::Load() API
[platform/core/uifw/dali-adaptor.git] / adaptors / common / bitmap-loader-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // EXTERNAL INCLUDES
18 #include <string>
19
20 // INTERNAL INCLUDES
21 #include "bitmap-loader-impl.h"
22 #include "image-loaders/image-loader.h"
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28
29 IntrusivePtr<BitmapLoader> BitmapLoader::New(const std::string& url,
30                                              ImageDimensions size,
31                                              FittingMode::Type fittingMode,
32                                              SamplingMode::Type samplingMode,
33                                              bool orientationCorrection)
34 {
35   IntrusivePtr<BitmapLoader> internal = new BitmapLoader( url, size, fittingMode, samplingMode, orientationCorrection );
36   return internal;
37 }
38
39 BitmapLoader::BitmapLoader(const std::string& url,
40              ImageDimensions size,
41              FittingMode::Type fittingMode,
42              SamplingMode::Type samplingMode,
43              bool orientationCorrection)
44 : mResourceType( size, fittingMode, samplingMode, orientationCorrection ),
45   mBitmap(NULL),
46   mUrl(url),
47   mIsLoaded( false )
48 {
49 }
50
51 BitmapLoader::~BitmapLoader()
52 {
53 }
54
55 void BitmapLoader::Load()
56 {
57   IntrusivePtr<Dali::RefObject> resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( mResourceType, mUrl );
58
59   mBitmap = static_cast<Integration::Bitmap*>(resource.Get());
60   mIsLoaded = true;
61 }
62
63 bool BitmapLoader::IsLoaded()
64 {
65   return mIsLoaded;
66 }
67
68 unsigned char* BitmapLoader::GetPixelData() const
69 {
70   if( mIsLoaded )
71   {
72     return mBitmap->GetBuffer();
73   }
74
75   return NULL;
76 }
77
78 unsigned int BitmapLoader::GetImageHeight() const
79 {
80   if( mIsLoaded )
81   {
82     return mBitmap->GetImageHeight();
83   }
84
85   return 0u;
86 }
87
88 unsigned int BitmapLoader::GetImageWidth() const
89 {
90   if( mIsLoaded )
91   {
92     return mBitmap->GetImageWidth();
93   }
94
95   return 0u;
96 }
97
98 Pixel::Format BitmapLoader::GetPixelFormat() const
99 {
100   if( mIsLoaded )
101   {
102     return mBitmap->GetPixelFormat();
103   }
104
105   return Pixel::RGBA8888;
106 }
107
108 } // namespace Internal
109 } // namespace Dali