Added formats conversion
Functor, NonCopyable, Tuple are now parts of NazaraCore (NazaraCore no longer needs NazaraUtility) Added loadFormat image parameter (ask loader to load image in specific format) Fixed utility project building It is now possible to convert, get validity or get name of pixel formats Changed endianness macros' name Removed useless NazaraEndianness macro Removed unused files
This commit is contained in:
@@ -74,7 +74,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_ENDIANNESS_BIGENDIAN
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
// Les fichiers PCX sont en little endian
|
||||
NzByteSwap(&header.xmin, sizeof(nzUInt16));
|
||||
NzByteSwap(&header.ymin, sizeof(nzUInt16));
|
||||
@@ -93,7 +93,7 @@ namespace
|
||||
unsigned int width = header.xmax - header.xmin+1;
|
||||
unsigned int height = header.ymax - header.ymin+1;
|
||||
|
||||
if (!resource->Create(nzImageType_2D, nzPixelFormat_R8G8B8, width, height))
|
||||
if (!resource->Create(nzImageType_2D, nzPixelFormat_RGB8, width, height))
|
||||
{
|
||||
NazaraError("Failed to create image");
|
||||
return false;
|
||||
@@ -343,6 +343,9 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parameters.loadFormat != nzPixelFormat_Undefined)
|
||||
resource->Convert(parameters.loadFormat);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,15 +63,44 @@ namespace
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
static nzPixelFormat format[4] = {
|
||||
static nzPixelFormat formats[4] = {
|
||||
nzPixelFormat_L8,
|
||||
nzPixelFormat_L8A8,
|
||||
nzPixelFormat_R8G8B8,
|
||||
nzPixelFormat_R8G8B8A8
|
||||
nzPixelFormat_LA8,
|
||||
nzPixelFormat_RGB8,
|
||||
nzPixelFormat_RGBA8
|
||||
};
|
||||
|
||||
nzPixelFormat format;
|
||||
int stbiFormat;
|
||||
switch (parameters.loadFormat)
|
||||
{
|
||||
case nzPixelFormat_L8:
|
||||
format = nzPixelFormat_L8;
|
||||
stbiFormat = STBI_grey;
|
||||
break;
|
||||
|
||||
case nzPixelFormat_LA8:
|
||||
format = nzPixelFormat_LA8;
|
||||
stbiFormat = STBI_grey_alpha;
|
||||
break;
|
||||
|
||||
case nzPixelFormat_RGB8:
|
||||
format = nzPixelFormat_RGB8;
|
||||
stbiFormat = STBI_rgb;
|
||||
break;
|
||||
|
||||
case nzPixelFormat_RGBA8:
|
||||
format = nzPixelFormat_RGBA8;
|
||||
stbiFormat = STBI_rgb_alpha;
|
||||
break;
|
||||
|
||||
default:
|
||||
format = nzPixelFormat_Undefined;
|
||||
stbiFormat = STBI_default;
|
||||
}
|
||||
|
||||
int width, height, bpp;
|
||||
nzUInt8* ptr = stbi_load_from_callbacks(&callbacks, &stream, &width, &height, &bpp, STBI_default);
|
||||
nzUInt8* ptr = stbi_load_from_callbacks(&callbacks, &stream, &width, &height, &bpp, stbiFormat);
|
||||
|
||||
if (!ptr)
|
||||
{
|
||||
@@ -79,7 +108,10 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!resource->Create(nzImageType_2D, format[bpp-1], width, height))
|
||||
if (format == nzPixelFormat_Undefined)
|
||||
format = formats[bpp-1];
|
||||
|
||||
if (!resource->Create(nzImageType_2D, format, width, height))
|
||||
{
|
||||
NazaraError("Failed to create image");
|
||||
stbi_image_free(ptr);
|
||||
@@ -90,6 +122,9 @@ namespace
|
||||
resource->Update(ptr);
|
||||
stbi_image_free(ptr);
|
||||
|
||||
if (stbiFormat == STBI_default && parameters.loadFormat != nzPixelFormat_Undefined)
|
||||
resource->Convert(parameters.loadFormat);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user