794be9545048c55edde91ea2d6801678bfa16c0f
[platform/core/uifw/dali-core.git] / dali / integration-api / bitmap.cpp
1 /*
2  * Copyright (c) 2017 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/platform-abstraction.h>
24 #include <dali/internal/event/common/thread-local-storage.h>
25 #include <dali/internal/event/images/bitmap-packed-pixel.h>
26 #include <dali/internal/event/images/bitmap-compressed.h>
27 #include <dali/integration-api/gl-abstraction.h>
28 #include <dali/integration-api/gl-defines.h>
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:
166     case COMPRESSED_RGB8_ETC1:
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; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
170       break;
171     }
172     case COMPRESSED_RGB_PVRTC_4BPPV1:
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; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
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     }
186     case COMPRESSED_SIGNED_R11_EAC:
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     }
198     case COMPRESSED_SIGNED_RG11_EAC:
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     }
204     case COMPRESSED_RGB8_ETC2:
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     }
210     case COMPRESSED_SRGB8_ETC2:
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     }
216     case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
217     {
218       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
219       internalFormat = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
220       break;
221     }
222     case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
223     {
224       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
225       internalFormat = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
226       break;
227     }
228     case COMPRESSED_RGBA8_ETC2_EAC:
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     }
234     case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
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:
242     case COMPRESSED_RGBA_ASTC_4x4_KHR:
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     }
248     case COMPRESSED_RGBA_ASTC_5x4_KHR:
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     }
254     case COMPRESSED_RGBA_ASTC_5x5_KHR:
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     }
260     case COMPRESSED_RGBA_ASTC_6x5_KHR:
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     }
266     case COMPRESSED_RGBA_ASTC_6x6_KHR:
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     }
272     case COMPRESSED_RGBA_ASTC_8x5_KHR:
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     }
278     case COMPRESSED_RGBA_ASTC_8x6_KHR:
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     }
284     case COMPRESSED_RGBA_ASTC_8x8_KHR:
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     }
290     case COMPRESSED_RGBA_ASTC_10x5_KHR:
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     }
296     case COMPRESSED_RGBA_ASTC_10x6_KHR:
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     }
302     case COMPRESSED_RGBA_ASTC_10x8_KHR:
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     }
308     case COMPRESSED_RGBA_ASTC_10x10_KHR:
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     }
314     case COMPRESSED_RGBA_ASTC_12x10_KHR:
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     }
320     case COMPRESSED_RGBA_ASTC_12x12_KHR:
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     }
326     case COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
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" );
329       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
330       break;
331     }
332     case COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
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" );
335       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
336       break;
337     }
338     case COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
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" );
341       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
342       break;
343     }
344     case COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
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" );
347       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
348       break;
349     }
350     case COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
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" );
353       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
354       break;
355     }
356     case COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
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" );
359       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
360       break;
361     }
362     case COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
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" );
365       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
366       break;
367     }
368     case COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
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" );
371       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
372       break;
373     }
374     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
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" );
377       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
378       break;
379     }
380     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
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" );
383       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
384       break;
385     }
386     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
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" );
389       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
390       break;
391     }
392     case COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
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" );
395       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
396       break;
397     }
398     case COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
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" );
401       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
402       break;
403     }
404     case COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
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" );
407       internalFormat = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
408       break;
409     }
410
411     // GLES 3.0 floating point formats.
412     case RGB16F:
413     {
414       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 GLES 3.0 floating point format.\n" );
415       pixelDataType = GL_HALF_FLOAT;
416       internalFormat= GL_RGB;
417       break;
418     }
419     case RGB32F:
420     {
421       DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 GLES 3.0 floating point format.\n" );
422       pixelDataType = GL_FLOAT;
423       internalFormat= GL_RGB;
424       break;
425     }
426
427     // GLES 3.0 depth and stencil formats
428     case Pixel::DEPTH_UNSIGNED_INT:
429     {
430       pixelDataType = GL_UNSIGNED_INT;
431       internalFormat = GL_DEPTH_COMPONENT;
432       break;
433     }
434     case Pixel::DEPTH_FLOAT:
435     {
436       pixelDataType = GL_FLOAT;
437       internalFormat = GL_DEPTH_COMPONENT;
438       break;
439     }
440     case Pixel::DEPTH_STENCIL:
441     {
442       pixelDataType = GL_UNSIGNED_INT_24_8;
443       internalFormat = GL_DEPTH_STENCIL;
444       break;
445     }
446
447     case INVALID:
448     {
449       DALI_LOG_ERROR( "Invalid pixel format for bitmap\n" );
450       internalFormat = 0;
451       break;
452     }
453   }
454 }
455
456 Bitmap* Bitmap::New( const Profile profile = BITMAP_2D_PACKED_PIXELS,
457                      ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_DISCARD )
458 {
459   DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
460
461   switch( profile )
462   {
463     /** A 2D array of pixels where each pixel is a whole number of bytes
464      * and each scanline of the backing memory buffer may have additional
465      * bytes off the right edge if requested, and there may be additional
466      * scanlines past the bottom of the image in the buffer if requested.*/
467     case BITMAP_2D_PACKED_PIXELS:
468     {
469       Bitmap * const bitmap = new Dali::Internal::BitmapPackedPixel( discardable );
470       return bitmap;
471     }
472
473     /** The data for the bitmap is buffered in an opaque form.*/
474     case BITMAP_COMPRESSED:
475     {
476       return new Dali::Internal::BitmapCompressed( discardable );
477     }
478   }
479   return nullptr;
480 }
481
482
483 Bitmap::Bitmap( ResourcePolicy::Discardable discardable, Dali::Integration::PixelBuffer* pixBuf)
484 : mImageWidth(0),
485   mImageHeight(0),
486   mPixelFormat(Pixel::RGBA8888),
487   mHasAlphaChannel(true),
488   mAlphaChannelUsed(true),
489   mData(pixBuf),
490   mDiscardable(discardable)
491 {
492 }
493
494 PixelBuffer* Bitmap::GetBufferOwnership()
495 {
496   PixelBuffer* buffer = mData;
497   mData = nullptr;
498   return buffer;
499 }
500
501 void Bitmap::DiscardBuffer()
502 {
503   if( mDiscardable == ResourcePolicy::OWNED_DISCARD )
504   {
505     DeletePixelBuffer();
506   }
507 }
508
509 Bitmap::~Bitmap()
510 {
511   DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
512   DeletePixelBuffer();
513 }
514
515 /**
516  * */
517 void Bitmap::DeletePixelBuffer()
518 {
519   if( !mData )
520   {
521     return;
522   }
523   free ( mData );
524   mData = nullptr;
525 }
526
527
528 void Bitmap::Initialize( Pixel::Format pixelFormat,
529                           unsigned int width,
530                           unsigned int height)
531 {
532   DALI_ASSERT_DEBUG(width * height < (32 * 1024) * (32 * 1024) && "The total area of the bitmap is too great.\n");
533   mImageWidth   = width;
534   mImageHeight  = height;
535   mPixelFormat  = pixelFormat;
536
537   mHasAlphaChannel = Pixel::HasAlpha(pixelFormat);
538 }
539
540 } //namespace Integration
541
542 } //namespace Dali