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