Merge "Allow multiple renderers per Actor and sharing renderers between actors" into...
[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) 2015 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   // GLES 3 Standard compressed formats:
59   COMPRESSED_R11_EAC,                       ///< ETC2 / EAC single-channel, unsigned
60   COMPRESSED_SIGNED_R11_EAC,                ///< ETC2 / EAC single-channel, signed
61   COMPRESSED_RG11_EAC,                      ///< ETC2 / EAC dual-channel, unsigned
62   COMPRESSED_SIGNED_RG11_EAC,               ///< ETC2 / EAC dual-channel, signed
63   COMPRESSED_RGB8_ETC2,                     ///< ETC2 / EAC RGB
64   COMPRESSED_SRGB8_ETC2,                    ///< ETC2 / EAC RGB using sRGB colourspace.
65   COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, ///< ETC2 / EAC RGB with single bit per pixel alpha mask.
66   COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,///< ETC2 / EAC RGB using sRGB colourspace, with single bit per pixel alpha mask.
67   COMPRESSED_RGBA8_ETC2_EAC,                ///< ETC2 / EAC RGB plus separate alpha channel.
68   COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,         ///< ETC2 / EAC RGB using sRGB colourspace, plus separate alpha channel.
69   // GLES 2 extension compressed formats:
70   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
71   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
72   ///! Update LAST_VALID_PIXEL_FORMAT below if you add an enum value here.
73 };
74
75 /**
76  * @brief For asserting that a variable has a valid pixel format.
77  *
78  * Sync it to the first value above.
79  */
80 const Format FIRST_VALID_PIXEL_FORMAT = A8;
81
82 /**
83  * @brief For asserting that a variable has a valid pixel format.
84  *
85  * Sync it to the last value above.
86  */
87 const Format LAST_VALID_PIXEL_FORMAT = COMPRESSED_RGB_PVRTC_4BPPV1;
88
89 /**
90  * @brief Whether specified pixel format contains an alpha value.
91  *
92  * @param [in] pixelformat pixel format
93  * @return true if format has alpha, false otherwise
94  */
95 DALI_IMPORT_API bool HasAlpha(Format pixelformat);
96
97 /**
98  * @brief Returns The number of bytes per pixel for the specified pixel format.
99  *
100  * @param [in] pixelFormat The pixel format
101  * @return The number of bytes per pixel
102  */
103 DALI_IMPORT_API unsigned int GetBytesPerPixel(Format pixelFormat);
104
105 /**
106  * @brief Returns the offset of the byte containing the alpha value from the start of the pixel data
107  * and the bitmask of that byte to get the alpha value.
108  * For example, in case of RGBA4444, byteOffset value is 1 and bitMask value is 0x0f.
109  * It means the second byte contains the alpha value and the last 4 bits of the byte is the alpha value.
110  *
111  * Bitmask is zero if the pixelFormat does not support alpha
112  * @param[in]  pixelFormat the pixel format
113  * @param[out] byteOffset the byte offset of the byte containing the alpha value
114  * @param[out] bitMask the bitmask of the byte to get the alpha value
115  */
116 DALI_IMPORT_API void GetAlphaOffsetAndMask(Format pixelFormat, int& byteOffset, int& bitMask);
117
118 } //namespace Pixel
119
120 /**
121  * @}
122  */
123 } // namespace Dali
124
125 #endif // __DALI_PIXEL_H__