REVIEWED: Improved log info on image/textures laoding
ADDED: rlGetPixelFormatName()
This commit is contained in:
parent
7cbfca8bd1
commit
4b6e6ce20e
2 changed files with 151 additions and 123 deletions
241
src/textures.c
241
src/textures.c
|
@ -186,7 +186,8 @@ static Image LoadPVR(const unsigned char *fileData, unsigned int fileSize); //
|
|||
#if defined(SUPPORT_FILEFORMAT_ASTC)
|
||||
static Image LoadASTC(const unsigned char *fileData, unsigned int fileSize); // Load ASTC file data
|
||||
#endif
|
||||
static Vector4 *LoadImageDataNormalized(Image image); // Load pixel data from image as Vector4 array (float normalized)
|
||||
|
||||
static Vector4 *LoadImageDataNormalized(Image image); // Load pixel data from image as Vector4 array (float normalized)
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
|
@ -212,16 +213,10 @@ Image LoadImage(const char *fileName)
|
|||
unsigned int fileSize = 0;
|
||||
unsigned char *fileData = LoadFileData(fileName, &fileSize);
|
||||
|
||||
if (fileData != NULL)
|
||||
{
|
||||
// Loading image from memory data
|
||||
image = LoadImageFromMemory(GetFileExtension(fileName), fileData, fileSize);
|
||||
// Loading image from memory data
|
||||
if (fileData != NULL) image = LoadImageFromMemory(GetFileExtension(fileName), fileData, fileSize);
|
||||
|
||||
if (image.data != NULL) TRACELOG(LOG_INFO, "IMAGE: [%s] Data loaded successfully (%ix%i)", fileName, image.width, image.height);
|
||||
else TRACELOG(LOG_WARNING, "IMAGE: [%s] Failed to load data", fileName);
|
||||
|
||||
RL_FREE(fileData);
|
||||
}
|
||||
RL_FREE(fileData);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
@ -383,7 +378,9 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
|
|||
#if defined(SUPPORT_FILEFORMAT_ASTC)
|
||||
else if (TextIsEqual(fileExtLower, ".astc")) image = LoadASTC(fileData, dataSize);
|
||||
#endif
|
||||
else TRACELOG(LOG_WARNING, "IMAGE: File format not supported");
|
||||
else TRACELOG(LOG_WARNING, "IMAGE: Data format not supported");
|
||||
|
||||
TRACELOG(LOG_INFO, "IMAGE: Data loaded successfully (%ix%i | %s | %i mipmaps)", image.width, image.height, rlGetPixelFormatName(image.format), image.mipmaps);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
@ -2203,117 +2200,6 @@ void UnloadImagePalette(Color *colors)
|
|||
RL_FREE(colors);
|
||||
}
|
||||
|
||||
// Get pixel data from image as Vector4 array (float normalized)
|
||||
static Vector4 *LoadImageDataNormalized(Image image)
|
||||
{
|
||||
Vector4 *pixels = (Vector4 *)RL_MALLOC(image.width*image.height*sizeof(Vector4));
|
||||
|
||||
if (image.format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "IMAGE: Pixel data retrieval not supported for compressed image formats");
|
||||
else
|
||||
{
|
||||
for (int i = 0, k = 0; i < image.width*image.height; i++)
|
||||
{
|
||||
switch (image.format)
|
||||
{
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[i]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[i]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[i]/255.0f;
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].w = (float)((unsigned char *)image.data)[k + 1]/255.0f;
|
||||
|
||||
k += 2;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
|
||||
{
|
||||
unsigned short pixel = ((unsigned short *)image.data)[i];
|
||||
|
||||
pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
|
||||
pixels[i].y = (float)((pixel & 0b0000011111000000) >> 6)*(1.0f/31);
|
||||
pixels[i].z = (float)((pixel & 0b0000000000111110) >> 1)*(1.0f/31);
|
||||
pixels[i].w = ((pixel & 0b0000000000000001) == 0)? 0.0f : 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
|
||||
{
|
||||
unsigned short pixel = ((unsigned short *)image.data)[i];
|
||||
|
||||
pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
|
||||
pixels[i].y = (float)((pixel & 0b0000011111100000) >> 5)*(1.0f/63);
|
||||
pixels[i].z = (float)(pixel & 0b0000000000011111)*(1.0f/31);
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4:
|
||||
{
|
||||
unsigned short pixel = ((unsigned short *)image.data)[i];
|
||||
|
||||
pixels[i].x = (float)((pixel & 0b1111000000000000) >> 12)*(1.0f/15);
|
||||
pixels[i].y = (float)((pixel & 0b0000111100000000) >> 8)*(1.0f/15);
|
||||
pixels[i].z = (float)((pixel & 0b0000000011110000) >> 4)*(1.0f/15);
|
||||
pixels[i].w = (float)(pixel & 0b0000000000001111)*(1.0f/15);
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
|
||||
pixels[i].w = (float)((unsigned char *)image.data)[k + 3]/255.0f;
|
||||
|
||||
k += 4;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
k += 3;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32:
|
||||
{
|
||||
pixels[i].x = ((float *)image.data)[k];
|
||||
pixels[i].y = 0.0f;
|
||||
pixels[i].z = 0.0f;
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32:
|
||||
{
|
||||
pixels[i].x = ((float *)image.data)[k];
|
||||
pixels[i].y = ((float *)image.data)[k + 1];
|
||||
pixels[i].z = ((float *)image.data)[k + 2];
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
k += 3;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32:
|
||||
{
|
||||
pixels[i].x = ((float *)image.data)[k];
|
||||
pixels[i].y = ((float *)image.data)[k + 1];
|
||||
pixels[i].z = ((float *)image.data)[k + 2];
|
||||
pixels[i].w = ((float *)image.data)[k + 3];
|
||||
|
||||
k += 4;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
// Get image alpha border rectangle
|
||||
// NOTE: Threshold is defined as a percentatge: 0.0f -> 1.0f
|
||||
Rectangle GetImageAlphaBorder(Image image, float threshold)
|
||||
|
@ -4600,3 +4486,114 @@ static Image LoadASTC(const unsigned char *fileData, unsigned int fileSize)
|
|||
return image;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get pixel data from image as Vector4 array (float normalized)
|
||||
static Vector4 *LoadImageDataNormalized(Image image)
|
||||
{
|
||||
Vector4 *pixels = (Vector4 *)RL_MALLOC(image.width*image.height*sizeof(Vector4));
|
||||
|
||||
if (image.format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "IMAGE: Pixel data retrieval not supported for compressed image formats");
|
||||
else
|
||||
{
|
||||
for (int i = 0, k = 0; i < image.width*image.height; i++)
|
||||
{
|
||||
switch (image.format)
|
||||
{
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[i]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[i]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[i]/255.0f;
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].w = (float)((unsigned char *)image.data)[k + 1]/255.0f;
|
||||
|
||||
k += 2;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
|
||||
{
|
||||
unsigned short pixel = ((unsigned short *)image.data)[i];
|
||||
|
||||
pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
|
||||
pixels[i].y = (float)((pixel & 0b0000011111000000) >> 6)*(1.0f/31);
|
||||
pixels[i].z = (float)((pixel & 0b0000000000111110) >> 1)*(1.0f/31);
|
||||
pixels[i].w = ((pixel & 0b0000000000000001) == 0)? 0.0f : 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
|
||||
{
|
||||
unsigned short pixel = ((unsigned short *)image.data)[i];
|
||||
|
||||
pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
|
||||
pixels[i].y = (float)((pixel & 0b0000011111100000) >> 5)*(1.0f/63);
|
||||
pixels[i].z = (float)(pixel & 0b0000000000011111)*(1.0f/31);
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4:
|
||||
{
|
||||
unsigned short pixel = ((unsigned short *)image.data)[i];
|
||||
|
||||
pixels[i].x = (float)((pixel & 0b1111000000000000) >> 12)*(1.0f/15);
|
||||
pixels[i].y = (float)((pixel & 0b0000111100000000) >> 8)*(1.0f/15);
|
||||
pixels[i].z = (float)((pixel & 0b0000000011110000) >> 4)*(1.0f/15);
|
||||
pixels[i].w = (float)(pixel & 0b0000000000001111)*(1.0f/15);
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
|
||||
pixels[i].w = (float)((unsigned char *)image.data)[k + 3]/255.0f;
|
||||
|
||||
k += 4;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R8G8B8:
|
||||
{
|
||||
pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
|
||||
pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
|
||||
pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
k += 3;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32:
|
||||
{
|
||||
pixels[i].x = ((float *)image.data)[k];
|
||||
pixels[i].y = 0.0f;
|
||||
pixels[i].z = 0.0f;
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32:
|
||||
{
|
||||
pixels[i].x = ((float *)image.data)[k];
|
||||
pixels[i].y = ((float *)image.data)[k + 1];
|
||||
pixels[i].z = ((float *)image.data)[k + 2];
|
||||
pixels[i].w = 1.0f;
|
||||
|
||||
k += 3;
|
||||
} break;
|
||||
case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32:
|
||||
{
|
||||
pixels[i].x = ((float *)image.data)[k];
|
||||
pixels[i].y = ((float *)image.data)[k + 1];
|
||||
pixels[i].z = ((float *)image.data)[k + 2];
|
||||
pixels[i].w = ((float *)image.data)[k + 3];
|
||||
|
||||
k += 4;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue