Encoder works

This commit is contained in:
Surma
2021-05-13 23:47:07 +01:00
parent 4dd2296eaf
commit 2e3361af79
5 changed files with 91 additions and 3175 deletions

View File

@@ -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)

View File

@@ -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*/) {
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 dont need the encoder to read/decode files from the filesystem
params.m_read_source_images = false;
// Writing is unnecessary, too

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -1,4 +1,5 @@
{
"type": "module",
"scripts": {
"build": "../build-cpp.sh"
}