mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-02 22:14:37 +00:00
support loading *.qoi images
Now png/qoi/jpg are supported, and some subset of tga because we need that to load zga files for savegame thumbnails
This commit is contained in:
parent
1719fb5e74
commit
d1cbc6f783
6 changed files with 687 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "Image.h"
|
||||
#include "stb_image.h"
|
||||
#include "stb_image_write.h"
|
||||
#include "qoi.h"
|
||||
#include "DeflateCompressor.h"
|
||||
#include "ttvfs_stdio.h"
|
||||
#include "Base.h"
|
||||
|
@ -139,3 +140,24 @@ ImageData imageLoadZGA(const char *filename)
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ImageData imageLoadQOI(const char* filename, bool forceRGBA)
|
||||
{
|
||||
ImageData ret = {};
|
||||
size_t size = 0;
|
||||
void *buf = readFile(filename, &size);
|
||||
if(buf)
|
||||
{
|
||||
qoi_desc d;
|
||||
stbi_uc *pix = (stbi_uc*)qoi_decode(buf, size, &d, forceRGBA ? 4 : 0);
|
||||
if(pix)
|
||||
{
|
||||
ret.w = d.width;
|
||||
ret.h = d.height;
|
||||
ret.channels = forceRGBA ? 4 : d.channels;
|
||||
ret.pixels = pix;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -16,5 +16,6 @@ struct ImageData
|
|||
|
||||
ImageData imageLoadGeneric(const char *filename, bool forceRGBA);
|
||||
ImageData imageLoadZGA(const char *filename);
|
||||
ImageData imageLoadQOI(const char *filename, bool forceRGBA);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
struct TexLoadTmp
|
||||
{
|
||||
TexLoadTmp() : curTex(NULL), success(false) { img.pixels = NULL; }
|
||||
TexLoadTmp() : loadmode(TextureMgr::KEEP), curTex(NULL), success(false) { img.pixels = NULL; }
|
||||
std::string name, filename;
|
||||
ImageData img;
|
||||
TextureMgr::LoadMode loadmode;
|
||||
|
@ -34,6 +34,11 @@ static ImageData loadGeneric(const char *fn)
|
|||
return imageLoadGeneric(fn, false);
|
||||
}
|
||||
|
||||
static ImageData loadQOI(const char *fn)
|
||||
{
|
||||
return imageLoadQOI(fn, false);
|
||||
}
|
||||
|
||||
// This handles unix/win32 relative paths: ./rel/path
|
||||
// Unix abs paths: /home/user/...
|
||||
// Win32 abs paths: C:/Stuff/.. and also C:\Stuff\...
|
||||
|
@ -62,6 +67,7 @@ struct ExtAndLoader
|
|||
static const ExtAndLoader s_extAndLoader[] =
|
||||
{
|
||||
{ "png", loadGeneric },
|
||||
{ "qoi", loadQOI },
|
||||
{ "jpg", loadGeneric },
|
||||
{ "zga", imageLoadZGA },
|
||||
{ "tga", loadGeneric },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue