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 * <i>Customizing load requests</i>
47 * Size, scaling mode, filter mode, and orientation compensation can be set when requesting an image.
49 * <i>Reloading images</i>
51 * The same request used on creating the ResourceImage is re-issued when reloading images.
52 * If the file changed since the last load operation, this might result in a different resource.
53 * Reload only takes effect if the ResourceImage has already finished loading.
56 * | %Signal Name | Method |
57 * |----------------------|------------------------------|
58 * | imageLoadingFinished | @ref LoadingFinishedSignal() |
61 class DALI_IMPORT_API ResourceImage : public Image
66 * @DEPRECATED_1_1.3. Image loading starts immediately in the frame when then ResourceImage object is created.
68 * @brief LoadPolicy controls the way images are loaded into memory.
70 * @remarks This is an experimental feature and might not be supported in the next release.
71 * We do recommend not to use it.
75 IMMEDIATE, ///< Load image once it is created (default) @SINCE_1_0.0
76 ON_DEMAND ///< Delay loading until the image is being used (a related actor is added to Stage) @SINCE_1_0.0
80 * @brief Type of signal for LoadingFinished and Uploaded.
83 typedef Signal< void (ResourceImage) > ResourceImageSignal;
88 * @brief Get the size of an image from disk.
90 * This function will read the header info from file on disk and is
91 * synchronous, so it should not be used repeatedly or in tight
95 * @param [in] url The URL of the image file.
96 * @return The width and height in pixels of the image.
98 static ImageDimensions GetImageSize( const std::string& url );
101 * @brief Constructor which creates an empty ResourceImage object.
103 * Use ResourceImage::New(...) to create an initialised object.
111 * This is non-virtual since derived Handle types must not contain data or virtual methods.
117 * @brief This copy constructor is required for (smart) pointer semantics.
120 * @param [in] handle A reference to the copied handle
122 ResourceImage( const ResourceImage& handle );
125 * @brief This assignment operator is required for (smart) pointer semantics.
128 * @param [in] rhs A reference to the copied handle
129 * @return A reference to this
131 ResourceImage& operator=( const ResourceImage& rhs );
134 * @name ResourceImageFactoryFunctions
135 * Create ResourceImage object instances using these functions.
140 * @brief Create an initialised ResourceImage object.
142 * Uses defaults for all options.
144 * @sa Dali::FittingMode::Type Dali::SamplingMode::Type
147 * @param [in] url The URL of the image file to use.
148 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
149 * @return A handle to a newly allocated object
151 static ResourceImage New( const std::string& url, bool orientationCorrection = true );
154 * @DEPRECATED_1_1.3. Use New( const std::string& url ) instead.
156 * @brief Create an initialised ResourceImage object.
160 * @param [in] url The URL of the image file to use.
161 * @param [in] loadPol The LoadPolicy to apply when loading the image resource.
162 * @param [in] releasePol The ReleasePolicy to apply to Image.
163 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
164 * @return A handle to a newly allocated object
166 static ResourceImage New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol, bool orientationCorrection = true );
169 * @brief Create an initialised ResourceImage object.
173 * @param [in] url The URL of the image file to use.
174 * @param [in] size The width and height to fit the loaded image to.
175 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
176 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
177 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
178 * @return A handle to a newly allocated object
180 static ResourceImage New( const std::string& url,
181 ImageDimensions size,
182 FittingMode::Type fittingMode = FittingMode::DEFAULT,
183 SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
184 bool orientationCorrection = true );
187 * @DEPRECATED_1_1.3. Use New( const std::string& url, ImageDimensions size ) instead.
189 * @brief Create an initialised ResourceImage object.
193 * @param [in] url The URL of the image file to use.
194 * @param [in] loadPol The LoadPolicy to apply when loading the image resource.
195 * @param [in] releasePol The ReleasePolicy to apply to Image.
196 * @param [in] size The width and height to fit the loaded image to.
197 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
198 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
199 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
200 * @return A handle to a newly allocated object
202 static ResourceImage New( const std::string& url,
204 ReleasePolicy releasePol,
205 ImageDimensions size,
206 FittingMode::Type fittingMode = FittingMode::DEFAULT,
207 SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
208 bool orientationCorrection = true );
213 * @brief Downcast a handle to ResourceImage handle.
215 * If handle points to a ResourceImage object the
216 * downcast produces valid handle. If not the returned handle is left uninitialized.
218 * @param[in] handle Handle to an object
219 * @return Handle to a Image object or an uninitialized handle
221 static ResourceImage DownCast( BaseHandle handle );
226 * @brief Return load policy.
229 * @remarks This is an experimental feature and might not be supported in the next release.
230 * We do recommend not to use it.
231 * @return Resource load policy
233 LoadPolicy GetLoadPolicy() const;
236 * @brief Query whether the image data has loaded.
238 * The asynchronous loading begins when the Image object is created.
239 * After the Image object is discarded, the image data will be released from memory.
241 * @return The loading state, either Loading, Success or Failed.
243 LoadingState GetLoadingState() const;
246 * @brief Returns the URL of the image.
249 * @return The URL of the image file.
251 std::string GetUrl() const;
254 * @brief Reload image from filesystem.
256 * The original set of image loading attributes (requested dimensions, scaling
257 * mode and filter mode) are used when requesting the image again.
259 * @note If image is offstage and OnDemand policy is set, the reload request is
267 * @brief Emitted when the image data loads successfully, or when the loading fails.
270 * @return A signal object to Connect() with.
272 ResourceImageSignal& LoadingFinishedSignal();
274 public: // Not intended for application developers
276 explicit DALI_INTERNAL ResourceImage( Internal::ResourceImage* );
284 #endif // __DALI_RESOURCE_IMAGE_H__