Add WebP2 support

This commit is contained in:
Surma
2020-10-30 16:56:52 +00:00
committed by Ingvar Stepanyan
parent e60ffddfd7
commit 18b2bd1135
24 changed files with 726 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
#include <cstdio>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include "src/wp2/decode.h"
using namespace emscripten;
class RawImage {
public:
val buffer;
int width;
int height;
RawImage(val b, int w, int h) : buffer(b), width(w), height(h) {}
};
WP2::ArgbBuffer *buffer = new WP2::ArgbBuffer(WP2_rgbA_32);
RawImage decode(std::string image_in) {
WP2Status status;
status = WP2::Decode(image_in, buffer);
if (status != WP2_STATUS_OK) {
return RawImage(val::null(), -1, -1);
}
return RawImage(val(typed_memory_view(buffer->width * buffer->height * 4,
(uint8_t *)buffer->GetRow(0))),
buffer->width, buffer->height);
}
void free_result() { delete buffer; }
EMSCRIPTEN_BINDINGS(my_module) {
class_<RawImage>("RawImage")
.property("buffer", &RawImage::buffer)
.property("width", &RawImage::width)
.property("height", &RawImage::height);
function("decode", &decode);
function("free_result", &free_result);
}