2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/integration-api/bitmap.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/internal/event/images/bitmap-packed-pixel.h>
25 #include <dali/internal/event/images/bitmap-compressed.h>
26 #include <dali/internal/event/images/bitmap-external.h>
27 #include <dali/integration-api/gl-abstraction.h>
34 using namespace Dali::Pixel;
36 void ConvertToGlFormat( Format pixelformat, unsigned& pixelDataType, unsigned& internalFormat )
38 // Compressed textures have no pixelDataType, so init to an invalid value:
45 pixelDataType = GL_UNSIGNED_BYTE;
46 internalFormat= GL_ALPHA;
52 pixelDataType = GL_UNSIGNED_BYTE;
53 internalFormat= GL_LUMINANCE;
59 pixelDataType = GL_UNSIGNED_BYTE;
60 internalFormat= GL_LUMINANCE_ALPHA;
66 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
67 internalFormat= GL_RGB;
73 DALI_LOG_ERROR("Pixel format BGR565 is not supported by GLES.\n");
74 pixelDataType = GL_UNSIGNED_SHORT_5_6_5;
76 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
78 internalFormat= GL_RGBA; // alpha is reserved but not used
85 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
86 internalFormat= GL_RGBA;
92 DALI_LOG_ERROR("Pixel format BGRA4444 is not supported by GLES.\n");
93 pixelDataType = GL_UNSIGNED_SHORT_4_4_4_4;
95 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
97 internalFormat= GL_RGBA; // alpha is reserved but not used
104 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
105 internalFormat= GL_RGBA;
111 DALI_LOG_ERROR("Pixel format BGRA5551 is not supported by GLES.\n");
112 pixelDataType = GL_UNSIGNED_SHORT_5_5_5_1;
114 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
116 internalFormat= GL_RGBA; // alpha is reserved but not used
123 pixelDataType = GL_UNSIGNED_BYTE;
124 internalFormat= GL_RGB;
130 pixelDataType = GL_UNSIGNED_BYTE;
131 internalFormat= GL_RGBA; // alpha is reserved but not used
137 pixelDataType = GL_UNSIGNED_BYTE;
139 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
141 internalFormat= GL_RGBA; // alpha is reserved but not used
148 pixelDataType = GL_UNSIGNED_BYTE;
149 internalFormat= GL_RGBA;
155 pixelDataType = GL_UNSIGNED_BYTE;
157 internalFormat= GL_BGRA_EXT; // alpha is reserved but not used
159 internalFormat= GL_RGBA; // alpha is reserved but not used
164 // GLES 3.0 standard compressed formats:
165 case COMPRESSED_R11_EAC:
167 DALI_LOG_INFO(Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_R11_EAC.\n");
168 internalFormat = 0x9270; ///! < Hardcoded until we move to GLES 3.0 or greater.
171 case COMPRESSED_SIGNED_R11_EAC:
173 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_R11_EAC.\n" );
174 internalFormat = 0x9271; ///! < Hardcoded until we move to GLES 3.0 or greater.
178 case COMPRESSED_RG11_EAC:
180 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RG11_EAC.\n" );
181 internalFormat = 0x9272; ///! < Hardcoded until we move to GLES 3.0 or greater.
184 case COMPRESSED_SIGNED_RG11_EAC:
186 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SIGNED_RG11_EAC.\n" );
187 internalFormat = 0x9273; ///! < Hardcoded until we move to GLES 3.0 or greater.
190 case COMPRESSED_RGB8_ETC2:
192 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_ETC2.\n" );
193 internalFormat = 0x9274; ///! < Hardcoded until we move to GLES 3.0 or greater.
196 case COMPRESSED_SRGB8_ETC2:
198 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ETC2.\n" );
199 internalFormat = 0x9275; ///! < Hardcoded until we move to GLES 3.0 or greater.
202 case COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
204 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
205 internalFormat = 0x9276; ///! < Hardcoded until we move to GLES 3.0 or greater.
208 case COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
210 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2.\n" );
211 internalFormat = 0x9277; ///! < Hardcoded until we move to GLES 3.0 or greater.
214 case COMPRESSED_RGBA8_ETC2_EAC:
216 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_RGBA8_ETC2_EAC.\n" );
217 internalFormat = 0x9278; ///! < Hardcoded until we move to GLES 3.0 or greater.
220 case COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
222 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using GLES 3.0 standard compressed pixel format COMPRESSED_SRGB8_ALPHA8_ETC2_EAC.\n" );
223 internalFormat = 0x9279; ///! < Hardcoded until we move to GLES 3.0 or greater.
227 // GLES 2 extension compressed formats:
228 case COMPRESSED_RGB8_ETC1:
230 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB8_ETC1.\n" );
231 internalFormat = 0x8D64; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
234 case COMPRESSED_RGB_PVRTC_4BPPV1:
236 DALI_LOG_INFO( Debug::Filter::gImage, Debug::Verbose, "Using non-standard GLES 2.0 extension compressed pixel format COMPRESSED_RGB_PVRTC_4BPPV1.\n" );
237 internalFormat = 0x8C00; ///! < Hardcoded so we can test before we move to GLES 3.0 or greater.
243 Bitmap* Bitmap::New(const Profile profile = BITMAP_2D_PACKED_PIXELS, const bool managePixelBuffer = true)
245 DALI_ASSERT_DEBUG(profile == BITMAP_2D_PACKED_PIXELS || profile == BITMAP_COMPRESSED);
249 /** A 2D array of pixels where each pixel is a whole number of bytes
250 * and each scanline of the backing memory buffer may have additional
251 * bytes off the right edge if requested, and there may be additional
252 * scanlines past the bottom of the image in the buffer if requested.*/
253 case BITMAP_2D_PACKED_PIXELS:
255 Bitmap * const bitmap = new Dali::Internal::BitmapPackedPixel(managePixelBuffer);
259 /** The data for the bitmap is buffered in an opaque form.*/
260 case BITMAP_COMPRESSED:
262 return new Dali::Internal::BitmapCompressed(managePixelBuffer);
268 Bitmap::Bitmap( bool discardable, Dali::Integration::PixelBuffer* pixBuf)
271 mPixelFormat(Pixel::RGBA8888),
272 mHasAlphaChannel(true),
273 mAlphaChannelUsed(true),
275 mDiscardable(discardable)
279 void Bitmap::DiscardBuffer()
287 PixelBuffer* Bitmap::ReleaseBuffer()
289 PixelBuffer* const data = mData;
291 // Ownership of mData has been transferred, so indicate that mData pointer is no longer valid:
299 DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
305 void Bitmap::DeletePixelBuffer()
316 void Bitmap::Initialize( Pixel::Format pixelFormat,
320 DALI_ASSERT_DEBUG(width * height < (32 * 1024) * (32 * 1024) && "The total area of the bitmap is too great.\n");
322 mImageHeight = height;
323 mPixelFormat = pixelFormat;
325 mHasAlphaChannel = Pixel::HasAlpha(pixelFormat);
328 } //namespace Integration