2 * Copyright (c) 2017 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/internal/imaging/common/loader-ktx.h>
23 #include <dali/public-api/common/compile-time-assert.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
26 #include <dali/internal/imaging/common/pixel-buffer-impl.h>
31 namespace TizenPlatform
37 /** Max width or height of an image. */
38 const unsigned MAX_TEXTURE_DIMENSION = 4096;
39 /** Max bytes of image data allowed. Not a precise number, just a sanity check. */
40 const unsigned MAX_IMAGE_DATA_SIZE = MAX_TEXTURE_DIMENSION * MAX_TEXTURE_DIMENSION;
41 /** We don't read any of this but limit it to a resonable amount in order to be
42 * friendly to files from random tools. */
43 const unsigned MAX_BYTES_OF_KEYVALUE_DATA = 65536U;
47 const Byte FileIdentifier[] = {
48 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
52 /** The formats we support inside a KTX file container.
53 * Currently only compressed formats are allowed as we'd rather
54 * use a PNG or JPEG with their own compression for the general
56 enum KtxInternalFormat
60 // GLES 2 Extension formats:
61 KTX_ETC1_RGB8_OES = 0x8D64,
62 KTX_COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
64 // GLES 3 Standard compressed formats (values same as in gl3.h):
65 KTX_COMPRESSED_R11_EAC = 0x9270,
66 KTX_COMPRESSED_SIGNED_R11_EAC = 0x9271,
67 KTX_COMPRESSED_RG11_EAC = 0x9272,
68 KTX_COMPRESSED_SIGNED_RG11_EAC = 0x9273,
69 KTX_COMPRESSED_RGB8_ETC2 = 0x9274,
70 KTX_COMPRESSED_SRGB8_ETC2 = 0x9275,
71 KTX_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
72 KTX_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,
73 KTX_COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
74 KTX_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
76 // GLES 3.1 compressed formats:
77 KTX_COMPRESSED_RGBA_ASTC_4x4_KHR = 0x93B0,
78 KTX_COMPRESSED_RGBA_ASTC_5x4_KHR = 0x93B1,
79 KTX_COMPRESSED_RGBA_ASTC_5x5_KHR = 0x93B2,
80 KTX_COMPRESSED_RGBA_ASTC_6x5_KHR = 0x93B3,
81 KTX_COMPRESSED_RGBA_ASTC_6x6_KHR = 0x93B4,
82 KTX_COMPRESSED_RGBA_ASTC_8x5_KHR = 0x93B5,
83 KTX_COMPRESSED_RGBA_ASTC_8x6_KHR = 0x93B6,
84 KTX_COMPRESSED_RGBA_ASTC_8x8_KHR = 0x93B7,
85 KTX_COMPRESSED_RGBA_ASTC_10x5_KHR = 0x93B8,
86 KTX_COMPRESSED_RGBA_ASTC_10x6_KHR = 0x93B9,
87 KTX_COMPRESSED_RGBA_ASTC_10x8_KHR = 0x93BA,
88 KTX_COMPRESSED_RGBA_ASTC_10x10_KHR = 0x93BB,
89 KTX_COMPRESSED_RGBA_ASTC_12x10_KHR = 0x93BC,
90 KTX_COMPRESSED_RGBA_ASTC_12x12_KHR = 0x93BD,
91 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR = 0x93D0,
92 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR = 0x93D1,
93 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR = 0x93D2,
94 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR = 0x93D3,
95 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR = 0x93D4,
96 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR = 0x93D5,
97 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR = 0x93D6,
98 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR = 0x93D7,
99 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR = 0x93D8,
100 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR = 0x93D9,
101 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR = 0x93DA,
102 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR = 0x93DB,
103 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR = 0x93DC,
104 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR = 0x93DD,
106 // Uncompressed Alpha format
107 KTX_UNCOMPRESSED_ALPHA8 = 0x1906,
112 const unsigned KtxInternalFormats[] =
114 // GLES 2 Extension formats:
116 KTX_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,
118 // GLES 3 Standard compressed formats:
119 KTX_COMPRESSED_R11_EAC,
120 KTX_COMPRESSED_SIGNED_R11_EAC,
121 KTX_COMPRESSED_RG11_EAC,
122 KTX_COMPRESSED_SIGNED_RG11_EAC,
123 KTX_COMPRESSED_RGB8_ETC2,
124 KTX_COMPRESSED_SRGB8_ETC2,
125 KTX_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
126 KTX_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
127 KTX_COMPRESSED_RGBA8_ETC2_EAC,
128 KTX_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
130 // GLES 3.1 Compressed formats:
131 KTX_COMPRESSED_RGBA_ASTC_4x4_KHR,
132 KTX_COMPRESSED_RGBA_ASTC_5x4_KHR,
133 KTX_COMPRESSED_RGBA_ASTC_5x5_KHR,
134 KTX_COMPRESSED_RGBA_ASTC_6x5_KHR,
135 KTX_COMPRESSED_RGBA_ASTC_6x6_KHR,
136 KTX_COMPRESSED_RGBA_ASTC_8x5_KHR,
137 KTX_COMPRESSED_RGBA_ASTC_8x6_KHR,
138 KTX_COMPRESSED_RGBA_ASTC_8x8_KHR,
139 KTX_COMPRESSED_RGBA_ASTC_10x5_KHR,
140 KTX_COMPRESSED_RGBA_ASTC_10x6_KHR,
141 KTX_COMPRESSED_RGBA_ASTC_10x8_KHR,
142 KTX_COMPRESSED_RGBA_ASTC_10x10_KHR,
143 KTX_COMPRESSED_RGBA_ASTC_12x10_KHR,
144 KTX_COMPRESSED_RGBA_ASTC_12x12_KHR,
145 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
146 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
147 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
148 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
149 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
150 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
151 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
152 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
153 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
154 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
155 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
156 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
157 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
158 KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
160 // Uncompressed Alpha format
161 KTX_UNCOMPRESSED_ALPHA8,
173 uint32_t glInternalFormat;
174 uint32_t glBaseInternalFormat;
176 uint32_t pixelHeight;
178 uint32_t numberOfArrayElements;
179 uint32_t numberOfFaces;
180 uint32_t numberOfMipmapLevels;
181 uint32_t bytesOfKeyValueData;
182 } __attribute__ ( (__packed__));
183 // Packed attribute stops the structure from being aligned to compiler defaults
184 // so we can be sure of reading the whole thing from file in one call to fread.
187 * Function to read from the file directly into our structure.
188 * @param[in] fp The file to read from
189 * @param[out] header The structure we want to store our information in
190 * @return true, if read successful, false otherwise
192 inline bool ReadHeader( FILE* filePointer, KtxFileHeader& header )
194 const unsigned int readLength = sizeof( KtxFileHeader );
196 // Load the information directly into our structure
197 if( fread( &header, 1, readLength, filePointer ) != readLength )
205 /** Check whether the array passed in is the right size and matches the magic
206 * values defined to be at the start of a KTX file by the specification.*/
207 template<int BYTES_IN_SIGNATURE>
208 bool CheckFileIdentifier(const Byte * const signature)
210 const unsigned signatureSize = BYTES_IN_SIGNATURE;
211 const unsigned identifierSize = sizeof(FileIdentifier);
212 DALI_COMPILE_TIME_ASSERT(signatureSize == identifierSize);
213 const bool signatureGood = 0 == memcmp( signature, FileIdentifier, std::min( signatureSize, identifierSize ) );
214 return signatureGood;
218 * @returns True if the argument is a GLES compressed texture format that we support.
220 bool ValidInternalFormat(const unsigned format)
222 unsigned candidateFormat = 0;
223 for(unsigned iFormat = 0; (candidateFormat = KtxInternalFormats[iFormat]) != KTX_SENTINEL; ++iFormat)
225 if(format == candidateFormat)
230 DALI_LOG_ERROR("Rejecting unsupported compressed format when loading compressed texture from KTX file: 0x%x.\n", format);
235 * @returns The Pixel::Format Dali enum corresponding to the KTX internal format
236 * passed in, or Pixel::INVALID_PIXEL_FORMAT if the format is not valid.
238 bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& format)
240 using namespace Dali::Pixel;
241 switch(ktxPixelFormat)
243 // GLES 2 extension compressed formats:
244 case KTX_ETC1_RGB8_OES:
246 format = COMPRESSED_RGB8_ETC1;
249 case KTX_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
251 format = COMPRESSED_RGB_PVRTC_4BPPV1;
255 // GLES 3 extension compressed formats:
256 case KTX_COMPRESSED_R11_EAC:
258 format = COMPRESSED_R11_EAC;
261 case KTX_COMPRESSED_SIGNED_R11_EAC:
263 format = COMPRESSED_SIGNED_R11_EAC;
266 case KTX_COMPRESSED_RG11_EAC:
268 format = COMPRESSED_RG11_EAC;
271 case KTX_COMPRESSED_SIGNED_RG11_EAC:
273 format = COMPRESSED_SIGNED_RG11_EAC;
276 case KTX_COMPRESSED_RGB8_ETC2:
278 format = COMPRESSED_RGB8_ETC2;
281 case KTX_COMPRESSED_SRGB8_ETC2:
283 format = COMPRESSED_SRGB8_ETC2;
286 case KTX_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
288 format = COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
291 case KTX_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
293 format = COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
296 case KTX_COMPRESSED_RGBA8_ETC2_EAC:
298 format = COMPRESSED_RGBA8_ETC2_EAC;
301 case KTX_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
303 format = COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
307 // GLES 3.1 extension compressed formats:
308 case KTX_COMPRESSED_RGBA_ASTC_4x4_KHR:
310 format = COMPRESSED_RGBA_ASTC_4x4_KHR;
313 case KTX_COMPRESSED_RGBA_ASTC_5x4_KHR:
315 format = COMPRESSED_RGBA_ASTC_5x4_KHR;
318 case KTX_COMPRESSED_RGBA_ASTC_5x5_KHR:
320 format = COMPRESSED_RGBA_ASTC_5x5_KHR;
323 case KTX_COMPRESSED_RGBA_ASTC_6x5_KHR:
325 format = COMPRESSED_RGBA_ASTC_6x5_KHR;
328 case KTX_COMPRESSED_RGBA_ASTC_6x6_KHR:
330 format = COMPRESSED_RGBA_ASTC_6x6_KHR;
333 case KTX_COMPRESSED_RGBA_ASTC_8x5_KHR:
335 format = COMPRESSED_RGBA_ASTC_8x5_KHR;
338 case KTX_COMPRESSED_RGBA_ASTC_8x6_KHR:
340 format = COMPRESSED_RGBA_ASTC_8x6_KHR;
343 case KTX_COMPRESSED_RGBA_ASTC_8x8_KHR:
345 format = COMPRESSED_RGBA_ASTC_8x8_KHR;
348 case KTX_COMPRESSED_RGBA_ASTC_10x5_KHR:
350 format = COMPRESSED_RGBA_ASTC_10x5_KHR;
353 case KTX_COMPRESSED_RGBA_ASTC_10x6_KHR:
355 format = COMPRESSED_RGBA_ASTC_10x6_KHR;
358 case KTX_COMPRESSED_RGBA_ASTC_10x8_KHR:
360 format = COMPRESSED_RGBA_ASTC_10x8_KHR;
363 case KTX_COMPRESSED_RGBA_ASTC_10x10_KHR:
365 format = COMPRESSED_RGBA_ASTC_10x10_KHR;
368 case KTX_COMPRESSED_RGBA_ASTC_12x10_KHR:
370 format = COMPRESSED_RGBA_ASTC_12x10_KHR;
373 case KTX_COMPRESSED_RGBA_ASTC_12x12_KHR:
375 format = COMPRESSED_RGBA_ASTC_12x12_KHR;
378 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
380 format = COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
383 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
385 format = COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
388 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
390 format = COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
393 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
395 format = COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
398 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
400 format = COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
403 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
405 format = COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
408 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
410 format = COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
413 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
415 format = COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
418 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
420 format = COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
423 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
425 format = COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
428 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
430 format = COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
433 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
435 format = COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
438 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
440 format = COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
443 case KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
445 format = COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
449 // Uncompressed Alpha format
450 case KTX_UNCOMPRESSED_ALPHA8:
464 bool LoadKtxHeader( FILE * const fp, unsigned int& width, unsigned int& height, KtxFileHeader& fileHeader )
466 // Pull the bytes of the file header in as a block:
467 if ( !ReadHeader( fp, fileHeader ) )
471 width = fileHeader.pixelWidth;
472 height = fileHeader.pixelHeight;
474 if ( width > MAX_TEXTURE_DIMENSION || height > MAX_TEXTURE_DIMENSION )
479 // Validate file header contents meet our minimal subset:
480 const bool signatureGood = CheckFileIdentifier<sizeof(fileHeader.identifier)>(fileHeader.identifier);
481 const bool fileEndiannessMatchesSystemEndianness = fileHeader.endianness == 0x04030201; // Magic number from KTX spec.
482 const bool glTypeIsCompressed = fileHeader.glType == 0;
483 const bool glTypeSizeCompatibleWithCompressedTex = fileHeader.glTypeSize == 1;
484 const bool glFormatCompatibleWithCompressedTex = fileHeader.glFormat == 0;
485 const bool glInternalFormatIsSupportedCompressedTex = ValidInternalFormat(fileHeader.glInternalFormat);
486 // Ignore glBaseInternalFormat
487 const bool textureIsNot3D = fileHeader.pixelDepth == 0 || fileHeader.pixelDepth == 1;
488 const bool textureIsNotAnArray = fileHeader.numberOfArrayElements == 0 || fileHeader.numberOfArrayElements == 1;
489 const bool textureIsNotACubemap = fileHeader.numberOfFaces == 0 || fileHeader.numberOfFaces == 1;
490 const bool textureHasNoMipmapLevels = fileHeader.numberOfMipmapLevels == 0 || fileHeader.numberOfMipmapLevels == 1;
491 const bool keyValueDataNotTooLarge = fileHeader.bytesOfKeyValueData <= MAX_BYTES_OF_KEYVALUE_DATA;
493 bool headerIsValid = signatureGood && fileEndiannessMatchesSystemEndianness &&
494 glTypeSizeCompatibleWithCompressedTex && textureIsNot3D && textureIsNotAnArray &&
495 textureIsNotACubemap && textureHasNoMipmapLevels && keyValueDataNotTooLarge;
497 if( !glTypeIsCompressed ) // check for uncompressed Alpha
499 const bool isAlpha = ( ( fileHeader.glBaseInternalFormat == KTX_UNCOMPRESSED_ALPHA8 ) && ( fileHeader.glFormat == KTX_UNCOMPRESSED_ALPHA8 ) &&
500 ( fileHeader.glInternalFormat == KTX_UNCOMPRESSED_ALPHA8 ) );
501 headerIsValid = headerIsValid && isAlpha;
505 headerIsValid = headerIsValid && glFormatCompatibleWithCompressedTex && glInternalFormatIsSupportedCompressedTex;
510 DALI_LOG_ERROR( "KTX file invalid or using unsupported features. Header tests: sig: %d, endian: %d, gl_type: %d, gl_type_size: %d, gl_format: %d, internal_format: %d, depth: %d, array: %d, faces: %d, mipmap: %d, vey-vals: %d.\n", 0+signatureGood, 0+fileEndiannessMatchesSystemEndianness, 0+glTypeIsCompressed, 0+glTypeSizeCompatibleWithCompressedTex, 0+glFormatCompatibleWithCompressedTex, 0+glInternalFormatIsSupportedCompressedTex, 0+textureIsNot3D, 0+textureIsNotAnArray, 0+textureIsNotACubemap, 0+textureHasNoMipmapLevels, 0+keyValueDataNotTooLarge);
513 // Warn if there is space wasted in the file:
514 if( fileHeader.bytesOfKeyValueData > 0U )
516 DALI_LOG_WARNING("Loading of KTX file with key/value header data requested. This should be stripped in application asset/resource build.\n");
519 return headerIsValid;
523 } // unnamed namespace
525 // File loading API entry-point:
526 bool LoadKtxHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
528 KtxFileHeader fileHeader;
529 FILE* const fp = input.file;
531 bool ret = LoadKtxHeader(fp, width, height, fileHeader);
535 // File loading API entry-point:
536 bool LoadBitmapFromKtx( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
538 DALI_COMPILE_TIME_ASSERT( sizeof(Byte) == 1);
539 DALI_COMPILE_TIME_ASSERT( sizeof(uint32_t) == 4);
541 FILE* const fp = input.file;
544 DALI_LOG_ERROR( "Null file handle passed to KTX compressed bitmap file loader.\n" );
547 KtxFileHeader fileHeader;
549 // Load the header info
550 unsigned int width, height;
552 if (!LoadKtxHeader(fp, width, height, fileHeader))
557 // Skip the key-values:
558 const long int imageSizeOffset = sizeof(KtxFileHeader) + fileHeader.bytesOfKeyValueData;
559 if(fseek(fp, imageSizeOffset, SEEK_SET))
561 DALI_LOG_ERROR( "Seek past key/vals in KTX compressed bitmap file failed.\n" );
565 // Load the size of the image data:
566 uint32_t imageByteCount = 0;
567 if ( fread( &imageByteCount, 1, 4, fp ) != 4 )
569 DALI_LOG_ERROR( "Read of image size failed.\n" );
572 // Sanity-check the image size:
573 if( imageByteCount > MAX_IMAGE_DATA_SIZE ||
574 // A compressed texture should certainly be less than 2 bytes per texel:
575 imageByteCount > width * height * 2)
577 DALI_LOG_ERROR( "KTX file with too-large image-data field.\n" );
581 Pixel::Format pixelFormat;
582 const bool pixelFormatKnown = ConvertPixelFormat(fileHeader.glInternalFormat, pixelFormat);
583 if(!pixelFormatKnown)
585 DALI_LOG_ERROR( "No internal pixel format supported for KTX file pixel format.\n" );
589 // Load up the image bytes:
590 bitmap = Dali::Devel::PixelBuffer::New(width, height, pixelFormat);
592 // Compressed format won't allocate the buffer
593 auto pixels = bitmap.GetBuffer();
596 // allocate buffer manually
597 auto &impl = GetImplementation(bitmap);
598 impl.AllocateFixedSize(imageByteCount);
599 pixels = bitmap.GetBuffer();
604 DALI_LOG_ERROR( "Unable to reserve a pixel buffer to load the requested bitmap into.\n" );
608 const size_t bytesRead = fread(pixels, 1, imageByteCount, fp);
609 if(bytesRead != imageByteCount)
611 DALI_LOG_ERROR( "Read of image pixel data failed.\n" );
618 } // namespace TizenPlatform