Added PixelBuffer for image loading and operations.
[platform/core/uifw/dali-adaptor.git] / adaptors / devel-api / adaptor-framework / image-loading.h
1 #ifndef DALI_IMAGE_LOADING_H
2 #define DALI_IMAGE_LOADING_H
3
4 /*
5  * Copyright (c) 2017 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 <string>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/images/image-operations.h>
24
25 #ifdef DALI_ADAPTOR_COMPILATION  // full path doesn't exist until adaptor is installed so we have to use relative
26 // @todo Make dali-adaptor code folder structure mirror the folder structure installed to dali-env
27 #include <pixel-buffer.h>
28 #else
29 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
30 #endif
31
32 namespace Dali
33 {
34
35 /**
36  * @brief Load an image synchronously from local file.
37  *
38  * @note This method is thread safe, i.e. can be called from any thread.
39  *
40  * @param [in] url The URL of the image file to load.
41  * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
42  * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
43  * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
44  * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
45  * @return handle to the loaded PixelBuffer object or an empty handle in case loading failed.
46  */
47 DALI_IMPORT_API Devel::PixelBuffer LoadImageFromFile(
48   const std::string& url,
49   ImageDimensions size = ImageDimensions( 0, 0 ),
50   FittingMode::Type fittingMode = FittingMode::DEFAULT,
51   SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
52   bool orientationCorrection = true );
53
54 /**
55  * @brief Determine the size of an image that LoadImageFromFile will provide when
56  * given the same image loading parameters.
57  *
58  * This is a synchronous request.
59  * This function is used to determine the size of an image before it has loaded.
60  * @param[in] filename name of the image.
61  * @param[in] size The requested size for the image.
62  * @param[in] fittingMode The method to use to map the source image to the desired
63  * dimensions.
64  * @param[in] samplingMode The image filter to use if the image needs to be
65  * downsampled to the requested size.
66  * @param[in] orientationCorrection Whether to use image metadata to rotate or
67  * flip the image, e.g., from portrait to landscape.
68  * @return dimensions that image will have if it is loaded with given parameters.
69  */
70 DALI_IMPORT_API ImageDimensions GetClosestImageSize(
71   const std::string& filename,
72   ImageDimensions size = ImageDimensions(0, 0),
73   FittingMode::Type fittingMode = FittingMode::DEFAULT,
74   SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR ,
75   bool orientationCorrection = true );
76
77 /**
78  * @brief Load an image synchronously from a remote resource.
79  *
80  * @param [in] url The URL of the image file to load.
81  * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
82  * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
83  * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
84  * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
85  *
86  * @return handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed.
87  */
88 DALI_IMPORT_API Devel::PixelBuffer DownloadImageSynchronously(
89   const std::string& url,
90   ImageDimensions size = ImageDimensions( 0, 0 ),
91   FittingMode::Type fittingMode = FittingMode::DEFAULT,
92   SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
93   bool orientationCorrection = true );
94
95
96 } // Dali
97
98 #endif // DALI_IMAGE_LOADING_H