mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 01:37:26 +00:00
Build webp
This commit is contained in:
29
codecs/webp/wasm_build/simd/dec/webp_dec.cpp
Normal file
29
codecs/webp/wasm_build/simd/dec/webp_dec.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <string>
|
||||
#include "emscripten/bind.h"
|
||||
#include "emscripten/val.h"
|
||||
#include "webp/decode.h"
|
||||
#include "webp/demux.h"
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
int version() {
|
||||
return WebPGetDecoderVersion();
|
||||
}
|
||||
|
||||
thread_local const val Uint8ClampedArray = val::global("Uint8ClampedArray");
|
||||
thread_local const val ImageData = val::global("ImageData");
|
||||
|
||||
val decode(std::string buffer) {
|
||||
int width, height;
|
||||
std::unique_ptr<uint8_t[]> rgba(
|
||||
WebPDecodeRGBA((const uint8_t*)buffer.c_str(), buffer.size(), &width, &height));
|
||||
return rgba ? ImageData.new_(
|
||||
Uint8ClampedArray.new_(typed_memory_view(width * height * 4, rgba.get())),
|
||||
width, height)
|
||||
: val::null();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(my_module) {
|
||||
function("decode", &decode);
|
||||
function("version", &version);
|
||||
}
|
||||
Reference in New Issue
Block a user