diff options
author | chai <chaifix@163.com> | 2021-10-27 01:06:48 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-27 01:06:48 +0800 |
commit | 0035e0d47bbce8311d3a4e559e74b8cdc5209d47 (patch) | |
tree | 51429abc6f8e50af1fc6ecfac0301a5667f6564b /Runtime/Scripting/Resource | |
parent | 12f3ac102d3aea08af540dd7f2cf0e08e939a70d (diff) |
*load image
Diffstat (limited to 'Runtime/Scripting/Resource')
-rw-r--r-- | Runtime/Scripting/Resource/Resource.bind.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp index 785115a..6f9c0bb 100644 --- a/Runtime/Scripting/Resource/Resource.bind.cpp +++ b/Runtime/Scripting/Resource/Resource.bind.cpp @@ -1,11 +1,14 @@ #include "Runtime/Lua/LuaHelper.h" #include "Runtime/Debug/Log.h" #include "Runtime/FileSystem/ImageJobs.h" +#include "Runtime/Graphics/ImageData.h" +#define STB_IMAGE_IMPLEMENTATION +#include "ThirdParty/stb/stb_image.h" using namespace LuaBind; // Resource.LoadImageDataAsync(path, callback) -int ReadImageDataAsync(lua_State* L) +int LoadImageDataJob(lua_State* L) { LUA_BIND_STATE(L); LUA_BIND_CHECK(L, "SF"); @@ -19,8 +22,26 @@ int ReadImageDataAsync(lua_State* L) return 0; } +int LoadImageData(lua_State* L) +{ + LUA_BIND_STATE(L); + + const char* path = state.GetValue<const char*>(1, ""); + + stbi_set_flip_vertically_on_load(true); + ImageData* data = new ImageData(state.GetVM()); + int channels; + data->pixels = stbi_load(path, &data->width, &data->height, &channels, 0); + data->format = ImageData::EPixelFormat::RGB; + data->type = ImageData::EPixelElementType::UNSIGNED_BYTE; + + data->PushUserdata(state); + return 1; +} + static luaL_Reg funcs[] = { - {"ReadImageDataAsync", ReadImageDataAsync}, + { "LoadImageData", LoadImageData }, + { "LoadImageDataJob", LoadImageDataJob }, {0, 0} }; |