mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 01:37:26 +00:00
Rollup build
This commit is contained in:
24
codecs/wp2/dec/wp2_dec.cpp
Normal file
24
codecs/wp2/dec/wp2_dec.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <emscripten/bind.h>
|
||||
#include <emscripten/val.h>
|
||||
#include <cstdio>
|
||||
#include "src/wp2/decode.h"
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
thread_local const val Uint8ClampedArray = val::global("Uint8ClampedArray");
|
||||
thread_local const val ImageData = val::global("ImageData");
|
||||
|
||||
val decode(std::string image_in) {
|
||||
WP2::ArgbBuffer buffer(WP2_rgbA_32);
|
||||
WP2Status status = WP2::Decode(image_in, &buffer);
|
||||
if (status != WP2_STATUS_OK) {
|
||||
return val::null();
|
||||
}
|
||||
return ImageData.new_(
|
||||
Uint8ClampedArray.new_(typed_memory_view(buffer.stride * buffer.height, buffer.GetRow8(0))),
|
||||
buffer.width, buffer.height);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(my_module) {
|
||||
function("decode", &decode);
|
||||
}
|
||||
Reference in New Issue
Block a user