mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 10:09:45 +00:00
Encoder works
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
CODEC_URL := https://github.com/BinomialLLC/basis_universal/archive/refs/tags/v1.15_rel2.tar.gz
|
||||
CODEC_DIR := node_modules/basis
|
||||
BUILD_DIR := build
|
||||
ENVIRONMENT = node
|
||||
ENVIRONMENT = worker
|
||||
|
||||
OUT_JS := enc/basis_enc.js # enc/basis_node_enc.js
|
||||
OUT_WASM := $(OUT_JS:.js=.wasm)
|
||||
|
||||
override CXXFLAGS += -O3
|
||||
override CFLAGS += -O3
|
||||
|
||||
CODEC_CPP_SOURCE_FILES := \
|
||||
encoder/basisu_comp.cpp \
|
||||
encoder/basisu_enc.cpp \
|
||||
@@ -20,6 +23,7 @@ CODEC_CPP_SOURCE_FILES := \
|
||||
encoder/basisu_astc_decomp.cpp \
|
||||
encoder/basisu_global_selector_palette_helpers.cpp \
|
||||
encoder/basisu_resampler.cpp \
|
||||
encoder/basisu_kernels_sse.cpp \
|
||||
encoder/jpgd.cpp \
|
||||
encoder/lodepng.cpp \
|
||||
transcoder/basisu_transcoder.cpp
|
||||
@@ -35,7 +39,7 @@ CODEC_C_OBJECT_FILE_PATHS := $(addprefix $(CODEC_DIR)/, $(CODEC_C_OBJECT_FILES))
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(OUT_JS)
|
||||
all: $(CODEC_DIR) $(OUT_JS)
|
||||
|
||||
# Define dependencies for all variations of build artifacts.
|
||||
$(filter enc/%,$(OUT_JS)): enc/basis_enc.cpp
|
||||
@@ -60,11 +64,13 @@ $(filter enc/%,$(OUT_JS)): enc/basis_enc.cpp
|
||||
|
||||
$(CODEC_CPP_OBJECT_FILES): $(CODEC_DIR)
|
||||
$(CXX) \
|
||||
${CXXFLAGS} \
|
||||
-o $@ \
|
||||
-c $(@:.o=.cpp)
|
||||
|
||||
$(CODEC_C_OBJECT_FILES): $(CODEC_DIR)
|
||||
$(CC) \
|
||||
${CFLAGS} \
|
||||
-o $@ \
|
||||
-c $(@:.o=.c)
|
||||
|
||||
|
||||
@@ -7,14 +7,15 @@
|
||||
using namespace emscripten;
|
||||
using namespace basisu;
|
||||
|
||||
|
||||
|
||||
thread_local const val Uint8Array = val::global("Uint8Array");
|
||||
|
||||
val encode(std::string image_in, int image_width, int image_height/*, MozJpegOptions opts*/) {
|
||||
val encode(std::string image_in, int image_width, int image_height /*, MozJpegOptions opts*/) {
|
||||
basisu_encoder_init();
|
||||
|
||||
basis_compressor_params params;
|
||||
basis_compressor compressor;
|
||||
image img = image(reinterpret_cast<const uint8_t*>(image_in.c_str()), image_width, image_height, 4);
|
||||
image img =
|
||||
image(reinterpret_cast<const uint8_t*>(image_in.c_str()), image_width, image_height, 4);
|
||||
// We don’t need the encoder to read/decode files from the filesystem
|
||||
params.m_read_source_images = false;
|
||||
// Writing is unnecessary, too
|
||||
@@ -24,11 +25,11 @@ val encode(std::string image_in, int image_width, int image_height/*, MozJpegOpt
|
||||
params.m_compression_level = 2; /* 0-4 */
|
||||
params.m_source_images.push_back(img);
|
||||
|
||||
if(!compressor.init(params)) {
|
||||
if (!compressor.init(params)) {
|
||||
return val(std::string("Well something went wrong during init"));
|
||||
}
|
||||
|
||||
if(compressor.process() != 0) {
|
||||
if (compressor.process() != 0) {
|
||||
return val(std::string("Well something went wrong during processing"));
|
||||
}
|
||||
|
||||
|
||||
3242
codecs/basis/enc/basis_enc.js
generated
3242
codecs/basis/enc/basis_enc.js
generated
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "../build-cpp.sh"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user