imagescript 4.0.0-rc.1 → 4.0.0-rc.3
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 +16 -12
- package/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/animation-encoder.d.ts +1 -0
- package/dist/animation-encoder.js +27 -11
- package/dist/animation.d.ts +22 -22
- package/dist/animation.js +50 -27
- package/dist/codecs/av1/decode.js +1 -1
- package/dist/codecs/av1/encode.js +1 -1
- package/dist/codecs/jxl/frame-header.js +6 -4
- package/dist/codecs/jxl/headers.js +1 -1
- package/dist/codecs/jxl/patches-enc.js +1 -1
- package/dist/codecs/quantize.js +23 -9
- package/dist/codecs/zlib.js +1 -1
- package/dist/colors.js +10 -0
- package/dist/frame.d.ts +5 -2
- package/dist/frame.js +4 -7
- package/dist/gainmap.d.ts +6 -3
- package/dist/gainmap.js +23 -17
- package/dist/image.d.ts +109 -72
- package/dist/image.js +120 -100
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1 -0
- package/dist/metadata.d.ts +6 -5
- package/dist/metadata.js +9 -7
- package/dist/render/colr.js +1 -1
- package/dist/render/font.js +1 -1
- package/dist/render/layout.js +1 -1
- package/dist/render/segment.js +1 -1
- package/dist/render/shapers/hangul.js +1 -1
- package/dist/render/svg.js +102 -35
- package/dist/render/text.js +17 -17
- package/dist/text-layout.d.ts +21 -11
- package/dist/text-layout.js +18 -32
- package/dist/util/limits.d.ts +35 -0
- package/dist/util/limits.js +1 -0
- package/dist/util/optimize.js +3 -1
- package/dist/util/options.js +42 -2
- package/package.json +15 -10
- package/LICENSE.AGPL-3.0 +0 -619
- package/LICENSE.MIT +0 -19
- package/dist/version.js +0 -1
package/dist/gainmap.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Image } from './image.js';
|
|
2
|
+
import type { DecodeOptions } from './image.js';
|
|
2
3
|
import { BinaryData } from './util/mem.js';
|
|
3
|
-
/** Options of {@link GainMap.
|
|
4
|
+
/** Options of {@link GainMap.encodeJPEG} */
|
|
4
5
|
export interface GainMapEncodeOptions {
|
|
5
6
|
/** The JPEG quality (1-100). Default: `90` */
|
|
6
7
|
quality?: number;
|
|
@@ -130,11 +131,13 @@ export declare class GainMap {
|
|
|
130
131
|
* Ultra HDR JPEG
|
|
131
132
|
* @param options See {@link GainMapEncodeOptions}
|
|
132
133
|
*/
|
|
133
|
-
|
|
134
|
+
encodeJPEG(options?: GainMapEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
134
135
|
/**
|
|
135
136
|
* Decodes a gain map JPEG with its parameters (hdrgm XMP or ISO 21496-1), like the second image in an Ultra HDR
|
|
136
137
|
* JPEG, or the gain map of an Ultra HDR JPEG (or an iPhone's JPEG: its values converted to these parameters)
|
|
137
138
|
* @param data The JPEG
|
|
139
|
+
* @param options The `maxPixels` limit, like {@link DecodeOptions.maxPixels} (a map larger than that throws a
|
|
140
|
+
* {@link LimitError}); a damaged JPEG throws an error saying so, like {@link Image.decode}
|
|
138
141
|
*/
|
|
139
|
-
static decode(data: BinaryData): Promise<GainMap>;
|
|
142
|
+
static decode(data: BinaryData, options?: Pick<DecodeOptions, 'maxPixels'>): Promise<GainMap>;
|
|
140
143
|
}
|
package/dist/gainmap.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Image } from "./image.js";
|
|
1
|
+
import { Image, alignedPixels } from "./image.js";
|
|
2
|
+
import { MAX_PIXELS, decoding } from "./util/limits.js";
|
|
2
3
|
import * as jpeg from "./codecs/jpeg.js";
|
|
3
4
|
import * as codec from "./codecs/gainmap.js";
|
|
4
5
|
import { view } from "./util/mem.js";
|
|
5
|
-
import { finite, checkOptions, quality as checkQuality } from "./util/options.js";
|
|
6
|
+
import { finite, checkOptions, pixelLimit, quality as checkQuality } from "./util/options.js";
|
|
6
7
|
const perChannel = (value, name) => {
|
|
7
8
|
const values = typeof value === 'number' ? [value, value, value] : Array.from(value);
|
|
8
9
|
if (values.length === 1)
|
|
@@ -67,10 +68,10 @@ export class GainMap {
|
|
|
67
68
|
this.__pixels__ = image;
|
|
68
69
|
this.__check__();
|
|
69
70
|
}
|
|
70
|
-
static __from_jpeg__(map, params, apple = 0) {
|
|
71
|
-
const { width, height, pixels } = jpeg.decode(map);
|
|
71
|
+
static __from_jpeg__(map, params, apple = 0, maxPixels = MAX_PIXELS) {
|
|
72
|
+
const { width, height, pixels } = jpeg.decode(map, { maxPixels });
|
|
72
73
|
const image = new Image(width, height);
|
|
73
|
-
image.bitmap = pixels;
|
|
74
|
+
image.bitmap = alignedPixels(pixels);
|
|
74
75
|
if (apple) {
|
|
75
76
|
const table = new Uint8Array(256);
|
|
76
77
|
for (let v = 0; v < 256; v++)
|
|
@@ -118,9 +119,9 @@ export class GainMap {
|
|
|
118
119
|
__check__() {
|
|
119
120
|
for (let c = 0; c < 3; c++)
|
|
120
121
|
if (this.__max__[c] < this.__min__[c])
|
|
121
|
-
throw new RangeError(
|
|
122
|
+
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)`);
|
|
122
123
|
if (this.__capacityMax__ <= this.__capacityMin__)
|
|
123
|
-
throw new RangeError(
|
|
124
|
+
throw new RangeError(`The gain map's hdrCapacityMax (by default the largest max) must be above its hdrCapacityMin (${this.__capacityMax__} <= ${this.__capacityMin__})`);
|
|
124
125
|
}
|
|
125
126
|
get image() {
|
|
126
127
|
return this.__pixels__;
|
|
@@ -200,21 +201,26 @@ export class GainMap {
|
|
|
200
201
|
}
|
|
201
202
|
this.image = out;
|
|
202
203
|
}
|
|
203
|
-
async
|
|
204
|
-
checkOptions(options, '
|
|
204
|
+
async encodeJPEG(options) {
|
|
205
|
+
checkOptions(options, 'gainMap.encodeJPEG({ quality: 80 })');
|
|
205
206
|
let quality = options?.quality;
|
|
206
207
|
if (quality !== undefined)
|
|
207
208
|
quality = Math.max(1, checkQuality(quality));
|
|
208
209
|
return codec.mapWithMetadata(this.__body__(quality), this.__params__());
|
|
209
210
|
}
|
|
210
|
-
static async decode(data) {
|
|
211
|
+
static async decode(data, options = {}) {
|
|
212
|
+
checkOptions(options, 'GainMap.decode(data, { maxPixels: 1e8 })');
|
|
213
|
+
const { maxPixels = MAX_PIXELS } = options;
|
|
214
|
+
pixelLimit(maxPixels);
|
|
211
215
|
const bytes = view(data);
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
return decoding(() => {
|
|
217
|
+
const found = codec.find(bytes);
|
|
218
|
+
if (found)
|
|
219
|
+
return GainMap.__from_jpeg__(found.map, found.params, found.apple, maxPixels);
|
|
220
|
+
const params = codec.readParams(bytes);
|
|
221
|
+
if (!params)
|
|
222
|
+
throw new Error('No gain map (or no gain map parameters) found');
|
|
223
|
+
return GainMap.__from_jpeg__(bytes, params, 0, maxPixels);
|
|
224
|
+
});
|
|
219
225
|
}
|
|
220
226
|
}
|
package/dist/image.d.ts
CHANGED
|
@@ -68,11 +68,6 @@ export type ResizeToOptions = ResizeOptions & ({
|
|
|
68
68
|
export interface ResizeOptions {
|
|
69
69
|
/** The resizing mode. Default: `'bilinear'` */
|
|
70
70
|
mode?: ResizeMode;
|
|
71
|
-
/**
|
|
72
|
-
* Whether to use faster, lower-precision arithmetic. It can cause small color differences, especially around
|
|
73
|
-
* transparent edges. Only affects `'bilinear'` and `'area'` resizing. Default: `true`
|
|
74
|
-
*/
|
|
75
|
-
fast?: boolean;
|
|
76
71
|
}
|
|
77
72
|
/** Options of {@link Image.sharpen} */
|
|
78
73
|
export interface SharpenOptions {
|
|
@@ -87,31 +82,40 @@ export interface SharpenOptions {
|
|
|
87
82
|
* errors to nearby pixels; `'ordered'` uses a repeating pattern. Atkinson tends to give a higher-contrast result.
|
|
88
83
|
*/
|
|
89
84
|
export type DitherMethod = 'none' | 'floyd-steinberg' | 'atkinson' | 'ordered';
|
|
90
|
-
/**
|
|
91
|
-
export interface
|
|
85
|
+
/** How colors are dithered when they are reduced to a palette: options of {@link Image.quantize} and the GIF encoders */
|
|
86
|
+
export interface DitherOptions {
|
|
87
|
+
/**
|
|
88
|
+
* How to spread small color changes across nearby pixels to make gradients look smoother with few colors, see
|
|
89
|
+
* {@link DitherMethod}. Default: `'floyd-steinberg'`
|
|
90
|
+
*/
|
|
91
|
+
dither?: DitherMethod;
|
|
92
|
+
/** How strongly to apply dithering: `0` disables it (like `'none'`); `1` applies it fully. Default: `0.85` */
|
|
93
|
+
ditherStrength?: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Options of {@link Image.quantize}: either `colors` or `palette` (TypeScript reports a call with both), and the
|
|
97
|
+
* dithering
|
|
98
|
+
*/
|
|
99
|
+
export type QuantizeOptions = DitherOptions & ({
|
|
92
100
|
/**
|
|
93
101
|
* The maximum number of colors to keep (2-256). Images with fewer distinct colors keep them exactly; otherwise
|
|
94
102
|
* ImageScript chooses a smaller set of representative colors. Give `palette` instead to choose exact colors.
|
|
95
|
-
* Default: `256
|
|
103
|
+
* Default: `256`
|
|
96
104
|
*/
|
|
97
105
|
colors?: number;
|
|
106
|
+
/** Not with `colors`: give one of them */
|
|
107
|
+
palette?: never;
|
|
108
|
+
} | {
|
|
98
109
|
/**
|
|
99
110
|
* A fixed palette (1-256 colors, e.g. a Game Boy's four greens). Every pixel is changed to the nearest palette
|
|
100
|
-
* color by its red, green and blue values; transparency in palette colors is ignored
|
|
101
|
-
* not both
|
|
102
|
-
*/
|
|
103
|
-
palette?: Color[];
|
|
104
|
-
/**
|
|
105
|
-
* How to spread small color changes across nearby pixels to make gradients look smoother with few colors, see
|
|
106
|
-
* {@link DitherMethod}. Default: `'floyd-steinberg'`, like {@link GIFEncodeOptions.dither}
|
|
107
|
-
*/
|
|
108
|
-
dither?: DitherMethod;
|
|
109
|
-
/**
|
|
110
|
-
* How strongly to apply dithering: `0` disables it; `1` applies it fully. Default: `0.85`, like
|
|
111
|
-
* {@link GIFEncodeOptions.ditherStrength}
|
|
111
|
+
* color by its red, green and blue values; transparency in palette colors is ignored
|
|
112
112
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
palette: Color[];
|
|
114
|
+
/** Not with `palette`: give one of them */
|
|
115
|
+
colors?: never;
|
|
116
|
+
});
|
|
117
|
+
/** The directions of {@link Image.flip} and {@link Animation.flip}: `'horizontal'` mirrors left and right, `'vertical'` top and bottom */
|
|
118
|
+
export type FlipDirection = 'horizontal' | 'vertical';
|
|
115
119
|
/** How {@link Image.transform} and {@link Image.rotate} sample the pixels between the source's */
|
|
116
120
|
export type TransformMode = 'nearest-neighbor' | 'bilinear' | 'bicubic';
|
|
117
121
|
/** The six values `[a, b, c, d, e, f]` of an affine transform */
|
|
@@ -219,23 +223,20 @@ export interface PNGEncodeOptions extends EncodeOptions {
|
|
|
219
223
|
/** The compression level (0-9), higher is smaller but slower. Default: `4` */
|
|
220
224
|
compression?: number;
|
|
221
225
|
}
|
|
222
|
-
/** Options of {@link Image.encodeTGA} */
|
|
223
|
-
export
|
|
226
|
+
/** Options of {@link Image.encodeTGA}: the metadata, which TGA keeps in its extension area */
|
|
227
|
+
export interface TGAEncodeOptions extends EncodeOptions {
|
|
228
|
+
}
|
|
224
229
|
/** Options of {@link Image.encodeGIF}, and of {@link Animation.encodeGIF} with {@link GIFAnimationEncodeOptions} */
|
|
225
|
-
export interface GIFEncodeOptions extends EncodeOptions {
|
|
230
|
+
export interface GIFEncodeOptions extends EncodeOptions, DitherOptions {
|
|
226
231
|
/**
|
|
227
232
|
* The maximum colors in each frame's palette (2-256, including transparency). Frames with fewer colors keep them
|
|
228
233
|
* exactly; otherwise ImageScript chooses representative colors. Default: `256`
|
|
229
234
|
*/
|
|
230
235
|
colors?: number;
|
|
231
|
-
/** How the rounding error is spread when the colors don't fit the palette, see {@link DitherMethod}. Default: `'floyd-steinberg'` */
|
|
232
|
-
dither?: DitherMethod;
|
|
233
|
-
/** How strongly to dither, from `0` (like `'none'`) to `1` (the full error). Default: `0.85` */
|
|
234
|
-
ditherStrength?: number;
|
|
235
236
|
}
|
|
236
237
|
/** Options of {@link Image.encodeJPEG} */
|
|
237
238
|
export interface JPEGEncodeOptions extends EncodeOptions {
|
|
238
|
-
/** The JPEG quality (
|
|
239
|
+
/** The JPEG quality (0-100, 0 is the same as 1). Default: `90` */
|
|
239
240
|
quality?: number;
|
|
240
241
|
/**
|
|
241
242
|
* How much color detail to keep: `'4:4:4'` keeps it all; `'4:2:0'` stores less color detail to make a smaller
|
|
@@ -292,26 +293,29 @@ export interface FisheyeOptions {
|
|
|
292
293
|
/** The distortion strength (exponent of the radial mapping), higher values bulge the center more. Default: `2` */
|
|
293
294
|
strength?: number;
|
|
294
295
|
}
|
|
295
|
-
/**
|
|
296
|
-
export interface
|
|
296
|
+
/** The limits, fonts and images of {@link Image.renderSVG}, part of {@link RenderSVGOptions} */
|
|
297
|
+
export interface SVGResourceOptions {
|
|
297
298
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
299
|
+
* Maximum total pixels in the rendered output. Output over the limit throws a RangeError before anything is
|
|
300
|
+
* rendered. It's also the default of {@link SVGResourceOptions.maxLayerPixels} and
|
|
301
|
+
* {@link SVGResourceOptions.maxImagePixels}. Default: `268402689` (16383²); `Infinity` disables the limit
|
|
300
302
|
*/
|
|
301
|
-
|
|
302
|
-
/** The height in pixels, the width follows the SVG's aspect ratio. Give one of `width`, `height` and `scale` */
|
|
303
|
-
height?: number;
|
|
303
|
+
maxPixels?: number;
|
|
304
304
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
305
|
+
* Maximum pixels of the layers rendering uses at once, the output's included. Groups with opacity, masks, clip
|
|
306
|
+
* paths of nested viewports, filters and blend modes are each rendered into a layer of their own (up to the
|
|
307
|
+
* output's size, 16 bytes per pixel) while their content is drawn, so deeply nested ones multiply the memory a
|
|
308
|
+
* small SVG takes. Exceeding it throws a RangeError. With the defaults, rendering can take about 90 bytes per pixel
|
|
309
|
+
* of `maxPixels` (64 for the layers, up to 20 for the images, 4 for the output): lower `maxPixels` to bound it for
|
|
310
|
+
* untrusted SVGs. Default: `4 * maxPixels`; `Infinity` disables the limit
|
|
307
311
|
*/
|
|
308
|
-
|
|
312
|
+
maxLayerPixels?: number;
|
|
309
313
|
/**
|
|
310
|
-
* Maximum total pixels
|
|
311
|
-
*
|
|
312
|
-
*
|
|
314
|
+
* Maximum total pixels of the raster images the SVG references (data URIs and {@link SVGResourceOptions.images}),
|
|
315
|
+
* decoded together; already-decoded {@link Image} values are used as supplied and don't count. Drawing an image
|
|
316
|
+
* beyond the limit throws a RangeError. Default: `maxPixels`; `Infinity` disables the limit
|
|
313
317
|
*/
|
|
314
|
-
|
|
318
|
+
maxImagePixels?: number;
|
|
315
319
|
/**
|
|
316
320
|
* Fonts for `<text>` (TrueType, OpenType or WOFF; not WOFF2 or some newer OpenType outline formats such as CFF2):
|
|
317
321
|
* each text gets the face its `font-family`, `font-weight`, `font-style`
|
|
@@ -322,16 +326,43 @@ export interface RenderSVGOptions {
|
|
|
322
326
|
* before these for their family names. Without any fonts text isn't rendered. One font can be given without an
|
|
323
327
|
* array. Default: `[]`
|
|
324
328
|
*/
|
|
325
|
-
|
|
329
|
+
font?: BinaryData | BinaryData[];
|
|
326
330
|
/**
|
|
327
331
|
* Images for the `<image>` elements (and `feImage`) by their `href`, the same string the SVG uses: with
|
|
328
332
|
* `images: { 'logo.png': bytes }`, `<image href="logo.png" .../>` draws the image. Values are encoded images (PNG,
|
|
329
333
|
* JPEG, WebP, GIF's first frame, ...) or {@link Image}s, decoded like data URI images are, and only for the hrefs
|
|
330
|
-
* the SVG references. Nothing else is read: no files and no URLs, so an href
|
|
331
|
-
*
|
|
334
|
+
* the SVG references. Nothing else is read: no files and no URLs, so drawing an image whose href isn't given (and
|
|
335
|
+
* isn't a data URI) throws, as does drawing one that can't be decoded. SVG documents can't be given this way, use a
|
|
336
|
+
* data URI for them. Default: `{}`
|
|
332
337
|
*/
|
|
333
338
|
images?: Record<string, BinaryData | Image>;
|
|
334
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Options of {@link Image.renderSVG}: the size (one of `width`, `height` and `scale`, TypeScript reports a call with
|
|
342
|
+
* more; by default the SVG's own size), and the limits, fonts and images (see {@link SVGResourceOptions})
|
|
343
|
+
*/
|
|
344
|
+
export type RenderSVGOptions = SVGResourceOptions & ({
|
|
345
|
+
/** The width in pixels, the height follows the SVG's aspect ratio. Default: the SVG's own width */
|
|
346
|
+
width?: number;
|
|
347
|
+
/** Not with `width`: give one of `width`, `height` and `scale` */
|
|
348
|
+
height?: never;
|
|
349
|
+
/** Not with `width`: give one of `width`, `height` and `scale` */
|
|
350
|
+
scale?: never;
|
|
351
|
+
} | {
|
|
352
|
+
/** Not with `height`: give one of `width`, `height` and `scale` */
|
|
353
|
+
width?: never;
|
|
354
|
+
/** The height in pixels, the width follows the SVG's aspect ratio */
|
|
355
|
+
height: number;
|
|
356
|
+
/** Not with `height`: give one of `width`, `height` and `scale` */
|
|
357
|
+
scale?: never;
|
|
358
|
+
} | {
|
|
359
|
+
/** Not with `scale`: give one of `width`, `height` and `scale` */
|
|
360
|
+
width?: never;
|
|
361
|
+
/** Not with `scale`: give one of `width`, `height` and `scale` */
|
|
362
|
+
height?: never;
|
|
363
|
+
/** A factor of the SVG's own size (`2` renders it twice as large). Default: `1` */
|
|
364
|
+
scale: number;
|
|
365
|
+
});
|
|
335
366
|
/**
|
|
336
367
|
* Options of {@link Image.renderText}: the font and size, the text color, the layout (wrapping, cutting off and alignment,
|
|
337
368
|
* see {@link TextLayoutOptions}) and the style (see {@link TextStyleOptions})
|
|
@@ -350,6 +381,11 @@ export interface RenderTextOptions extends TextStyleOptions, TextLayoutOptions {
|
|
|
350
381
|
size: number;
|
|
351
382
|
/** The text color. Default: `0xffffffff` */
|
|
352
383
|
color?: Color;
|
|
384
|
+
/**
|
|
385
|
+
* Maximum total pixels of the rendered image (the outline included): larger text throws a RangeError before its
|
|
386
|
+
* pixels are allocated. Default: `268402689` (16383²); `Infinity` disables the limit
|
|
387
|
+
*/
|
|
388
|
+
maxPixels?: number;
|
|
353
389
|
}
|
|
354
390
|
/** Options of {@link Image.decode}, {@link Animation.decode} and {@link decode} */
|
|
355
391
|
export interface DecodeOptions {
|
|
@@ -369,7 +405,10 @@ export interface DecodeOptions {
|
|
|
369
405
|
/**
|
|
370
406
|
* The maximum total pixels to decode. An image declaring more pixels throws a RangeError before its pixel buffer
|
|
371
407
|
* is allocated, helping prevent a small or untrusted file from requesting an enormous amount of memory.
|
|
372
|
-
* {@link Animation.decode} counts all frames together because each frame uses a full canvas.
|
|
408
|
+
* {@link Animation.decode} counts all frames together because each frame uses a full canvas. The decoded image
|
|
409
|
+
* takes 4 bytes per pixel (about 1 GiB at the default), and decoding needs more while it runs: for 8-bit images,
|
|
410
|
+
* about 4-7 bytes per pixel for PNG, JPEG, WebP, GIF and the simpler formats, about 14 for AVIF and about 30 for
|
|
411
|
+
* JPEG XL (more with high bit depths). Lower it to bound the memory of servers decoding untrusted files. Default:
|
|
373
412
|
* `268402689` (16383²); `Infinity` disables the limit
|
|
374
413
|
*/
|
|
375
414
|
maxPixels?: number;
|
|
@@ -479,11 +518,11 @@ export interface CropCircleOptions {
|
|
|
479
518
|
}
|
|
480
519
|
/** Options of {@link Image.dominantColor} */
|
|
481
520
|
export interface DominantColorOptions {
|
|
482
|
-
/** Whether to ignore dark colors (all channels below
|
|
521
|
+
/** Whether to ignore dark colors (all channels below `threshold`). Default: `true` */
|
|
483
522
|
ignoreBlack?: boolean;
|
|
484
|
-
/** Whether to ignore light colors (all channels above 255 minus
|
|
523
|
+
/** Whether to ignore light colors (all channels above 255 minus `threshold`). Default: `true` */
|
|
485
524
|
ignoreWhite?: boolean;
|
|
486
|
-
/**
|
|
525
|
+
/** How close (in channel values, 0-256) to black or white a color has to be to be ignored. Default: `60` */
|
|
487
526
|
threshold?: number;
|
|
488
527
|
}
|
|
489
528
|
/** Options of {@link Image.rotate} */
|
|
@@ -546,14 +585,14 @@ export declare class Image {
|
|
|
546
585
|
set gainMap(gainMap: GainMap | null);
|
|
547
586
|
/**
|
|
548
587
|
* The image's RGBA pixel data (red, green, blue and transparency, four bytes per pixel). It can be replaced by any
|
|
549
|
-
* 8-bit array with width * height * 4 bytes
|
|
550
|
-
*
|
|
551
|
-
* image's gain map.
|
|
588
|
+
* 8-bit array with width * height * 4 bytes starting at a byte offset divisible by 4 (it is used as is, without
|
|
589
|
+
* copying). Direct changes to this array or {@link Image.setPixelAt} don't update the image's gain map.
|
|
552
590
|
*/
|
|
553
591
|
get bitmap(): Uint8ClampedArray;
|
|
554
592
|
/**
|
|
555
593
|
* Replaces the pixel data
|
|
556
|
-
* @param bitmap The new RGBA data, width * height * 4 bytes (used as is, without copying
|
|
594
|
+
* @param bitmap The new RGBA data, width * height * 4 bytes (used as is, without copying, so its byte offset has to be
|
|
595
|
+
* divisible by 4: the image reads it as 32-bit pixels too)
|
|
557
596
|
*/
|
|
558
597
|
set bitmap(bitmap: Uint8ClampedArray | Uint8Array);
|
|
559
598
|
/** A short description for debugging, e.g. `Image<64x64>` */
|
|
@@ -566,11 +605,6 @@ export declare class Image {
|
|
|
566
605
|
* The image's height
|
|
567
606
|
*/
|
|
568
607
|
get height(): number;
|
|
569
|
-
/**
|
|
570
|
-
* Yields an [x, y] array for every pixel in the image (0-based), row by row
|
|
571
|
-
* @yields The coordinates of the pixel ([x, y])
|
|
572
|
-
*/
|
|
573
|
-
coordinates(): Generator<[x: number, y: number], void, undefined>;
|
|
574
608
|
/**
|
|
575
609
|
* Yields an [x, y, color] array for every pixel in the image (0-based), row by row
|
|
576
610
|
* @yields The coordinates and color of the pixel ([x, y, color])
|
|
@@ -608,7 +642,8 @@ export declare class Image {
|
|
|
608
642
|
setPixelAt(x: number, y: number, color: Color): this;
|
|
609
643
|
/**
|
|
610
644
|
* Fills the image data with the supplied color
|
|
611
|
-
* @param color The color, or a function returning the color of each pixel
|
|
645
|
+
* @param color The color, or a function returning the color of each pixel (checked like any color: a result that
|
|
646
|
+
* isn't one throws a RangeError)
|
|
612
647
|
*/
|
|
613
648
|
fill(color: Color | ColorFunction): this;
|
|
614
649
|
/**
|
|
@@ -681,9 +716,9 @@ export declare class Image {
|
|
|
681
716
|
recolor(colors: Image): this;
|
|
682
717
|
/**
|
|
683
718
|
* Scales the opacity of the image
|
|
684
|
-
* @param
|
|
719
|
+
* @param factor The factor to multiply the opacity with (0..1 lowers it, >1 raises it, results are clamped)
|
|
685
720
|
*/
|
|
686
|
-
opacity(
|
|
721
|
+
opacity(factor: number): this;
|
|
687
722
|
/**
|
|
688
723
|
* Scales the red channel
|
|
689
724
|
* @param factor The factor to multiply the channel with (>= 0, results are clamped)
|
|
@@ -836,8 +871,8 @@ export declare class Image {
|
|
|
836
871
|
*/
|
|
837
872
|
averageColor(): Color;
|
|
838
873
|
/**
|
|
839
|
-
* Gets the image's dominant color: the colors are
|
|
840
|
-
* the
|
|
874
|
+
* Gets the image's dominant color: the colors are counted in a histogram of 16 levels per channel, and the average
|
|
875
|
+
* of the pixels in the fullest bin is returned (so it is a color the image has, not a mix of two hues)
|
|
841
876
|
* @param options Which colors to ignore, see {@link DominantColorOptions}
|
|
842
877
|
* @return The image's dominant color (fully opaque); mostly transparent pixels are ignored.
|
|
843
878
|
* If every pixel is ignored as black or white, the filter is dropped
|
|
@@ -846,16 +881,17 @@ export declare class Image {
|
|
|
846
881
|
/**
|
|
847
882
|
* Rotates the image clockwise by the given angle in degrees (like CSS' `rotate()`; negative angles turn it
|
|
848
883
|
* counterclockwise). Multiples of 90° move whole pixels; other angles resample the image (see
|
|
849
|
-
* {@link RotateOptions.mode})
|
|
884
|
+
* {@link RotateOptions.mode}). By default the image grows so the corners fit (a quarter turn swaps width and
|
|
885
|
+
* height); with `expand: false` it keeps its size, also for quarter turns, and what doesn't fit is cut off
|
|
850
886
|
* @param angle The angle in degrees, clockwise
|
|
851
887
|
* @param options See {@link RotateOptions}
|
|
852
888
|
*/
|
|
853
889
|
rotate(angle: number, options?: RotateOptions): this;
|
|
854
890
|
/**
|
|
855
891
|
* Flips / mirrors the image horizontally or vertically
|
|
856
|
-
* @param direction The direction to flip
|
|
892
|
+
* @param direction The direction to flip, see {@link FlipDirection}
|
|
857
893
|
*/
|
|
858
|
-
flip(direction:
|
|
894
|
+
flip(direction: FlipDirection): this;
|
|
859
895
|
/**
|
|
860
896
|
* Rounds the image's corners, with antialiased edges
|
|
861
897
|
* @param options See {@link RoundCornersOptions}
|
|
@@ -942,8 +978,9 @@ export declare class Image {
|
|
|
942
978
|
* Creates a new image from the given SVG.
|
|
943
979
|
* Supports shapes, paths, transforms, use/symbol, CSS styles, gradients, patterns, strokes, markers, clip paths,
|
|
944
980
|
* masks, opacity, blend modes, filters (all primitives and the filter functions) and images embedded as data URIs
|
|
945
|
-
* (PNG, JPEG, GIF, WebP, SVG) or given with {@link
|
|
946
|
-
* (see {@link
|
|
981
|
+
* (PNG, JPEG, GIF, WebP, SVG) or given with {@link SVGResourceOptions.images}, and text with the given or embedded fonts
|
|
982
|
+
* (see {@link SVGResourceOptions.font}). Hrefs are resolved from the options and the data URIs only, never from files or URLs:
|
|
983
|
+
* drawing an image that isn't given, or can't be decoded, throws.
|
|
947
984
|
* @example
|
|
948
985
|
* ```ts
|
|
949
986
|
* const logo = await Image.renderSVG(
|
|
@@ -959,8 +996,8 @@ export declare class Image {
|
|
|
959
996
|
/**
|
|
960
997
|
* Creates a new image containing the rendered text.
|
|
961
998
|
* @param text Text to render
|
|
962
|
-
* @param options The font and size, color, layout and style, see {@link RenderTextOptions}
|
|
963
|
-
* outline width on every side
|
|
999
|
+
* @param options The font and size, color, layout and style, see {@link RenderTextOptions}. Without a `width` or
|
|
1000
|
+
* `height`, the image grows by the outline width on every side; with one, it has exactly that size
|
|
964
1001
|
* @return The rendered text
|
|
965
1002
|
*/
|
|
966
1003
|
static renderText(text: string, options: RenderTextOptions): Promise<Image>;
|