Exemplo n.º 1
0
const char *imageInit(love_image *self, const char *filename) {

	int type = getType(filename);

	if (!loadNoGameGraphics(self, filename)) {

		if (!fileExists(filename)) {
			luaError(L, "Could not open image, does not exist");
			return NULL;
		}

		if (type == 0) { // PNG

			self->texture = sfil_load_PNG_file(filename, SF2D_PLACE_RAM);

		} else if (type == 1) { // JPG
			
			self->texture = sfil_load_JPEG_file(filename, SF2D_PLACE_RAM);

		} else if (type == 2) { // BMP
			
			self->texture = sfil_load_BMP_file(filename, SF2D_PLACE_RAM);

		} else if (type == 4) {

			luaError(L, "Unknown image type");

		}

	}

	return NULL;

}
Exemplo n.º 2
0
raw_texture* TextureManager::loadFromFile(const std::string path) {
    unsigned int extension = getExtension(path);
    
    if( extension ) {
        if( extension == JPEG )
             return sfil_load_JPEG_file(path.c_str(), SF2D_PLACE_RAM);
        
        else if( extension == PNG )
            return sfil_load_PNG_file(path.c_str(), SF2D_PLACE_RAM);
        
        else if( extension == BMP )
            return sfil_load_BMP_file(path.c_str(), SF2D_PLACE_RAM);
        
    }
    
    return nullptr;
}
Exemplo n.º 3
0
/***
Load a texture from a file. Supported formats: PNG, JPEG, BMP, GIF, PSD, TGA, HDR, PIC, PNM.
@function load
@tparam string path path to the image file
@tparam[opt=PLACE_RAM] number place where to put the loaded texture
@tparam[opt=auto] number type type of the image. This is only used to force loading PNG, JPEG or BMP files with the sfil library; any value between 5 and 250 will force using the stbi library. Leave nil to autodetect the format.
@treturn[1] texture the loaded texture object
@treturn[2] nil in case of error
@treturn[2] string error message
*/
static int texture_load(lua_State *L) {
	const char *path = luaL_checkstring(L, 1);
	u8 place = luaL_optinteger(L, 2, SF2D_PLACE_RAM); //place in ram by default
	u8 type = luaL_optinteger(L, 3, 3); //type 3 is "search at the end of the filename"

	texture_userdata *texture;
	texture = (texture_userdata *)lua_newuserdata(L, sizeof(*texture));

	luaL_getmetatable(L, "LTexture");
	lua_setmetatable(L, -2);

	if (type==3) type = getType(path);
	if (type==0) { //PNG
		texture->texture = sfil_load_PNG_file(path, place);
	} else if (type==1) { //JPEG
		texture->texture = sfil_load_JPEG_file(path, place);
	} else if (type==2) { //BMP
		texture->texture = sfil_load_BMP_file(path, place); //appears to be broken right now.
	} else {
		int w, h;
		char* data = (char*)stbi_load(path, &w, &h, NULL, 4);
		if (data == NULL) {
			lua_pushnil(L);
			lua_pushstring(L, "Can't open file");
			return 2;
		}
		texture->texture = sf2d_create_texture_mem_RGBA8(data, w, h, TEXFMT_RGBA8, place);
		free(data);
	}

	if (texture->texture == NULL) {
	  lua_pushnil(L);
	  lua_pushstring(L, "No such file");
	  return 2;
	}

	texture->scaleX = 1.0f;
	texture->scaleY = 1.0f;
	texture->blendColor = 0xffffffff;

	return 1;
}
Exemplo n.º 4
0
const char *imageInit(love_image *self, const char *filename) {

	int type = getType(filename);

	if (type == 0) { // PNG

		self->texture = sfil_load_PNG_file(filename, SF2D_PLACE_RAM);

	} else if (type == 1) { // JPG
		
		self->texture = sfil_load_JPEG_file(filename, SF2D_PLACE_RAM);

	} else if (type == 2) { // BMP
		
		self->texture = sfil_load_BMP_file(filename, SF2D_PLACE_RAM);

	}

	return NULL;

}