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