imagescript 3.4.0 → 3.6.0
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/README.md +5 -1
- package/THIRD_PARTY_NOTICES.md +40 -3
- package/dist/animation.d.ts +1 -1
- package/dist/animation.js +1 -1
- package/dist/codecs/av1/cdef.js +17 -3
- package/dist/codecs/av1/encode.js +1630 -0
- package/dist/codecs/av1/fdct-lee.js +156 -0
- package/dist/codecs/av1/fdct.js +185 -0
- package/dist/codecs/av1/itx.js +15 -0
- package/dist/codecs/av1/msac-enc.js +126 -0
- package/dist/codecs/av1/obu-enc.js +153 -0
- package/dist/codecs/av1/palette.js +110 -0
- package/dist/codecs/avif-enc.js +224 -0
- package/dist/codecs/jxl/color.js +28 -10
- package/dist/codecs/jxl/dct.js +3 -38
- package/dist/codecs/jxl/entropy.js +27 -23
- package/dist/codecs/jxl/fast-lossless.js +805 -0
- package/dist/codecs/jxl/filters.js +66 -32
- package/dist/codecs/jxl/modular.js +69 -42
- package/dist/codecs/jxl.js +13 -0
- package/dist/codecs/png.js +29 -26
- package/dist/codecs/vp8-enc-dsp.js +20 -13
- package/dist/codecs/vp8-enc.js +35 -14
- package/dist/image.d.ts +29 -3
- package/dist/image.js +9 -1
- package/dist/metadata.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,9 @@ deno add jsr:@matmen/imagescript # Deno (npm:imagescript works too)
|
|
|
67
67
|
, [JPEGs](https://imagescript.matmen.dev/classes/Image.html#encodejpeg)
|
|
68
68
|
, lossless and lossy [WebPs](https://imagescript.matmen.dev/classes/Image.html#encodewebp) (lossy ones byte for
|
|
69
69
|
byte like libwebp's cwebp)
|
|
70
|
+
, [AVIFs](https://imagescript.matmen.dev/classes/Image.html#encodeavif) (lossy and lossless, with alpha)
|
|
71
|
+
, lossless [JPEG XLs](https://imagescript.matmen.dev/classes/Image.html#encodejxl) (byte for byte like libjxl's
|
|
72
|
+
`cjxl -e 1`)
|
|
70
73
|
, [BMPs](https://imagescript.matmen.dev/classes/Image.html#encodebmp)
|
|
71
74
|
, [QOIs](https://imagescript.matmen.dev/classes/Image.html#encodeqoi)
|
|
72
75
|
, [Netpbm images](https://imagescript.matmen.dev/classes/Image.html#encodepnm) (PBM, PGM, PPM or PAM, whichever is
|
|
@@ -126,7 +129,8 @@ the text shaping is ported from [HarfBuzz](https://github.com/harfbuzz/harfbuzz)
|
|
|
126
129
|
[Unicode Character Database](https://www.unicode.org/ucd/). The AV1 decoder is ported from
|
|
127
130
|
[dav1d](https://code.videolan.org/videolan/dav1d), AVIFs are converted to RGB like
|
|
128
131
|
[libavif](https://github.com/AOMediaCodec/libavif) does, the JPEG XL decoder is ported from
|
|
129
|
-
[jxl-oxide](https://github.com/tirr-c/jxl-oxide) and [libjxl](https://github.com/libjxl/libjxl)
|
|
132
|
+
[jxl-oxide](https://github.com/tirr-c/jxl-oxide) and [libjxl](https://github.com/libjxl/libjxl), the JPEG XL encoder
|
|
133
|
+
from libjxl's fast lossless encoder, the AV1 encoder mirrors the decoder and uses libaom's symbol encoder.
|
|
130
134
|
See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for their licenses.
|
|
131
135
|
|
|
132
136
|
---
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -13,10 +13,11 @@ following projects, under their own licenses. Each derived file says so in its h
|
|
|
13
13
|
| [RFC 9649](https://www.rfc-editor.org/rfc/rfc9649) (WebP Image Format) | `src/codecs/vp8l.ts` (lossless bitstream, short distance code table), `src/codecs/webp.ts` (container) | BSD-3-Clause (Revised BSD) |
|
|
14
14
|
| [RFC 6386](https://www.rfc-editor.org/rfc/rfc6386) (VP8 Data Format and Decoding Guide, with the libvpx reference decoder) | `src/codecs/vp8-tables.ts` (probability and quantizer tables), `src/codecs/vp8.ts` (decoding procedures) | BSD-3-Clause |
|
|
15
15
|
| [libwebp](https://chromium.googlesource.com/webm/libwebp) | `src/codecs/vp8.ts` (YUV to RGB conversion, "fancy" chroma upsampling), `src/codecs/webp.ts` (animation frame blending), `src/codecs/vp8-enc.ts`, `src/codecs/vp8-enc-dsp.ts` (the lossy encoder: RGB to YUV conversion, analysis, segments, rate-distortion optimized mode decisions, quantization, token probabilities, bitstream, alpha filtering), `src/codecs/vp8-enc-tables.ts` (its tables, generated from libwebp by `scripts/vp8-enc-tables.py`) | BSD-3-Clause |
|
|
16
|
-
| [dav1d](https://code.videolan.org/videolan/dav1d) by VideoLAN, the dav1d authors and Two Orioles | `src/codecs/av1/*` (the AV1 decoder: bitstream parsing, symbol decoding, prediction, inverse transforms, loop filters, film grain; the tables in `src/codecs/av1/data.ts`, generated from dav1d by `scripts/av1-tables.c`) | BSD-2-Clause |
|
|
16
|
+
| [dav1d](https://code.videolan.org/videolan/dav1d) by VideoLAN, the dav1d authors and Two Orioles | `src/codecs/av1/*` (the AV1 decoder, and the encoder's syntax, contexts and reconstruction mirrored from it: bitstream parsing, symbol decoding, prediction, inverse transforms, loop filters, film grain; the tables in `src/codecs/av1/data.ts`, generated from dav1d by `scripts/av1-tables.c`) | BSD-2-Clause |
|
|
17
|
+
| [libaom](https://aomedia.googlesource.com/aom/) by the Alliance for Open Media | `src/codecs/av1/msac-enc.ts` (the symbol encoder), `src/codecs/av1/fdct.ts` (the forward Walsh-Hadamard transform), `src/codecs/av1/encode.ts` (the loop filter level from the quantizer), `src/codecs/avif-enc.ts` (the quantizer to qindex table) | BSD-2-Clause |
|
|
17
18
|
| [libavif](https://github.com/AOMediaCodec/libavif) by Joe Drago | `src/codecs/avif.ts` (YUV to RGB conversion with bilinear chroma upsampling, alpha range expansion and unpremultiplication) | BSD-2-Clause |
|
|
18
19
|
| [jxl-oxide](https://github.com/tirr-c/jxl-oxide) by Wonwoo Choi | `src/codecs/jxl/*` (the JPEG XL decoder: bit reader, header and frame header fields, entropy decoding, VarDCT, dequantization matrices, transforms, restoration filters, upsampling, the parsing of patches, splines and noise) | MIT (or Apache-2.0) |
|
|
19
|
-
| [libjxl](https://github.com/libjxl/libjxl) by the JPEG XL Project Authors | `src/codecs/jxl/modular.ts` (Modular decoding: MA trees, predictors, the self-correcting predictor, transforms), `src/codecs/jxl/frame.ts` (the sections of frames, the order of the rendering stages, reference frames), `src/codecs/jxl/blend.ts`, `src/codecs/jxl/color.ts` (XYB to RGB), `src/codecs/jxl/features.ts` (rendering patches, splines and noise) | BSD-3-Clause |
|
|
20
|
+
| [libjxl](https://github.com/libjxl/libjxl) by the JPEG XL Project Authors | `src/codecs/jxl/modular.ts` (Modular decoding: MA trees, predictors, the self-correcting predictor, transforms), `src/codecs/jxl/frame.ts` (the sections of frames, the order of the rendering stages, reference frames), `src/codecs/jxl/blend.ts`, `src/codecs/jxl/color.ts` (XYB to RGB), `src/codecs/jxl/features.ts` (rendering patches, splines and noise), `src/codecs/jxl/fast-lossless.ts` (the lossless encoder: palette detection, YCoCg, the gradient predictor, prefix codes, runs as LZ77, the headers) | BSD-3-Clause |
|
|
20
21
|
| [JPEG XL conformance](https://github.com/libjxl/conformance) by the JPEG XL Project Authors | `tests/jxl/alpha-*.jxl`, `animation-spline.jxl`, `blendmodes.jxl`, `mul-no-extra-channels.jxl` (test files) | BSD-3-Clause |
|
|
21
22
|
| [FreeType](https://freetype.org) | `src/render/hinting.ts` (behavior and parts of the logic of the TrueType interpreter) | FreeType License |
|
|
22
23
|
| [QOI](https://github.com/phoboslab/qoi) by Dominic Szablewski | `src/codecs/qoi.ts` (the reference encoder's choices of operations) | MIT |
|
|
@@ -188,6 +189,41 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
188
189
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
189
190
|
```
|
|
190
191
|
|
|
192
|
+
## libaom
|
|
193
|
+
|
|
194
|
+
The AV1 encoder's symbol encoder and forward Walsh-Hadamard transform are ported from libaom, the AV1 reference
|
|
195
|
+
implementation, as are its guess of the loop filter level and the quantizer table of the quality. AV1 is covered by the
|
|
196
|
+
[Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/).
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
Copyright (c) 2016, Alliance for Open Media. All rights reserved.
|
|
200
|
+
|
|
201
|
+
Redistribution and use in source and binary forms, with or without
|
|
202
|
+
modification, are permitted provided that the following conditions
|
|
203
|
+
are met:
|
|
204
|
+
|
|
205
|
+
1. Redistributions of source code must retain the above copyright
|
|
206
|
+
notice, this list of conditions and the following disclaimer.
|
|
207
|
+
|
|
208
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
209
|
+
notice, this list of conditions and the following disclaimer in
|
|
210
|
+
the documentation and/or other materials provided with the
|
|
211
|
+
distribution.
|
|
212
|
+
|
|
213
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
214
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
215
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
216
|
+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
217
|
+
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
218
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
219
|
+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
220
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
221
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
222
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
223
|
+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
224
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
225
|
+
```
|
|
226
|
+
|
|
191
227
|
## libavif
|
|
192
228
|
|
|
193
229
|
The conversion of decoded AVIFs to RGB reproduces libavif's reference conversion (in floating point, with bilinear
|
|
@@ -254,7 +290,8 @@ DEALINGS IN THE SOFTWARE.
|
|
|
254
290
|
## libjxl, JPEG XL conformance
|
|
255
291
|
|
|
256
292
|
The Modular decoding, the rendering pipeline, blending, the XYB conversion and the rendering of patches, splines and
|
|
257
|
-
noise follow libjxl, the JPEG XL reference implementation
|
|
293
|
+
noise follow libjxl, the JPEG XL reference implementation, and the lossless encoder is ported from its fast lossless
|
|
294
|
+
encoder; tests/jxl includes files of its conformance suite. JPEG XL
|
|
258
295
|
is covered by Google's patent grant for libjxl (the "Additional IP Rights Grant" in libjxl's PATENTS file).
|
|
259
296
|
|
|
260
297
|
```
|
package/dist/animation.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface WebPAnimationEncodeOptions extends AnimationEncodeOptions {
|
|
|
36
36
|
* frames are lossless
|
|
37
37
|
*/
|
|
38
38
|
quality?: number;
|
|
39
|
-
/** How much effort lossy frames take (0-6), see {@link WebPEncodeOptions.effort}. Default: `
|
|
39
|
+
/** How much effort lossy frames take (0-6), see {@link WebPEncodeOptions.effort}. Default: `2` */
|
|
40
40
|
effort?: number;
|
|
41
41
|
}
|
|
42
42
|
/** Options of {@link Animation.encodeGIF} */
|
package/dist/animation.js
CHANGED
|
@@ -124,7 +124,7 @@ export class Animation extends Array {
|
|
|
124
124
|
: this.__apngFrames__().map(({ blend: _, ...f }) => f);
|
|
125
125
|
return png.encodeAnimation(frames, this.width, this.height, toPlays(this.loopCount), compression, pngText(resolveMetadata(metadata)));
|
|
126
126
|
}
|
|
127
|
-
async encodeWebP({ metadata = {}, optimize = true, quality, effort =
|
|
127
|
+
async encodeWebP({ metadata = {}, optimize = true, quality, effort = 2 } = {}) {
|
|
128
128
|
this.__validate__();
|
|
129
129
|
if (!this.length)
|
|
130
130
|
throw new Error('An animation needs at least one frame');
|
package/dist/codecs/av1/cdef.js
CHANGED
|
@@ -11,7 +11,7 @@ export function cdefActive(f) {
|
|
|
11
11
|
const c = f.hdr.cdef;
|
|
12
12
|
return f.seq.cdef && (c.yStrengths.some(s => s) || c.uvStrengths.some(s => s));
|
|
13
13
|
}
|
|
14
|
-
export function cdef(f, src) {
|
|
14
|
+
export function cdef(f, src, dirs) {
|
|
15
15
|
const c = f.hdr.cdef;
|
|
16
16
|
const coeffShift = f.bitdepth - 8;
|
|
17
17
|
const s4 = f.b4Stride;
|
|
@@ -24,8 +24,22 @@ export function cdef(f, src) {
|
|
|
24
24
|
if (f.skip[o] && f.skip[o + s4] && f.skip[o + 1] && f.skip[o + s4 + 1])
|
|
25
25
|
continue;
|
|
26
26
|
const usesDirection = c.yStrengths[idx] >> 2 || (f.planes.length > 1 && c.uvStrengths[idx] >> 2);
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
let yDir = 0, variance = 0;
|
|
28
|
+
if (usesDirection) {
|
|
29
|
+
const k = (r >> 1) * (s4 >> 1) + (col >> 1);
|
|
30
|
+
if (dirs && dirs[2 * k] >= 0) {
|
|
31
|
+
yDir = dirs[2 * k];
|
|
32
|
+
variance = dirs[2 * k + 1];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
yDir = direction(src[0], r * 4 * f.strides[0] + col * 4, f.strides[0], coeffShift);
|
|
36
|
+
variance = directionVariance;
|
|
37
|
+
if (dirs) {
|
|
38
|
+
dirs[2 * k] = yDir;
|
|
39
|
+
dirs[2 * k + 1] = variance;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
29
43
|
const ys = c.yStrengths[idx];
|
|
30
44
|
let priStr = (ys >> 2) << coeffShift;
|
|
31
45
|
const secY = ys & 3;
|