Reviewed some functions

- GetImageData()
- GetImageDataNormalized()
This commit is contained in:
Ray 2018-06-12 16:30:03 +02:00
parent 64804f30e6
commit 372e4a1139

View file

@ -409,6 +409,13 @@ Color *GetImageData(Image image)
{ {
Color *pixels = (Color *)malloc(image.width*image.height*sizeof(Color)); Color *pixels = (Color *)malloc(image.width*image.height*sizeof(Color));
if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats");
else
{
if ((image.format == UNCOMPRESSED_R32) ||
(image.format == UNCOMPRESSED_R32G32B32) ||
(image.format == UNCOMPRESSED_R32G32B32A32)) TraceLog(LOG_WARNING, "32bit pixel format converted to 8bit per channel");
for (int i = 0, k = 0; i < image.width*image.height; i++) for (int i = 0, k = 0; i < image.width*image.height; i++)
{ {
switch (image.format) switch (image.format)
@ -480,8 +487,6 @@ Color *GetImageData(Image image)
} break; } break;
case UNCOMPRESSED_R32: case UNCOMPRESSED_R32:
{ {
TraceLog(LOG_WARNING, "32bit pixel format converted to 8bit per channel"); break;
pixels[i].r = (unsigned char)(((float *)image.data)[k]*255.0f); pixels[i].r = (unsigned char)(((float *)image.data)[k]*255.0f);
pixels[i].g = 0; pixels[i].g = 0;
pixels[i].b = 0; pixels[i].b = 0;
@ -506,7 +511,8 @@ Color *GetImageData(Image image)
k += 4; k += 4;
} }
default: TraceLog(LOG_WARNING, "Format not supported for pixel data retrieval"); break; default: break;
}
} }
} }
@ -518,6 +524,9 @@ Vector4 *GetImageDataNormalized(Image image)
{ {
Vector4 *pixels = (Vector4 *)malloc(image.width*image.height*sizeof(Vector4)); Vector4 *pixels = (Vector4 *)malloc(image.width*image.height*sizeof(Vector4));
if (image.format >= COMPRESSED_DXT1_RGB) TraceLog(LOG_WARNING, "Pixel data retrieval not supported for compressed image formats");
else
{
for (int i = 0, k = 0; i < image.width*image.height; i++) for (int i = 0, k = 0; i < image.width*image.height; i++)
{ {
switch (image.format) switch (image.format)
@ -613,7 +622,8 @@ Vector4 *GetImageDataNormalized(Image image)
k += 4; k += 4;
} }
default: TraceLog(LOG_WARNING, "Format not supported for pixel data retrieval"); break; default: break;
}
} }
} }
@ -792,7 +802,7 @@ void ImageToPOT(Image *image, Color fillColor)
// Convert image data to desired format // Convert image data to desired format
void ImageFormat(Image *image, int newFormat) void ImageFormat(Image *image, int newFormat)
{ {
if (image->format != newFormat) if ((newFormat != 0) && (image->format != newFormat))
{ {
if ((image->format < COMPRESSED_DXT1_RGB) && (newFormat < COMPRESSED_DXT1_RGB)) if ((image->format < COMPRESSED_DXT1_RGB) && (newFormat < COMPRESSED_DXT1_RGB))
{ {
@ -2119,7 +2129,11 @@ Image GenImageCellular(int width, int height, int tileSize)
// NOTE: Characters info data should be allocated by user for charsCount // NOTE: Characters info data should be allocated by user for charsCount
Image GenImageFont(const char *fileName, int fontSize, int charsCount, int *fontChars, CharInfo *chars) Image GenImageFont(const char *fileName, int fontSize, int charsCount, int *fontChars, CharInfo *chars)
{ {
Image image = { 0 };
// TODO. // TODO.
return image;
} }
#endif // SUPPORT_IMAGE_GENERATION #endif // SUPPORT_IMAGE_GENERATION