compress-jpeg 1.0.6 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -7
- package/README.md +82 -121
- package/compress_jpeg.d.ts +19 -18
- package/compress_jpeg.js +95 -240
- package/compress_jpeg_bg.wasm +0 -0
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright © 2025 Ganemede Labs
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright © 2025 Ganemede Labs
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,121 +1,82 @@
|
|
|
1
|
-
# Compress JPEG
|
|
2
|
-
|
|
3
|
-

|
|
6
|
-
|
|
7
|
-
A
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
img.onload = () => {
|
|
85
|
-
originalCanvas.width = img.width;
|
|
86
|
-
originalCanvas.height = img.height;
|
|
87
|
-
const ctx = originalCanvas.getContext("2d")!;
|
|
88
|
-
ctx.drawImage(img, 0, 0);
|
|
89
|
-
|
|
90
|
-
// Extract raw pixel data
|
|
91
|
-
const browserImageData = ctx.getImageData(0, 0, img.width, img.height);
|
|
92
|
-
const input = new RustImageData(
|
|
93
|
-
new Uint8ClampedArray(browserImageData.data),
|
|
94
|
-
browserImageData.width,
|
|
95
|
-
browserImageData.height
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// Simulate JPEG compression at quality=30
|
|
99
|
-
const output = compress_jpeg(input, 30);
|
|
100
|
-
|
|
101
|
-
// Convert back to browser ImageData
|
|
102
|
-
const processedData = new ImageData(new Uint8ClampedArray(output.data()), output.width(), output.height());
|
|
103
|
-
|
|
104
|
-
// Draw on visible canvas
|
|
105
|
-
processedCanvas.width = output.width();
|
|
106
|
-
processedCanvas.height = output.height();
|
|
107
|
-
processedCanvas.getContext("2d")!.putImageData(processedData, 0, 0);
|
|
108
|
-
|
|
109
|
-
// Free the WebAssembly memory
|
|
110
|
-
output.free();
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## 📜 License
|
|
116
|
-
|
|
117
|
-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
118
|
-
|
|
119
|
-
## 📧 Contact
|
|
120
|
-
|
|
121
|
-
For inquiries or more information, you can reach out to us at [ganemedelabs@gmail.com](mailto:ganemedelabs@gmail.com).
|
|
1
|
+
# Compress JPEG
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A lightweight WebAssembly-powered JPEG-like compressor written in Rust, exposed as an easy-to-use JavaScript API. This package performs a simplified JPEG pipeline entirely in WASM, including:
|
|
8
|
+
|
|
9
|
+
- RGB → YCbCr conversion
|
|
10
|
+
- 4:2:0 chroma subsampling
|
|
11
|
+
- 8×8 DCT + quantization
|
|
12
|
+
- Inverse DCT
|
|
13
|
+
- Reconstruction to RGBA
|
|
14
|
+
|
|
15
|
+
The output is not a `.jpg` file, but a visually compressed `ImageData` that simulates JPEG compression artifacts—including blockiness, color loss, and ringing—directly in the browser.
|
|
16
|
+
|
|
17
|
+
## 📋 Table of Contents
|
|
18
|
+
|
|
19
|
+
- [Features](#-features)
|
|
20
|
+
- [Installation](#-installation)
|
|
21
|
+
- [Usage](#-usage)
|
|
22
|
+
- [License](#-license)
|
|
23
|
+
- [Contact](#-contact)
|
|
24
|
+
|
|
25
|
+
## ✨ Features
|
|
26
|
+
|
|
27
|
+
- Fast WebAssembly image compression (Rust + wasm-bindgen)
|
|
28
|
+
- Fully controllable compression strength (`0.0 → 1.0`)
|
|
29
|
+
- Implements a full JPEG-style DCT/IDCT pipeline
|
|
30
|
+
- Produces visible JPEG artifacts at higher compression levels
|
|
31
|
+
- Works directly with Canvas `ImageData`
|
|
32
|
+
- Zero dependencies — tiny package size
|
|
33
|
+
- Browser-friendly and easy to use
|
|
34
|
+
- Simple API: `compress_jpeg(imageData: ImageData, compression: number): ImageData`
|
|
35
|
+
|
|
36
|
+
## 🔧 Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install compress-jpeg
|
|
40
|
+
# or
|
|
41
|
+
yarn add compress-jpeg
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 🚀 Usage
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import init, { compress_jpeg } from "compress-jpeg";
|
|
48
|
+
|
|
49
|
+
async function run() {
|
|
50
|
+
await init(); // initialize WASM module
|
|
51
|
+
|
|
52
|
+
const canvas = document.getElementById("my-canvas") as HTMLCanvasElement;
|
|
53
|
+
const ctx = canvas.getContext("2d")!;
|
|
54
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Compression strength (0.0 → 1.0)
|
|
58
|
+
*
|
|
59
|
+
* - 0.0 = no compression (highest quality)
|
|
60
|
+
* - 1.0 = strongest compression (lowest quality, heavy artifacts)
|
|
61
|
+
*
|
|
62
|
+
* Recommended ranges:
|
|
63
|
+
* - 0.7–1.0 → strong blockiness / heavy JPEG artifacts
|
|
64
|
+
* - 0.3–0.7 → medium compression
|
|
65
|
+
* - 0.0–0.3 → light compression / near-lossless
|
|
66
|
+
*/
|
|
67
|
+
const compression = 0.4;
|
|
68
|
+
|
|
69
|
+
const output = compress_jpeg(imageData, compression);
|
|
70
|
+
|
|
71
|
+
// Draw result onto canvas
|
|
72
|
+
ctx.putImageData(output, 0, 0);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 📜 License
|
|
77
|
+
|
|
78
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
79
|
+
|
|
80
|
+
## 📧 Contact
|
|
81
|
+
|
|
82
|
+
For inquiries or more information, you can reach out to us at [ganemedelabs@gmail.com](mailto:ganemedelabs@gmail.com).
|
package/compress_jpeg.d.ts
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compress an ImageData using a simplified JPEG-style pipeline.
|
|
6
|
+
*
|
|
7
|
+
* **Parameters:**
|
|
8
|
+
* - `image_data`: The RGBA ImageData to compress.
|
|
9
|
+
* - `compression`: A value from 0.0–1.0:
|
|
10
|
+
* - 0.0 = no compression (highest quality)
|
|
11
|
+
* - 1.0 = strongest compression (lowest quality)
|
|
12
|
+
*
|
|
13
|
+
* **Returns:**
|
|
14
|
+
* A new `ImageData` object containing the visually compressed pixels.
|
|
15
|
+
*/
|
|
16
|
+
export function compress_jpeg(image_data: ImageData, compression: number): ImageData;
|
|
11
17
|
|
|
12
18
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
13
19
|
|
|
14
20
|
export interface InitOutput {
|
|
15
21
|
readonly memory: WebAssembly.Memory;
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
readonly imagedata_width: (a: number) => number;
|
|
19
|
-
readonly imagedata_height: (a: number) => number;
|
|
20
|
-
readonly imagedata_data: (a: number) => any;
|
|
21
|
-
readonly compress_jpeg: (a: number, b: number) => any;
|
|
22
|
+
readonly compress_jpeg: (a: any, b: number) => [number, number, number];
|
|
23
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
22
24
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
23
25
|
readonly __externref_table_alloc: () => number;
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
26
|
-
readonly closure6_externref_shim: (a: number, b: number, c: any) => void;
|
|
27
|
-
readonly closure23_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
26
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
27
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
28
28
|
readonly __wbindgen_start: () => void;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
32
|
+
|
|
32
33
|
/**
|
|
33
34
|
* Instantiates the given `module`, which can either be bytes or
|
|
34
35
|
* a precompiled `WebAssembly.Module`.
|
package/compress_jpeg.js
CHANGED
|
@@ -2,25 +2,29 @@ let wasm;
|
|
|
2
2
|
|
|
3
3
|
function addToExternrefTable0(obj) {
|
|
4
4
|
const idx = wasm.__externref_table_alloc();
|
|
5
|
-
wasm.
|
|
5
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
6
6
|
return idx;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} catch (e) {
|
|
13
|
-
const idx = addToExternrefTable0(e);
|
|
14
|
-
wasm.__wbindgen_exn_store(idx);
|
|
15
|
-
}
|
|
9
|
+
function getClampedArrayU8FromWasm0(ptr, len) {
|
|
10
|
+
ptr = ptr >>> 0;
|
|
11
|
+
return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
16
12
|
}
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
let cachedDataViewMemory0 = null;
|
|
15
|
+
function getDataViewMemory0() {
|
|
16
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
17
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
18
|
+
}
|
|
19
|
+
return cachedDataViewMemory0;
|
|
20
|
+
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
function getStringFromWasm0(ptr, len) {
|
|
23
|
+
ptr = ptr >>> 0;
|
|
24
|
+
return decodeText(ptr, len);
|
|
25
|
+
}
|
|
21
26
|
|
|
22
27
|
let cachedUint8ArrayMemory0 = null;
|
|
23
|
-
|
|
24
28
|
function getUint8ArrayMemory0() {
|
|
25
29
|
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
26
30
|
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
@@ -28,138 +32,86 @@ function getUint8ArrayMemory0() {
|
|
|
28
32
|
return cachedUint8ArrayMemory0;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return x === undefined || x === null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
|
|
41
|
-
? { register: () => {}, unregister: () => {} }
|
|
42
|
-
: new FinalizationRegistry(state => {
|
|
43
|
-
wasm.__wbindgen_export_3.get(state.dtor)(state.a, state.b)
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
function makeMutClosure(arg0, arg1, dtor, f) {
|
|
47
|
-
const state = { a: arg0, b: arg1, cnt: 1, dtor };
|
|
48
|
-
const real = (...args) => {
|
|
49
|
-
// First up with a closure we increment the internal reference
|
|
50
|
-
// count. This ensures that the Rust closure environment won't
|
|
51
|
-
// be deallocated while we're invoking it.
|
|
52
|
-
state.cnt++;
|
|
53
|
-
const a = state.a;
|
|
54
|
-
state.a = 0;
|
|
55
|
-
try {
|
|
56
|
-
return f(a, state.b, ...args);
|
|
57
|
-
} finally {
|
|
58
|
-
if (--state.cnt === 0) {
|
|
59
|
-
wasm.__wbindgen_export_3.get(state.dtor)(a, state.b);
|
|
60
|
-
CLOSURE_DTORS.unregister(state);
|
|
61
|
-
} else {
|
|
62
|
-
state.a = a;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
real.original = state;
|
|
67
|
-
CLOSURE_DTORS.register(real, state, state);
|
|
68
|
-
return real;
|
|
35
|
+
let cachedUint8ClampedArrayMemory0 = null;
|
|
36
|
+
function getUint8ClampedArrayMemory0() {
|
|
37
|
+
if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) {
|
|
38
|
+
cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
|
|
39
|
+
}
|
|
40
|
+
return cachedUint8ClampedArrayMemory0;
|
|
69
41
|
}
|
|
70
42
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
43
|
+
function handleError(f, args) {
|
|
44
|
+
try {
|
|
45
|
+
return f.apply(this, args);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
const idx = addToExternrefTable0(e);
|
|
48
|
+
wasm.__wbindgen_exn_store(idx);
|
|
74
49
|
}
|
|
75
50
|
}
|
|
76
|
-
/**
|
|
77
|
-
* @param {ImageData} image_data
|
|
78
|
-
* @param {number} quality
|
|
79
|
-
* @returns {Promise<ImageData>}
|
|
80
|
-
*/
|
|
81
|
-
export function compress_jpeg(image_data, quality) {
|
|
82
|
-
_assertClass(image_data, ImageData);
|
|
83
|
-
var ptr0 = image_data.__destroy_into_raw();
|
|
84
|
-
const ret = wasm.compress_jpeg(ptr0, quality);
|
|
85
|
-
return ret;
|
|
86
|
-
}
|
|
87
51
|
|
|
88
|
-
function
|
|
89
|
-
|
|
52
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
53
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
54
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
55
|
+
WASM_VECTOR_LEN = arg.length;
|
|
56
|
+
return ptr;
|
|
90
57
|
}
|
|
91
58
|
|
|
92
|
-
function
|
|
93
|
-
wasm.
|
|
59
|
+
function takeFromExternrefTable0(idx) {
|
|
60
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
61
|
+
wasm.__externref_table_dealloc(idx);
|
|
62
|
+
return value;
|
|
94
63
|
}
|
|
95
64
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ImageDataFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
107
|
-
return obj;
|
|
65
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
66
|
+
cachedTextDecoder.decode();
|
|
67
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
68
|
+
let numBytesDecoded = 0;
|
|
69
|
+
function decodeText(ptr, len) {
|
|
70
|
+
numBytesDecoded += len;
|
|
71
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
72
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
73
|
+
cachedTextDecoder.decode();
|
|
74
|
+
numBytesDecoded = len;
|
|
108
75
|
}
|
|
76
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
77
|
+
}
|
|
109
78
|
|
|
110
|
-
|
|
111
|
-
const ptr = this.__wbg_ptr;
|
|
112
|
-
this.__wbg_ptr = 0;
|
|
113
|
-
ImageDataFinalization.unregister(this);
|
|
114
|
-
return ptr;
|
|
115
|
-
}
|
|
79
|
+
let WASM_VECTOR_LEN = 0;
|
|
116
80
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const ret = wasm.imagedata_width(this.__wbg_ptr);
|
|
137
|
-
return ret >>> 0;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* @returns {number}
|
|
141
|
-
*/
|
|
142
|
-
height() {
|
|
143
|
-
const ret = wasm.imagedata_height(this.__wbg_ptr);
|
|
144
|
-
return ret >>> 0;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* @returns {Uint8ClampedArray}
|
|
148
|
-
*/
|
|
149
|
-
data() {
|
|
150
|
-
const ret = wasm.imagedata_data(this.__wbg_ptr);
|
|
151
|
-
return ret;
|
|
81
|
+
/**
|
|
82
|
+
* Compress an ImageData using a simplified JPEG-style pipeline.
|
|
83
|
+
*
|
|
84
|
+
* **Parameters:**
|
|
85
|
+
* - `image_data`: The RGBA ImageData to compress.
|
|
86
|
+
* - `compression`: A value from 0.0–1.0:
|
|
87
|
+
* - 0.0 = no compression (highest quality)
|
|
88
|
+
* - 1.0 = strongest compression (lowest quality)
|
|
89
|
+
*
|
|
90
|
+
* **Returns:**
|
|
91
|
+
* A new `ImageData` object containing the visually compressed pixels.
|
|
92
|
+
* @param {ImageData} image_data
|
|
93
|
+
* @param {number} compression
|
|
94
|
+
* @returns {ImageData}
|
|
95
|
+
*/
|
|
96
|
+
export function compress_jpeg(image_data, compression) {
|
|
97
|
+
const ret = wasm.compress_jpeg(image_data, compression);
|
|
98
|
+
if (ret[2]) {
|
|
99
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
152
100
|
}
|
|
101
|
+
return takeFromExternrefTable0(ret[0]);
|
|
153
102
|
}
|
|
154
103
|
|
|
104
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
105
|
+
|
|
155
106
|
async function __wbg_load(module, imports) {
|
|
156
107
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
157
108
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
158
109
|
try {
|
|
159
110
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
160
|
-
|
|
161
111
|
} catch (e) {
|
|
162
|
-
|
|
112
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
113
|
+
|
|
114
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
163
115
|
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
164
116
|
|
|
165
117
|
} else {
|
|
@@ -170,13 +122,11 @@ async function __wbg_load(module, imports) {
|
|
|
170
122
|
|
|
171
123
|
const bytes = await module.arrayBuffer();
|
|
172
124
|
return await WebAssembly.instantiate(bytes, imports);
|
|
173
|
-
|
|
174
125
|
} else {
|
|
175
126
|
const instance = await WebAssembly.instantiate(module, imports);
|
|
176
127
|
|
|
177
128
|
if (instance instanceof WebAssembly.Instance) {
|
|
178
129
|
return { instance, module };
|
|
179
|
-
|
|
180
130
|
} else {
|
|
181
131
|
return instance;
|
|
182
132
|
}
|
|
@@ -186,140 +136,52 @@ async function __wbg_load(module, imports) {
|
|
|
186
136
|
function __wbg_get_imports() {
|
|
187
137
|
const imports = {};
|
|
188
138
|
imports.wbg = {};
|
|
189
|
-
imports.wbg.
|
|
190
|
-
|
|
191
|
-
return ret;
|
|
192
|
-
};
|
|
193
|
-
imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
|
|
194
|
-
const ret = arg0.call(arg1);
|
|
195
|
-
return ret;
|
|
196
|
-
}, arguments) };
|
|
197
|
-
imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
198
|
-
const ret = arg0.call(arg1, arg2);
|
|
199
|
-
return ret;
|
|
200
|
-
}, arguments) };
|
|
201
|
-
imports.wbg.__wbg_imagedata_new = function(arg0) {
|
|
202
|
-
const ret = ImageData.__wrap(arg0);
|
|
203
|
-
return ret;
|
|
204
|
-
};
|
|
205
|
-
imports.wbg.__wbg_length_238152a0aedbb6e7 = function(arg0) {
|
|
206
|
-
const ret = arg0.length;
|
|
207
|
-
return ret;
|
|
208
|
-
};
|
|
209
|
-
imports.wbg.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
|
|
210
|
-
try {
|
|
211
|
-
var state0 = {a: arg0, b: arg1};
|
|
212
|
-
var cb0 = (arg0, arg1) => {
|
|
213
|
-
const a = state0.a;
|
|
214
|
-
state0.a = 0;
|
|
215
|
-
try {
|
|
216
|
-
return __wbg_adapter_36(a, state0.b, arg0, arg1);
|
|
217
|
-
} finally {
|
|
218
|
-
state0.a = a;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
const ret = new Promise(cb0);
|
|
222
|
-
return ret;
|
|
223
|
-
} finally {
|
|
224
|
-
state0.a = state0.b = 0;
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
imports.wbg.__wbg_new_7a91e41fe43b3c92 = function(arg0) {
|
|
228
|
-
const ret = new Uint8ClampedArray(arg0);
|
|
229
|
-
return ret;
|
|
230
|
-
};
|
|
231
|
-
imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
|
|
232
|
-
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
233
|
-
return ret;
|
|
234
|
-
};
|
|
235
|
-
imports.wbg.__wbg_newwithbyteoffsetandlength_6d34787141015158 = function(arg0, arg1, arg2) {
|
|
236
|
-
const ret = new Uint8ClampedArray(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
237
|
-
return ret;
|
|
139
|
+
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
140
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
238
141
|
};
|
|
239
|
-
imports.wbg.
|
|
240
|
-
|
|
142
|
+
imports.wbg.__wbg_data_83b2a9a09dd4ab39 = function(arg0, arg1) {
|
|
143
|
+
const ret = arg1.data;
|
|
144
|
+
const ptr1 = passArray8ToWasm0(ret, wasm.__wbindgen_malloc);
|
|
145
|
+
const len1 = WASM_VECTOR_LEN;
|
|
146
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
147
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
241
148
|
};
|
|
242
|
-
imports.wbg.
|
|
243
|
-
const ret = arg0.
|
|
149
|
+
imports.wbg.__wbg_height_93d6779af8295699 = function(arg0) {
|
|
150
|
+
const ret = arg0.height;
|
|
244
151
|
return ret;
|
|
245
152
|
};
|
|
246
|
-
imports.wbg.
|
|
247
|
-
const ret =
|
|
153
|
+
imports.wbg.__wbg_new_with_u8_clamped_array_and_sh_5ac77cce3f6497ff = function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
154
|
+
const ret = new ImageData(getClampedArrayU8FromWasm0(arg0, arg1), arg2 >>> 0, arg3 >>> 0);
|
|
248
155
|
return ret;
|
|
249
|
-
};
|
|
250
|
-
imports.wbg.
|
|
251
|
-
|
|
252
|
-
};
|
|
253
|
-
imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
|
|
254
|
-
const ret = typeof global === 'undefined' ? null : global;
|
|
255
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
256
|
-
};
|
|
257
|
-
imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
|
|
258
|
-
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
259
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
260
|
-
};
|
|
261
|
-
imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
|
|
262
|
-
const ret = typeof self === 'undefined' ? null : self;
|
|
263
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
264
|
-
};
|
|
265
|
-
imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
|
|
266
|
-
const ret = typeof window === 'undefined' ? null : window;
|
|
267
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
268
|
-
};
|
|
269
|
-
imports.wbg.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) {
|
|
270
|
-
const ret = arg0.then(arg1);
|
|
271
|
-
return ret;
|
|
272
|
-
};
|
|
273
|
-
imports.wbg.__wbindgen_cb_drop = function(arg0) {
|
|
274
|
-
const obj = arg0.original;
|
|
275
|
-
if (obj.cnt-- == 1) {
|
|
276
|
-
obj.a = 0;
|
|
277
|
-
return true;
|
|
278
|
-
}
|
|
279
|
-
const ret = false;
|
|
156
|
+
}, arguments) };
|
|
157
|
+
imports.wbg.__wbg_width_73a6511a2370c184 = function(arg0) {
|
|
158
|
+
const ret = arg0.width;
|
|
280
159
|
return ret;
|
|
281
160
|
};
|
|
282
|
-
imports.wbg.
|
|
283
|
-
|
|
161
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
162
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
163
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
284
164
|
return ret;
|
|
285
165
|
};
|
|
286
166
|
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
287
|
-
const table = wasm.
|
|
167
|
+
const table = wasm.__wbindgen_externrefs;
|
|
288
168
|
const offset = table.grow(4);
|
|
289
169
|
table.set(0, undefined);
|
|
290
170
|
table.set(offset + 0, undefined);
|
|
291
171
|
table.set(offset + 1, null);
|
|
292
172
|
table.set(offset + 2, true);
|
|
293
173
|
table.set(offset + 3, false);
|
|
294
|
-
;
|
|
295
|
-
};
|
|
296
|
-
imports.wbg.__wbindgen_is_function = function(arg0) {
|
|
297
|
-
const ret = typeof(arg0) === 'function';
|
|
298
|
-
return ret;
|
|
299
|
-
};
|
|
300
|
-
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
|
301
|
-
const ret = arg0 === undefined;
|
|
302
|
-
return ret;
|
|
303
|
-
};
|
|
304
|
-
imports.wbg.__wbindgen_memory = function() {
|
|
305
|
-
const ret = wasm.memory;
|
|
306
|
-
return ret;
|
|
307
|
-
};
|
|
308
|
-
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
309
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
310
174
|
};
|
|
311
175
|
|
|
312
176
|
return imports;
|
|
313
177
|
}
|
|
314
178
|
|
|
315
|
-
function __wbg_init_memory(imports, memory) {
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
179
|
function __wbg_finalize_init(instance, module) {
|
|
320
180
|
wasm = instance.exports;
|
|
321
181
|
__wbg_init.__wbindgen_wasm_module = module;
|
|
182
|
+
cachedDataViewMemory0 = null;
|
|
322
183
|
cachedUint8ArrayMemory0 = null;
|
|
184
|
+
cachedUint8ClampedArrayMemory0 = null;
|
|
323
185
|
|
|
324
186
|
|
|
325
187
|
wasm.__wbindgen_start();
|
|
@@ -339,15 +201,10 @@ function initSync(module) {
|
|
|
339
201
|
}
|
|
340
202
|
|
|
341
203
|
const imports = __wbg_get_imports();
|
|
342
|
-
|
|
343
|
-
__wbg_init_memory(imports);
|
|
344
|
-
|
|
345
204
|
if (!(module instanceof WebAssembly.Module)) {
|
|
346
205
|
module = new WebAssembly.Module(module);
|
|
347
206
|
}
|
|
348
|
-
|
|
349
207
|
const instance = new WebAssembly.Instance(module, imports);
|
|
350
|
-
|
|
351
208
|
return __wbg_finalize_init(instance, module);
|
|
352
209
|
}
|
|
353
210
|
|
|
@@ -372,8 +229,6 @@ async function __wbg_init(module_or_path) {
|
|
|
372
229
|
module_or_path = fetch(module_or_path);
|
|
373
230
|
}
|
|
374
231
|
|
|
375
|
-
__wbg_init_memory(imports);
|
|
376
|
-
|
|
377
232
|
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
378
233
|
|
|
379
234
|
return __wbg_finalize_init(instance, module);
|
package/compress_jpeg_bg.wasm
CHANGED
|
Binary file
|