[dali_2.3.32] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / integration-api / bitmap.cpp
1 /*
2  * Copyright (c) 2024 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
19 #include <dali/integration-api/bitmap.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/integration-api/debug.h>
23 #include <dali/integration-api/gl-defines.h>
24 #include <dali/integration-api/platform-abstraction.h>
25 #include <dali/internal/event/common/thread-local-storage.h>
26 #include <dali/internal/event/images/bitmap-compressed.h>
27 #include <dali/internal/event/images/bitmap-packed-pixel.h>
28
29 namespace Dali
30 {
31 namespace Integration
32 {
33 using namespace Dali::Pixel;
34
35 void ConvertToGlFormat(Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat)
36 {
37   // Compressed textures have no pixelDataType, so init to an invalid value:
38   pixelDataType = GL_INVALID_VALUE;
39
40   switch(pixelformat)
41   {
42     case A8:
43     {
44       pixelDataType  = GL_UNSIGNED_BYTE;
45       internalFormat = GL_ALPHA;
46       break;
47     }
48
49     case L8:
50     {
51       pixelDataType  = GL_UNSIGNED_BYTE;
52       internalFormat = GL_LUMINANCE;
53       break;
54     }
55
56     case LA88:
57     {
58       pixelDataType  = GL_UNSIGNED_BYTE;
59       internalFormat = GL_LUMINANCE_ALPHA;
60       break;
61     }
62
63     case RGB565:
64     {
65       pixelDataType  = GL_UNSIGNED_SHORT_5_6_5;
66       internalFormat = GL_RGB;
67       break;
68     }
69
70     case BGR565:
71     {
72       DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
73       pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
74 #ifdef _ARCH_ARM_
75       internalFormat = GL_BGRA_EXT; // alpha is reserved but not used
76 #else
77       internalFormat = GL_RGBA; // alpha is reserved but not used
78 #endif
79       break;
80     }
81
82     case RGBA4444:
83     {
84       pixelDataType  = GL_UNSIGNED_SHORT_4_4_4_4;
85       internalFormat = GL_RGBA;
86       break;
87     }
88
89     case BGRA4444:
90     {
91       DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
92       pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
93 #ifdef _ARCH_ARM_
94       internalFormat = GL_BGRA_EXT; // alpha is reserved but not used
95 #else
96       internalFormat = GL_RGBA; // alpha is reserved but not used
97 #endif
98       break;
99     }
100
101     case RGBA5551:
102     {
103       pixelDataType  = GL_UNSIGNED_SHORT_5_5_5_1;
104       internalFormat = GL_RGBA;
105       break;
106     }
107
108     case BGRA5551:
109     {
110       DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
111       pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
112 #ifdef _ARCH_ARM_
113       internalFormat = GL_BGRA_EXT; // alpha is reserved but not used
114 #else
115       internalFormat = GL_RGBA; // alpha is reserved but not used
116 #endif
117       break;
118     }
119
120     case RGB888:
121     {
122       pixelDataType  = GL_UNSIGNED_BYTE;
123       internalFormat = GL_RGB;
124       break;
125     }
126
127     case RGB8888:
128     {
129       pixelDataType  = GL_UNSIGNED_BYTE;
130       internalFormat = GL_RGBA; // alpha is reserved but not used
131       break;
132     }
133
134     case BGR8888:
135     {
136       pixelDataType = GL_UNSIGNED_BYTE;
137 #ifdef GL_BGRA_EXT
138       internalFormat = GL_BGRA_EXT; // alpha is reserved but not used
139 #else
140       internalFormat = GL_RGBA; // alpha is reserved but not used
141 #endif
142       break;
143     }
144
145     case RGBA8888:
146     {
147       pixelDataType  = GL_UNSIGNED_BYTE;
148       internalFormat = GL_RGBA;
149       break;
150     }
151
152     case BGRA8888:
153     {
154       pixelDataType = GL_UNSIGNED_BYTE;
155 #ifdef GL_BGRA_EXT
156       internalFormat = GL_BGRA_EXT; // alpha is reserved but not used
157 #else
158       internalFormat = GL_RGBA; // alpha is reserved but not used
159 #endif
160       break;
161     }
162
163     // GLES 2 extension compressed formats:
164     case COMPRESSED_RGB8_ETC1:
165     {
166       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n");
167       internalFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
168       break;
169     }
170     case COMPRESSED_RGB_PVRTC_4BPPV1:
171     {
172       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n");
173       internalFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
174       break;
175     }
176
177     // GLES 3.0 standard compressed formats:
178     case COMPRESSED_R11_EAC:
179     {
180       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
181       internalFormat = GL_COMPRESSED_R11_EAC;
182       break;
183     }
184     case COMPRESSED_SIGNED_R11_EAC:
185     {
186       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n");
187       internalFormat = GL_COMPRESSED_SIGNED_R11_EAC;
188       break;
189     }
190     case COMPRESSED_RG11_EAC:
191     {
192       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n");
193       internalFormat = GL_COMPRESSED_RG11_EAC;
194       break;
195     }
196     case COMPRESSED_SIGNED_RG11_EAC:
197     {
198       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n");
199       internalFormat = GL_COMPRESSED_SIGNED_RG11_EAC;
200       break;
201     }
202     case COMPRESSED_RGB8_ETC2:
203     {
204       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n");
205       internalFormat = GL_COMPRESSED_RGB8_ETC2;
206       break;
207     }
208     case COMPRESSED_SRGB8_ETC2:
209     {
210       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n");
211       internalFormat = GL_COMPRESSED_SRGB8_ETC2;
212       break;
213     }
214     case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
215     {
216       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n");
217       internalFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
218       break;
219     }
220     case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
221     {
222       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n");
223       internalFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
224       break;
225     }
226     case COMPRESSED_RGBA8_ETC2_EAC:
227     {
228       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n");
229       internalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
230       break;
231     }
232     case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
233     {
234       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n");
235       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
236       break;
237     }
238
239     // GLES 3.1 extension compressed formats:
240     case COMPRESSED_RGBA_ASTC_4x4_KHR:
241     {
242       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_4x4_KHR.\n");
243       internalFormat = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
244       break;
245     }
246     case COMPRESSED_RGBA_ASTC_5x4_KHR:
247     {
248       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x4_KHR.\n");
249       internalFormat = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
250       break;
251     }
252     case COMPRESSED_RGBA_ASTC_5x5_KHR:
253     {
254       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_5x5_KHR.\n");
255       internalFormat = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
256       break;
257     }
258     case COMPRESSED_RGBA_ASTC_6x5_KHR:
259     {
260       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x5_KHR.\n");
261       internalFormat = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
262       break;
263     }
264     case COMPRESSED_RGBA_ASTC_6x6_KHR:
265     {
266       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_6x6_KHR.\n");
267       internalFormat = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
268       break;
269     }
270     case COMPRESSED_RGBA_ASTC_8x5_KHR:
271     {
272       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x5_KHR.\n");
273       internalFormat = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
274       break;
275     }
276     case COMPRESSED_RGBA_ASTC_8x6_KHR:
277     {
278       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x6_KHR.\n");
279       internalFormat = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
280       break;
281     }
282     case COMPRESSED_RGBA_ASTC_8x8_KHR:
283     {
284       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_8x8_KHR.\n");
285       internalFormat = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
286       break;
287     }
288     case COMPRESSED_RGBA_ASTC_10x5_KHR:
289     {
290       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x5_KHR.\n");
291       internalFormat = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
292       break;
293     }
294     case COMPRESSED_RGBA_ASTC_10x6_KHR:
295     {
296       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x6_KHR.\n");
297       internalFormat = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
298       break;
299     }
300     case COMPRESSED_RGBA_ASTC_10x8_KHR:
301     {
302       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x8_KHR.\n");
303       internalFormat = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
304       break;
305     }
306     case COMPRESSED_RGBA_ASTC_10x10_KHR:
307     {
308       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_10x10_KHR.\n");
309       internalFormat = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
310       break;
311     }
312     case COMPRESSED_RGBA_ASTC_12x10_KHR:
313     {
314       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x10_KHR.\n");
315       internalFormat = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
316       break;
317     }
318     case COMPRESSED_RGBA_ASTC_12x12_KHR:
319     {
320       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_RGBA_ASTC_12x12_KHR.\n");
321       internalFormat = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
322       break;
323     }
324     case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
325     {
326       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR.\n");
327       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
328       break;
329     }
330     case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
331     {
332       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR.\n");
333       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
334       break;
335     }
336     case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
337     {
338       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR.\n");
339       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
340       break;
341     }
342     case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
343     {
344       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR.\n");
345       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
346       break;
347     }
348     case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
349     {
350       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR.\n");
351       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
352       break;
353     }
354     case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
355     {
356       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR.\n");
357       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
358       break;
359     }
360     case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
361     {
362       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR.\n");
363       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
364       break;
365     }
366     case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
367     {
368       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR.\n");
369       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
370       break;
371     }
372     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
373     {
374       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR.\n");
375       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
376       break;
377     }
378     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
379     {
380       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR.\n");
381       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
382       break;
383     }
384     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
385     {
386       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR.\n");
387       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
388       break;
389     }
390     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
391     {
392       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR.\n");
393       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
394       break;
395     }
396     case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
397     {
398       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR.\n");
399       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
400       break;
401     }
402     case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
403     {
404       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.1 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR.\n");
405       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
406       break;
407     }
408
409     // GLES 3.0 floating point formats.
410     case RGB16F:
411     {
412       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 GLES 3.0 floating point format.\n");
413       pixelDataType  = GL_HALF_FLOAT;
414       internalFormat = GL_RGB;
415       break;
416     }
417     case RGB32F:
418     {
419       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 GLES 3.0 floating point format.\n");
420       pixelDataType  = GL_FLOAT;
421       internalFormat = GL_RGB;
422       break;
423     }
424     case R11G11B10F:
425     {
426       DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 GLES 3.0 floating point format.\n");
427       pixelDataType  = GL_FLOAT;
428       internalFormat = GL_R11F_G11F_B10F;
429       break;
430     }
431
432     // GLES 3.0 depth and stencil formats
433     case Pixel::DEPTH_UNSIGNED_INT:
434     {
435       pixelDataType  = GL_UNSIGNED_INT;
436       internalFormat = GL_DEPTH_COMPONENT;
437       break;
438     }
439     case Pixel::DEPTH_FLOAT:
440     {
441       pixelDataType  = GL_FLOAT;
442       internalFormat = GL_DEPTH_COMPONENT;
443       break;
444     }
445     case Pixel::DEPTH_STENCIL:
446     {
447       pixelDataType  = GL_UNSIGNED_INT_24_8;
448       internalFormat = GL_DEPTH_STENCIL;
449       break;
450     }
451
452     // Chrominance formats
453     case Pixel::CHROMINANCE_U:
454     {
455       pixelDataType  = GL_UNSIGNED_BYTE;
456       internalFormat = GL_LUMINANCE; // GL doesn't support chrominance format. We should convert it in the shader.
457       break;
458     }
459     case Pixel::CHROMINANCE_V:
460     {
461       pixelDataType  = GL_UNSIGNED_BYTE;
462       internalFormat = GL_LUMINANCE; // GL doesn't support chrominance format. We should convert it in the shader.
463       break;
464     }
465
466     case INVALID:
467     {
468       DALI_LOG_ERROR("Invalid pixel format for bitmap\n");
469       internalFormat = 0;
470       break;
471     }
472   }
473 }
474
475 Bitmap* Bitmap::New(const Profile               profile     = BITMAP_2D_PACKED_PIXELS,
476                     ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_DISCARD)
477 {
478   DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
479
480   switch(profile)
481   {
482     /** A 2D array of pixels where each pixel is a whole number of bytes
483      * and each scanline of the backing memory buffer may have additional
484      * bytes off the right edge if requested, and there may be additional
485      * scanlines past the bottom of the image in the buffer if requested.*/
486     case BITMAP_2D_PACKED_PIXELS:
487     {
488       Bitmap* const bitmap = new Dali::Internal::BitmapPackedPixel(discardable);
489       return bitmap;
490     }
491
492     /** The data for the bitmap is buffered in an opaque form.*/
493     case BITMAP_COMPRESSED:
494     {
495       return new Dali::Internal::BitmapCompressed(discardable);
496     }
497   }
498   return nullptr;
499 }
500
501 Bitmap::Bitmap(ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf)
502 : mImageWidth(0),
503   mImageHeight(0),
504   mPixelFormat(Pixel::RGBA8888),
505   mHasAlphaChannel(true),
506   mAlphaChannelUsed(true),
507   mData(pixBuf),
508   mDiscardable(discardable)
509 {
510 }
511
512 PixelBuffer* Bitmap::GetBufferOwnership()
513 {
514   PixelBuffer* buffer = mData;
515   mData               = nullptr;
516   return buffer;
517 }
518
519 void Bitmap::DiscardBuffer()
520 {
521   if(mDiscardable == ResourcePolicy::OWNED_DISCARD)
522   {
523     DeletePixelBuffer();
524   }
525 }
526
527 Bitmap::~Bitmap()
528 {
529   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
530   DeletePixelBuffer();
531 }
532
533 /**
534  * */
535 void Bitmap::DeletePixelBuffer()
536 {
537   if(!mData)
538   {
539     return;
540   }
541   free(mData);
542   mData = nullptr;
543 }
544
545 void Bitmap::Initialize(Pixel::Format pixelFormat,
546                         unsigned int  width,
547                         unsigned int  height)
548 {
549   DALI_ASSERT_DEBUG(width * height < (32 * 1024) * (32 * 1024) && "The total area of the bitmap is too great.\n");
550   mImageWidth  = width;
551   mImageHeight = height;
552   mPixelFormat = pixelFormat;
553
554   mHasAlphaChannel = Pixel::HasAlpha(pixelFormat);
555 }
556
557 } //namespace Integration
558
559 } //namespace Dali