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