[Tizen] 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  *
54  * @param [in] url The URL of the image file to load.
55  * @param [out] buffers The loaded PixelBuffer object list or an empty list in case loading failed.
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  */
61 DALI_ADAPTOR_API void LoadImagePlanesFromFile(
62   const std::string&               url,
63   std::vector<Devel::PixelBuffer>& buffers,
64   ImageDimensions                  size                  = ImageDimensions(0, 0),
65   FittingMode::Type                fittingMode           = FittingMode::DEFAULT,
66   SamplingMode::Type               samplingMode          = SamplingMode::BOX_THEN_LINEAR,
67   bool                             orientationCorrection = true);
68
69 /**
70  * @brief Load an image synchronously from encoded buffer.
71  *
72  * @note This method is thread safe, i.e. can be called from any thread.
73  *
74  * @param [in] buffer The encoded buffer of the image to load.
75  *                    The buffer is not owned by FileStream and must be valid for entire lifetime of FileStream
76  * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
77  * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
78  * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
79  * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
80  * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
81  */
82 DALI_ADAPTOR_API Devel::PixelBuffer LoadImageFromBuffer(
83   const Dali::Vector<uint8_t>& buffer,
84   ImageDimensions              size                  = ImageDimensions(0, 0),
85   FittingMode::Type            fittingMode           = FittingMode::DEFAULT,
86   SamplingMode::Type           samplingMode          = SamplingMode::BOX_THEN_LINEAR,
87   bool                         orientationCorrection = true);
88
89 /**
90  * @brief Determine the size of an image that LoadImageFromFile will provide when
91  * given the same image loading parameters.
92  *
93  * This is a synchronous request.
94  * This function is used to determine the size of an image before it has loaded.
95  * @param[in] filename name of the image.
96  * @param[in] size The requested size for the image.
97  * @param[in] fittingMode The method to use to map the source image to the desired
98  * dimensions.
99  * @param[in] samplingMode The image filter to use if the image needs to be
100  * downsampled to the requested size.
101  * @param[in] orientationCorrection Whether to use image metadata to rotate or
102  * flip the image, e.g., from portrait to landscape.
103  * @return dimensions that image will have if it is loaded with given parameters.
104  */
105 DALI_ADAPTOR_API ImageDimensions GetClosestImageSize(
106   const std::string& filename,
107   ImageDimensions    size                  = ImageDimensions(0, 0),
108   FittingMode::Type  fittingMode           = FittingMode::DEFAULT,
109   SamplingMode::Type samplingMode          = SamplingMode::BOX_THEN_LINEAR,
110   bool               orientationCorrection = true);
111
112 /**
113  * @brief Get the size of an original image. this method will respect any rotation of image.
114  * @param[in] filename name of the image.
115  * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
116  *
117  * @return dimensions to original image
118  */
119 DALI_ADAPTOR_API ImageDimensions GetOriginalImageSize(
120   const std::string& filename, bool orientationCorrection = true);
121
122 /**
123  * @brief Load an image synchronously from a remote resource.
124  *
125  * @param [in] url The URL of the image file to load.
126  * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
127  * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
128  * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
129  * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
130  *
131  * @return handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.
132  */
133 DALI_ADAPTOR_API Devel::PixelBuffer DownloadImageSynchronously(
134   const std::string& url,
135   ImageDimensions    size                  = ImageDimensions(0, 0),
136   FittingMode::Type  fittingMode           = FittingMode::DEFAULT,
137   SamplingMode::Type samplingMode          = SamplingMode::BOX_THEN_LINEAR,
138   bool               orientationCorrection = true);
139
140 /**
141  * @brief get the maximum texture size.
142  *
143  * @return The maximum texture size
144  */
145 DALI_ADAPTOR_API unsigned int GetMaxTextureSize();
146
147 } // namespace Dali
148
149 #endif // DALI_IMAGE_LOADING_H