Hi, I’m currently looking at native sharing dialogues to share a screenshot when a player dies for example. Things seem pretty straight forward using Defold-Screenshot and Defold-Sharing (thanks @britzl ).
It would be nice if the screenshot could be reduced in size as they’re pretty large when taken from devices these days.
Is this possible at all (maybe using Defold-PNG and buffers or something)?
Thanks
Pkeod
February 13, 2019, 12:22am
2
Should be easy to do a nearest step based reduction of the buffer data. You can apply bilinear filtering to each sample too.
britzl
February 13, 2019, 5:24am
3
Ah, that would be nice functionality to have as an extension. It could either go into the screenshot extension itself, or perhaps added to Defold-Imp (Image Processing).
I’m happily accepting pull requests!
1 Like
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)
1 Like
In game related libraries like these, they try to leave most of the memory management to the user, since it’s so important. And this is such a case.
Here’s the corresponding example:
static void resizer(int argc, char **argv)
{
unsigned char* input_pixels;
unsigned char* output_pixels;
int w, h;
int n;
int out_w, out_h;
input_pixels = stbi_load(argv[1], &w, &h, &n, 0);
out_w = w*3;
out_h = h*3;
output_pixels = (unsigned char*) malloc(out_w*out_h*n);
//stbir_resize_uint8_srgb(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, n, -1,0);
stbir_resize_uint8(input_pixels, w, h, 0, output_pixels, out_w, out_h, 0, n);
stbi_write_png("output.png", out_w, out_h, n, output_pixels, 0);
exit(0);
}
static void performance(int argc, char **argv)
{
unsigned char* input_pixels;
unsigned char* output_pixels;
1 Like