From d593bd0081ea2dcafe3182ffc874882b5b7110b4 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 30 Apr 2017 13:03:31 +0200 Subject: Some code tweaks --- src/textures.c | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) (limited to 'src/textures.c') diff --git a/src/textures.c b/src/textures.c index 6c56d6c5..2b61c241 100644 --- a/src/textures.c +++ b/src/textures.c @@ -154,14 +154,7 @@ static Image LoadASTC(const char *fileName); // Load ASTC file // Load image from file into CPU memory (RAM) Image LoadImage(const char *fileName) { - Image image; - - // Initialize image default values - image.data = NULL; - image.width = 0; - image.height = 0; - image.mipmaps = 0; - image.format = 0; + Image image = { 0 }; if (IsFileExtension(fileName, ".rres")) { @@ -282,13 +275,7 @@ Image LoadImagePro(void *data, int width, int height, int format) // Load an image from RAW file data Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize) { - Image image; - - image.data = NULL; - image.width = 0; - image.height = 0; - image.mipmaps = 0; - image.format = 0; + Image image = { 0 }; FILE *rawFile = fopen(fileName, "rb"); @@ -342,7 +329,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int // Load texture from file into GPU memory (VRAM) Texture2D LoadTexture(const char *fileName) { - Texture2D texture; + Texture2D texture = { 0 }; Image image = LoadImage(fileName); @@ -351,11 +338,7 @@ Texture2D LoadTexture(const char *fileName) texture = LoadTextureFromImage(image); UnloadImage(image); } - else - { - TraceLog(WARNING, "Texture could not be created"); - texture.id = 0; - } + else TraceLog(WARNING, "Texture could not be created"); return texture; } @@ -364,14 +347,7 @@ Texture2D LoadTexture(const char *fileName) // NOTE: image is not unloaded, it must be done manually Texture2D LoadTextureFromImage(Image image) { - Texture2D texture; - - // Init texture to default values - texture.id = 0; - texture.width = 0; - texture.height = 0; - texture.mipmaps = 0; - texture.format = 0; + Texture2D texture = { 0 }; texture.id = rlglLoadTexture(image.data, image.width, image.height, image.format, image.mipmaps); @@ -510,9 +486,8 @@ Color *GetImageData(Image image) // NOTE: Compressed texture formats not supported Image GetTextureData(Texture2D texture) { - Image image; - image.data = NULL; - + Image image = { 0 }; + if (texture.format < 8) { image.data = rlglReadTexturePixels(texture); -- cgit v1.2.3 From 2d5c8e61b1d34b9b482b807f5bef555f532533fd Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 3 May 2017 14:16:53 +0200 Subject: Some code tweaks --- src/textures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/textures.c') diff --git a/src/textures.c b/src/textures.c index 2b61c241..d944bd64 100644 --- a/src/textures.c +++ b/src/textures.c @@ -98,7 +98,7 @@ defined(SUPPORT_FILEFORMAT_JPG) || defined(SUPPORT_FILEFORMAT_PSD) || defined(SUPPORT_FILEFORMAT_GIF) || \ defined(SUPPORT_FILEFORMAT_HDR)) #define STB_IMAGE_IMPLEMENTATION - #include "external/stb_image.h" // Required for: stbi_load() + #include "external/stb_image.h" // Required for: stbi_load_from_file() // NOTE: Used to read image data (multiple formats support) #endif -- cgit v1.2.3 From 50c887cb0a0aa80eae78c56198cbfe29280102ea Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 12:31:47 +0200 Subject: Support HDR R32G32B32 float textures loading --- src/textures.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/textures.c') diff --git a/src/textures.c b/src/textures.c index d944bd64..3c336587 100644 --- a/src/textures.c +++ b/src/textures.c @@ -53,6 +53,7 @@ // Default configuration flags (supported features) //------------------------------------------------- #define SUPPORT_FILEFORMAT_PNG +#define SUPPORT_FILEFORMAT_HDR #define SUPPORT_IMAGE_MANIPULATION //------------------------------------------------- @@ -205,6 +206,25 @@ Image LoadImage(const char *fileName) else if (imgBpp == 3) image.format = UNCOMPRESSED_R8G8B8; else if (imgBpp == 4) image.format = UNCOMPRESSED_R8G8B8A8; } +#if defined(SUPPORT_FILEFORMAT_HDR) + else if (IsFileExtension(fileName, ".hdr")) + { + int imgBpp = 0; + + FILE *imFile = fopen(fileName, "rb"); + + // Load 32 bit per channel floats data + image.data = stbi_loadf(imFile, &image.width, &image.height, &imgBpp, 0); + + if (imgBpp == 3) image.format = UNCOMPRESSED_R32G32B32; + else + { + // TODO: Support different number of channels at 32 bit float + TraceLog(WARNING, "[%s] Image fileformat not supported (only 3 channel 32 bit floats)", fileName); + UnloadImage(image); + } + } +#endif #if defined(SUPPORT_FILEFORMAT_DDS) else if (IsFileExtension(fileName, ".dds")) image = LoadDDS(fileName); #endif @@ -298,6 +318,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int case UNCOMPRESSED_R5G5B5A1: image.data = (unsigned short *)malloc(size); break; // 16 bpp (1 bit alpha) case UNCOMPRESSED_R4G4B4A4: image.data = (unsigned short *)malloc(size); break; // 16 bpp (4 bit alpha) case UNCOMPRESSED_R8G8B8A8: image.data = (unsigned char *)malloc(size*4); size *= 4; break; // 32 bpp + case UNCOMPRESSED_R32G32B32: image.data = (float *)malloc(size*12); size *= 12; break; // 4 byte per channel (12 byte) default: TraceLog(WARNING, "Image format not suported"); break; } @@ -762,6 +783,7 @@ Image ImageCopy(Image image) case UNCOMPRESSED_R4G4B4A4: byteSize *= 2; break; // 16 bpp (2 bytes) case UNCOMPRESSED_R8G8B8: byteSize *= 3; break; // 24 bpp (3 bytes) case UNCOMPRESSED_R8G8B8A8: byteSize *= 4; break; // 32 bpp (4 bytes) + case UNCOMPRESSED_R32G32B32: byteSize *= 12; break; // 4 byte per channel (12 bytes) case COMPRESSED_DXT3_RGBA: case COMPRESSED_DXT5_RGBA: case COMPRESSED_ETC2_EAC_RGBA: -- cgit v1.2.3 From 35c6aff21f3935bbf950839b84925d4f1cb230bb Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 May 2017 12:50:24 +0200 Subject: Corrected bug on HDR loading --- src/textures.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/textures.c') diff --git a/src/textures.c b/src/textures.c index 3c336587..115c8fff 100644 --- a/src/textures.c +++ b/src/textures.c @@ -212,9 +212,13 @@ Image LoadImage(const char *fileName) int imgBpp = 0; FILE *imFile = fopen(fileName, "rb"); - + // Load 32 bit per channel floats data - image.data = stbi_loadf(imFile, &image.width, &image.height, &imgBpp, 0); + image.data = stbi_loadf_from_file(imFile, &image.width, &image.height, &imgBpp, 0); + + fclose(imFile); + + image.mipmaps = 1; if (imgBpp == 3) image.format = UNCOMPRESSED_R32G32B32; else -- cgit v1.2.3