Over the past few days I’ve had a go at implementing https://github.com/nothings/stb/blob/master/stb_image_resize.h into imp as suggested.
Having never used c / c++ it all came as a bit of a shock! This is also my first attempt at creating anything NE related.
Here’s where I shamefully am after 4 days (pretty much exactly where I was on day one):
Include stb_image_resize in imp.cpp
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "stb_image_resize.h"
Added a resize function to imp.cpp
static int Resize(lua_State* L) {
dmLogInfo("Imp resize");
int top = lua_gettop(L);
dmBuffer::HBuffer src_buffer = check_and_validate_buffer(L, 1);
uint8_t* bytes = 0x0;
uint32_t size = 0;
unsigned char* out_bytes = nullptr;
dmBuffer::Result r = dmBuffer::GetBytes(src_buffer, (void**)&bytes, &size);
if (r == dmBuffer::RESULT_OK) {
stbir_resize_uint8(bytes, 960, 540, 0, out_bytes, 480, 270, 0, 4);
} else {
// handle error
}
// make a buffer to return later
assert(top == lua_gettop(L));
return 0;
}
In lua:
local png_shot, w, h = screenshot.png()
local src_buffer, w, h = png.decode_rgba(png_shot)
pprint(src_buffer)
imp.resize(src_buffer)
All builds ok but the engine simply closes when the resize function is called (on mouse press).
Any pointers would be greatly appreciated. I’ve cleaned up all my crap from the test project and attached if anyone fancies a look.
Thanks
imp_resize.zip (300.0 KB)