[3.0] Added EventThreadCallback class & BitmapLoader::Load() API
[platform/core/uifw/dali-adaptor.git] / adaptors / common / bitmap-loader-impl.h
1 #ifndef __DALI_BITMAP_LOADER_IMPL_H__
2 #define __DALI_BITMAP_LOADER_IMPL_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <string>
22 #include <dali/public-api/images/pixel.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/common/intrusive-ptr.h>
25 #include <dali/integration-api/bitmap.h>
26 #include <dali/integration-api/resource-types.h>
27
28 // INTERNAL INCLUDES
29 #include <bitmap-loader.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35
36 class BitmapLoader : public BaseObject
37 {
38 public:
39
40   /**
41    * @copydoc Dali::BitmapLoader::New
42    */
43   static IntrusivePtr<BitmapLoader> New( const std::string& url,
44                                          ImageDimensions size,
45                                          FittingMode::Type fittingMode,
46                                          SamplingMode::Type samplingMode,
47                                          bool orientationCorrection);
48
49   /**
50    * Create the bitmap loader object.
51    */
52    BitmapLoader(const std::string& url,
53                ImageDimensions size,
54                FittingMode::Type fittingMode,
55                SamplingMode::Type samplingMode,
56                bool orientationCorrection);
57
58 protected:
59   /**
60    * Destructor
61    */
62   ~BitmapLoader();
63
64 public:
65
66   /**
67    * @copydoc Dali::BitmapLoader::Load
68    */
69   void Load();
70
71   /**
72    * @copydoc Dali::BitmapLoader::IsLoaded
73    */
74   bool IsLoaded();
75
76   /**
77    * Get the raw pixel data.
78    * @return The pixel data. Use the GetHeight(), GetWidth(), GetStride() and GetPixelFormat() methods
79    * to decode the data.
80    */
81   unsigned char* GetPixelData() const;
82
83   /**
84    * Get the buffer height in pixels
85    * @return the height of the buffer in pixels
86    */
87   unsigned int GetImageHeight() const;
88
89   /**
90    * Get the buffer width in pixels
91    * @return the width of the buffer in pixels
92    */
93   unsigned int GetImageWidth() const;
94
95   /**
96    * Get the pixel format of the loaded bitmap.
97    */
98   Pixel::Format GetPixelFormat() const;
99
100 private:
101   Integration::BitmapResourceType mResourceType;
102   Integration::BitmapPtr mBitmap;
103   const std::string mUrl;
104   bool mIsLoaded;
105 };
106
107 } // Internal
108
109
110 inline Internal::BitmapLoader& GetImplementation(Dali::BitmapLoader& handle)
111 {
112   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
113
114   BaseObject& object = handle.GetBaseObject();
115
116   return static_cast<Internal::BitmapLoader&>(object);
117 }
118
119 inline const Internal::BitmapLoader& GetImplementation(const Dali::BitmapLoader& handle)
120 {
121   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
122
123   const BaseObject& object = handle.GetBaseObject();
124
125   return static_cast<const Internal::BitmapLoader&>(object);
126 }
127
128 } // Dali
129
130 #endif // __DALI_BITMAP_LOADER_IMPL_H__