mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 18:19:47 +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_URL := https://github.com/BinomialLLC/basis_universal/archive/refs/tags/v1.15_rel2.tar.gz
|
||||||
CODEC_DIR := node_modules/basis
|
CODEC_DIR := node_modules/basis
|
||||||
BUILD_DIR := build
|
BUILD_DIR := build
|
||||||
ENVIRONMENT = node
|
ENVIRONMENT = worker
|
||||||
|
|
||||||
OUT_JS := enc/basis_enc.js # enc/basis_node_enc.js
|
OUT_JS := enc/basis_enc.js # enc/basis_node_enc.js
|
||||||
OUT_WASM := $(OUT_JS:.js=.wasm)
|
OUT_WASM := $(OUT_JS:.js=.wasm)
|
||||||
|
|
||||||
|
override CXXFLAGS += -O3
|
||||||
|
override CFLAGS += -O3
|
||||||
|
|
||||||
CODEC_CPP_SOURCE_FILES := \
|
CODEC_CPP_SOURCE_FILES := \
|
||||||
encoder/basisu_comp.cpp \
|
encoder/basisu_comp.cpp \
|
||||||
encoder/basisu_enc.cpp \
|
encoder/basisu_enc.cpp \
|
||||||
@@ -20,6 +23,7 @@ CODEC_CPP_SOURCE_FILES := \
|
|||||||
encoder/basisu_astc_decomp.cpp \
|
encoder/basisu_astc_decomp.cpp \
|
||||||
encoder/basisu_global_selector_palette_helpers.cpp \
|
encoder/basisu_global_selector_palette_helpers.cpp \
|
||||||
encoder/basisu_resampler.cpp \
|
encoder/basisu_resampler.cpp \
|
||||||
|
encoder/basisu_kernels_sse.cpp \
|
||||||
encoder/jpgd.cpp \
|
encoder/jpgd.cpp \
|
||||||
encoder/lodepng.cpp \
|
encoder/lodepng.cpp \
|
||||||
transcoder/basisu_transcoder.cpp
|
transcoder/basisu_transcoder.cpp
|
||||||
@@ -35,7 +39,7 @@ CODEC_C_OBJECT_FILE_PATHS := $(addprefix $(CODEC_DIR)/, $(CODEC_C_OBJECT_FILES))
|
|||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
||||||
all: $(OUT_JS)
|
all: $(CODEC_DIR) $(OUT_JS)
|
||||||
|
|
||||||
# Define dependencies for all variations of build artifacts.
|
# Define dependencies for all variations of build artifacts.
|
||||||
$(filter enc/%,$(OUT_JS)): enc/basis_enc.cpp
|
$(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)
|
$(CODEC_CPP_OBJECT_FILES): $(CODEC_DIR)
|
||||||
$(CXX) \
|
$(CXX) \
|
||||||
|
${CXXFLAGS} \
|
||||||
-o $@ \
|
-o $@ \
|
||||||
-c $(@:.o=.cpp)
|
-c $(@:.o=.cpp)
|
||||||
|
|
||||||
$(CODEC_C_OBJECT_FILES): $(CODEC_DIR)
|
$(CODEC_C_OBJECT_FILES): $(CODEC_DIR)
|
||||||
$(CC) \
|
$(CC) \
|
||||||
|
${CFLAGS} \
|
||||||
-o $@ \
|
-o $@ \
|
||||||
-c $(@:.o=.c)
|
-c $(@:.o=.c)
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,15 @@
|
|||||||
using namespace emscripten;
|
using namespace emscripten;
|
||||||
using namespace basisu;
|
using namespace basisu;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
thread_local const val Uint8Array = val::global("Uint8Array");
|
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_params params;
|
||||||
basis_compressor compressor;
|
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
|
// We don’t need the encoder to read/decode files from the filesystem
|
||||||
params.m_read_source_images = false;
|
params.m_read_source_images = false;
|
||||||
// Writing is unnecessary, too
|
// 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_compression_level = 2; /* 0-4 */
|
||||||
params.m_source_images.push_back(img);
|
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"));
|
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"));
|
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": {
|
"scripts": {
|
||||||
"build": "../build-cpp.sh"
|
"build": "../build-cpp.sh"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user