Dali 3D User Interface Engine
bitmap.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 // CLASS HEADER
20 
21 // INTERNAL INCLUDES
29 
30 namespace Dali
31 {
32 
33 namespace Integration
34 {
35 using namespace Dali::Pixel;
36 
37 void ConvertToGlFormat( Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat )
38 {
39  // Compressed textures have no pixelDataType, so init to an invalid value:
40  pixelDataType = -1;
41 
42  switch( pixelformat )
43  {
44  case A8:
45  {
46  pixelDataType = GL_UNSIGNED_BYTE;
47  internalFormat= GL_ALPHA;
48  break;
49  }
50 
51  case L8:
52  {
53  pixelDataType = GL_UNSIGNED_BYTE;
54  internalFormat= GL_LUMINANCE;
55  break;
56  }
57 
58  case LA88:
59  {
60  pixelDataType = GL_UNSIGNED_BYTE;
61  internalFormat= GL_LUMINANCE_ALPHA;
62  break;
63  }
64 
65  case RGB565:
66  {
67  pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
68  internalFormat= GL_RGB;
69  break;
70  }
71 
72  case BGR565:
73  {
74  DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
75  pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
76 #ifdef _ARCH_ARM_
77  internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
78 #else
79  internalFormat= GL_RGBA; // alpha is reserved but not used
80 #endif
81  break;
82  }
83 
84  case RGBA4444:
85  {
86  pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
87  internalFormat= GL_RGBA;
88  break;
89  }
90 
91  case BGRA4444:
92  {
93  DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
94  pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
95 #ifdef _ARCH_ARM_
96  internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
97 #else
98  internalFormat= GL_RGBA; // alpha is reserved but not used
99 #endif
100  break;
101  }
102 
103  case RGBA5551:
104  {
105  pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
106  internalFormat= GL_RGBA;
107  break;
108  }
109 
110  case BGRA5551:
111  {
112  DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
113  pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
114 #ifdef _ARCH_ARM_
115  internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
116 #else
117  internalFormat= GL_RGBA; // alpha is reserved but not used
118 #endif
119  break;
120  }
121 
122  case RGB888:
123  {
124  pixelDataType = GL_UNSIGNED_BYTE;
125  internalFormat= GL_RGB;
126  break;
127  }
128 
129  case RGB8888:
130  {
131  pixelDataType = GL_UNSIGNED_BYTE;
132  internalFormat= GL_RGBA; // alpha is reserved but not used
133  break;
134  }
135 
136  case BGR8888:
137  {
138  pixelDataType = GL_UNSIGNED_BYTE;
139 #ifdef GL_BGRA_EXT
140  internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
141 #else
142  internalFormat= GL_RGBA; // alpha is reserved but not used
143 #endif
144  break;
145  }
146 
147  case RGBA8888:
148  {
149  pixelDataType = GL_UNSIGNED_BYTE;
150  internalFormat= GL_RGBA;
151  break;
152  }
153 
154  case BGRA8888:
155  {
156  pixelDataType = GL_UNSIGNED_BYTE;
157 #ifdef GL_BGRA_EXT
158  internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
159 #else
160  internalFormat= GL_RGBA; // alpha is reserved but not used
161 #endif
162  break;
163  }
164 
165  // GLES 2 extension compressed formats:
167  {
168  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n" );
169  internalFormat = 0x8D64;
170  break;
171  }
173  {
174  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n" );
175  internalFormat = 0x8C00;
176  break;
177  }
178 
179  // GLES 3.0 standard compressed formats:
180  case COMPRESSED_R11_EAC:
181  {
182  DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
183  internalFormat = GL_COMPRESSED_R11_EAC;
184  break;
185  }
187  {
188  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n" );
189  internalFormat = GL_COMPRESSED_SIGNED_R11_EAC;
190  break;
191  }
192  case COMPRESSED_RG11_EAC:
193  {
194  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n" );
195  internalFormat = GL_COMPRESSED_RG11_EAC;
196  break;
197  }
199  {
200  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n" );
201  internalFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
202  break;
203  }
205  {
206  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n" );
207  internalFormat = GL_COMPRESSED_RGB8_ETC2;
208  break;
209  }
211  {
212  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n" );
213  internalFormat = GL_COMPRESSED_SRGB8_ETC2;
214  break;
215  }
217  {
218  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
220  break;
221  }
223  {
224  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
226  break;
227  }
229  {
230  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n" );
231  internalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
232  break;
233  }
235  {
236  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n" );
237  internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
238  break;
239  }
240 
241  // GLES 3.1 extension compressed formats:
243  {
244  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_4x4_KHR.\n" );
245  internalFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
246  break;
247  }
249  {
250  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x4_KHR.\n" );
251  internalFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
252  break;
253  }
255  {
256  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x5_KHR.\n" );
257  internalFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
258  break;
259  }
261  {
262  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x5_KHR.\n" );
263  internalFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
264  break;
265  }
267  {
268  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x6_KHR.\n" );
269  internalFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
270  break;
271  }
273  {
274  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x5_KHR.\n" );
275  internalFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
276  break;
277  }
279  {
280  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x6_KHR.\n" );
281  internalFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
282  break;
283  }
285  {
286  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x8_KHR.\n" );
287  internalFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
288  break;
289  }
291  {
292  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x5_KHR.\n" );
293  internalFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
294  break;
295  }
297  {
298  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x6_KHR.\n" );
299  internalFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
300  break;
301  }
303  {
304  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x8_KHR.\n" );
305  internalFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
306  break;
307  }
309  {
310  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x10_KHR.\n" );
311  internalFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
312  break;
313  }
315  {
316  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x10_KHR.\n" );
317  internalFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
318  break;
319  }
321  {
322  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x12_KHR.\n" );
323  internalFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
324  break;
325  }
327  {
328  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR.\n" );
330  break;
331  }
333  {
334  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR.\n" );
336  break;
337  }
339  {
340  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR.\n" );
342  break;
343  }
345  {
346  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR.\n" );
348  break;
349  }
351  {
352  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR.\n" );
354  break;
355  }
357  {
358  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR.\n" );
360  break;
361  }
363  {
364  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR.\n" );
366  break;
367  }
369  {
370  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR.\n" );
372  break;
373  }
375  {
376  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR.\n" );
378  break;
379  }
381  {
382  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR.\n" );
384  break;
385  }
387  {
388  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR.\n" );
390  break;
391  }
393  {
394  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR.\n" );
396  break;
397  }
399  {
400  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR.\n" );
402  break;
403  }
405  {
406  DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR.\n" );
408  break;
409  }
410 
411  case INVALID:
412  {
413  DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
414  internalFormat = 0;
415  break;
416  }
417  }
418 }
419 
420 Bitmap* Bitmap::New( const Profile profile = BITMAP_2D_PACKED_PIXELS,
422 {
423  DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
424 
425  switch( profile )
426  {
431  case BITMAP_2D_PACKED_PIXELS:
432  {
433  Bitmap * const bitmap = new Dali::Internal::BitmapPackedPixel( discardable );
434  return bitmap;
435  }
436 
438  case BITMAP_COMPRESSED:
439  {
440  return new Dali::Internal::BitmapCompressed( discardable );
441  }
442  }
443  return 0;
444 }
445 
446 
448 : mImageWidth(0),
449  mImageHeight(0),
450  mPixelFormat(Pixel::RGBA8888),
451  mHasAlphaChannel(true),
452  mAlphaChannelUsed(true),
453  mData(pixBuf),
454  mDiscardable(discardable)
455 {
456 }
457 
459 {
460  PixelBuffer* buffer = mData;
461  mData = NULL;
462  return buffer;
463 }
464 
466 {
468  {
470  }
471 }
472 
474 {
475  DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
477 }
478 
482 {
483  if( !mData )
484  {
485  return;
486  }
487  free ( mData );
488  mData = NULL;
489 }
490 
491 
493  unsigned int width,
494  unsigned int height)
495 {
496  DALI_ASSERT_DEBUG(width * height < (32 * 1024) * (32 * 1024) && "The total area of the bitmap is too great.\n");
497  mImageWidth = width;
499  mPixelFormat = pixelFormat;
500 
501  mHasAlphaChannel = Pixel::HasAlpha(pixelFormat);
502 }
503 
504 } //namespace Integration
505 
506 } //namespace Dali
Dali Docs Home
Read more about Dali