Tizen 2.4.0 rev3 SDK Public Release
[framework/graphics/dali.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  * @since_tizen 2.4
34  */
35 namespace Pixel
36 {
37 /**
38  * @brief Pixel formats
39  *
40  * Pixel format, default color depth is RGBA 32 bit with alpha
41  * @since_tizen 2.4
42  * @note BufferImage::Update might not work with BGR/BGRA formats!
43  */
44 enum Format
45 {
46   // Start at > 0 to distinguish null data:
47   A8 = 1,          ///< color depth 8-bit, alpha @since_tizen 2.4
48   L8,              ///< color depth 8-bit, luminance @since_tizen 2.4
49   LA88,            ///< color depth 16-bit, luminance with 8 bit alpha @since_tizen 2.4
50   RGB565,          ///< color depth 16 bit, 5-6-5 @since_tizen 2.4
51   BGR565,          ///< color depth 16 bit, 5-6-5 @since_tizen 2.4
52   RGBA4444,        ///< color depth 16 bit with alpha, 4-4-4-4 @since_tizen 2.4
53   BGRA4444,        ///< color depth 16 bit with alpha, 4-4-4-4 @since_tizen 2.4
54   RGBA5551,        ///< color depth 16 bit with alpha, 5-5-5-1 @since_tizen 2.4
55   BGRA5551,        ///< color depth 16 bit with alpha, 5-5-5-1 @since_tizen 2.4
56   RGB888,          ///< color depth 24 bit, 8-8-8 @since_tizen 2.4
57   RGB8888,         ///< color depth 32 bit, alpha is reserved but not used, 8-8-8-8# @since_tizen 2.4
58   BGR8888,         ///< color depth 32 bit, alpha is reserved but not used, 8-8-8-8# @since_tizen 2.4
59   RGBA8888,        ///< color depth 32 bit with alpha, 8-8-8-8 @since_tizen 2.4
60   BGRA8888,        ///< color depth 32 bit with alpha, 8-8-8-8 @since_tizen 2.4
61   // GLES 3 Standard compressed formats:
62   COMPRESSED_R11_EAC,                       ///< ETC2 / EAC single-channel, unsigned @since_tizen 2.4
63   COMPRESSED_SIGNED_R11_EAC,                ///< ETC2 / EAC single-channel, signed @since_tizen 2.4
64   COMPRESSED_RG11_EAC,                      ///< ETC2 / EAC dual-channel, unsigned @since_tizen 2.4
65   COMPRESSED_SIGNED_RG11_EAC,               ///< ETC2 / EAC dual-channel, signed @since_tizen 2.4
66   COMPRESSED_RGB8_ETC2,                     ///< ETC2 / EAC RGB @since_tizen 2.4
67   COMPRESSED_SRGB8_ETC2,                    ///< ETC2 / EAC RGB using sRGB colourspace. @since_tizen 2.4
68   COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, ///< ETC2 / EAC RGB with single bit per pixel alpha mask. @since_tizen 2.4
69   COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,///< ETC2 / EAC RGB using sRGB colourspace, with single bit per pixel alpha mask. @since_tizen 2.4
70   COMPRESSED_RGBA8_ETC2_EAC,                ///< ETC2 / EAC RGB plus separate alpha channel. @since_tizen 2.4
71   COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,         ///< ETC2 / EAC RGB using sRGB colourspace, plus separate alpha channel. @since_tizen 2.4
72   // GLES 2 extension compressed formats:
73   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_tizen 2.4
74   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_tizen 2.4
75   ///! Update LAST_VALID_PIXEL_FORMAT below if you add an enum value here.
76 };
77
78 /**
79  * @brief For asserting that a variable has a valid pixel format.
80  *
81  * Sync it to the first value above.
82  */
83 const Format FIRST_VALID_PIXEL_FORMAT = A8;
84
85 /**
86  * @brief For asserting that a variable has a valid pixel format.
87  *
88  * Sync it to the last value above.
89  */
90 const Format LAST_VALID_PIXEL_FORMAT = COMPRESSED_RGB_PVRTC_4BPPV1;
91
92 /**
93  * @brief Whether specified pixel format contains an alpha value.
94  *
95  * @since_tizen 2.4
96  * @param [in] pixelformat Pixel format
97  * @return True if format has alpha, false otherwise
98  *
99  */
100 DALI_IMPORT_API bool HasAlpha(Format pixelformat);
101
102 /**
103  * @brief Returns The number of bytes per pixel for the specified pixel format.
104  *
105  * @since_tizen 2.4
106  * @param [in] pixelFormat The pixel format
107  * @return The number of bytes per pixel
108  *
109  */
110 DALI_IMPORT_API unsigned int GetBytesPerPixel(Format pixelFormat);
111
112 /**
113  * @brief Returns the offset of the byte containing the alpha value from the start of the pixel data
114  * and the bitmask of that byte to get the alpha value.
115  *
116  * For example, in case of Pixel::RGBA4444, byteOffset value is 1 and bitMask value is 0x0f.
117  * It means the second byte contains the alpha value and the last 4 bits of the byte is the alpha value.
118  *
119  * Bitmask is zero if the pixelFormat does not support alpha
120  * @since_tizen 2.4
121  * @param[in]  pixelFormat The pixel format
122  * @param[out] byteOffset The byte offset of the byte containing the alpha value
123  * @param[out] bitMask The bitmask of the byte to get the alpha value
124  *
125  */
126 DALI_IMPORT_API void GetAlphaOffsetAndMask(Format pixelFormat, int& byteOffset, int& bitMask);
127
128 } //namespace Pixel
129
130 /**
131  * @}
132  */
133 } // namespace Dali
134
135 #endif // __DALI_PIXEL_H__