1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Merge pull request #2 from VideahGams/VideahGams-patch-1

Added auto-detection of image type from the filename. Thanks VideahGams :)
This commit is contained in:
Firewolf 2015-10-02 18:16:09 +02:00
commit 5579c8d9e8

View file

@ -13,9 +13,19 @@ The `gfx.texture` module.
#include "texture.h" #include "texture.h"
u8 getType(const char *name) { int getType(const char *name) {
// NYI, always return the PNG type, because PNG is the best type. const char *dot = strrchr(name, '.');
return 0; if(!dot || dot == name) dot = "";
const char *ext = dot + 1;
if (strncmp(ext, "png", 3) == 0) {
return 0;
} else if (strncmp(ext, "jpeg", 4) == 0 || strncmp(ext, "jpg", 3) == 0) {
return 1;
} else if (strncmp(ext, "bmp", 3) == 0) {
return 2;
} else {
return 4;
}
} }
// module functions // module functions
@ -45,7 +55,7 @@ static int texture_load(lua_State *L) {
} else if (type==1) { //JPEG } else if (type==1) { //JPEG
texture->texture = sfil_load_JPEG_file(path, place); texture->texture = sfil_load_JPEG_file(path, place);
} else if (type==2) { //BMP } else if (type==2) { //BMP
texture->texture = sfil_load_BMP_file(path, place); texture->texture = sfil_load_BMP_file(path, place); //appears to be broken right now.
} else { } else {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, "Bad type"); lua_pushstring(L, "Bad type");