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:
commit
5579c8d9e8
1 changed files with 14 additions and 4 deletions
|
|
@ -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");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue