diff options
| author | Ray <[email protected]> | 2020-02-27 13:21:51 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2020-02-27 13:21:51 +0100 |
| commit | 2a408d789c72f433ae5abdfde67dc8fa10232f11 (patch) | |
| tree | 77fbddc39451d7e7500c9da748d9ca3a71ee7f40 | |
| parent | 5100cb3e7fc736454ed9079f0e4086e1f9c5e6e3 (diff) | |
| download | raylib-2a408d789c72f433ae5abdfde67dc8fa10232f11.tar.gz raylib-2a408d789c72f433ae5abdfde67dc8fa10232f11.zip | |
REDESIGNED: LoadImage() -WIP-
Using new file I/O ABI
| -rw-r--r-- | src/textures.c | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/textures.c b/src/textures.c index 12f72ddf..7099e78c 100644 --- a/src/textures.c +++ b/src/textures.c @@ -195,6 +195,7 @@ Image LoadImage(const char *fileName) defined(SUPPORT_FILEFORMAT_TGA) || \ defined(SUPPORT_FILEFORMAT_GIF) || \ defined(SUPPORT_FILEFORMAT_PIC) || \ + defined(SUPPORT_FILEFORMAT_HDR) || \ defined(SUPPORT_FILEFORMAT_PSD) #define STBI_REQUIRED #endif @@ -225,53 +226,53 @@ Image LoadImage(const char *fileName) ) { #if defined(STBI_REQUIRED) - int imgWidth = 0; - int imgHeight = 0; - int imgBpp = 0; + // NOTE: Using stb_image to load images (Supports multiple image formats) - FILE *imFile = fopen(fileName, "rb"); - - if (imFile != NULL) + int dataSize = 0; + unsigned char *fileData = LoadFileData(fileName, &dataSize); + + if (fileData != NULL) { - // NOTE: Using stb_image to load images (Supports multiple image formats) - image.data = stbi_load_from_file(imFile, &imgWidth, &imgHeight, &imgBpp, 0); - - fclose(imFile); + int comp = 0; + image.data = stbi_load_from_memory(fileData, dataSize, &image.width, &image.height, &comp, 0); - image.width = imgWidth; - image.height = imgHeight; image.mipmaps = 1; - - if (imgBpp == 1) image.format = UNCOMPRESSED_GRAYSCALE; - else if (imgBpp == 2) image.format = UNCOMPRESSED_GRAY_ALPHA; - else if (imgBpp == 3) image.format = UNCOMPRESSED_R8G8B8; - else if (imgBpp == 4) image.format = UNCOMPRESSED_R8G8B8A8; + + if (comp == 1) image.format = UNCOMPRESSED_GRAYSCALE; + else if (comp == 2) image.format = UNCOMPRESSED_GRAY_ALPHA; + else if (comp == 3) image.format = UNCOMPRESSED_R8G8B8; + else if (comp == 4) image.format = UNCOMPRESSED_R8G8B8A8; + + RL_FREE(fileData); } #endif } #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 - //stbi_set_flip_vertically_on_load(true); - image.data = stbi_loadf_from_file(imFile, &image.width, &image.height, &imgBpp, 0); - - fclose(imFile); - - image.mipmaps = 1; - - if (imgBpp == 1) image.format = UNCOMPRESSED_R32; - else if (imgBpp == 3) image.format = UNCOMPRESSED_R32G32B32; - else if (imgBpp == 4) image.format = UNCOMPRESSED_R32G32B32A32; - else +#if defined(STBI_REQUIRED) + int dataSize = 0; + unsigned char *fileData = LoadFileData(fileName, &dataSize); + + if (fileData != NULL) { - TRACELOG(LOG_WARNING, "[%s] Image fileformat not supported", fileName); - UnloadImage(image); + int comp = 0; + image.data = stbi_loadf_from_memory(fileData, dataSize, &image.width, &image.height, &comp, 0); + + image.mipmaps = 1; + + if (imgBpp == 1) image.format = UNCOMPRESSED_R32; + else if (imgBpp == 3) image.format = UNCOMPRESSED_R32G32B32; + else if (imgBpp == 4) image.format = UNCOMPRESSED_R32G32B32A32; + else + { + TRACELOG(LOG_WARNING, "[%s] HDR Image fileformat not supported", fileName); + UnloadImage(image); + } + + RL_FREE(fileData); } +#endif } #endif #if defined(SUPPORT_FILEFORMAT_DDS) |
