af5ac92d8c780ff3d55e7958cd97489cf0012dd2
[platform/core/uifw/dali-adaptor.git] / adaptors / devel-api / adaptor-framework / bitmap-loader.h
1 #ifndef __DALI_BITMAP_LOADER_H__
2 #define __DALI_BITMAP_LOADER_H__
3
4 /*
5  * Copyright (c) 2015 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/common/dali-common.h>
23 #include <dali/public-api/images/pixel.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/public-api/object/base-handle.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class BitmapLoader;
32 }
33
34 /**
35  * @brief The BitmapLoader class is used to load bitmap from the URL synchronously.
36  *
37  * As the loading is synchronous, it will block the loop whilst executing.
38  * Therefore, it should be used sparingly in the main event thread, and better to be called in the worker thread.
39  * The Load() API is thread safe, it can be called from any thread without changing the state of DALI.
40  */
41 class DALI_IMPORT_API BitmapLoader : public BaseHandle
42 {
43 public:
44
45   /**
46    * @brief Create an initialized bitmap loader.
47    *
48    * By calling Load(), the synchronous loading is started immediately.
49    *
50    * @param [in] url The URL of the image file to load.
51    * @param [in] size The width and height to fit the loaded image to.
52    * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
53    * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
54    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
55    */
56   static BitmapLoader New( const std::string& url,
57                            ImageDimensions size = ImageDimensions( 0, 0 ),
58                            FittingMode::Type fittingMode = FittingMode::DEFAULT,
59                            SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
60                            bool orientationCorrection = true);
61
62   /**
63    * @brief Create an empty handle.
64    *
65    * Use BitmapLoader::New() to create an initialized object.
66    */
67   BitmapLoader();
68
69   /**
70    * Destructor
71    */
72   ~BitmapLoader();
73
74   /**
75    * @brief This copy constructor is required for (smart) pointer semantics.
76    *
77    * @param [in] handle A reference to the copied handle
78    */
79   BitmapLoader(const BitmapLoader& handle);
80
81   /**
82    * @brief This assignment operator is required for (smart) pointer semantics.
83    *
84    * @param [in] rhs  A reference to the copied handle
85    * @return A reference to this
86    */
87   BitmapLoader& operator=(const BitmapLoader& rhs);
88
89 public:
90
91   /**
92    * @brief Start the synchronous loading.
93    */
94   void Load();
95
96   /**
97    * @brief Query whether the image is loaded.
98    *
99    * @reture true if the image is loaded, false otherwise.
100    */
101   bool IsLoaded();
102
103   /**
104    * Get the raw pixel data.
105    * @return The pixel data. Use the GetHeight(), GetWidth(), GetStride() and GetPixelFormat() methods
106    * to decode the data.
107    */
108   unsigned char* GetPixelData() const;
109
110   /**
111    * Get the buffer height in pixels
112    * @return the height of the buffer in pixels
113    */
114   unsigned int GetImageHeight() const;
115
116   /**
117    * Get the buffer width in pixels
118    * @return the width of the buffer in pixels
119    */
120   unsigned int GetImageWidth() const;
121
122   /**
123    * Get the pixel format of the loaded bitmap.
124    */
125   Pixel::Format GetPixelFormat() const;
126
127 public: // Not intended for application developers
128
129   explicit DALI_INTERNAL BitmapLoader(Internal::BitmapLoader*);
130 };
131
132 } // Dali
133
134 #endif // __DALI_BITMAP_LOADER_H__