From 0d2de019c33c9e2de9a439497f3678f79d5ebb5d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 18 Sep 2019 20:23:32 -0300 Subject: [PATCH] Fix ImageData:getPixel and ImageData:mapPixel when 1- and 2-component formats are used and the JIT compiler isn't available. --- src/modules/image/wrap_ImageData.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index ea8921a76..029af308e 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -184,12 +184,16 @@ static void luax_checkpixel_rgba32f(lua_State *L, int startidx, Pixel &p) luax_checkpixel_float32<4>(L, startidx, p); } +static lua_Number fillValues[] = {0.0, 0.0, 0.0, 1.0}; + template static int luax_pushpixel_unorm8(lua_State *L, const Pixel &p) { for (int i = 0; i < components; i++) lua_pushnumber(L, (lua_Number) p.rgba8[i] / 255.0); - return components; + for (int i = components; i < 4; i++) + lua_pushnumber(L, fillValues[i]); + return 4; } template @@ -197,7 +201,9 @@ static int luax_pushpixel_unorm16(lua_State *L, const Pixel &p) { for (int i = 0; i < components; i++) lua_pushnumber(L, (lua_Number) p.rgba16[i] / 65535.0); - return components; + for (int i = components; i < 4; i++) + lua_pushnumber(L, fillValues[i]); + return 4; } template @@ -205,7 +211,9 @@ static int luax_pushpixel_float16(lua_State *L, const Pixel &p) { for (int i = 0; i < components; i++) lua_pushnumber(L, (lua_Number) halfToFloat(p.rgba16f[i])); - return components; + for (int i = components; i < 4; i++) + lua_pushnumber(L, fillValues[i]); + return 4; } template @@ -213,7 +221,9 @@ static int luax_pushpixel_float32(lua_State *L, const Pixel &p) { for (int i = 0; i < components; i++) lua_pushnumber(L, (lua_Number) p.rgba32f[i]); - return components; + for (int i = components; i < 4; i++) + lua_pushnumber(L, fillValues[i]); + return 4; } static int luax_pushpixel_r8(lua_State *L, const Pixel &p)