2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/images/pixel.h>
22 #include <dali/integration-api/debug.h>
23 #include <dali/public-api/common/dali-common.h>
27 bool Pixel::HasAlpha(Format pixelformat)
39 // Note, Can be used for alpha if you want: COMPRESSED_R11_EAC, ///< ETC2 / EAC single-channel, unsigned
40 // Note, Can be used for alpha if you want: COMPRESSED_SIGNED_R11_EAC, ///< ETC2 / EAC single-channel, signed
41 case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
42 case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
43 case COMPRESSED_RGBA8_ETC2_EAC:
44 case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
45 case COMPRESSED_RGBA_ASTC_4x4_KHR:
46 case COMPRESSED_RGBA_ASTC_5x4_KHR:
47 case COMPRESSED_RGBA_ASTC_5x5_KHR:
48 case COMPRESSED_RGBA_ASTC_6x5_KHR:
49 case COMPRESSED_RGBA_ASTC_6x6_KHR:
50 case COMPRESSED_RGBA_ASTC_8x5_KHR:
51 case COMPRESSED_RGBA_ASTC_8x6_KHR:
52 case COMPRESSED_RGBA_ASTC_8x8_KHR:
53 case COMPRESSED_RGBA_ASTC_10x5_KHR:
54 case COMPRESSED_RGBA_ASTC_10x6_KHR:
55 case COMPRESSED_RGBA_ASTC_10x8_KHR:
56 case COMPRESSED_RGBA_ASTC_10x10_KHR:
57 case COMPRESSED_RGBA_ASTC_12x10_KHR:
58 case COMPRESSED_RGBA_ASTC_12x12_KHR:
59 case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
60 case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
61 case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
62 case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
63 case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
64 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
65 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
66 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
67 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
68 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
69 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
70 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
71 case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
72 case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
80 case RGB8888: // alpha not used
81 case BGR8888: // alpha not used
83 case COMPRESSED_R11_EAC:
84 case COMPRESSED_SIGNED_R11_EAC:
85 case COMPRESSED_RG11_EAC:
86 case COMPRESSED_SIGNED_RG11_EAC:
87 case COMPRESSED_RGB8_ETC2:
88 case COMPRESSED_SRGB8_ETC2:
89 case COMPRESSED_RGB8_ETC1:
90 case COMPRESSED_RGB_PVRTC_4BPPV1:
93 case DEPTH_UNSIGNED_INT:
105 uint32_t Pixel::GetBytesPerPixel(Format pixelFormat)
135 case DEPTH_UNSIGNED_INT:
153 case COMPRESSED_R11_EAC:
154 case COMPRESSED_SIGNED_R11_EAC:
155 case COMPRESSED_RG11_EAC:
156 case COMPRESSED_SIGNED_RG11_EAC:
157 case COMPRESSED_RGB8_ETC2:
158 case COMPRESSED_SRGB8_ETC2:
159 case COMPRESSED_RGB8_ETC1:
160 case COMPRESSED_RGB_PVRTC_4BPPV1:
161 case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
162 case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
163 case COMPRESSED_RGBA8_ETC2_EAC:
164 case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
165 case COMPRESSED_RGBA_ASTC_4x4_KHR:
166 case COMPRESSED_RGBA_ASTC_5x4_KHR:
167 case COMPRESSED_RGBA_ASTC_5x5_KHR:
168 case COMPRESSED_RGBA_ASTC_6x5_KHR:
169 case COMPRESSED_RGBA_ASTC_6x6_KHR:
170 case COMPRESSED_RGBA_ASTC_8x5_KHR:
171 case COMPRESSED_RGBA_ASTC_8x6_KHR:
172 case COMPRESSED_RGBA_ASTC_8x8_KHR:
173 case COMPRESSED_RGBA_ASTC_10x5_KHR:
174 case COMPRESSED_RGBA_ASTC_10x6_KHR:
175 case COMPRESSED_RGBA_ASTC_10x8_KHR:
176 case COMPRESSED_RGBA_ASTC_10x10_KHR:
177 case COMPRESSED_RGBA_ASTC_12x10_KHR:
178 case COMPRESSED_RGBA_ASTC_12x12_KHR:
179 case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
180 case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
181 case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
182 case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
183 case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
184 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
185 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
186 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
187 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
188 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
189 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
190 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
191 case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
192 case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
195 DALI_LOG_ERROR("Pixel formats for compressed images do not have meaningful integer bits per pixel values.\n");
202 void Pixel::GetAlphaOffsetAndMask(Format pixelFormat, int& byteOffset, int& bitMask)
256 case COMPRESSED_R11_EAC:
257 case COMPRESSED_SIGNED_R11_EAC:
258 case COMPRESSED_RG11_EAC:
259 case COMPRESSED_SIGNED_RG11_EAC:
260 case COMPRESSED_RGB8_ETC2:
261 case COMPRESSED_SRGB8_ETC2:
262 case COMPRESSED_RGB8_ETC1:
263 case COMPRESSED_RGB_PVRTC_4BPPV1:
264 case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
265 case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
266 case COMPRESSED_RGBA8_ETC2_EAC:
267 case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
268 case COMPRESSED_RGBA_ASTC_4x4_KHR:
269 case COMPRESSED_RGBA_ASTC_5x4_KHR:
270 case COMPRESSED_RGBA_ASTC_5x5_KHR:
271 case COMPRESSED_RGBA_ASTC_6x5_KHR:
272 case COMPRESSED_RGBA_ASTC_6x6_KHR:
273 case COMPRESSED_RGBA_ASTC_8x5_KHR:
274 case COMPRESSED_RGBA_ASTC_8x6_KHR:
275 case COMPRESSED_RGBA_ASTC_8x8_KHR:
276 case COMPRESSED_RGBA_ASTC_10x5_KHR:
277 case COMPRESSED_RGBA_ASTC_10x6_KHR:
278 case COMPRESSED_RGBA_ASTC_10x8_KHR:
279 case COMPRESSED_RGBA_ASTC_10x10_KHR:
280 case COMPRESSED_RGBA_ASTC_12x10_KHR:
281 case COMPRESSED_RGBA_ASTC_12x12_KHR:
282 case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
283 case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
284 case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
285 case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
286 case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
287 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
288 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
289 case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
290 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
291 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
292 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
293 case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
294 case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
295 case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
298 case DEPTH_UNSIGNED_INT:
304 DALI_LOG_ERROR("Pixel formats are not compatible with simple masking-out of per-pixel alpha.\n");