1 #ifndef __DALI_TOOLKIT_ASYNC_IMAGE_LOADER_H__
2 #define __DALI_TOOLKIT_ASYNC_IMAGE_LOADER_H__
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/images/image-operations.h>
24 #include <dali/public-api/signals/dali-signal.h>
33 namespace Internal DALI_INTERNAL
35 class AsyncImageLoader;
39 *@brief The AysncImageLoader is used to load pixel data from the URL asynchronously.
41 * The images are loaded in a worker thread to avoid blocking the main event thread.
43 * Each load call is assigned with an ID, connect to the ImageLoadedSignal and receive the corresponding pixel data by comparing the ID.
45 * To make sure the signal is always received, the signal should get connected before invoking the load call.
47 * class MyClass : public ConnectionTracker
51 * MyCallback( uint32_t id, PixelData pixelData)
55 * // use the loaded pixel data from the first image
57 * else if( id == mId2 )
59 * // use the loaded pixel data from the second image
68 * AsyncImageLoader imageLoader = AsyncImageLoader::New();
69 * // connect the signal here
70 * imageLoader.ImageLoadedSignal().Connect( &myObject, &MyClass::MyCallback );
71 * // then invoke the load calls
72 * testCallback.mId1 = imageLoader.Load( "first_image_url.jpg" );
73 * testCallback.mId2 = imageLoader.Load( "second_image_url.jpg" );
77 class DALI_IMPORT_API AsyncImageLoader : public BaseHandle
82 * @brief Type of signal for image loading finished.
84 * The signal is emit with the load ID and its corresponding loaded pixel data
86 typedef Signal< void( uint32_t, PixelData ) > ImageLoadedSignalType;
91 * @brief Constructor which creates an empty AsyncImageLoader handle.
93 * Use AsyncImageLoader::New() to create an initialised object.
100 * This is non-virtual since derived Handle types must not contain data or virtual methods.
105 * @brief This copy constructor is required for (smart) pointer semantics.
107 * @param [in] handle A reference to the copied handle
109 AsyncImageLoader( const AsyncImageLoader& handle );
112 * @brief This assignment operator is required for (smart) pointer semantics.
114 * @param [in] handle A reference to the copied handle
115 * @return A reference to this
117 AsyncImageLoader& operator=( const AsyncImageLoader& handle );
120 * @brief Create a new loader to load the image asynchronously in a worker thread.
122 * @return The image loader.
124 static AsyncImageLoader New();
127 * @brief Start a image loading task.
129 * @param[in] url The URL of the image file to load.
130 * @return The loading task id.
132 uint32_t Load( const std::string& url );
134 * @brief Start a image loading task.
136 * @param[in] url The URL of the image file to load.
137 * @param[in] size The width and height to fit the loaded image to.
138 * @return The loading task id.
140 uint32_t Load( const std::string& url, ImageDimensions size );
143 * @brief Start a image loading task.
145 * @param[in] url The URL of the image file to load.
146 * @param[in] size The width and height to fit the loaded image to.
147 * @param[in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
148 * @param[in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
149 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
150 * @return The loading task id.
152 uint32_t Load( const std::string& url,
153 ImageDimensions size,
154 FittingMode::Type fittingMode,
155 SamplingMode::Type samplingMode,
156 bool orientationCorrection );
159 * @brief Cancel a image loading task if it is still queuing in the work thread.
161 * @param[in] loadingTaskId The task id returned when invoking the load call.
162 * @return If true, the loading task is removed from the queue, otherwise the loading is already implemented and unable to cancel anymore
164 bool Cancel( uint32_t loadingTaskId);
167 * @brief Cancel all the loading tasks in the queue
172 * @brief Signal emit for connected callback functions to get access to the loaded pixel data.
174 * A callback of the following type may be connected:
176 * void YourCallbackName( uint32_t id, PixelData pixelData );
179 * @return A signal object to Connect() with.
181 ImageLoadedSignalType& ImageLoadedSignal();
183 public: // Not intended for developer use
185 explicit DALI_INTERNAL AsyncImageLoader( Internal::AsyncImageLoader* impl );
189 } // namespace Toolkit
193 #endif /* __DALI_TOOLKIT_ASYNC_IMAGE_LOADER_H__ */