Support YUV decoding for JPEG
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / image-loading.h
1 #ifndef DALI_IMAGE_LOADING_H
2 #define DALI_IMAGE_LOADING_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
22 #include <dali/public-api/images/image-operations.h>
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/dali-adaptor-common.h>
27
28 namespace Dali
29 {
30 /**
31  * @brief Load an image synchronously from local file.
32  *
33  * @note This method is thread safe, i.e. can be called from any thread.
34  *
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.
41  */
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);
48
49 /**
50  * @brief Load an image and save each plane to a separate buffer synchronously from local file.
51  *
52  * @note This method is thread safe, i.e. can be called from any thread.
53  *       If the image file doesn't support to load planes, this method returns a bitmap image instead.
54  *
55  * @param [in] url The URL of the image file to load.
56  * @param [out] buffers The loaded PixelBuffer object list or an empty list in case loading failed.
57  * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
58  * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
59  * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
60  * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
61  */
62 DALI_ADAPTOR_API void LoadImagePlanesFromFile(
63   const std::string&               url,
64   std::vector<Devel::PixelBuffer>& buffers,
65   ImageDimensions                  size                  = ImageDimensions(0, 0),
66   FittingMode::Type                fittingMode           = FittingMode::DEFAULT,
67   SamplingMode::Type               samplingMode          = SamplingMode::BOX_THEN_LINEAR,
68   bool                             orientationCorrection = true);
69
70 /**
71  * @brief Load an image synchronously from encoded buffer.
72  *
73  * @note This method is thread safe, i.e. can be called from any thread.
74  *
75  * @param [in] buffer The encoded buffer of the image to load.
76  *                    The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
77  * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
78  * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
79  * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
80  * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
81  * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
82  */
83 DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromBuffer(
84   const Dali::Vector<uint8_t>& buffer,
85   ImageDimensions              size                  = ImageDimensions(0, 0),
86   FittingMode::Type            fittingMode           = FittingMode::DEFAULT,
87   SamplingMode::Type           samplingMode          = SamplingMode::BOX_THEN_LINEAR,
88   bool                         orientationCorrection = true);
89
90 /**
91  * @brief Determine the size of an image that LoadImageFromFile will provide when
92  * given the same image loading parameters.
93  *
94  * This is a synchronous request.
95  * This function is used to determine the size of an image before it has loaded.
96  * @param[in] filename name of the image.
97  * @param[in] size The requested size for the image.
98  * @param[in] fittingMode The method to use to map the source image to the desired
99  * dimensions.
100  * @param[in] samplingMode The image filter to use if the image needs to be
101  * downsampled to the requested size.
102  * @param[in] orientationCorrection Whether to use image metadata to rotate or
103  * flip the image, e.g., from portrait to landscape.
104  * @return dimensions that image will have if it is loaded with given parameters.
105  */
106 DALI_ADAPTOR_API ImageDimensions GetClosestImageSize(
107   const std::string& filename,
108   ImageDimensions    size                  = ImageDimensions(0, 0),
109   FittingMode::Type  fittingMode           = FittingMode::DEFAULT,
110   SamplingMode::Type samplingMode          = SamplingMode::BOX_THEN_LINEAR,
111   bool               orientationCorrection = true);
112
113 /**
114  * @brief Get the size of an original image. this method will respect any rotation of image.
115  * @param[in] filename name of the image.
116  * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
117  *
118  * @return dimensions to original image
119  */
120 DALI_ADAPTOR_API ImageDimensions GetOriginalImageSize(
121   const std::string& filename, bool orientationCorrection = true);
122
123 /**
124  * @brief Load an image synchronously from a remote resource.
125  *
126  * @param [in] url The URL of the image file to load.
127  * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
128  * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
129  * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
130  * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
131  *
132  * @return handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.
133  */
134 DALI_ADAPTOR_API Devel::PixelBuffer DownloadImageSynchronously(
135   const std::string& url,
136   ImageDimensions    size                  = ImageDimensions(0, 0),
137   FittingMode::Type  fittingMode           = FittingMode::DEFAULT,
138   SamplingMode::Type samplingMode          = SamplingMode::BOX_THEN_LINEAR,
139   bool               orientationCorrection = true);
140
141 /**
142  * @brief get the maximum texture size.
143  *
144  * @return The maximum texture size
145  */
146 DALI_ADAPTOR_API unsigned int GetMaxTextureSize();
147
148 } // namespace Dali
149
150 #endif // DALI_IMAGE_LOADING_H