REDESIGNED: LoadImage() -WIP-
Using new file I/O ABI
This commit is contained in:
parent
5100cb3e7f
commit
2a408d789c
1 changed files with 36 additions and 35 deletions
|
@ -195,6 +195,7 @@ Image LoadImage(const char *fileName)
|
||||||
defined(SUPPORT_FILEFORMAT_TGA) || \
|
defined(SUPPORT_FILEFORMAT_TGA) || \
|
||||||
defined(SUPPORT_FILEFORMAT_GIF) || \
|
defined(SUPPORT_FILEFORMAT_GIF) || \
|
||||||
defined(SUPPORT_FILEFORMAT_PIC) || \
|
defined(SUPPORT_FILEFORMAT_PIC) || \
|
||||||
|
defined(SUPPORT_FILEFORMAT_HDR) || \
|
||||||
defined(SUPPORT_FILEFORMAT_PSD)
|
defined(SUPPORT_FILEFORMAT_PSD)
|
||||||
#define STBI_REQUIRED
|
#define STBI_REQUIRED
|
||||||
#endif
|
#endif
|
||||||
|
@ -225,53 +226,53 @@ Image LoadImage(const char *fileName)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
#if defined(STBI_REQUIRED)
|
#if defined(STBI_REQUIRED)
|
||||||
int imgWidth = 0;
|
// NOTE: Using stb_image to load images (Supports multiple image formats)
|
||||||
int imgHeight = 0;
|
|
||||||
int imgBpp = 0;
|
|
||||||
|
|
||||||
FILE *imFile = fopen(fileName, "rb");
|
int dataSize = 0;
|
||||||
|
unsigned char *fileData = LoadFileData(fileName, &dataSize);
|
||||||
if (imFile != NULL)
|
|
||||||
|
if (fileData != NULL)
|
||||||
{
|
{
|
||||||
// NOTE: Using stb_image to load images (Supports multiple image formats)
|
int comp = 0;
|
||||||
image.data = stbi_load_from_file(imFile, &imgWidth, &imgHeight, &imgBpp, 0);
|
image.data = stbi_load_from_memory(fileData, dataSize, &image.width, &image.height, &comp, 0);
|
||||||
|
|
||||||
fclose(imFile);
|
|
||||||
|
|
||||||
image.width = imgWidth;
|
|
||||||
image.height = imgHeight;
|
|
||||||
image.mipmaps = 1;
|
image.mipmaps = 1;
|
||||||
|
|
||||||
if (imgBpp == 1) image.format = UNCOMPRESSED_GRAYSCALE;
|
if (comp == 1) image.format = UNCOMPRESSED_GRAYSCALE;
|
||||||
else if (imgBpp == 2) image.format = UNCOMPRESSED_GRAY_ALPHA;
|
else if (comp == 2) image.format = UNCOMPRESSED_GRAY_ALPHA;
|
||||||
else if (imgBpp == 3) image.format = UNCOMPRESSED_R8G8B8;
|
else if (comp == 3) image.format = UNCOMPRESSED_R8G8B8;
|
||||||
else if (imgBpp == 4) image.format = UNCOMPRESSED_R8G8B8A8;
|
else if (comp == 4) image.format = UNCOMPRESSED_R8G8B8A8;
|
||||||
|
|
||||||
|
RL_FREE(fileData);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if defined(SUPPORT_FILEFORMAT_HDR)
|
#if defined(SUPPORT_FILEFORMAT_HDR)
|
||||||
else if (IsFileExtension(fileName, ".hdr"))
|
else if (IsFileExtension(fileName, ".hdr"))
|
||||||
{
|
{
|
||||||
int imgBpp = 0;
|
#if defined(STBI_REQUIRED)
|
||||||
|
int dataSize = 0;
|
||||||
FILE *imFile = fopen(fileName, "rb");
|
unsigned char *fileData = LoadFileData(fileName, &dataSize);
|
||||||
|
|
||||||
// Load 32 bit per channel floats data
|
if (fileData != NULL)
|
||||||
//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
|
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "[%s] Image fileformat not supported", fileName);
|
int comp = 0;
|
||||||
UnloadImage(image);
|
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
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_DDS)
|
#if defined(SUPPORT_FILEFORMAT_DDS)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue