1 #ifndef DALI_IMAGE_LOADING_H
2 #define DALI_IMAGE_LOADING_H
5 * Copyright (c) 2021 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/images/image-operations.h>
26 #include <dali/public-api/dali-adaptor-common.h>
31 * @brief Load an image synchronously from local file.
33 * @note This method is thread safe, i.e. can be called from any thread.
35 * @param [in] url The URL of the image file to load.
36 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
37 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
38 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
39 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
40 * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
42 DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromFile(
43 const std::string& url,
44 ImageDimensions size = ImageDimensions(0, 0),
45 FittingMode::Type fittingMode = FittingMode::DEFAULT,
46 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
47 bool orientationCorrection = true);
50 * @brief Load an image synchronously from encoded buffer.
52 * @note This method is thread safe, i.e. can be called from any thread.
54 * @param [in] buffer The encoded buffer of the image to load.
55 * The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
56 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
57 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
58 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
59 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
60 * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
62 DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromBuffer(
63 const Dali::Vector<uint8_t>& buffer,
64 ImageDimensions size = ImageDimensions(0, 0),
65 FittingMode::Type fittingMode = FittingMode::DEFAULT,
66 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
67 bool orientationCorrection = true);
70 * @brief Determine the size of an image that LoadImageFromFile will provide when
71 * given the same image loading parameters.
73 * This is a synchronous request.
74 * This function is used to determine the size of an image before it has loaded.
75 * @param[in] filename name of the image.
76 * @param[in] size The requested size for the image.
77 * @param[in] fittingMode The method to use to map the source image to the desired
79 * @param[in] samplingMode The image filter to use if the image needs to be
80 * downsampled to the requested size.
81 * @param[in] orientationCorrection Whether to use image metadata to rotate or
82 * flip the image, e.g., from portrait to landscape.
83 * @return dimensions that image will have if it is loaded with given parameters.
85 DALI_ADAPTOR_API ImageDimensions GetClosestImageSize(
86 const std::string& filename,
87 ImageDimensions size = ImageDimensions(0, 0),
88 FittingMode::Type fittingMode = FittingMode::DEFAULT,
89 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
90 bool orientationCorrection = true);
93 * @brief Get the size of an original image. this method will respect any rotation of image.
94 * @param[in] filename name of the image.
95 * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
97 * @return dimensions to original image
99 DALI_ADAPTOR_API ImageDimensions GetOriginalImageSize(
100 const std::string& filename, bool orientationCorrection = true);
103 * @brief Load an image synchronously from a remote resource.
105 * @param [in] url The URL of the image file to load.
106 * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
107 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
108 * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
109 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
111 * @return handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.
113 DALI_ADAPTOR_API Devel::PixelBuffer DownloadImageSynchronously(
114 const std::string& url,
115 ImageDimensions size = ImageDimensions(0, 0),
116 FittingMode::Type fittingMode = FittingMode::DEFAULT,
117 SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
118 bool orientationCorrection = true);
121 * @brief get the maximum texture size.
123 * @return The maximum texture size
125 DALI_ADAPTOR_API unsigned int GetMaxTextureSize();
129 #endif // DALI_IMAGE_LOADING_H