1 #ifndef DALI_IMAGE_LOADING_H
2 #define DALI_IMAGE_LOADING_H
5 * Copyright (c) 2023 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.
21 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/images/image-operations.h>
27 #include <dali/public-api/dali-adaptor-common.h>
32 * @brief Load an image synchronously from local file.
34 * @note This method is thread safe, i.e. can be called from any thread.
36 * @param [in] url The URL of the image file to load.
37 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
38 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
39 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
40 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
41 * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
43 DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromFile(
44 const std::string& url,
45 ImageDimensions size = ImageDimensions(0, 0),
46 FittingMode::Type fittingMode = FittingMode::DEFAULT,
47 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
48 bool orientationCorrection = true);
51 * @brief Load an image and save each plane to a separate buffer synchronously from local file.
53 * @note This method is thread safe, i.e. can be called from any thread.
54 * If the image file doesn't support to load planes, this method returns a bitmap image instead.
56 * @param [in] url The URL of the image file to load.
57 * @param [out] buffers The loaded PixelBuffer object list or an empty list in case loading failed.
58 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
59 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
60 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
61 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
63 DALI_ADAPTOR_API void LoadImagePlanesFromFile(
64 const std::string& url,
65 std::vector<Devel::PixelBuffer>& buffers,
66 ImageDimensions size = ImageDimensions(0, 0),
67 FittingMode::Type fittingMode = FittingMode::DEFAULT,
68 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
69 bool orientationCorrection = true);
72 * @brief Load an image synchronously from encoded buffer.
74 * @note This method is thread safe, i.e. can be called from any thread.
76 * @param [in] buffer The encoded buffer of the image to load.
77 * The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
78 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
79 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
80 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
81 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
82 * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
84 DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromBuffer(
85 const Dali::Vector<uint8_t>& buffer,
86 ImageDimensions size = ImageDimensions(0, 0),
87 FittingMode::Type fittingMode = FittingMode::DEFAULT,
88 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
89 bool orientationCorrection = true);
92 * @brief Load an image synchronously from encoded buffer.
94 * @note This method is thread safe, i.e. can be called from any thread.
96 * @param [in] buffer The encoded buffer of the image to load.
97 * The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
98 * @param [in] bufferSize Size of the encoded buffer.
99 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
100 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
101 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
102 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
103 * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
105 DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromBuffer(
108 ImageDimensions size = ImageDimensions(0, 0),
109 FittingMode::Type fittingMode = FittingMode::DEFAULT,
110 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
111 bool orientationCorrection = true);
114 * @brief Determine the size of an image that LoadImageFromFile will provide when
115 * given the same image loading parameters.
117 * This is a synchronous request.
118 * This function is used to determine the size of an image before it has loaded.
119 * @param[in] filename name of the image.
120 * @param[in] size The requested size for the image.
121 * @param[in] fittingMode The method to use to map the source image to the desired
123 * @param[in] samplingMode The image filter to use if the image needs to be
124 * downsampled to the requested size.
125 * @param[in] orientationCorrection Whether to use image metadata to rotate or
126 * flip the image, e.g., from portrait to landscape.
127 * @return dimensions that image will have if it is loaded with given parameters.
129 DALI_ADAPTOR_API ImageDimensions GetClosestImageSize(
130 const std::string& filename,
131 ImageDimensions size = ImageDimensions(0, 0),
132 FittingMode::Type fittingMode = FittingMode::DEFAULT,
133 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
134 bool orientationCorrection = true);
137 * @brief Get the size of an original image. this method will respect any rotation of image.
138 * @param[in] filename name of the image.
139 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
141 * @return dimensions to original image
143 DALI_ADAPTOR_API ImageDimensions GetOriginalImageSize(
144 const std::string& filename, bool orientationCorrection = true);
147 * @brief Load an image synchronously from a remote resource.
149 * @param [in] url The URL of the image file to load.
150 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
151 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
152 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
153 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
155 * @return handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.
157 DALI_ADAPTOR_API Devel::PixelBuffer DownloadImageSynchronously(
158 const std::string& url,
159 ImageDimensions size = ImageDimensions(0, 0),
160 FittingMode::Type fittingMode = FittingMode::DEFAULT,
161 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
162 bool orientationCorrection = true);
165 * @brief get the maximum texture size.
167 * @return The maximum texture size
169 DALI_ADAPTOR_API unsigned int GetMaxTextureSize();
173 #endif // DALI_IMAGE_LOADING_H