diff --git a/codecs/basis/Makefile b/codecs/basis/Makefile index c8dada8c..b4c39467 100644 --- a/codecs/basis/Makefile +++ b/codecs/basis/Makefile @@ -1,5 +1,7 @@ CODEC_URL := https://github.com/BinomialLLC/basis_universal/archive/refs/tags/v1.15_rel2.tar.gz CODEC_DIR := node_modules/basis +CODEC_BUILD_DIR := $(CODEC_DIR)/build +CODEC_LIB := $(CODEC_BUILD_DIR)/basis.a ENVIRONMENT = worker OUT_JS := enc/basis_enc.js dec/basis_dec.js @@ -33,10 +35,8 @@ CODEC_C_SOURCE_FILES := \ encoder/apg_bmp.c \ zstd/zstd.c -CODEC_CPP_OBJECT_FILES := $(CODEC_CPP_SOURCE_FILES:.cpp=.o) -CODEC_C_OBJECT_FILES := $(CODEC_C_SOURCE_FILES:.c=.o) -CODEC_CPP_OBJECT_FILE_PATHS := $(addprefix $(CODEC_DIR)/, $(CODEC_CPP_OBJECT_FILES)) -CODEC_C_OBJECT_FILE_PATHS := $(addprefix $(CODEC_DIR)/, $(CODEC_C_OBJECT_FILES)) +CODEC_CPP_SOURCE_FILE_PATHS := $(addprefix $(CODEC_DIR)/, $(CODEC_CPP_SOURCE_FILES)) +CODEC_C_SOURCE_FILE_PATHS := $(addprefix $(CODEC_DIR)/, $(CODEC_C_SOURCE_FILES)) override CXXFLAGS += -DBASISU_FORCE_DEVEL_MESSAGES=1 @@ -52,7 +52,7 @@ $(filter dec/%,$(OUT_JS)): dec/basis_dec.cpp # enc/mozjpeg_node_enc.js dec/mozjpeg_node_dec.js: ENVIRONMENT = node -%.js: $(CODEC_CPP_OBJECT_FILE_PATHS) $(CODEC_C_OBJECT_FILE_PATHS) +%.js: $(CODEC_LIB) $(CXX) \ -I $(CODEC_DIR)/encoder \ -I $(CODEC_DIR)/transcoder \ @@ -68,21 +68,21 @@ $(filter dec/%,$(OUT_JS)): dec/basis_dec.cpp -o $@ \ $+ -$(CODEC_CPP_OBJECT_FILES): $(CODEC_DIR) +$(CODEC_LIB): $(CODEC_DIR) + mkdir -p $(CODEC_BUILD_DIR) + cd $(CODEC_BUILD_DIR) && \ $(CXX) \ ${CXXFLAGS} \ - -o $@ \ - -c $(@:.o=.cpp) - -$(CODEC_C_OBJECT_FILES): $(CODEC_DIR) + -c $(addprefix ../, $(CODEC_CPP_SOURCE_FILES)) + cd $(CODEC_BUILD_DIR) && \ $(CC) \ ${CFLAGS} \ - -o $@ \ - -c $(@:.o=.c) + -c $(addprefix ../, $(CODEC_C_SOURCE_FILES)) + $(AR) rc $(CODEC_LIB) $(CODEC_BUILD_DIR)/*.o $(CODEC_DIR): mkdir -p $@ curl -sL $(CODEC_URL) | tar xz --strip 1 -C $@ clean: - $(RM) $(OUT_JS) $(OUT_WASM) + $(RM) $(OUT_JS) $(OUT_WASM) $(CODEC_BUILD_DIR) diff --git a/codecs/basis/dec/basis_dec.js b/codecs/basis/dec/basis_dec.js index 509c0f42..e0439a0b 100644 --- a/codecs/basis/dec/basis_dec.js +++ b/codecs/basis/dec/basis_dec.js @@ -971,9 +971,9 @@ function updateGlobalBufferAndViews(buf) { Module['HEAPF64'] = HEAPF64 = new Float64Array(buf); } -var STACK_BASE = 5776352, +var STACK_BASE = 5775920, STACKTOP = STACK_BASE, - STACK_MAX = 533472; + STACK_MAX = 533040; var TOTAL_STACK = 5242880; @@ -1418,12 +1418,6 @@ var ASM_CONSTS = { abort('Assertion failed: ' + UTF8ToString(condition) + ', at: ' + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']); } - var ExceptionInfoAttrs={DESTRUCTOR_OFFSET:0,REFCOUNT_OFFSET:4,TYPE_OFFSET:8,CAUGHT_OFFSET:12,RETHROWN_OFFSET:13,SIZE:16}; - function ___cxa_allocate_exception(size) { - // Thrown object is prepended by exception metadata block - return _malloc(size + ExceptionInfoAttrs.SIZE) + ExceptionInfoAttrs.SIZE; - } - function _atexit(func, arg) { } function ___cxa_thread_atexit(a0,a1 @@ -1431,88 +1425,6 @@ var ASM_CONSTS = { return _atexit(a0,a1); } - function ExceptionInfo(excPtr) { - this.excPtr = excPtr; - this.ptr = excPtr - ExceptionInfoAttrs.SIZE; - - this.set_type = function(type) { - HEAP32[(((this.ptr)+(ExceptionInfoAttrs.TYPE_OFFSET))>>2)]=type; - }; - - this.get_type = function() { - return HEAP32[(((this.ptr)+(ExceptionInfoAttrs.TYPE_OFFSET))>>2)]; - }; - - this.set_destructor = function(destructor) { - HEAP32[(((this.ptr)+(ExceptionInfoAttrs.DESTRUCTOR_OFFSET))>>2)]=destructor; - }; - - this.get_destructor = function() { - return HEAP32[(((this.ptr)+(ExceptionInfoAttrs.DESTRUCTOR_OFFSET))>>2)]; - }; - - this.set_refcount = function(refcount) { - HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)]=refcount; - }; - - this.set_caught = function (caught) { - caught = caught ? 1 : 0; - HEAP8[(((this.ptr)+(ExceptionInfoAttrs.CAUGHT_OFFSET))>>0)]=caught; - }; - - this.get_caught = function () { - return HEAP8[(((this.ptr)+(ExceptionInfoAttrs.CAUGHT_OFFSET))>>0)] != 0; - }; - - this.set_rethrown = function (rethrown) { - rethrown = rethrown ? 1 : 0; - HEAP8[(((this.ptr)+(ExceptionInfoAttrs.RETHROWN_OFFSET))>>0)]=rethrown; - }; - - this.get_rethrown = function () { - return HEAP8[(((this.ptr)+(ExceptionInfoAttrs.RETHROWN_OFFSET))>>0)] != 0; - }; - - // Initialize native structure fields. Should be called once after allocated. - this.init = function(type, destructor) { - this.set_type(type); - this.set_destructor(destructor); - this.set_refcount(0); - this.set_caught(false); - this.set_rethrown(false); - } - - this.add_ref = function() { - var value = HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)]; - HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)]=value + 1; - }; - - // Returns true if last reference released. - this.release_ref = function() { - var prev = HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)]; - HEAP32[(((this.ptr)+(ExceptionInfoAttrs.REFCOUNT_OFFSET))>>2)]=prev - 1; - return prev === 1; - }; - } - - var exceptionLast=0; - - function __ZSt18uncaught_exceptionv() { // std::uncaught_exception() - return __ZSt18uncaught_exceptionv.uncaught_exceptions > 0; - } - function ___cxa_throw(ptr, type, destructor) { - var info = new ExceptionInfo(ptr); - // Initialize ExceptionInfo content after it was allocated in __cxa_allocate_exception. - info.init(type, destructor); - exceptionLast = ptr; - if (!("uncaught_exception" in __ZSt18uncaught_exceptionv)) { - __ZSt18uncaught_exceptionv.uncaught_exceptions = 1; - } else { - __ZSt18uncaught_exceptionv.uncaught_exceptions++; - } - throw ptr; - } - function getShiftFromSize(size) { switch (size) { case 1: return 0; @@ -2619,9 +2531,7 @@ function intArrayToString(array) { __ATINIT__.push({ func: function() { ___wasm_call_ctors() } }); var asmLibraryArg = { "__assert_fail": ___assert_fail, - "__cxa_allocate_exception": ___cxa_allocate_exception, "__cxa_thread_atexit": ___cxa_thread_atexit, - "__cxa_throw": ___cxa_throw, "_embind_register_bool": __embind_register_bool, "_embind_register_emval": __embind_register_emval, "_embind_register_float": __embind_register_float, @@ -2651,11 +2561,6 @@ var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() { return (___wasm_call_ctors = Module["___wasm_call_ctors"] = Module["asm"]["__wasm_call_ctors"]).apply(null, arguments); }; -/** @type {function(...*):?} */ -var _free = Module["_free"] = function() { - return (_free = Module["_free"] = Module["asm"]["free"]).apply(null, arguments); -}; - /** @type {function(...*):?} */ var _realloc = Module["_realloc"] = function() { return (_realloc = Module["_realloc"] = Module["asm"]["realloc"]).apply(null, arguments); @@ -2666,6 +2571,11 @@ var _malloc = Module["_malloc"] = function() { return (_malloc = Module["_malloc"] = Module["asm"]["malloc"]).apply(null, arguments); }; +/** @type {function(...*):?} */ +var _free = Module["_free"] = function() { + return (_free = Module["_free"] = Module["asm"]["free"]).apply(null, arguments); +}; + /** @type {function(...*):?} */ var ___getTypeName = Module["___getTypeName"] = function() { return (___getTypeName = Module["___getTypeName"] = Module["asm"]["__getTypeName"]).apply(null, arguments); diff --git a/codecs/basis/dec/basis_dec.wasm b/codecs/basis/dec/basis_dec.wasm index 303432de..62aeb4ae 100755 Binary files a/codecs/basis/dec/basis_dec.wasm and b/codecs/basis/dec/basis_dec.wasm differ diff --git a/codecs/basis/enc/basis_enc.cpp b/codecs/basis/enc/basis_enc.cpp index 376fe5c7..4da04f31 100644 --- a/codecs/basis/enc/basis_enc.cpp +++ b/codecs/basis/enc/basis_enc.cpp @@ -21,7 +21,6 @@ val encode(std::string image_in, int image_width, int image_height, BasisOptions basist::etc1_global_selector_codebook sel_codebook(basist::g_global_selector_cb_size, basist::g_global_selector_cb); - basis_compressor_params params; basis_compressor compressor; image img = diff --git a/codecs/basis/enc/basis_enc.js b/codecs/basis/enc/basis_enc.js index 277d5787..e6f61d60 100644 --- a/codecs/basis/enc/basis_enc.js +++ b/codecs/basis/enc/basis_enc.js @@ -971,9 +971,9 @@ function updateGlobalBufferAndViews(buf) { Module['HEAPF64'] = HEAPF64 = new Float64Array(buf); } -var STACK_BASE = 5878720, +var STACK_BASE = 5878144, STACKTOP = STACK_BASE, - STACK_MAX = 635840; + STACK_MAX = 635264; var TOTAL_STACK = 5242880; @@ -2971,11 +2971,6 @@ var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() { return (___wasm_call_ctors = Module["___wasm_call_ctors"] = Module["asm"]["__wasm_call_ctors"]).apply(null, arguments); }; -/** @type {function(...*):?} */ -var _free = Module["_free"] = function() { - return (_free = Module["_free"] = Module["asm"]["free"]).apply(null, arguments); -}; - /** @type {function(...*):?} */ var _realloc = Module["_realloc"] = function() { return (_realloc = Module["_realloc"] = Module["asm"]["realloc"]).apply(null, arguments); @@ -2986,6 +2981,11 @@ var _malloc = Module["_malloc"] = function() { return (_malloc = Module["_malloc"] = Module["asm"]["malloc"]).apply(null, arguments); }; +/** @type {function(...*):?} */ +var _free = Module["_free"] = function() { + return (_free = Module["_free"] = Module["asm"]["free"]).apply(null, arguments); +}; + /** @type {function(...*):?} */ var ___getTypeName = Module["___getTypeName"] = function() { return (___getTypeName = Module["___getTypeName"] = Module["asm"]["__getTypeName"]).apply(null, arguments); diff --git a/codecs/basis/enc/basis_enc.wasm b/codecs/basis/enc/basis_enc.wasm index d6ebe539..f016e033 100755 Binary files a/codecs/basis/enc/basis_enc.wasm and b/codecs/basis/enc/basis_enc.wasm differ