@pbk20191/icodec 0.6.1 → 0.6.2

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/lib/jxl.d.ts ADDED
@@ -0,0 +1,179 @@
1
+ import { ImageDataLike, WasmSource } from "./common.js";
2
+ export declare enum Override {
3
+ Default = -1,
4
+ False = 0,
5
+ True = 1
6
+ }
7
+ export declare enum Predictor {
8
+ Default = -1,
9
+ Zero = 0,
10
+ Left = 1,
11
+ Top = 2,
12
+ Average0 = 3,
13
+ Select = 4,
14
+ Gradient = 5,
15
+ Weighted = 6,
16
+ TopRight = 7,
17
+ TopLeft = 8,
18
+ LeftLeft = 9,
19
+ Average1 = 10,
20
+ Average2 = 11,
21
+ Average3 = 12,
22
+ Average4 = 13,
23
+ Best = 14,
24
+ Variable = 15
25
+ }
26
+ export interface Options {
27
+ /**
28
+ * If true, encode the image without any loss.
29
+ * Some options are ignored in lossless mode.
30
+ *
31
+ * @default false
32
+ */
33
+ lossless?: boolean;
34
+ /**
35
+ * Quality setting, higher value = higher quality.
36
+ * 100 = mathematically lossless, 90 = visually lossless.
37
+ *
38
+ * Quality values roughly match libjpeg quality.
39
+ * Recommended range: [68, 96]. Allowed range: [0, 100].
40
+ *
41
+ * @default 75
42
+ */
43
+ quality?: number;
44
+ /**
45
+ * Quality setting of alpha channel.
46
+ *
47
+ * @default 100
48
+ */
49
+ alphaQuality?: number;
50
+ /**
51
+ * Sets encoder effort/speed level without affecting decoding speed.
52
+ * Valid values are, from faster to slower speed: [1, 9].
53
+ *
54
+ * @default 7
55
+ */
56
+ effort?: number;
57
+ /**
58
+ * Sets brotli encode effort for use in JPEG recompression and compressed metadata boxes (brob).
59
+ * Can be -1 (default) or 0 (fastest) to 11 (slowest).
60
+ *
61
+ * Default is based on the general encode effort in case of JPEG recompression, and 4 for brob boxes.
62
+ *
63
+ * @default -1
64
+ */
65
+ brotliEffort?: number;
66
+ /**
67
+ * Enables or disables progressive encoding for modular mode.
68
+ *
69
+ * @default Override.Default
70
+ */
71
+ responsive?: Override;
72
+ /**
73
+ * Progressive-DC setting. Valid values are: -1, 0, 1, 2.
74
+ *
75
+ * @default -1
76
+ */
77
+ progressiveDC?: -1;
78
+ /**
79
+ * Set the progressive mode for the AC coefficients of VarDCT,
80
+ * using spectral progression from the DCT coefficients.
81
+ *
82
+ * @default Override.Default
83
+ */
84
+ progressiveAC?: Override;
85
+ /**
86
+ * Set the progressive mode for the AC coefficients of VarDCT,
87
+ * using quantization of the least significant bits.
88
+ *
89
+ * @default Override.Default
90
+ */
91
+ qProgressiveAC?: Override;
92
+ /**
93
+ * Edge preserving filter level, -1 to 3.
94
+ * Use -1 for the default (encoder chooses), 0 to 3 to set a strength.
95
+ *
96
+ * @default -1
97
+ */
98
+ epf?: number;
99
+ /**
100
+ * Enables or disables the gaborish filter.
101
+ *
102
+ * @default Override.Default
103
+ */
104
+ gaborish?: Override;
105
+ /**
106
+ * Sets the decoding speed tier for the provided options.
107
+ *
108
+ * Minimum is 0 (slowest to decode, best quality/density), and
109
+ * maximum is 4 (fastest to decode, at the cost of some quality/density).
110
+ *
111
+ * @default 0
112
+ */
113
+ decodingSpeed?: number;
114
+ /**
115
+ * Adds noise to the image emulating photographic film noise, the higher the
116
+ * given number, the grainier the image will be. As an example, a value of 100
117
+ * gives low noise whereas a value of 3200 gives a lot of noise.
118
+ *
119
+ * @default 0
120
+ */
121
+ photonNoiseIso?: number;
122
+ /**
123
+ * Enables modular encoding.
124
+ *
125
+ * false to enforce VarDCT mode (e.g. for photographic images),
126
+ * true to enforce modular mode (e.g. for lossless images).
127
+ *
128
+ * @default false
129
+ */
130
+ modular?: boolean;
131
+ /**
132
+ * Enables or disables delta palette, used in modular mode.
133
+ *
134
+ * @default false
135
+ */
136
+ lossyPalette?: boolean;
137
+ /**
138
+ * Use color palette if amount of colors is smaller than or equal to this amount,
139
+ * or -1 to use the encoder default. Used for modular encoding.
140
+ *
141
+ * @default -1
142
+ */
143
+ paletteColors?: number;
144
+ /**
145
+ * Fraction of pixels used to learn MA trees as a percentage.
146
+ * Higher values use more memory.
147
+ *
148
+ * -1 = default, 0 = no MA and fast decode, 50 = default value, 100 = all.
149
+ *
150
+ * @default -1
151
+ */
152
+ iterations?: number;
153
+ /**
154
+ * Reversible color transform for modular encoding: -1=default, 0-41=RCT
155
+ * index, e.g. index 0 = none, index 6 = YCoCg.
156
+ *
157
+ * If this option is set to a non-default value, the RCT will be globally applied to the whole frame.
158
+ *
159
+ * The default behavior is to try several RCTs locally per modular group,
160
+ * depending on the speed and distance setting.
161
+ *
162
+ * @default -1
163
+ */
164
+ modularColorspace?: number;
165
+ /**
166
+ * Predictor for modular encoding.
167
+ *
168
+ * @default Predictor.Default,
169
+ */
170
+ modularPredictor?: Predictor;
171
+ }
172
+ export declare const defaultOptions: Required<Options>;
173
+ export declare const mimeType = "image/jxl";
174
+ export declare const extension = "jxl";
175
+ export declare const bitDepth: number[];
176
+ export declare function loadEncoder(input?: WasmSource): Promise<any>;
177
+ export declare function loadDecoder(input?: WasmSource): Promise<any>;
178
+ export declare function encode(image: ImageDataLike, options?: Options): Uint8Array<ArrayBufferLike>;
179
+ export declare function decode(input: BufferSource): ImageData;
package/lib/jxl.js ADDED
@@ -0,0 +1,69 @@
1
+ import wasmFactoryEnc from "../dist/jxl-enc.js";
2
+ import wasmFactoryDec from "../dist/jxl-dec.js";
3
+ import { check, encodeES, loadES } from "./common.js";
4
+ // Tristate bool value, `Default` means encoder chooses.
5
+ export var Override;
6
+ (function (Override) {
7
+ Override[Override["Default"] = -1] = "Default";
8
+ Override[Override["False"] = 0] = "False";
9
+ Override[Override["True"] = 1] = "True";
10
+ })(Override || (Override = {}));
11
+ export var Predictor;
12
+ (function (Predictor) {
13
+ Predictor[Predictor["Default"] = -1] = "Default";
14
+ Predictor[Predictor["Zero"] = 0] = "Zero";
15
+ Predictor[Predictor["Left"] = 1] = "Left";
16
+ Predictor[Predictor["Top"] = 2] = "Top";
17
+ Predictor[Predictor["Average0"] = 3] = "Average0";
18
+ Predictor[Predictor["Select"] = 4] = "Select";
19
+ Predictor[Predictor["Gradient"] = 5] = "Gradient";
20
+ Predictor[Predictor["Weighted"] = 6] = "Weighted";
21
+ Predictor[Predictor["TopRight"] = 7] = "TopRight";
22
+ Predictor[Predictor["TopLeft"] = 8] = "TopLeft";
23
+ Predictor[Predictor["LeftLeft"] = 9] = "LeftLeft";
24
+ Predictor[Predictor["Average1"] = 10] = "Average1";
25
+ Predictor[Predictor["Average2"] = 11] = "Average2";
26
+ Predictor[Predictor["Average3"] = 12] = "Average3";
27
+ Predictor[Predictor["Average4"] = 13] = "Average4";
28
+ // The following predictors are encoder-only.
29
+ Predictor[Predictor["Best"] = 14] = "Best";
30
+ Predictor[Predictor["Variable"] = 15] = "Variable";
31
+ })(Predictor || (Predictor = {}));
32
+ export const defaultOptions = {
33
+ lossless: false,
34
+ quality: 75,
35
+ alphaQuality: 100,
36
+ effort: 7,
37
+ brotliEffort: -1,
38
+ epf: -1,
39
+ gaborish: -1,
40
+ responsive: -1,
41
+ progressiveDC: -1,
42
+ progressiveAC: -1,
43
+ qProgressiveAC: -1,
44
+ decodingSpeed: 0,
45
+ photonNoiseIso: 0,
46
+ modular: false,
47
+ lossyPalette: false,
48
+ paletteColors: -1,
49
+ iterations: -1,
50
+ modularColorspace: -1,
51
+ modularPredictor: Predictor.Default,
52
+ };
53
+ export const mimeType = "image/jxl";
54
+ export const extension = "jxl";
55
+ export const bitDepth = [8, 9, 10, 11, 12, 13, 14, 15, 16];
56
+ let encoderWASM;
57
+ let decoderWASM;
58
+ export async function loadEncoder(input) {
59
+ return encoderWASM ??= await loadES(wasmFactoryEnc, input);
60
+ }
61
+ export async function loadDecoder(input) {
62
+ return decoderWASM ??= await loadES(wasmFactoryDec, input);
63
+ }
64
+ export function encode(image, options) {
65
+ return encodeES("JXL Encode", encoderWASM, defaultOptions, image, options);
66
+ }
67
+ export function decode(input) {
68
+ return check(decoderWASM.decode(input), "JXL Decode");
69
+ }
package/lib/png.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { ImageDataLike, WasmSource } from "./common.js";
2
+ export interface QuantizeOptions {
3
+ /**
4
+ * Range: [1, 10], bigger is faster and generate images of lower quality,
5
+ * but may be useful for real-time generation of images.
6
+ *
7
+ * @default 4
8
+ */
9
+ speed?: number;
10
+ /**
11
+ * Range [0, 100], roughly like JPEG. the max 100 means best effort
12
+ * If less than 100, the library will try to use fewer colors.
13
+ *
14
+ * Images with fewer colors are not always smaller, due to increased dithering it causes.
15
+ *
16
+ * @default 75
17
+ */
18
+ quality?: number;
19
+ /**
20
+ * Limit the number of colors in palette, range: [2, 256].
21
+ *
22
+ * @default 256
23
+ */
24
+ colors?: number;
25
+ /**
26
+ * Range [0, 1] float, set to 1 to get nice smooth image.
27
+ *
28
+ * @default 1
29
+ */
30
+ dithering?: number;
31
+ }
32
+ export interface Options extends QuantizeOptions {
33
+ /**
34
+ * Range [0, 6], bigger means smallest file and slower compression.
35
+ *
36
+ * @default 3
37
+ */
38
+ level?: number;
39
+ /**
40
+ * Is the image made to support progressive loading?
41
+ * Enabling this feature will increase the size of the results.
42
+ *
43
+ * @default false
44
+ */
45
+ interlace?: boolean;
46
+ /**
47
+ * Lossy compress the image to PNG for significant file size reduction.
48
+ * Implements the same functionality as [pngquant](https://pngquant.org)
49
+ *
50
+ * if set to false, properties from `QuantizeOptions` are ignored.
51
+ *
52
+ * @default true
53
+ */
54
+ quantize?: boolean;
55
+ /** @internal */
56
+ bit_depth?: number;
57
+ }
58
+ export declare const defaultOptions: Required<Options>;
59
+ export declare const bitDepth: number[];
60
+ export declare const mimeType = "image/png";
61
+ export declare const extension = "png";
62
+ export declare const loadEncoder: (module_or_path?: WasmSource) => Promise<any>;
63
+ export declare const loadDecoder: (module_or_path?: WasmSource) => Promise<any>;
64
+ /**
65
+ * Reduces the colors used in the image at a slight loss, using a combination
66
+ * of vector quantization algorithms.
67
+ *
68
+ * Can be used before other compression algorithm to boost compression ratio.
69
+ */
70
+ export declare function reduceColors(image: ImageDataLike, options?: QuantizeOptions): Uint8Array<ArrayBufferLike>;
71
+ export declare function encode(image: ImageDataLike, options?: Options): Uint8Array<ArrayBufferLike>;
72
+ export declare function decode(input: Uint8Array): ImageDataLike;
package/lib/png.js ADDED
@@ -0,0 +1,45 @@
1
+ import wasmFactory, { optimize, png_to_rgba, quantize } from "../dist/pngquant.js";
2
+ import { toBitDepth } from "./common.js";
3
+ export const defaultOptions = {
4
+ speed: 4,
5
+ quality: 75,
6
+ colors: 256,
7
+ dithering: 1,
8
+ level: 3,
9
+ interlace: false,
10
+ quantize: true,
11
+ bit_depth: 8,
12
+ };
13
+ export const bitDepth = [8, 16];
14
+ export const mimeType = "image/png";
15
+ export const extension = "png";
16
+ export const loadEncoder = (module_or_path) => wasmFactory({ module_or_path });
17
+ export const loadDecoder = loadEncoder;
18
+ /**
19
+ * Reduces the colors used in the image at a slight loss, using a combination
20
+ * of vector quantization algorithms.
21
+ *
22
+ * Can be used before other compression algorithm to boost compression ratio.
23
+ */
24
+ export function reduceColors(image, options) {
25
+ options = { ...defaultOptions, ...options };
26
+ const { data, width, height } = toBitDepth(image, 8);
27
+ return quantize(data, width, height, { ...defaultOptions, ...options });
28
+ }
29
+ export function encode(image, options) {
30
+ options = { ...defaultOptions, ...options };
31
+ if (options.quantize) {
32
+ image = toBitDepth(image, 8);
33
+ }
34
+ const { data, width, height, depth } = image;
35
+ options.bit_depth = depth;
36
+ return optimize(data, width, height, { ...defaultOptions, ...options });
37
+ }
38
+ export function decode(input) {
39
+ const [data, width, depth] = png_to_rgba(input);
40
+ let height = data.byteLength / width / 4;
41
+ if (depth === 16) {
42
+ height /= 2;
43
+ }
44
+ return _icodec_ImageData(data, width, height, depth);
45
+ }
package/lib/qoi.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { ImageDataLike, WasmSource } from "./common.js";
2
+ /**
3
+ * QOI encoder does not have options, it's always lossless.
4
+ */
5
+ export type Options = never;
6
+ export declare const defaultOptions: never;
7
+ export declare const bitDepth: number[];
8
+ export declare const mimeType = "image/qoi";
9
+ export declare const extension = "qoi";
10
+ export declare function loadEncoder(input?: WasmSource): Promise<any>;
11
+ export declare const loadDecoder: typeof loadEncoder;
12
+ export declare function encode(image: ImageDataLike): Uint8Array<ArrayBufferLike>;
13
+ export declare function decode(input: BufferSource): ImageData;
package/lib/qoi.js ADDED
@@ -0,0 +1,19 @@
1
+ import wasmFactory from "../dist/qoi.js";
2
+ import { check, loadES } from "./common.js";
3
+ export const defaultOptions = undefined;
4
+ export const bitDepth = [8];
5
+ export const mimeType = "image/qoi";
6
+ export const extension = "qoi";
7
+ let codecWASM;
8
+ export async function loadEncoder(input) {
9
+ return codecWASM = await loadES(wasmFactory, input);
10
+ }
11
+ export const loadDecoder = loadEncoder;
12
+ export function encode(image) {
13
+ const { data, width, height } = image;
14
+ const result = codecWASM.encode(data, width, height, undefined);
15
+ return check(result, "QOI Encode");
16
+ }
17
+ export function decode(input) {
18
+ return check(codecWASM.decode(input), "QOI Decode");
19
+ }
package/lib/webp.d.ts ADDED
@@ -0,0 +1,219 @@
1
+ import { ImageDataLike, WasmSource } from "./common.js";
2
+ export declare enum Preprocess {
3
+ None = 0,
4
+ SegmentSmooth = 1,
5
+ Dithering = 2
6
+ }
7
+ export declare enum AlphaFiltering {
8
+ None = 0,
9
+ Fast = 1,
10
+ Best = 2
11
+ }
12
+ export interface Options {
13
+ /**
14
+ * Encode the image without any loss (pixel values of fully transparent area may different).
15
+ *
16
+ * @default false
17
+ */
18
+ lossless?: boolean;
19
+ /**
20
+ * Specify the level of near-lossless image preprocessing. This option adjusts pixel values
21
+ * to help compressibility, but has minimal impact on the visual quality.
22
+ * It triggers lossless compression mode automatically.
23
+ *
24
+ * The range is 0 (maximum preprocessing) to 100 (no preprocessing).
25
+ * The typical value is around 60. Note that lossy with -q 100 can at times yield better results.
26
+ *
27
+ * @default 100
28
+ */
29
+ nearLossless?: number;
30
+ /**
31
+ * Specify the compression factor for RGB channels between 0 and 100.
32
+ *
33
+ * In case of lossy compression (default), a small factor produces a smaller file
34
+ * with lower quality. Best quality is achieved by using a value of 100.
35
+ *
36
+ * In case of lossless compression, a small factor enables faster compression speed,
37
+ * but produces a larger file. Maximum compression is achieved by using a value of 100.
38
+ *
39
+ * @default 75
40
+ */
41
+ quality?: number;
42
+ /**
43
+ * Specify the compression factor for alpha compression between 0 and 100.
44
+ * Lossless compression of alpha is achieved using a value of 100, while the lower
45
+ * values result in a lossy compression. The default is 100.
46
+ *
47
+ * @default 100
48
+ */
49
+ alphaQuality?: number;
50
+ /**
51
+ * Specify the compression method to use. This parameter controls the trade off between
52
+ * encoding speed and the compressed file size and quality.
53
+ *
54
+ * Possible values range from 0 to 6. When higher values are used, the encoder will spend more
55
+ * time inspecting additional encoding possibilities and decide on the quality gain.
56
+ *
57
+ * Lower value can result in faster processing at the expense of larger file size and lower quality.
58
+ *
59
+ * @default 4
60
+ */
61
+ method?: number;
62
+ /**
63
+ * Specify the amplitude of the spatial noise shaping. Spatial noise shaping (or sns for short)
64
+ * refers to a general collection of built-in algorithms used to decide which area of the
65
+ * picture should use relatively less bits, and where else to better transfer these bits.
66
+ *
67
+ * The possible range goes from 0 (algorithm is off) to 100 (the maximal effect).
68
+ *
69
+ * @default 50
70
+ */
71
+ snsStrength?: number;
72
+ /**
73
+ * Specify the strength of the deblocking filter, between 0 (no filtering) and 100 (maximum filtering).
74
+ * A value of 0 will turn off any filtering. Higher value will increase the strength of the filtering
75
+ * process applied after decoding the picture. The higher the value the smoother the picture will appear.
76
+ *
77
+ * @default 60
78
+ */
79
+ filterStrength?: number;
80
+ /**
81
+ * Specify the sharpness of the filtering (if used). Range is 0 (sharpest) to 7 (least sharp).
82
+ *
83
+ * @default 0
84
+ */
85
+ filterSharpness?: number;
86
+ /**
87
+ * Use strong filtering (if filtering is being used thanks to the `filter_strength`).
88
+ *
89
+ * @default true
90
+ */
91
+ filterType?: boolean;
92
+ /**
93
+ * Change the number of partitions to use during the segmentation of the sns algorithm.
94
+ * Range [1, 4], this option has no effect for methods 3 and up, unless `low_memory` is used.
95
+ *
96
+ * @default 4
97
+ */
98
+ segments?: number;
99
+ /**
100
+ * Specify some pre-processing steps. Using a value of 2 will trigger quality-dependent pseudo-random
101
+ * dithering during RGBA->YUVA conversion (lossy compression only).
102
+ *
103
+ * @default Preprocess.None
104
+ */
105
+ preprocessing?: Preprocess;
106
+ /**
107
+ * Turns auto-filter on. This algorithm will spend additional time optimizing the
108
+ * filtering strength to reach a well-balanced quality.
109
+ *
110
+ * @default 0
111
+ */
112
+ autofilter?: boolean;
113
+ /**
114
+ * Degrade quality by limiting the number of bits used by some macroblocks.
115
+ * Range is 0 (no degradation, the default) to 100 (full degradation).
116
+ * Useful values are usually around 30-70 for moderately large images.
117
+ *
118
+ * In the VP8 format, the so-called control partition has a limit of 512k and is used to store
119
+ * the following information: whether the macroblock is skipped, which segment it belongs to,
120
+ * whether it is coded as intra 4x4 or intra 16x16 mode, and finally the prediction modes to use
121
+ * for each of the sub-blocks.
122
+ *
123
+ * For a very large image, 512k only leaves room for a few bits per 16x16 macroblock.
124
+ * The absolute minimum is 4 bits per macroblock. Skip, segment, and mode information can use up almost
125
+ * all these 4 bits (although the case is unlikely), which is problematic for very large images.
126
+ *
127
+ * `partitionLimit` controls how frequently the most bit-costly mode (intra 4x4) will be used.
128
+ * This is useful in case the 512k limit is reached.
129
+ *
130
+ * If using -partition_limit is not enough to meet the 512k constraint, one should use less segments
131
+ * in order to save more header bits per macroblock. See the `segments` option.
132
+ *
133
+ * Note the -m and -q options also influence the encoder's decisions and ability to hit this limit.
134
+ *
135
+ * @default 0
136
+ */
137
+ partitionLimit?: number;
138
+ /**
139
+ * Specify the algorithm used for alpha compression: 0 or 1.
140
+ * Algorithm 0 denotes no compression, 1 uses WebP lossless format for compression.
141
+ *
142
+ * @default 1
143
+ */
144
+ alphaCompression?: number;
145
+ /**
146
+ * Specify the predictive filtering method for the alpha plane. One of none,
147
+ * fast or best, in increasing complexity and slowness order.
148
+ *
149
+ * Internally, alpha filtering is performed using four possible predictions (none, horizontal, vertical, gradient).
150
+ * The best mode will try each mode in turn and pick the one which gives the smaller size.
151
+ *
152
+ * The fast mode will just try to form an a priori guess without testing all modes.
153
+ *
154
+ * @default AlphaFiltering.Fast
155
+ */
156
+ alphaFiltering?: AlphaFiltering;
157
+ /**
158
+ * Use more accurate and sharper RGB->YUV conversion if needed.
159
+ * Note that this process is slower than the default conversion.
160
+ *
161
+ * @default false
162
+ */
163
+ sharpYUV?: boolean;
164
+ /**
165
+ * Preserve RGB values in transparent area. The default is off, to help compressibility.
166
+ */
167
+ exact?: boolean;
168
+ /**
169
+ * Specify a target size (in bytes) to try and reach for the compressed output.
170
+ * The compressor will make several passes of partial encoding in order to get as close as possible to this target.
171
+ * If both `target_size` and `target_PSNR` are used, `target_size` value will prevail.
172
+ */
173
+ targetSize?: number;
174
+ /**
175
+ * Specify a target PSNR (in dB) to try and reach for the compressed output.
176
+ * The compressor will make several passes of partial encoding in order to get as close as possible to this target.
177
+ * If both `target_size` and `target_PSNR` are used, `target_size` value will prevail.
178
+ */
179
+ targetPSNR?: number;
180
+ /**
181
+ * Set a maximum number of passes to use during the dichotomy used by `target_size` or `target_PSNR`.
182
+ *
183
+ * Maximum value is 10. If options `target_size` or `target_PSNR` were used, but `pass` wasn't specified,
184
+ * a default value of '6' passes will be used. If `pass` is specified,
185
+ * but neither `target_size` nor `target_PSNR` are, a target PSNR of 40dB will be used.
186
+ *
187
+ * @default 1
188
+ */
189
+ pass?: number;
190
+ /**
191
+ * Reduce memory usage of lossy encoding by saving four times the compressed size (typically).
192
+ * This will make the encoding slower and the output slightly different in size and distortion.
193
+ *
194
+ * This flag is only effective for methods 3 and up, and is off by default.
195
+ *
196
+ * Note that leaving this flag off will have some side effects on the bitstream:
197
+ * it forces certain bitstream features like number of partitions (forced to 1).
198
+ *
199
+ * @default false
200
+ */
201
+ lowMemory?: boolean;
202
+ /**
203
+ * Change the internal parameter mapping to better match the expected size of JPEG compression.
204
+ *
205
+ * This flag will generally produce an output file of similar size to its JPEG equivalent
206
+ * (for the same `quality` setting), but with less visual distortion.
207
+ *
208
+ * @default false
209
+ */
210
+ emulateJpegSize?: boolean;
211
+ }
212
+ export declare const defaultOptions: Required<Options> & Record<string, any>;
213
+ export declare const bitDepth: number[];
214
+ export declare const mimeType = "image/webp";
215
+ export declare const extension = "webp";
216
+ export declare function loadEncoder(input?: WasmSource): Promise<any>;
217
+ export declare function loadDecoder(input?: WasmSource): Promise<any>;
218
+ export declare function encode(image: ImageDataLike, options?: Options): Uint8Array<ArrayBufferLike>;
219
+ export declare function decode(input: BufferSource): ImageData;
package/lib/webp.js ADDED
@@ -0,0 +1,62 @@
1
+ import wasmFactoryEnc from "../dist/webp-enc.js";
2
+ import wasmFactoryDec from "../dist/webp-dec.js";
3
+ import { check, encodeES, loadES } from "./common.js";
4
+ export var Preprocess;
5
+ (function (Preprocess) {
6
+ Preprocess[Preprocess["None"] = 0] = "None";
7
+ Preprocess[Preprocess["SegmentSmooth"] = 1] = "SegmentSmooth";
8
+ Preprocess[Preprocess["Dithering"] = 2] = "Dithering";
9
+ })(Preprocess || (Preprocess = {}));
10
+ export var AlphaFiltering;
11
+ (function (AlphaFiltering) {
12
+ AlphaFiltering[AlphaFiltering["None"] = 0] = "None";
13
+ AlphaFiltering[AlphaFiltering["Fast"] = 1] = "Fast";
14
+ AlphaFiltering[AlphaFiltering["Best"] = 2] = "Best";
15
+ })(AlphaFiltering || (AlphaFiltering = {}));
16
+ export const defaultOptions = {
17
+ lossless: false,
18
+ nearLossless: 100,
19
+ quality: 75,
20
+ targetSize: 0,
21
+ targetPSNR: 0,
22
+ method: 4,
23
+ snsStrength: 50,
24
+ filterStrength: 60,
25
+ filterSharpness: 0,
26
+ filterType: true,
27
+ segments: 4,
28
+ pass: 1,
29
+ sharpYUV: false,
30
+ preprocessing: Preprocess.None,
31
+ autofilter: false,
32
+ partitionLimit: 0,
33
+ alphaCompression: 1,
34
+ alphaFiltering: AlphaFiltering.Fast,
35
+ alphaQuality: 100,
36
+ exact: false,
37
+ emulateJpegSize: false,
38
+ lowMemory: false,
39
+ // Undocumented options, only for compatibility.
40
+ partitions: 0,
41
+ showCompressed: 0,
42
+ imageHint: 0,
43
+ threadLevel: 0,
44
+ useDeltaPalette: 0,
45
+ };
46
+ export const bitDepth = [8];
47
+ export const mimeType = "image/webp";
48
+ export const extension = "webp";
49
+ let encoderWASM;
50
+ let decoderWASM;
51
+ export async function loadEncoder(input) {
52
+ return encoderWASM ??= await loadES(wasmFactoryEnc, input);
53
+ }
54
+ export async function loadDecoder(input) {
55
+ return decoderWASM ??= await loadES(wasmFactoryDec, input);
56
+ }
57
+ export function encode(image, options) {
58
+ return encodeES("Webp Encode", encoderWASM, defaultOptions, image, options);
59
+ }
60
+ export function decode(input) {
61
+ return check(decoderWASM.decode(input), "Webp Decode");
62
+ }