mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4a16022ef | ||
|
|
12153c72dc | ||
|
|
ae7782031d | ||
|
|
7cd6487a28 | ||
|
|
62c53c9fed | ||
|
|
53a38b2ba1 | ||
|
|
f3dfcae3f0 | ||
|
|
3f7274a6ac | ||
|
|
f5bc715bc0 | ||
|
|
d7fb0d9b40 | ||
|
|
309947a08f | ||
|
|
6aeaae6160 |
@@ -12,11 +12,7 @@ echo "Compiling libimagequant"
|
|||||||
echo "============================================="
|
echo "============================================="
|
||||||
(
|
(
|
||||||
emcc \
|
emcc \
|
||||||
--bind \
|
|
||||||
${OPTIMIZE} \
|
${OPTIMIZE} \
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
|
||||||
-s MODULARIZE=1 \
|
|
||||||
-s 'EXPORT_NAME="imagequant"' \
|
|
||||||
-I node_modules/libimagequant \
|
-I node_modules/libimagequant \
|
||||||
--std=c99 \
|
--std=c99 \
|
||||||
-c \
|
-c \
|
||||||
@@ -29,6 +25,7 @@ echo "============================================="
|
|||||||
emcc \
|
emcc \
|
||||||
--bind \
|
--bind \
|
||||||
${OPTIMIZE} \
|
${OPTIMIZE} \
|
||||||
|
--closure 1 \
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
-s MODULARIZE=1 \
|
-s MODULARIZE=1 \
|
||||||
-s 'EXPORT_NAME="imagequant"' \
|
-s 'EXPORT_NAME="imagequant"' \
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -30,6 +30,7 @@ echo "============================================="
|
|||||||
emcc \
|
emcc \
|
||||||
--bind \
|
--bind \
|
||||||
${OPTIMIZE} \
|
${OPTIMIZE} \
|
||||||
|
--closure 1 \
|
||||||
-s WASM=1 \
|
-s WASM=1 \
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
-s MODULARIZE=1 \
|
-s MODULARIZE=1 \
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@@ -2,6 +2,26 @@
|
|||||||
//! These implementations are compatible with the standard signatures
|
//! These implementations are compatible with the standard signatures
|
||||||
//! but use Rust allocator instead of including libc one as well.
|
//! but use Rust allocator instead of including libc one as well.
|
||||||
//!
|
//!
|
||||||
|
//! Rust allocator APIs requires passing size and alignment to the
|
||||||
|
//! `dealloc` function. This is different from C API, which only
|
||||||
|
//! expects a pointer in `free` and expects allocators to take care of
|
||||||
|
//! storing any necessary information elsewhere.
|
||||||
|
//!
|
||||||
|
//! In order to simulate C API, we allocate a `size_and_data_ptr`
|
||||||
|
//! of size `sizeof(usize) + size` where `size` is the requested number
|
||||||
|
//! of bytes. Then, we store `size` at the beginning of the allocated
|
||||||
|
//! chunk (within those `sizeof(usize)` bytes) and return
|
||||||
|
//! `data_ptr = size_and_data_ptr + sizeof(usize)` to the calleer:
|
||||||
|
//!
|
||||||
|
//! [`size`][...actual data]
|
||||||
|
//! -^------------------ `size_and_data_ptr`
|
||||||
|
//! ---------^---------- `data_ptr`
|
||||||
|
//!
|
||||||
|
//! Then, in `free`, the caller gives us `data_ptr`. We can subtract
|
||||||
|
//! `sizeof(usize)` back and get the original `size_and_data_ptr`.
|
||||||
|
//! At this point we can read `size` back and call the Rust `dealloc`
|
||||||
|
//! for the whole allocated chunk.
|
||||||
|
//!
|
||||||
//! I've raised an upstream issue to hopefully make this easier in
|
//! I've raised an upstream issue to hopefully make this easier in
|
||||||
//! future: https://github.com/ebiggers/libdeflate/issues/62
|
//! future: https://github.com/ebiggers/libdeflate/issues/62
|
||||||
|
|
||||||
@@ -20,8 +40,8 @@ pub unsafe extern "C" fn malloc(size: usize) -> *mut u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn free(ptr: *mut u8) {
|
pub unsafe extern "C" fn free(data_ptr: *mut u8) {
|
||||||
let size_and_data_ptr = ptr.sub(size_of::<usize>());
|
let size_and_data_ptr = data_ptr.sub(size_of::<usize>());
|
||||||
let size = *(size_and_data_ptr as *const usize);
|
let size = *(size_and_data_ptr as *const usize);
|
||||||
dealloc(ptr, layout_for(size))
|
dealloc(size_and_data_ptr, layout_for(size))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ echo "============================================="
|
|||||||
(
|
(
|
||||||
emcc \
|
emcc \
|
||||||
${OPTIMIZE} \
|
${OPTIMIZE} \
|
||||||
|
--closure 1 \
|
||||||
--bind \
|
--bind \
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
-s MODULARIZE=1 \
|
-s MODULARIZE=1 \
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -40,6 +40,7 @@ echo "============================================="
|
|||||||
(
|
(
|
||||||
emcc \
|
emcc \
|
||||||
${OPTIMIZE} \
|
${OPTIMIZE} \
|
||||||
|
--closure 1 \
|
||||||
--bind \
|
--bind \
|
||||||
-s ALLOW_MEMORY_GROWTH=1 \
|
-s ALLOW_MEMORY_GROWTH=1 \
|
||||||
-s MODULARIZE=1 \
|
-s MODULARIZE=1 \
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "squoosh",
|
"name": "squoosh",
|
||||||
"version": "1.10.0",
|
"version": "1.10.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "squoosh",
|
"name": "squoosh",
|
||||||
"version": "1.10.0",
|
"version": "1.10.2",
|
||||||
"license": "apache-2.0",
|
"license": "apache-2.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack-dev-server --host 0.0.0.0 --hot",
|
"start": "webpack-dev-server --host 0.0.0.0 --hot",
|
||||||
|
|||||||
Reference in New Issue
Block a user