1 #ifndef __DALI_RESOURCE_IMAGE_H__
2 #define __DALI_RESOURCE_IMAGE_H__
5 * Copyright (c) 2015 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.
25 #include <dali/public-api/common/loading-state.h>
26 #include <dali/public-api/images/image.h>
27 #include <dali/public-api/signals/dali-signal.h>
28 #include <dali/public-api/images/image-operations.h>
33 * @addtogroup dali_core_images
37 namespace Internal DALI_INTERNAL
43 * @brief ResourceImage is an image loaded using a URL
45 * <h3>ResourceImage Loading</h3>
47 * When the ResourceImage is created, resource loading will be attempted unless
48 * the ResourceImage is created with ResourceImage::IMMEDIATE loading policy or a compatible resource is found in cache.
49 * In case of loading images ResourceImage::ON_DEMAND, resource loading will only be attempted if the associated Dali::Toolkit::ImageView
51 * Scaling of images to a desired smaller size can be requested by providing desired dimensions,
52 * scaling mode and filter mode to to ResourceImage::New().
54 * <i>Custom load requests</i>
56 * Size, scaling mode, filter mode, and orientation compensation can be set when requesting an image.
58 * <i>Compatible resources</i>
60 * Before loading a new ResourceImage the internal image resource cache is checked by dali.
61 * If there is an image already loaded in memory and is deemed "compatible" with the requested image,
62 * that resource is reused.
63 * This happens for example if a loaded image exists with the same URL, scaling and filtering modes,
64 * and the difference between both of the dimensions is less than a few pixels.
66 * <i>Reloading images</i>
68 * The same request used on creating the ResourceImage is re-issued when reloading images.
69 * If the file changed since the last load operation, this might result in a different resource.
70 * Reload only takes effect if both of these conditions apply:
71 * - The ResourceImage has already finished loading
72 * - The ResourceImage is either on Stage or using ResourceImage::IMMEDIATE load policy
76 class DALI_IMPORT_API ResourceImage : public Image
80 * @brief Resource management options.
84 * @brief LoadPolicy controls the way images are loaded into memory.
86 * @remarks This is an experimental feature and might not be supported in the next release.
87 * We do recommend not to use it.
91 IMMEDIATE, ///< Load image once it is created (default) @since_tizen 2.4
92 ON_DEMAND ///< Delay loading until the image is being used (a related actor is added to Stage) @since_tizen 2.4
96 * @brief Type of signal for LoadingFinished and Uploaded.
99 typedef Signal< void (ResourceImage) > ResourceImageSignal;
104 * @brief Get the size of an image from disk.
106 * This function will read the header info from file on disk and is
107 * synchronous, so it should not be used repeatedly or in tight
111 * @param [in] url The URL of the image file.
112 * @return The width and height in pixels of the image.
114 static ImageDimensions GetImageSize( const std::string& url );
117 * @brief Constructor which creates an empty ResourceImage object.
119 * Use ResourceImage::New(...) to create an initialised object.
127 * This is non-virtual since derived Handle types must not contain data or virtual methods.
133 * @brief This copy constructor is required for (smart) pointer semantics.
136 * @param [in] handle A reference to the copied handle
138 ResourceImage( const ResourceImage& handle );
141 * @brief This assignment operator is required for (smart) pointer semantics.
144 * @param [in] rhs A reference to the copied handle
145 * @return A reference to this
147 ResourceImage& operator=( const ResourceImage& rhs );
150 * @name ResourceImageFactoryFunctions
151 * Create ResourceImage object instances using these functions.
156 * @brief Create an initialised ResourceImage object.
158 * Uses defaults for all options.
160 * @sa Dali::FittingMode::Type Dali::SamplingMode::Type
163 * @privilege %http://tizen.org/privilege/internet
164 * @remarks %http://tizen.org/privilege/internet is needed if @a url is a http or https address.
165 * @param [in] url The URL of the image file to use (can be a local file path, http or https address).
166 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
167 * @return A handle to a newly allocated object
169 static ResourceImage New( const std::string& url, bool orientationCorrection = true );
172 * @brief Create an initialised ResourceImage object.
176 * @privilege %http://tizen.org/privilege/internet
177 * @remarks ResourceImage::LoadPolicy and Image::ReleasePolicy are experimental features and might not be supported in the next release.
178 * We do recommend not to use this method.
179 * Please refer the Remarks of ResourceImage::LoadPolicy and Image::ReleasePolicy for more information.
180 * @remarks %http://tizen.org/privilege/internet is needed if @a url is a http or https address.
181 * @param [in] url The URL of the image file to use (can be a local file path, http or https address).
182 * @param [in] loadPol The LoadPolicy to apply when loading the image resource.
183 * @param [in] releasePol The ReleasePolicy to apply to Image.
184 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
185 * @return A handle to a newly allocated object
187 static ResourceImage New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol, bool orientationCorrection = true );
190 * @brief Create an initialised ResourceImage object.
194 * @privilege %http://tizen.org/privilege/internet
195 * @remarks %http://tizen.org/privilege/internet is needed if @a url is a http or https address.
196 * @param [in] url The URL of the image file to use (can be a local file path, http or https address).
197 * @param [in] size The width and height to fit the loaded image to.
198 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
199 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
200 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
201 * @return A handle to a newly allocated object
203 static ResourceImage New( const std::string& url,
204 ImageDimensions size,
205 FittingMode::Type fittingMode = FittingMode::DEFAULT,
206 SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
207 bool orientationCorrection = true );
210 * @brief Create an initialised ResourceImage object.
214 * @privilege %http://tizen.org/privilege/internet
215 * @remarks LoadPolicy and ReleasePolicy are experimental features and might not be supported in the next release.
216 * We do recommend not to use this method.
217 * Please refer the Remarks of LoadPolicy and ReleasePolicy for more information.
218 * @remarks %http://tizen.org/privilege/internet is needed if @a url is a http or https address.
219 * @param [in] url The URL of the image file to use (can be a local file path, http or https address).
220 * @param [in] loadPol The LoadPolicy to apply when loading the image resource.
221 * @param [in] releasePol The ReleasePolicy to apply to Image.
222 * @param [in] size The width and height to fit the loaded image to.
223 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
224 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
225 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
226 * @return A handle to a newly allocated object
228 static ResourceImage New( const std::string& url,
230 ReleasePolicy releasePol,
231 ImageDimensions size,
232 FittingMode::Type fittingMode = FittingMode::DEFAULT,
233 SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
234 bool orientationCorrection = true );
239 * @brief Downcast a handle to ResourceImage handle.
241 * If handle points to a ResourceImage object the
242 * downcast produces valid handle. If not the returned handle is left uninitialized.
244 * @param[in] handle Handle to an object
245 * @return Handle to a Image object or an uninitialized handle
247 static ResourceImage DownCast( BaseHandle handle );
250 * @brief Return load policy.
253 * @remarks This is an experimental feature and might not be supported in the next release.
254 * We do recommend not to use it.
255 * @return Resource load policy
257 LoadPolicy GetLoadPolicy() const;
260 * @brief Query whether the image data has loaded.
262 * The asynchronous loading begins when the Image object is created.
263 * After the Image object is discarded, the image data will be released from memory.
265 * @return The loading state, either Loading, Success or Failed.
267 LoadingState GetLoadingState() const;
270 * @brief Returns the URL of the image.
273 * @return The URL of the image file.
275 std::string GetUrl() const;
278 * @brief Reload image from filesystem.
280 * The original set of image loading attributes (requested dimensions, scaling
281 * mode and filter mode) are used when requesting the image again.
283 * @note If image is offstage and OnDemand policy is set, the reload request is
291 * @brief Emitted when the image data loads successfully, or when the loading fails.
294 * @return A signal object to Connect() with.
296 ResourceImageSignal& LoadingFinishedSignal();
298 public: // Not intended for application developers
300 explicit DALI_INTERNAL ResourceImage( Internal::ResourceImage* );
308 #endif // __DALI_RESOURCE_IMAGE_H__