Refactored image loaders, added public 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 <bitmap-loader.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32
33 class BitmapLoader : public BaseObject
34 {
35 public:
36   static IntrusivePtr<BitmapLoader> New(const std::string& filename);
37
38   /**
39    * Create the bitmap loader object.
40    */
41   BitmapLoader();
42
43 protected:
44   /**
45    * Destructor
46    */
47   ~BitmapLoader();
48
49   /**
50    * Second stage initialization - this will load the image synchronously.
51    * @param[in] filename  Filename of the bitmap image to load.
52    */
53   void Initialize(const std::string& filename);
54
55 public:
56
57   /**
58    * Get the raw pixel data.
59    * @return The pixel data. Use the GetHeight(), GetWidth(), GetStride() and GetPixelFormat() methods
60    * to decode the data.
61    */
62   unsigned char* GetPixelData() const;
63
64   /**
65    * Get the buffer height in pixels
66    * @return the height of the buffer in pixels
67    */
68   unsigned int GetImageHeight() const;
69
70   /**
71    * Get the buffer width in pixels
72    * @return the width of the buffer in pixels
73    */
74   unsigned int GetImageWidth() const;
75
76   /**
77    * Get the number of bytes in each row of pixels
78    * @return The buffer stride in bytes.
79    */
80   unsigned int GetBufferStride() const;
81
82   /**
83    * Get the pixel format of the loaded bitmap.
84    */
85   Pixel::Format GetPixelFormat() const;
86
87 private:
88   Integration::BitmapPtr mBitmap;
89 };
90
91 } // Internal
92
93
94 inline Internal::BitmapLoader& GetImplementation(Dali::BitmapLoader& handle)
95 {
96   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
97
98   BaseObject& object = handle.GetBaseObject();
99
100   return static_cast<Internal::BitmapLoader&>(object);
101 }
102
103 inline const Internal::BitmapLoader& GetImplementation(const Dali::BitmapLoader& handle)
104 {
105   DALI_ASSERT_ALWAYS( handle && "handle is empty" );
106
107   const BaseObject& object = handle.GetBaseObject();
108
109   return static_cast<const Internal::BitmapLoader&>(object);
110 }
111
112 } // Dali
113
114 #endif // __DALI_BITMAP_LOADER_IMPL_H__