ImageData (and Images loaded from them) now support different data formats. Resolves issue #1048.

Currently exposed formats are rgba8 and rgba16 (normalized), and rgba16f and rgba32f (floating-point). Some systems, especially mobile ones, won't support every format when creating a love.graphics Image. Use love.graphics.getRawImageFormats to check for support.

love.image.newImageData now takes an optional format parameter as its third argument when creating an empty sized ImageData. It defaults to rgba8.

16-bit PNGs, .hdr images, and floating-point OpenEXR images can now be loaded via love.image.newImageData and love.graphics.newImage.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-05-22 15:28:20 -03:00
parent 3e6d01748e
commit e71f95595c
31 changed files with 12018 additions and 241 deletions
+13 -4
View File
@@ -36,7 +36,7 @@ namespace image
int w_newImageData(lua_State *L)
{
// Case 1: Integers.
// Case 1: width & height.
if (lua_isnumber(L, 1))
{
int w = (int) luaL_checknumber(L, 1);
@@ -44,14 +44,23 @@ int w_newImageData(lua_State *L)
if (w <= 0 || h <= 0)
return luaL_error(L, "Invalid image size.");
ImageData::Format format = ImageData::FORMAT_RGBA8;
if (!lua_isnoneornil(L, 3))
{
const char *fstr = luaL_checkstring(L, 3);
if (!ImageData::getConstant(fstr, format))
return luaL_error(L, "Invalid ImageData format: %s", fstr);
}
size_t numbytes = 0;
const char *bytes = nullptr;
if (!lua_isnoneornil(L, 3))
bytes = luaL_checklstring(L, 3, &numbytes);
if (!lua_isnoneornil(L, 4))
bytes = luaL_checklstring(L, 4, &numbytes);
ImageData *t = nullptr;
luax_catchexcept(L, [&](){ t = instance()->newImageData(w, h); });
luax_catchexcept(L, [&](){ t = instance()->newImageData(w, h, format); });
if (bytes)
{