Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / public-api / images / pixel.h
1 #ifndef __DALI_PIXEL_H__
2 #define __DALI_PIXEL_H__
3
4 /*
5  * Copyright (c) 2018 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 <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26
27 namespace Dali
28 {
29 /**
30  * @addtogroup dali_core_images
31  * @{
32  */
33
34 /**
35  * @brief Pixel format types and their properties.
36  * @SINCE_1_0.0
37  */
38 namespace Pixel
39 {
40 /**
41  * @brief Enumeration for Pixel formats.
42  *
43  * Pixel format, default color depth is RGBA 32 bit with alpha.
44  * @SINCE_1_0.0
45  * @note BufferImage::Update might not work with BGR/BGRA formats!
46  */
47 enum Format
48 {
49   INVALID = 0,                              ///< Used to represent an unsupported format. @SINCE_1_1.17
50
51   // Start at > 0 to distinguish null data:
52   A8 = 1,                                   ///< color depth 8-bit, alpha @SINCE_1_0.0
53   L8,                                       ///< color depth 8-bit, luminance @SINCE_1_0.0
54   LA88,                                     ///< color depth 16-bit, luminance with 8 bit alpha @SINCE_1_0.0
55   RGB565,                                   ///< color depth 16 bit, 5-6-5 @SINCE_1_0.0
56   BGR565,                                   ///< color depth 16 bit, 5-6-5 @SINCE_1_0.0
57   RGBA4444,                                 ///< color depth 16 bit with alpha, 4-4-4-4 @SINCE_1_0.0
58   BGRA4444,                                 ///< color depth 16 bit with alpha, 4-4-4-4 @SINCE_1_0.0
59   RGBA5551,                                 ///< color depth 16 bit with alpha, 5-5-5-1 @SINCE_1_0.0
60   BGRA5551,                                 ///< color depth 16 bit with alpha, 5-5-5-1 @SINCE_1_0.0
61   RGB888,                                   ///< color depth 24 bit, 8-8-8 @SINCE_1_0.0
62   RGB8888,                                  ///< color depth 32 bit, alpha is reserved but not used, 8-8-8-8# @SINCE_1_0.0
63   BGR8888,                                  ///< color depth 32 bit, alpha is reserved but not used, 8-8-8-8# @SINCE_1_0.0
64   RGBA8888,                                 ///< color depth 32 bit with alpha, 8-8-8-8 @SINCE_1_0.0
65   BGRA8888,                                 ///< color depth 32 bit with alpha, 8-8-8-8 @SINCE_1_0.0
66
67   // GLES 3 Standard compressed formats:
68   COMPRESSED_R11_EAC,                       ///< ETC2 / EAC single-channel, unsigned @SINCE_1_0.0
69   COMPRESSED_SIGNED_R11_EAC,                ///< ETC2 / EAC single-channel, signed @SINCE_1_0.0
70   COMPRESSED_RG11_EAC,                      ///< ETC2 / EAC dual-channel, unsigned @SINCE_1_0.0
71   COMPRESSED_SIGNED_RG11_EAC,               ///< ETC2 / EAC dual-channel, signed @SINCE_1_0.0
72   COMPRESSED_RGB8_ETC2,                     ///< ETC2 / EAC RGB @SINCE_1_0.0
73   COMPRESSED_SRGB8_ETC2,                    ///< ETC2 / EAC RGB using sRGB colourspace. @SINCE_1_0.0
74   COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, ///< ETC2 / EAC RGB with single bit per pixel alpha mask. @SINCE_1_0.0
75   COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,///< ETC2 / EAC RGB using sRGB colourspace, with single bit per pixel alpha mask. @SINCE_1_0.0
76   COMPRESSED_RGBA8_ETC2_EAC,                ///< ETC2 / EAC RGB plus separate alpha channel. @SINCE_1_0.0
77   COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,         ///< ETC2 / EAC RGB using sRGB colourspace, plus separate alpha channel. @SINCE_1_0.0
78
79   // GLES 2 extension compressed formats:
80   COMPRESSED_RGB8_ETC1,                     ///< ETC1 RGB as defined by GLES 2 extension OES_compressed_ETC1_RGB8_texture: http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt @SINCE_1_0.0
81   COMPRESSED_RGB_PVRTC_4BPPV1,              ///< PowerVR 4bpp RGB format (v1) as defined by extension IMG_texture_compression_pvrtc: http://www.khronos.org/registry/gles/extensions/IMG/IMG_texture_compression_pvrtc.txt @SINCE_1_0.0
82
83   // GLES 3.1 compressed formats:
84   COMPRESSED_RGBA_ASTC_4x4_KHR,             ///< ASTC Linear color space with a 4x4 block-size. @SINCE_1_1.17
85   COMPRESSED_RGBA_ASTC_5x4_KHR,             ///< ASTC Linear color space with a 5x4 block-size. @SINCE_1_1.17
86   COMPRESSED_RGBA_ASTC_5x5_KHR,             ///< ASTC Linear color space with a 5x5 block-size. @SINCE_1_1.17
87   COMPRESSED_RGBA_ASTC_6x5_KHR,             ///< ASTC Linear color space with a 6x5 block-size. @SINCE_1_1.17
88   COMPRESSED_RGBA_ASTC_6x6_KHR,             ///< ASTC Linear color space with a 6x6 block-size. @SINCE_1_1.17
89   COMPRESSED_RGBA_ASTC_8x5_KHR,             ///< ASTC Linear color space with a 8x5 block-size. @SINCE_1_1.17
90   COMPRESSED_RGBA_ASTC_8x6_KHR,             ///< ASTC Linear color space with a 8x6 block-size. @SINCE_1_1.17
91   COMPRESSED_RGBA_ASTC_8x8_KHR,             ///< ASTC Linear color space with a 8x8 block-size. @SINCE_1_1.17
92   COMPRESSED_RGBA_ASTC_10x5_KHR,            ///< ASTC Linear color space with a 10x5 block-size. @SINCE_1_1.17
93   COMPRESSED_RGBA_ASTC_10x6_KHR,            ///< ASTC Linear color space with a 10x6 block-size. @SINCE_1_1.17
94   COMPRESSED_RGBA_ASTC_10x8_KHR,            ///< ASTC Linear color space with a 10x8 block-size. @SINCE_1_1.17
95   COMPRESSED_RGBA_ASTC_10x10_KHR,           ///< ASTC Linear color space with a 10x10 block-size. @SINCE_1_1.17
96   COMPRESSED_RGBA_ASTC_12x10_KHR,           ///< ASTC Linear color space with a 12x10 block-size. @SINCE_1_1.17
97   COMPRESSED_RGBA_ASTC_12x12_KHR,           ///< ASTC Linear color space with a 12x12 block-size. @SINCE_1_1.17
98   COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 4x4 block-size. @SINCE_1_1.17
99   COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 5x4 block-size. @SINCE_1_1.17
100   COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 5x5 block-size. @SINCE_1_1.17
101   COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 6x5 block-size. @SINCE_1_1.17
102   COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 6x6 block-size. @SINCE_1_1.17
103   COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 8x5 block-size. @SINCE_1_1.17
104   COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 8x6 block-size. @SINCE_1_1.17
105   COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,     ///< ASTC Non-linear (gamma-corrected) color space with a 8x8 block-size. @SINCE_1_1.17
106   COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,    ///< ASTC Non-linear (gamma-corrected) color space with a 10x5 block-size. @SINCE_1_1.17
107   COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,    ///< ASTC Non-linear (gamma-corrected) color space with a 10x6 block-size. @SINCE_1_1.17
108   COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,    ///< ASTC Non-linear (gamma-corrected) color space with a 10x8 block-size. @SINCE_1_1.17
109   COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,   ///< ASTC Non-linear (gamma-corrected) color space with a 10x10 block-size. @SINCE_1_1.17
110   COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,   ///< ASTC Non-linear (gamma-corrected) color space with a 12x10 block-size. @SINCE_1_1.17
111   COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,   ///< ASTC Non-linear (gamma-corrected) color space with a 12x12 block-size. @SINCE_1_1.17
112
113   // GLES 3.0 floating point formats.
114   RGB16F, ///< Color depth 48-bit, 16-16-16 half floating point. @SINCE_1_2.60
115   RGB32F, ///< Color depth 96-bit, 32-32-32 floating point. @SINCE_1_2.60
116
117   ///! Update LAST_VALID_PIXEL_FORMAT below if you add an enum value here.
118 };
119
120 /**
121  * @brief For asserting that a variable has a valid pixel format.
122  *
123  * Sync it to the first value above.
124  */
125 const Format FIRST_VALID_PIXEL_FORMAT = A8;
126
127 /**
128  * @brief For asserting that a variable has a valid pixel format.
129  *
130  * Sync it to the last value above.
131  */
132 const Format LAST_VALID_PIXEL_FORMAT = RGB32F;
133
134 /**
135  * @brief Whether specified pixel format contains an alpha value.
136  *
137  * @SINCE_1_0.0
138  * @param[in] pixelformat Pixel format
139  * @return @c true if format has alpha, @c false otherwise
140  */
141 DALI_CORE_API bool HasAlpha(Format pixelformat);
142
143 /**
144  * @brief Returns The number of bytes per pixel for the specified pixel format.
145  *
146  * @SINCE_1_0.0
147  * @param[in] pixelFormat The pixel format
148  * @return The number of bytes per pixel
149  */
150 DALI_CORE_API uint32_t GetBytesPerPixel(Format pixelFormat);
151
152 /**
153  * @brief Returns the offset of the byte containing the alpha value from the start of the pixel data
154  * and the bitmask of that byte to get the alpha value.
155  *
156  * For example, in case of Pixel::RGBA4444, byteOffset value is 1 and bitMask value is 0x0f.
157  * It means the second byte contains the alpha value and the last 4 bits of the byte is the alpha value.
158  *
159  * Bitmask is zero if the pixelFormat does not support alpha.
160  * @SINCE_1_0.0
161  * @param[in]  pixelFormat The pixel format
162  * @param[out] byteOffset The byte offset of the byte containing the alpha value
163  * @param[out] bitMask The bitmask of the byte to get the alpha value
164  *
165  */
166 DALI_CORE_API void GetAlphaOffsetAndMask(Format pixelFormat, int& byteOffset, int& bitMask);
167
168 } //namespace Pixel
169
170 /**
171  * @}
172  */
173 } // namespace Dali
174
175 #endif // __DALI_PIXEL_H__