summaryrefslogtreecommitdiffhomepage
path: root/src/textures.c
diff options
context:
space:
mode:
authorRay <[email protected]>2017-05-08 12:31:47 +0200
committerRay <[email protected]>2017-05-08 12:31:47 +0200
commit50c887cb0a0aa80eae78c56198cbfe29280102ea (patch)
tree9cb21fcac7a4d0f9c67e77cd9d33582a812aa79a /src/textures.c
parent822c2ddad59e9839aeb029f5a3dc26681188612b (diff)
downloadraylib-50c887cb0a0aa80eae78c56198cbfe29280102ea.tar.gz
raylib-50c887cb0a0aa80eae78c56198cbfe29280102ea.zip
Support HDR R32G32B32 float textures loading
Diffstat (limited to 'src/textures.c')
-rw-r--r--src/textures.c22
1 files changed, 22 insertions, 0 deletions
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: