Add npatch utility
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / utility / npatch-utilities.h
1 #ifndef DALI_TOOLKIT_NPATCH_UTILITIES_H
2 #define DALI_TOOLKIT_NPATCH_UTILITIES_H
3
4 /*
5  * Copyright (c) 2020 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
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23 #include <dali/public-api/math/uint-16-pair.h>
24 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/public-api/dali-toolkit-common.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace NPatchUtility
36 {
37
38 /**
39  * The list that includes stretch pixel ranges
40  */
41 using StretchRanges = Dali::Vector< Uint16Pair >;
42
43 /**
44  * @brief Get the offset of the red channel for the format.
45  *
46  * @param[in] pixelFormat The pixel format
47  * @param[out] byteOffset The byte offset of the red channel.
48  * @param[out] bitMask The bit mask of the red channel.
49  */
50 DALI_TOOLKIT_API void GetRedOffsetAndMask( Dali::Pixel::Format pixelFormat, int& byteOffset, int& bitMask );
51
52 /**
53  * @brief Read the borders of the buffer and determine the child area and stretch borders.
54  *
55  * @param[in] pixelBuffer The npatch image buffer.
56  * @param[out] stretchPixelsX The horizontal stretchable pixels in the cropped image space.
57  * @param[out] stretchPixelsY The vertical stretchable pixels in the cropped image space.
58  */
59 DALI_TOOLKIT_API void ParseBorders( Devel::PixelBuffer& pixelBuffer, StretchRanges& stretchPixelsX, StretchRanges& stretchPixelsY );
60
61 /**
62  * @brief Helper method to determine if the filename indicates that the image has a 9 patch or n patch border.
63  *
64  * @param [in] url The URL of the image file.
65  * @return true if it is a 9 patch or n patch image
66  */
67 DALI_TOOLKIT_API bool IsNinePatchUrl( const std::string& url );
68
69 } // namespace NPatchUtility
70
71 } // namespace Toolkit
72
73 } // namespace Dali
74
75 #endif // DALI_TOOLKIT_NPATCH_UTILITIES_H