/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "ktx-loader.h"
// EXTERNAL INCLUDES
-#include <dali/devel-api/images/pixel-devel.h>
-#include <dali/devel-api/images/pixel-data-devel.h>
#include <memory.h>
#include <stdio.h>
#include <stdint.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/file-stream.h>
namespace PbrDemo
{
/**
* Convert KTX format to Dali::Pixel::Format
*/
-bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::DevelPixel::Format& format)
+bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Dali::Pixel::Format& format)
{
switch( ktxPixelFormat )
{
case 0x93B0: // GL_COMPRESSED_RGBA_ASTC_4x4_KHR
{
- format = Dali::DevelPixel::COMPRESSED_RGBA_ASTC_4x4_KHR;
+ format = Dali::Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR;
break;
}
case 0x881B:// GL_RGB16F
{
- format = Dali::DevelPixel::RGB16F;
+ format = Dali::Pixel::RGB16F;
break;
}
case 0x8815: // GL_RGB32F
{
- format = Dali::DevelPixel::RGB32F;
+ format = Dali::Pixel::RGB32F;
break;
}
case 0x8C3A: // GL_R11F_G11F_B10F
{
- format = Dali::DevelPixel::RGB32F;
+ format = Dali::Pixel::RGB32F;
break;
}
case 0x8D7C: // GL_RGBA8UI
{
- format = Dali::DevelPixel::RGBA8888;
+ format = Dali::Pixel::RGBA8888;
break;
}
case 0x8D7D: // GL_RGB8UI
{
- format = Dali::DevelPixel::RGB888;
+ format = Dali::Pixel::RGB888;
break;
}
default:
bool LoadCubeMapFromKtxFile( const std::string& path, CubeData& cubedata )
{
- FILE* fp = fopen(path.c_str(),"rb");
-
+ Dali::FileStream fileStream( path, Dali::FileStream::READ | Dali::FileStream::BINARY );
+ FILE* fp = fileStream.GetFile();
if( NULL == fp )
{
return false;
// Skip the key-values:
const long int imageSizeOffset = sizeof(KtxFileHeader) + header.bytesOfKeyValueData;
- fseek(fp, imageSizeOffset, SEEK_END);
+ if( fseek(fp, imageSizeOffset, SEEK_END) )
+ {
+ return false;
+ }
+
lSize = ftell(fp);
+ if( lSize == -1L )
+ {
+ return false;
+ }
+
rewind(fp);
- if(fseek(fp, imageSizeOffset, SEEK_SET))
+ if( fseek(fp, imageSizeOffset, SEEK_SET) )
{
return false;
}
+
cubedata.img.resize(header.numberOfFaces);
for(unsigned int face=0; face < header.numberOfFaces; ++face) //array_element must be 0 or 1
unsigned int imgSize[6];
unsigned char* imgPointer = buffer;
result = fread(buffer,1,lSize,fp);
+
if( 0 == result )
{
+ free( buffer );
return false;
}
- fclose(fp);
-
if( 0 == header.numberOfMipmapLevels )
{
header.numberOfMipmapLevels = 1u;
header.pixelHeight = 1u;
}
- Dali::DevelPixel::Format daliformat = DevelPixel::RGB888;
+ Dali::Pixel::Format daliformat = Pixel::RGB888;
ConvertPixelFormat(header.glInternalFormat, daliformat);
memcpy(img[face],imgPointer,byteSize);
imgSize[face] = byteSize;
imgPointer += byteSize;
- cubedata.img[face][mipmapLevel] = DevelPixelData::New( img[face], imgSize[face], header.pixelWidth , header.pixelHeight , daliformat, PixelData::FREE );
+ cubedata.img[face][mipmapLevel] = PixelData::New( img[face], imgSize[face], header.pixelWidth , header.pixelHeight , daliformat, PixelData::FREE );
}
}
header.pixelHeight/=2u;