[dali_1.9.9] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / pixel-manipulation.h
1 #ifndef DALI_INTERNAL_ADAPTOR_PIXEL_MANIPULATION_H
2 #define DALI_INTERNAL_ADAPTOR_PIXEL_MANIPULATION_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 #include <dali/public-api/images/pixel.h>
21
22 namespace Dali
23 {
24
25 namespace Internal
26 {
27
28 namespace Adaptor
29 {
30
31 enum Channel
32 {
33   LUMINANCE,
34   RED,
35   GREEN,
36   BLUE,
37   ALPHA,
38   DEPTH,
39   STENCIL,
40   MAX_NUMBER_OF_CHANNELS
41 };
42
43 /**
44  * Return true if the channel exists in the pixel format
45  * @param[in] pixelFormat The pixelFormat
46  * @param[in] channel The channel to test for
47  * @return true if the channel exists
48  */
49 bool HasChannel( Dali::Pixel::Format pixelFormat, Channel channel );
50
51
52 /**
53  * Read a colour channel from the pixel with the given pixel format.
54  * Returns zero if the format does not support the channel
55  * @param[in] pixelData Location of the pixel
56  * @param[in] pixelFormat The format of the pixel
57  * @param[in] channel The channel to read
58  * @return the channel value
59  */
60 unsigned int ReadChannel( unsigned char* pixelData,
61                           Dali::Pixel::Format pixelFormat,
62                           Channel channel );
63
64 /**
65  * Write a colour channel to the pixel with the given pixel format.
66  * @param[in] pixelData Location of the pixel
67  * @param[in] pixelFormat The format of the pixel
68  * @param[in] channel The channel to write
69  * @param[in] channelValue the value to write to the channel
70  */
71 void WriteChannel( unsigned char* pixelData,
72                    Dali::Pixel::Format pixelFormat,
73                    Channel channel,
74                    unsigned int channelValue );
75
76 /**
77  * Convert the colors in the source pixel from their natural format to RGBA8888.
78  * @param[in] srcBuffer The source buffer to read from
79  * @param[in] srcOffset The offset of the pixel to convert
80  * @param[in] srcFormat The pixel format of the source pixel
81  * @param[in] destBuffer The destination buffer to write to
82  * @param[in] destOffset The offset of the pixel to write
83  */
84 void ConvertColorChannelsToRGBA8888(
85   unsigned char* srcBuffer,  int srcOffset,  Dali::Pixel::Format srcFormat,
86   unsigned char* destBuffer, int destOffset );
87
88 /**
89  * Convert the alpha in the source pixel to A8.
90  * @param[in] srcBuffer The source buffer to read from
91  * @param[in] srcOffset The offset of the pixel to convert
92  * @param[in] srcFormat The pixel format of the source pixel
93  * @return the alpha value in the range 0-255
94  */
95 int ConvertAlphaChannelToA8( unsigned char* srcPixel, int srcOffset, Dali::Pixel::Format srcFormat );
96
97
98 } // Adaptor
99 } // Internal
100 } // Dali
101
102
103 #endif // DALI_INTERNAL_ADAPTOR_PIXEL_MANIPULATION_H