| 993 | |
| 994 | |
| 995 | static int PushImageData(lua_State* L, PNGImageFile& image) { |
| 996 | if (!image.isOpen()) { |
| 997 | return luaL_pushnil(L); |
| 998 | } |
| 999 | |
| 1000 | const int width = image.getWidth(); |
| 1001 | const int height = image.getHeight(); |
| 1002 | const int channels = image.getNumChannels(); |
| 1003 | |
| 1004 | const int bufSize = width * height * channels; |
| 1005 | char* buf = new char[bufSize]; |
| 1006 | if (!image.read(buf)) { |
| 1007 | delete[] buf; |
| 1008 | return luaL_pushnil(L); |
| 1009 | } |
| 1010 | |
| 1011 | lua_pushinteger(L, width); |
| 1012 | lua_pushinteger(L, height); |
| 1013 | lua_pushinteger(L, channels); |
| 1014 | lua_pushlstring(L, buf, bufSize); |
| 1015 | |
| 1016 | delete[] buf; |
| 1017 | |
| 1018 | return 4; |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | int LuaCallOuts::ReadImageData(lua_State* L) { |
no test coverage detected