imagescript 4.0.0-rc.4 → 4.0.0-rc.6
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 +9 -5
- package/dist/animation-encoder.d.ts +2 -1
- package/dist/animation-encoder.js +23 -19
- package/dist/animation.d.ts +26 -20
- package/dist/animation.js +58 -55
- package/dist/codecs/avif-enc.js +3 -3
- package/dist/codecs/avif.js +7 -2
- package/dist/codecs/bmp.js +1 -1
- package/dist/codecs/gif.js +2 -2
- package/dist/codecs/jpeg.js +55 -14
- package/dist/codecs/jxl/vardct-enc.js +2 -1
- package/dist/codecs/png.js +7 -3
- package/dist/codecs/tga.js +4 -3
- package/dist/codecs/tiff.js +1 -1
- package/dist/codecs/vp8.js +1 -1
- package/dist/codecs/vp8l.js +4 -3
- package/dist/codecs/webp.js +11 -9
- package/dist/colors.d.ts +10 -8
- package/dist/colors.js +28 -31
- package/dist/frame.d.ts +4 -3
- package/dist/frame.js +6 -8
- package/dist/gainmap.d.ts +6 -6
- package/dist/gainmap.js +32 -24
- package/dist/image.d.ts +75 -37
- package/dist/image.js +189 -163
- package/dist/metadata.d.ts +12 -1
- package/dist/metadata.js +30 -5
- package/dist/render/color.js +16 -3
- package/dist/render/colr.js +3 -3
- package/dist/render/filter.js +27 -3
- package/dist/render/font.js +54 -18
- package/dist/render/layout.js +2 -2
- package/dist/render/linebreak.js +9 -12
- package/dist/render/svg-text.js +112 -28
- package/dist/render/svg.js +183 -34
- package/dist/render/text.js +93 -23
- package/dist/text-layout.d.ts +2 -1
- package/dist/text-layout.js +3 -8
- package/dist/util/alpha.js +1 -1
- package/dist/util/inspect.js +16 -0
- package/dist/util/limits.d.ts +16 -3
- package/dist/util/limits.js +20 -5
- package/dist/util/mem.d.ts +2 -0
- package/dist/util/mem.js +24 -4
- package/dist/util/optimize.js +4 -3
- package/dist/util/options.js +104 -7
- package/package.json +1 -1
package/dist/gainmap.js
CHANGED
|
@@ -3,17 +3,23 @@ import { MAX_PIXELS, decoding } from "./util/limits.js";
|
|
|
3
3
|
import * as jpeg from "./codecs/jpeg.js";
|
|
4
4
|
import * as codec from "./codecs/gainmap.js";
|
|
5
5
|
import { view } from "./util/mem.js";
|
|
6
|
-
import { finite, checkOptions, pixelLimit, quality as checkQuality } from "./util/options.js";
|
|
6
|
+
import { shown, instance, nonNegative, finite, checkOptions, pixelLimit, boolean, quality as checkQuality } from "./util/options.js";
|
|
7
|
+
const LIMIT = 2 ** 31 - 1;
|
|
8
|
+
const MIN_GAMMA = 2 ** -31;
|
|
9
|
+
const bounded = (value, name) => {
|
|
10
|
+
finite(value, name);
|
|
11
|
+
if (Math.abs(value) > LIMIT)
|
|
12
|
+
throw new RangeError(`${name} must be from -${LIMIT} to ${LIMIT}, not ${value}`);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
7
15
|
const perChannel = (value, name) => {
|
|
8
16
|
const given = value;
|
|
9
17
|
if (typeof given !== 'number' && !Array.isArray(given))
|
|
10
|
-
throw new TypeError(`${name} must be a number or an array of 3 numbers, not ${given
|
|
18
|
+
throw new TypeError(`${name} must be a number or an array of 3 numbers, not ${shown(given)}`);
|
|
11
19
|
const values = typeof value === 'number' ? [value, value, value] : Array.from(value);
|
|
12
|
-
if (values.length === 1)
|
|
13
|
-
values.push(values[0], values[0]);
|
|
14
20
|
if (values.length !== 3)
|
|
15
|
-
throw new RangeError(`${name} must be a number or an array of 3 numbers`);
|
|
16
|
-
return values.map(v =>
|
|
21
|
+
throw new RangeError(`${name} must be a number or an array of 3 numbers, not ${values.length}`);
|
|
22
|
+
return values.map(v => bounded(v, name));
|
|
17
23
|
};
|
|
18
24
|
export class GainMap {
|
|
19
25
|
__min__;
|
|
@@ -24,6 +30,7 @@ export class GainMap {
|
|
|
24
30
|
__capacityMin__;
|
|
25
31
|
__capacityMax__;
|
|
26
32
|
__useBaseColorSpace__;
|
|
33
|
+
__alternate__;
|
|
27
34
|
get min() { return [this.__min__[0], this.__min__[1], this.__min__[2]]; }
|
|
28
35
|
set min(value) { this.__min__ = perChannel(value, 'min'); }
|
|
29
36
|
get max() { return [this.__max__[0], this.__max__[1], this.__max__[2]]; }
|
|
@@ -31,8 +38,8 @@ export class GainMap {
|
|
|
31
38
|
get gamma() { return [this.__gamma__[0], this.__gamma__[1], this.__gamma__[2]]; }
|
|
32
39
|
set gamma(value) {
|
|
33
40
|
const gamma = perChannel(value, 'gamma');
|
|
34
|
-
if (gamma.some(g => g
|
|
35
|
-
throw new RangeError(
|
|
41
|
+
if (gamma.some(g => g < MIN_GAMMA))
|
|
42
|
+
throw new RangeError(`The gain map's gamma must be 2^-31 or more, not ${gamma.find(g => g < MIN_GAMMA)}`);
|
|
36
43
|
this.__gamma__ = gamma;
|
|
37
44
|
}
|
|
38
45
|
get offsetSDR() { return [this.__offsetSDR__[0], this.__offsetSDR__[1], this.__offsetSDR__[2]]; }
|
|
@@ -41,24 +48,26 @@ export class GainMap {
|
|
|
41
48
|
set offsetHDR(value) { this.__offsetHDR__ = perChannel(value, 'offsetHDR'); }
|
|
42
49
|
get hdrCapacityMin() { return this.__capacityMin__; }
|
|
43
50
|
set hdrCapacityMin(value) {
|
|
44
|
-
const capacity =
|
|
45
|
-
if (capacity <
|
|
46
|
-
throw new RangeError(
|
|
51
|
+
const capacity = bounded(nonNegative(value, 'hdrCapacityMin'), 'hdrCapacityMin');
|
|
52
|
+
if (this.__capacityMax__ !== undefined && !(capacity < this.__capacityMax__))
|
|
53
|
+
throw new RangeError(`The gain map's hdrCapacityMin must be below its hdrCapacityMax (${capacity} >= ${this.__capacityMax__})`);
|
|
47
54
|
this.__capacityMin__ = capacity;
|
|
48
55
|
}
|
|
49
56
|
get hdrCapacityMax() { return this.__capacityMax__; }
|
|
50
|
-
set hdrCapacityMax(value) {
|
|
57
|
+
set hdrCapacityMax(value) {
|
|
58
|
+
const capacity = bounded(value, 'hdrCapacityMax');
|
|
59
|
+
if (this.__capacityMin__ !== undefined && !(capacity > this.__capacityMin__))
|
|
60
|
+
throw new RangeError(`The gain map's hdrCapacityMax (by default the largest max) must be above its hdrCapacityMin (${capacity} <= ${this.__capacityMin__})`);
|
|
61
|
+
this.__capacityMax__ = capacity;
|
|
62
|
+
}
|
|
51
63
|
get useBaseColorSpace() { return this.__useBaseColorSpace__; }
|
|
52
64
|
set useBaseColorSpace(value) {
|
|
53
|
-
|
|
54
|
-
throw new TypeError('useBaseColorSpace must be a boolean');
|
|
55
|
-
this.__useBaseColorSpace__ = value;
|
|
65
|
+
this.__useBaseColorSpace__ = boolean(value, 'useBaseColorSpace');
|
|
56
66
|
}
|
|
57
67
|
__pixels__ = null;
|
|
58
68
|
constructor(image, options = {}) {
|
|
59
69
|
checkOptions(options, 'new GainMap(image, { max: 2 })');
|
|
60
|
-
|
|
61
|
-
throw new TypeError('The gain map has to be an Image');
|
|
70
|
+
instance(image, [Image], 'the gain map image');
|
|
62
71
|
const { min = 0, max = 2, gamma = 1, offsetSDR = 1 / 64, offsetHDR = 1 / 64, hdrCapacityMin = 0, useBaseColorSpace = true } = options;
|
|
63
72
|
this.min = min;
|
|
64
73
|
this.max = max;
|
|
@@ -111,27 +120,26 @@ export class GainMap {
|
|
|
111
120
|
this.__capacityMin__ = p.capacityMin;
|
|
112
121
|
this.__capacityMax__ = p.capacityMax;
|
|
113
122
|
this.__useBaseColorSpace__ = p.useBaseColorSpace;
|
|
123
|
+
this.__alternate__ = p.alternate?.slice();
|
|
114
124
|
}
|
|
115
125
|
__params__() {
|
|
116
126
|
this.__check__();
|
|
117
127
|
return {
|
|
118
128
|
min: this.__min__.slice(), max: this.__max__.slice(), gamma: this.__gamma__.slice(), offsetSDR: this.__offsetSDR__.slice(),
|
|
119
|
-
offsetHDR: this.__offsetHDR__.slice(), capacityMin: this.__capacityMin__, capacityMax: this.__capacityMax__, useBaseColorSpace: this.__useBaseColorSpace__
|
|
129
|
+
offsetHDR: this.__offsetHDR__.slice(), capacityMin: this.__capacityMin__, capacityMax: this.__capacityMax__, useBaseColorSpace: this.__useBaseColorSpace__,
|
|
130
|
+
...this.__alternate__ ? { alternate: this.__alternate__.slice() } : {}
|
|
120
131
|
};
|
|
121
132
|
}
|
|
122
133
|
__check__() {
|
|
123
134
|
for (let c = 0; c < 3; c++)
|
|
124
135
|
if (this.__max__[c] < this.__min__[c])
|
|
125
136
|
throw new RangeError(`The gain map's max must be at least its min (${this.__max__[c]} < ${this.__min__[c]}; the values are checked together when the map is cloned or encoded)`);
|
|
126
|
-
if (this.__capacityMax__ <= this.__capacityMin__)
|
|
127
|
-
throw new RangeError(`The gain map's hdrCapacityMax (by default the largest max) must be above its hdrCapacityMin (${this.__capacityMax__} <= ${this.__capacityMin__})`);
|
|
128
137
|
}
|
|
129
138
|
get image() {
|
|
130
139
|
return this.__pixels__;
|
|
131
140
|
}
|
|
132
141
|
set image(image) {
|
|
133
|
-
|
|
134
|
-
throw new TypeError('The gain map has to be an Image');
|
|
142
|
+
instance(image, [Image], 'gainMap.image');
|
|
135
143
|
this.__pixels__ = image;
|
|
136
144
|
}
|
|
137
145
|
get width() {
|
|
@@ -206,9 +214,9 @@ export class GainMap {
|
|
|
206
214
|
}
|
|
207
215
|
async encodeJPEG(options) {
|
|
208
216
|
checkOptions(options, 'gainMap.encodeJPEG({ quality: 80 })');
|
|
209
|
-
|
|
217
|
+
const quality = options?.quality;
|
|
210
218
|
if (quality !== undefined)
|
|
211
|
-
|
|
219
|
+
checkQuality(quality);
|
|
212
220
|
return codec.mapWithMetadata(this.__body__(quality), this.__params__());
|
|
213
221
|
}
|
|
214
222
|
static async decode(data, options = {}) {
|
package/dist/image.d.ts
CHANGED
|
@@ -242,7 +242,8 @@ export interface OutlineOptions {
|
|
|
242
242
|
export interface GradientOptions {
|
|
243
243
|
/**
|
|
244
244
|
* The colors along the gradient: their positions (0..1) and colors (`{ 0: 0xff0000ff, 0.5: 0xffff00ff, 1: 0x00ff00ff }`),
|
|
245
|
-
* or just the colors, evenly spaced (`[0xff0000ff, 0x00ff00ff]`), like {@link Colors.gradient} takes them
|
|
245
|
+
* or just the colors, evenly spaced (`[0xff0000ff, 0x00ff00ff]`), like {@link Colors.gradient} takes them. A
|
|
246
|
+
* position outside 0..1 is allowed, see {@link Colors.gradient}
|
|
246
247
|
*/
|
|
247
248
|
stops: Record<number, Color> | Color[];
|
|
248
249
|
}
|
|
@@ -285,7 +286,7 @@ export interface EncodeOptions {
|
|
|
285
286
|
*/
|
|
286
287
|
export interface GainMapEmbedOptions {
|
|
287
288
|
/**
|
|
288
|
-
* The map's quality (
|
|
289
|
+
* The map's quality (0-100, like the format's `quality`; for JPEG XL 100 is lossless)
|
|
289
290
|
* @defaultValue `90`
|
|
290
291
|
*/
|
|
291
292
|
quality?: number;
|
|
@@ -343,13 +344,14 @@ export interface JPEGEncodeOptions extends EncodeOptions {
|
|
|
343
344
|
/** Options of {@link Image.encodeWebP} */
|
|
344
345
|
export interface WebPEncodeOptions extends EncodeOptions {
|
|
345
346
|
/**
|
|
346
|
-
* Lossy compression (0-100): higher values usually preserve more detail but make larger files.
|
|
347
|
-
*
|
|
347
|
+
* Lossy compression (0-100): higher values usually preserve more detail but make larger files. `100`, like no
|
|
348
|
+
* quality, encodes losslessly and keeps every pixel exact (`99` is the highest lossy quality)
|
|
348
349
|
*/
|
|
349
350
|
quality?: number;
|
|
350
351
|
/**
|
|
351
352
|
* Compression effort (0-6): higher values usually take longer but may make smaller files. For lossless images,
|
|
352
|
-
* `0` prioritizes speed; `2` and above spend more time reducing file size
|
|
353
|
+
* `0` prioritizes speed; `2` and above spend more time reducing file size (lossless images are encoded the same at
|
|
354
|
+
* `2` and above)
|
|
353
355
|
* @defaultValue `2`
|
|
354
356
|
*/
|
|
355
357
|
effort?: number;
|
|
@@ -396,9 +398,10 @@ export interface FisheyeOptions {
|
|
|
396
398
|
/** The limits, fonts and images of {@link Image.renderSVG}, part of {@link RenderSVGOptions} */
|
|
397
399
|
export interface SVGResourceOptions {
|
|
398
400
|
/**
|
|
399
|
-
* Maximum total pixels in the rendered output. Output over the limit throws a RangeError before anything is
|
|
401
|
+
* Maximum total pixels in the rendered output. Output over the limit throws a {@link LimitError} (a RangeError) before anything is
|
|
400
402
|
* rendered. It's also the default of {@link SVGResourceOptions.maxLayerPixels} and
|
|
401
|
-
* {@link SVGResourceOptions.maxImagePixels}
|
|
403
|
+
* {@link SVGResourceOptions.maxImagePixels}. The work limits of rendering grow with it: see
|
|
404
|
+
* {@link SVGResourceOptions.maxLayerPixels}
|
|
402
405
|
* @defaultValue `268402689` (16383²); `Infinity` disables the limit
|
|
403
406
|
*/
|
|
404
407
|
maxPixels?: number;
|
|
@@ -406,16 +409,25 @@ export interface SVGResourceOptions {
|
|
|
406
409
|
* Maximum pixels of the layers rendering uses at once, the output's included. Groups with opacity, masks, clip
|
|
407
410
|
* paths of nested viewports, filters and blend modes are each rendered into a layer of their own (up to the
|
|
408
411
|
* output's size, 16 bytes per pixel) while their content is drawn, so deeply nested ones multiply the memory a
|
|
409
|
-
* small SVG takes. Exceeding it throws a RangeError. With the defaults, rendering can take
|
|
410
|
-
* of `maxPixels` (64 for the layers, up to 20 for the images, 4 for the output): lower
|
|
411
|
-
* untrusted SVGs
|
|
412
|
+
* small SVG takes. Exceeding it throws a {@link LimitError} (a RangeError). With the defaults, rendering can take
|
|
413
|
+
* about 90 bytes per pixel of `maxPixels` (64 for the layers, up to 20 for the images, 4 for the output): lower
|
|
414
|
+
* `maxPixels` to bound it for untrusted SVGs.
|
|
415
|
+
*
|
|
416
|
+
* Three limits on the work of a render don't depend on these options, and grow with the size of the output (so
|
|
417
|
+
* lowering `maxPixels` is what bounds them too). Each throws a {@link LimitError} when exceeded:
|
|
418
|
+
* - Painting: shapes and layers may paint 2²⁸ pixels plus 64 per pixel of the output
|
|
419
|
+
* - Paths: all paths together may be made of 2²⁵ points plus 4 per pixel of the output (curves flattened, each
|
|
420
|
+
* copy drawn through `<use>` counted, a command of a glyph outline 16), one path of 2²¹ (texts excepted)
|
|
421
|
+
* - Filters: all the filters' primitives together may work on 2²⁵ pixels plus 16 per pixel of the output (a
|
|
422
|
+
* primitive counts its region's pixels once per pass: an `feConvolveMatrix` per 9 taps of its kernel, an
|
|
423
|
+
* `feTurbulence` per octave, an `feMerge` per node)
|
|
412
424
|
* @defaultValue `4 * maxPixels`; `Infinity` disables the limit
|
|
413
425
|
*/
|
|
414
426
|
maxLayerPixels?: number;
|
|
415
427
|
/**
|
|
416
428
|
* Maximum total pixels of the raster images the SVG references (data URIs and {@link SVGResourceOptions.images}),
|
|
417
429
|
* decoded together; already-decoded {@link Image} values are used as supplied and don't count. Drawing an image
|
|
418
|
-
* beyond the limit throws a RangeError
|
|
430
|
+
* beyond the limit throws a {@link LimitError} (a RangeError)
|
|
419
431
|
* @defaultValue `maxPixels`; `Infinity` disables the limit
|
|
420
432
|
*/
|
|
421
433
|
maxImagePixels?: number;
|
|
@@ -426,8 +438,10 @@ export interface SVGResourceOptions {
|
|
|
426
438
|
* installed fonts). Generic families (`serif`, `sans-serif`, `monospace`, ...) are the first font that fits them,
|
|
427
439
|
* other families and text without one get the first font's family; characters a face doesn't have come from the
|
|
428
440
|
* other fonts (TrueType, OpenType or WOFF). Fonts the SVG embeds with `@font-face` (in data: URIs) are used too,
|
|
429
|
-
* before these for their family names. Without any fonts text isn't rendered
|
|
430
|
-
*
|
|
441
|
+
* before these for their family names. Without any fonts text isn't rendered (an empty array is the same as no
|
|
442
|
+
* option here; {@link Image.renderText} needs a font and throws for it). One font can be given without an
|
|
443
|
+
* array. A font here that can't be read throws an Error, like in {@link Image.renderText}; a damaged font that the
|
|
444
|
+
* SVG embeds is left out
|
|
431
445
|
* @defaultValue `[]`
|
|
432
446
|
*/
|
|
433
447
|
font?: BinaryData | BinaryData[];
|
|
@@ -496,7 +510,7 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
|
|
|
496
510
|
*/
|
|
497
511
|
color?: Color;
|
|
498
512
|
/**
|
|
499
|
-
* Maximum total pixels of the rendered image (the outline included): larger text throws a RangeError before its
|
|
513
|
+
* Maximum total pixels of the rendered image (the outline included): larger text throws a {@link LimitError} (a RangeError) before its
|
|
500
514
|
* pixels are allocated
|
|
501
515
|
* @defaultValue `268402689` (16383²); `Infinity` disables the limit
|
|
502
516
|
*/
|
|
@@ -506,7 +520,8 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
|
|
|
506
520
|
export interface DecodeOptions {
|
|
507
521
|
/**
|
|
508
522
|
* Whether to rotate or mirror the image according to its saved orientation information, so photos taken with a
|
|
509
|
-
* rotated camera display upright. This applies to every animation frame too
|
|
523
|
+
* rotated camera display upright. This applies to every animation frame too. AVIF's rotation and mirroring
|
|
524
|
+
* (`irot`, `imir`) are part of the image in that format and always applied, like other AVIF decoders do
|
|
510
525
|
* @defaultValue `true`
|
|
511
526
|
*/
|
|
512
527
|
applyOrientation?: boolean;
|
|
@@ -520,12 +535,14 @@ export interface DecodeOptions {
|
|
|
520
535
|
*/
|
|
521
536
|
applyColorProfile?: boolean;
|
|
522
537
|
/**
|
|
523
|
-
* The maximum total pixels to decode. An image declaring more pixels throws a RangeError before its pixel buffer
|
|
538
|
+
* The maximum total pixels to decode. An image declaring more pixels throws a {@link LimitError} (a RangeError) before its pixel buffer
|
|
524
539
|
* is allocated, helping prevent a small or untrusted file from requesting an enormous amount of memory.
|
|
525
|
-
* {@link Animation.decode} counts all frames together because each frame uses a full canvas
|
|
540
|
+
* {@link Animation.decode} counts all frames together because each frame uses a full canvas (and at least 1024
|
|
541
|
+
* pixels, for the memory a frame takes however small it is). The decoded image
|
|
526
542
|
* takes 4 bytes per pixel (about 1 GiB at the default), and decoding needs more while it runs: for 8-bit images,
|
|
527
|
-
* about 4-7 bytes per pixel for PNG, JPEG, WebP, GIF and the simpler formats, about 14 for AVIF and about
|
|
528
|
-
* JPEG XL (more with high bit depths). Lower it to bound the
|
|
543
|
+
* about 4-7 bytes per pixel for PNG, JPEG, WebP, GIF and the simpler formats, about 14 for AVIF and about 60 for
|
|
544
|
+
* lossy JPEG XL on one thread, about 110 with worker threads (more with high bit depths). Lower it to bound the
|
|
545
|
+
* memory of servers decoding untrusted files
|
|
529
546
|
* @defaultValue `268402689` (16383²); `Infinity` disables the limit
|
|
530
547
|
*/
|
|
531
548
|
maxPixels?: number;
|
|
@@ -562,7 +579,7 @@ export interface JXLEncodeOptions extends EncodeOptions {
|
|
|
562
579
|
quality?: number;
|
|
563
580
|
/**
|
|
564
581
|
* Compression effort (0-2): higher values usually take longer but may make smaller files. `0` prioritizes speed;
|
|
565
|
-
* `2` spends the most time compressing
|
|
582
|
+
* `2` spends the most time compressing (lossy images only: lossless images are encoded the same at `1` and `2`)
|
|
566
583
|
* @defaultValue `1`
|
|
567
584
|
*/
|
|
568
585
|
effort?: number;
|
|
@@ -741,19 +758,27 @@ export interface ColorToAlphaOptions {
|
|
|
741
758
|
/**
|
|
742
759
|
* An RGBA image; provides the codecs and the manipulation functions. Methods that change the image modify it in place
|
|
743
760
|
* and return it, so calls can be chained
|
|
761
|
+
*
|
|
762
|
+
* @remarks Subclassing is not supported: the methods that make an image ({@link Image.clone}, {@link Image.extract},
|
|
763
|
+
* {@link Image.decode}, ...) return plain `Image`s, without calling a subclass' constructor.
|
|
764
|
+
*
|
|
765
|
+
* The `maxPixels` limits guard what comes from outside: decoding and rendering. `new Image()`, `resize()` and
|
|
766
|
+
* `scale()` make the size they are asked for, so check sizes that come from users before you pass them on
|
|
744
767
|
*/
|
|
745
768
|
export declare class Image {
|
|
746
769
|
/**
|
|
747
770
|
* Creates a new image with the given dimensions, all pixels transparent black
|
|
748
|
-
* @param width The width in pixels
|
|
749
|
-
* @param height The height in pixels
|
|
750
|
-
* @throws `
|
|
771
|
+
* @param width The width in pixels (a fraction is truncated)
|
|
772
|
+
* @param height The height in pixels (a fraction is truncated)
|
|
773
|
+
* @throws `TypeError` if the width or height is not a number
|
|
774
|
+
* @throws `RangeError` if the width or height is less than 1, or the image is too large to allocate
|
|
751
775
|
*/
|
|
752
776
|
constructor(width: number, height: number);
|
|
753
777
|
/**
|
|
754
778
|
* Extra image data that lets high-dynamic-range (HDR) screens show brighter highlights. Standard screens show the
|
|
755
779
|
* image without the extra brightness. {@link Image.encodeJPEG}, {@link Image.encodeAVIF} and
|
|
756
|
-
* {@link Image.encodeJXL} can write it. `null` means there is no gain map
|
|
780
|
+
* {@link Image.encodeJXL} can write it. `null` means there is no gain map. This is the image's own map, not a
|
|
781
|
+
* copy: changing it (`image.gainMap.max = 3`) changes the image's
|
|
757
782
|
*/
|
|
758
783
|
get gainMap(): GainMap | null;
|
|
759
784
|
/**
|
|
@@ -788,7 +813,9 @@ export declare class Image {
|
|
|
788
813
|
*/
|
|
789
814
|
get height(): number;
|
|
790
815
|
/**
|
|
791
|
-
* Yields an [x, y, color] array for every pixel in the image (0-based), row by row
|
|
816
|
+
* Yields an [x, y, color] array for every pixel in the image (0-based), row by row. Resizing the image meanwhile
|
|
817
|
+
* doesn't affect the iteration (it goes on over the pixels the image had when `pixels()` was called), but other changes to the pixels, like
|
|
818
|
+
* `setPixelAt()`, are seen by the pixels not yet yielded
|
|
792
819
|
* @yields The coordinates and color of the pixel ([x, y, color])
|
|
793
820
|
*/
|
|
794
821
|
pixels(): Generator<[x: number, y: number, color: Color], void, undefined>;
|
|
@@ -810,8 +837,8 @@ export declare class Image {
|
|
|
810
837
|
static radialGradient(width: number, height: number, options: RadialGradientOptions): Image;
|
|
811
838
|
/**
|
|
812
839
|
* Gets the pixel color at the specified position (0-based). {@link Colors.toRGBA} splits it into its channels
|
|
813
|
-
* @param x The x coordinate
|
|
814
|
-
* @param y The y coordinate
|
|
840
|
+
* @param x The x coordinate (a fraction is dropped: 1.9 is the pixel 1)
|
|
841
|
+
* @param y The y coordinate (likewise)
|
|
815
842
|
* @returns The color value (`0xRRGGBBAA`)
|
|
816
843
|
* @throws `RangeError` if the position isn't inside the image
|
|
817
844
|
* @see {@link Image.pixels} to go over every pixel
|
|
@@ -826,9 +853,10 @@ export declare class Image {
|
|
|
826
853
|
*/
|
|
827
854
|
setPixelAt(x: number, y: number, color: Color): this;
|
|
828
855
|
/**
|
|
829
|
-
* Fills the image data with the supplied color
|
|
856
|
+
* Fills the image data with the supplied color. The image's gain map, if it has one, is made neutral (no boost
|
|
857
|
+
* anywhere): the new pixels have no HDR light beyond their own
|
|
830
858
|
* @param color The color, or a function returning the color of each pixel (checked like any color: a result that
|
|
831
|
-
* isn't
|
|
859
|
+
* isn't a number throws a TypeError, a number that isn't a color a RangeError)
|
|
832
860
|
*/
|
|
833
861
|
fill(color: Color | ColorFunction): this;
|
|
834
862
|
/**
|
|
@@ -836,7 +864,8 @@ export declare class Image {
|
|
|
836
864
|
*/
|
|
837
865
|
clone(): Image;
|
|
838
866
|
/**
|
|
839
|
-
* Resizes the image by the given factor
|
|
867
|
+
* Resizes the image by the given factor: a side of 7 pixels scaled by 0.5 is 3 (fractions are dropped, a side
|
|
868
|
+
* doesn't go below 1 pixel)
|
|
840
869
|
* @param factor The factor to resize the image with
|
|
841
870
|
* @param options See {@link ResizeOptions}
|
|
842
871
|
*/
|
|
@@ -1123,32 +1152,38 @@ export declare class Image {
|
|
|
1123
1152
|
fisheye(options?: FisheyeOptions): this;
|
|
1124
1153
|
/**
|
|
1125
1154
|
* Encodes the image into a PNG, with the smallest lossless color type (a palette for up to 256 colors,
|
|
1126
|
-
* grayscale or RGB, alpha only if needed). Uses the runtime's native zlib when available
|
|
1155
|
+
* grayscale or RGB, alpha only if needed). Uses the runtime's native zlib when available, so the compressed
|
|
1156
|
+
* bytes can differ between runtimes and browsers; the pixels are the same
|
|
1127
1157
|
* @param options See {@link PNGEncodeOptions}
|
|
1128
1158
|
* @return The encoded data
|
|
1129
1159
|
*/
|
|
1130
1160
|
encodePNG(options?: PNGEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
1131
1161
|
/**
|
|
1132
1162
|
* Encodes the image into a JPEG. JPEG has no transparency: an image with transparent or translucent pixels is
|
|
1133
|
-
* composited onto the `background` color (black by default) first, the image itself stays unchanged
|
|
1163
|
+
* composited onto the `background` color (black by default) first, the image itself stays unchanged. An image whose
|
|
1164
|
+
* pixels are all gray is written as a grayscale JPEG (one component)
|
|
1134
1165
|
* @param options See {@link JPEGEncodeOptions}
|
|
1166
|
+
* @throws `RangeError` if the image is wider or higher than 65535 pixels, or the comment or the Exif fields of the metadata are longer than 65533 bytes
|
|
1135
1167
|
*/
|
|
1136
1168
|
encodeJPEG(options?: JPEGEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
1137
1169
|
/**
|
|
1138
1170
|
* Encodes the image as WebP: lossless (usually 20-30% smaller than PNG, but slower to encode), or lossy with a
|
|
1139
|
-
* quality
|
|
1171
|
+
* quality below 100
|
|
1140
1172
|
* @param options See {@link WebPEncodeOptions}
|
|
1173
|
+
* @throws `RangeError` if the image is wider or higher than 16383 pixels (lossy) or 16384 (lossless): the limits of the two codecs
|
|
1141
1174
|
*/
|
|
1142
1175
|
encodeWebP(options?: WebPEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
1143
1176
|
/**
|
|
1144
1177
|
* Encodes the image as run length encoded TGA (32 bit, or 24 bit if the image is opaque)
|
|
1145
1178
|
* @param options See {@link TGAEncodeOptions}
|
|
1179
|
+
* @throws `RangeError` if the image is wider or higher than 65535 pixels
|
|
1146
1180
|
*/
|
|
1147
1181
|
encodeTGA(options?: TGAEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
1148
1182
|
/**
|
|
1149
1183
|
* Encodes the image as a GIF (one frame): at most 256 colors, transparency only on or off (pixels with an alpha below
|
|
1150
1184
|
* 128 become transparent). For animations, see {@link Animation.encodeGIF}
|
|
1151
1185
|
* @param options The palette size, the dithering and the metadata, see {@link GIFEncodeOptions}
|
|
1186
|
+
* @throws `RangeError` if the image is wider or higher than 65535 pixels
|
|
1152
1187
|
*/
|
|
1153
1188
|
encodeGIF(options?: GIFEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
1154
1189
|
/**
|
|
@@ -1163,6 +1198,7 @@ export declare class Image {
|
|
|
1163
1198
|
/**
|
|
1164
1199
|
* Encodes the image as AVIF (AV1, with an alpha image if the image has transparency)
|
|
1165
1200
|
* @param options See {@link AVIFEncodeOptions}
|
|
1201
|
+
* @throws `RangeError` if the image is wider or higher than 65536 pixels
|
|
1166
1202
|
*/
|
|
1167
1203
|
encodeAVIF(options?: AVIFEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
1168
1204
|
/**
|
|
@@ -1224,11 +1260,13 @@ export declare class Image {
|
|
|
1224
1260
|
* @param svg The SVG content
|
|
1225
1261
|
* @param options See {@link RenderSVGOptions}
|
|
1226
1262
|
* @return The rendered SVG graphic
|
|
1227
|
-
* @throws {@link LimitError} if the output, the layers or the images exceed the limits of the options
|
|
1263
|
+
* @throws {@link LimitError} if the output, the layers or the images exceed the limits of the options, or the SVG
|
|
1264
|
+
* exceeds a fixed limit of the work it may take: more than 100000 elements drawn through `<use>` references and
|
|
1265
|
+
* markers, more than 10000 markers, masks, clip paths, patterns, markers and filter images nested so deeply that
|
|
1266
|
+
* they would multiply, entities that expand past the size limit, or filters past their budget
|
|
1228
1267
|
* @throws `RangeError` if the requested size is below 1 pixel (or a scale isn't above 0)
|
|
1229
|
-
* @throws `Error` if the SVG can't be parsed (it has no `<svg>` element)
|
|
1230
|
-
* or can't be decoded)
|
|
1231
|
-
* would multiply
|
|
1268
|
+
* @throws `Error` if the SVG can't be parsed (it has no `<svg>` element) or an image in it can't be drawn (it isn't
|
|
1269
|
+
* given or can't be decoded)
|
|
1232
1270
|
*/
|
|
1233
1271
|
static renderSVG(svg: string | BinaryData, options?: RenderSVGOptions): Promise<Image>;
|
|
1234
1272
|
/**
|