imagescript 3.20.2 → 4.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -12
- package/dist/animation-encoder.d.ts +1 -34
- package/dist/animation-encoder.js +24 -26
- package/dist/animation.d.ts +108 -122
- package/dist/animation.js +274 -110
- package/dist/codecs/gif.js +11 -9
- package/dist/codecs/hdr.d.ts +1 -1
- package/dist/codecs/jpeg.js +13 -13
- package/dist/codecs/jxl/headers.js +2 -2
- package/dist/codecs/jxl.js +5 -5
- package/dist/codecs/netpbm.js +7 -7
- package/dist/codecs/png.js +15 -15
- package/dist/codecs/quantize.js +34 -8
- package/dist/codecs/tiff.js +1 -1
- package/dist/codecs/webp.js +3 -3
- package/dist/colors.d.ts +8 -7
- package/dist/colors.js +13 -3
- package/dist/frame.d.ts +93 -102
- package/dist/frame.js +89 -62
- package/dist/gainmap.d.ts +88 -46
- package/dist/gainmap.js +73 -49
- package/dist/image-type.d.ts +6 -1
- package/dist/image-type.js +4 -1
- package/dist/image.d.ts +287 -732
- package/dist/image.js +255 -404
- package/dist/index.d.ts +15 -25
- package/dist/index.js +15 -14
- package/dist/render/svg.js +7 -2
- package/dist/text-layout.d.ts +5 -35
- package/dist/text-layout.js +9 -9
- package/dist/util/gain.js +12 -12
- package/dist/util/mem.d.ts +1 -1
- package/dist/util/options.js +20 -6
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/gif.d.ts +0 -36
- package/dist/gif.js +0 -22
- package/dist/util/rotate.js +0 -43
package/dist/frame.d.ts
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import { Image,
|
|
2
|
-
/** Names of the frame disposal modes, see {@link Frame.disposalMode} */
|
|
3
|
-
export type FrameDisposalModeName = 'any' | 'keep' | 'previous' | 'background';
|
|
1
|
+
import { Image, ResizeOptions, ResizeToOptions, TrimOptions, RotateOptions, TransformOptions, AffineTransform, ShadowOptions, OutlineOptions } from './image.js';
|
|
4
2
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* What happens to a frame's area before the next frame is drawn, see {@link Frame.disposalMode}:
|
|
4
|
+
* - `'keep'` (the default): the frame stays, the next one is drawn over it
|
|
5
|
+
* - `'background'`: the frame's area is cleared to transparent
|
|
6
|
+
* - `'previous'`: the frame's area goes back to what it was before the frame
|
|
7
|
+
* - `'any'`: the decoder decides (in practice like `'keep'`)
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
10
|
-
/**
|
|
11
|
-
export declare class FrameDisposalModes {
|
|
12
|
-
/** The decoder decides (in practice like {@link FrameDisposalModes.KEEP}) */
|
|
13
|
-
static readonly ANY = "any";
|
|
14
|
-
/** The frame stays, the next one is drawn over it (the default) */
|
|
15
|
-
static readonly KEEP = "keep";
|
|
16
|
-
/** The frame's area goes back to what it was before the frame */
|
|
17
|
-
static readonly PREVIOUS = "previous";
|
|
18
|
-
/** The frame's area is cleared to transparent */
|
|
19
|
-
static readonly BACKGROUND = "background";
|
|
20
|
-
private constructor();
|
|
21
|
-
}
|
|
22
|
-
/** Options of {@link Frame} and {@link Frame.from} */
|
|
9
|
+
export type FrameDisposalMode = 'any' | 'keep' | 'previous' | 'background';
|
|
10
|
+
/** Options of {@link Frame} */
|
|
23
11
|
export interface FrameOptions {
|
|
24
12
|
/** The frame's duration in milliseconds. Default: `100` */
|
|
25
13
|
duration?: number;
|
|
@@ -28,124 +16,127 @@ export interface FrameOptions {
|
|
|
28
16
|
/** The frame's offset on the y-axis. Default: `0` */
|
|
29
17
|
yOffset?: number;
|
|
30
18
|
/** The frame's disposal mode, see {@link Frame.disposalMode}. Default: `'keep'` */
|
|
31
|
-
disposalMode?:
|
|
19
|
+
disposalMode?: FrameDisposalMode;
|
|
32
20
|
}
|
|
33
21
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
22
|
+
* A frame of an {@link Animation}: an {@link Image} ({@link Frame.image}) with a duration, offsets and a disposal mode.
|
|
23
|
+
* The frame has the methods that change the image's size (`resize()` including its `'contain'` and `'cover'` fit
|
|
24
|
+
* modes, `scale()`, `crop()`, `trim()`, `rotate()`, `transform()`, `dropShadow()` and `outline()`), which move the
|
|
25
|
+
* offsets along so the frame stays in place in the animation; every other change goes to the image
|
|
26
|
+
* (`frame.image.blur(2)`). The image's own size-changing methods leave the offsets as they are. Offsets can become
|
|
27
|
+
* negative: the parts of a frame outside the animation's canvas aren't encoded
|
|
36
28
|
*/
|
|
37
|
-
export declare class Frame
|
|
38
|
-
/**
|
|
39
|
-
* Milliseconds. GIFs store hundredths of a second, so this is rounded to 10 ms when encoding a GIF;
|
|
40
|
-
* note that browsers play frames shorter than 20 ms with 100 ms
|
|
41
|
-
*/
|
|
42
|
-
duration: number;
|
|
43
|
-
/** The frame's horizontal offset in the animation */
|
|
44
|
-
xOffset: number;
|
|
45
|
-
/** The frame's vertical offset in the animation */
|
|
46
|
-
yOffset: number;
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated Use {@link FrameDisposalModes.ANY}, `Frame.DISPOSAL_*` will be removed in 4.0
|
|
49
|
-
* @group Deprecated
|
|
50
|
-
*/
|
|
51
|
-
static readonly DISPOSAL_ANY: typeof FrameDisposalModes.ANY;
|
|
29
|
+
export declare class Frame {
|
|
52
30
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
31
|
+
* Creates a frame of an image. The frame uses the image as it is (it isn't copied): changes to it are the frame's
|
|
32
|
+
* @param image The frame's pixels
|
|
33
|
+
* @param options See {@link FrameOptions}
|
|
55
34
|
*/
|
|
56
|
-
|
|
35
|
+
constructor(image: Image, options?: FrameOptions);
|
|
36
|
+
/** The frame's pixels. Changing the image changes the frame; the offsets stay as they are */
|
|
37
|
+
get image(): Image;
|
|
57
38
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
39
|
+
* Replaces the frame's pixels
|
|
40
|
+
* @param image The new image (used as it is, not copied)
|
|
60
41
|
*/
|
|
61
|
-
|
|
42
|
+
set image(image: Image);
|
|
43
|
+
/** The frame's width (its image's) */
|
|
44
|
+
get width(): number;
|
|
45
|
+
/** The frame's height (its image's) */
|
|
46
|
+
get height(): number;
|
|
62
47
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
48
|
+
* The frame's duration in milliseconds (a finite number from 0, else it throws a RangeError). GIFs store
|
|
49
|
+
* hundredths of a second, so this is rounded to 10 ms when encoding a GIF; note that browsers play frames shorter
|
|
50
|
+
* than 20 ms with 100 ms
|
|
65
51
|
*/
|
|
66
|
-
|
|
52
|
+
get duration(): number;
|
|
67
53
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param
|
|
70
|
-
* @param height The height in pixels
|
|
71
|
-
* @param options See {@link FrameOptions}
|
|
54
|
+
* Sets the duration
|
|
55
|
+
* @param duration Milliseconds, a finite number from 0
|
|
72
56
|
*/
|
|
73
|
-
|
|
57
|
+
set duration(duration: number);
|
|
58
|
+
/** The frame's horizontal offset in the animation (a finite number, else it throws a RangeError) */
|
|
59
|
+
get xOffset(): number;
|
|
74
60
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @param height The height in pixels
|
|
78
|
-
* @param duration The frame's duration (in ms)
|
|
79
|
-
* @param xOffset The frame's offset on the x-axis
|
|
80
|
-
* @param yOffset The frame's offset on the y-axis
|
|
81
|
-
* @param disposalMode The frame's disposal mode
|
|
82
|
-
* @deprecated Pass {@link FrameOptions} instead, the positional arguments will be removed in 4.0
|
|
61
|
+
* Sets the horizontal offset
|
|
62
|
+
* @param x The offset in pixels
|
|
83
63
|
*/
|
|
84
|
-
|
|
64
|
+
set xOffset(x: number);
|
|
65
|
+
/** The frame's vertical offset in the animation (a finite number, else it throws a RangeError) */
|
|
66
|
+
get yOffset(): number;
|
|
85
67
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
68
|
+
* Sets the vertical offset
|
|
69
|
+
* @param y The offset in pixels
|
|
88
70
|
*/
|
|
89
|
-
|
|
71
|
+
set yOffset(y: number);
|
|
72
|
+
/** The frame's disposal mode, see {@link FrameDisposalMode} */
|
|
73
|
+
get disposalMode(): FrameDisposalMode;
|
|
90
74
|
/**
|
|
91
75
|
* Sets the disposal mode
|
|
92
|
-
* @param disposalMode The mode's name (`'any'`, `'keep'`, `'previous'`, `'background'`)
|
|
76
|
+
* @param disposalMode The mode's name (`'any'`, `'keep'`, `'previous'`, `'background'`)
|
|
93
77
|
*/
|
|
94
|
-
set disposalMode(disposalMode:
|
|
78
|
+
set disposalMode(disposalMode: FrameDisposalMode);
|
|
95
79
|
/** A short description for debugging, e.g. `Frame<64x64x100ms>` */
|
|
96
80
|
toString(): string;
|
|
81
|
+
/** Clones the frame: its image (with its pixels and gain map), duration, offsets and disposal mode */
|
|
82
|
+
clone(): Frame;
|
|
97
83
|
/**
|
|
98
|
-
*
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
84
|
+
* Resizes the frame, scaling its offsets along with it (as if the whole animation was resized by the same factor)
|
|
85
|
+
* @param width The new width
|
|
86
|
+
* @param height The new height
|
|
87
|
+
* @param options See {@link ResizeOptions}
|
|
88
|
+
*/
|
|
89
|
+
resize(width: number, height: number, options?: ResizeOptions): this;
|
|
90
|
+
/**
|
|
91
|
+
* Resizes the frame, scaling its offsets along with it: to the given width or height (the other side keeps the
|
|
92
|
+
* aspect ratio), or to both
|
|
93
|
+
* @param options The size and how to resize, see {@link ResizeToOptions}
|
|
101
94
|
*/
|
|
102
|
-
|
|
95
|
+
resize(options: ResizeToOptions): this;
|
|
103
96
|
/**
|
|
104
|
-
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
107
|
-
* @param xOffset The frame's offset on the x-axis
|
|
108
|
-
* @param yOffset The frame's offset on the y-axis
|
|
109
|
-
* @param disposalMode The frame's disposal mode
|
|
110
|
-
* @deprecated Pass {@link FrameOptions} instead, the positional arguments will be removed in 4.0
|
|
97
|
+
* Scales the frame by a factor, and its offsets along with it
|
|
98
|
+
* @param factor The factor
|
|
99
|
+
* @param options See {@link ResizeOptions}
|
|
111
100
|
*/
|
|
112
|
-
|
|
101
|
+
scale(factor: number, options?: ResizeOptions): this;
|
|
113
102
|
/**
|
|
114
|
-
*
|
|
103
|
+
* Crops the frame to a region of it, moving the offsets so the remaining pixels stay where they are in the
|
|
104
|
+
* animation. The region is clipped to the frame
|
|
105
|
+
* @param x The x offset in the frame (0-based)
|
|
106
|
+
* @param y The y offset in the frame (0-based)
|
|
107
|
+
* @param width The new width
|
|
108
|
+
* @param height The new height
|
|
115
109
|
*/
|
|
116
|
-
|
|
110
|
+
crop(x: number, y: number, width: number, height: number): this;
|
|
117
111
|
/**
|
|
118
|
-
* Removes borders of one color, moving the
|
|
112
|
+
* Removes borders of one color, moving the offsets so the remaining pixels stay where they are in the animation
|
|
119
113
|
* @param options See {@link TrimOptions}
|
|
120
114
|
*/
|
|
121
115
|
trim(options?: TrimOptions): this;
|
|
122
116
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* @param
|
|
126
|
-
* @
|
|
117
|
+
* Rotates the frame clockwise around its middle, like {@link Image.rotate}: when it grows (or shrinks), the
|
|
118
|
+
* offsets move so its middle stays where it is in the animation
|
|
119
|
+
* @param angle The angle in degrees, clockwise
|
|
120
|
+
* @param options See {@link RotateOptions}
|
|
127
121
|
*/
|
|
128
|
-
|
|
122
|
+
rotate(angle: number, options?: RotateOptions): this;
|
|
129
123
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @param
|
|
133
|
-
* @param
|
|
134
|
-
* @param options See {@link ResizeOptions}
|
|
124
|
+
* Transforms the frame with an affine transform, like {@link Image.transform}: when it grows, the offsets move
|
|
125
|
+
* so the transform's origin stays where it is in the animation
|
|
126
|
+
* @param matrix The six values [a, b, c, d, e, f]
|
|
127
|
+
* @param options See {@link TransformOptions}
|
|
135
128
|
*/
|
|
136
|
-
|
|
129
|
+
transform(matrix: AffineTransform, options?: TransformOptions): this;
|
|
137
130
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @param
|
|
141
|
-
* @param mode The resizing mode (default: {@link ResizeModes.BILINEAR})
|
|
142
|
-
* @deprecated Pass {@link ResizeOptions} with `mode` instead, the positional mode will be removed in 4.0
|
|
131
|
+
* Adds a shadow behind the frame's image, like {@link Image.dropShadow}: when it grows up or left, the offsets
|
|
132
|
+
* move so the image stays where it is in the animation
|
|
133
|
+
* @param options See {@link ShadowOptions}
|
|
143
134
|
*/
|
|
144
|
-
|
|
135
|
+
dropShadow(options?: ShadowOptions): this;
|
|
145
136
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* @param options
|
|
137
|
+
* Draws an outline around the frame's shape, like {@link Image.outline}: when it grows up or left, the offsets
|
|
138
|
+
* move so the image stays where it is in the animation
|
|
139
|
+
* @param options See {@link OutlineOptions}
|
|
149
140
|
*/
|
|
150
|
-
|
|
141
|
+
outline(options?: OutlineOptions): this;
|
|
151
142
|
}
|
package/dist/frame.js
CHANGED
|
@@ -1,40 +1,64 @@
|
|
|
1
|
-
import { Image
|
|
2
|
-
import {
|
|
1
|
+
import { Image } from "./image.js";
|
|
2
|
+
import { checkOptions, finite } from "./util/options.js";
|
|
3
3
|
const DISPOSAL_MODES = ['any', 'keep', 'previous', 'background'];
|
|
4
|
-
export class
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor() { }
|
|
10
|
-
}
|
|
11
|
-
export class Frame extends Image {
|
|
12
|
-
duration;
|
|
13
|
-
xOffset;
|
|
14
|
-
yOffset;
|
|
4
|
+
export class Frame {
|
|
5
|
+
__image__;
|
|
6
|
+
__duration__ = 100;
|
|
7
|
+
__x__ = 0;
|
|
8
|
+
__y__ = 0;
|
|
15
9
|
__disposalMode__ = 1;
|
|
16
|
-
static DISPOSAL_ANY = FrameDisposalModes.ANY;
|
|
17
|
-
static DISPOSAL_KEEP = FrameDisposalModes.KEEP;
|
|
18
|
-
static DISPOSAL_PREVIOUS = FrameDisposalModes.PREVIOUS;
|
|
19
|
-
static DISPOSAL_BACKGROUND = FrameDisposalModes.BACKGROUND;
|
|
20
10
|
static __convert_disposal_mode__(mode) {
|
|
21
|
-
const id =
|
|
22
|
-
if (
|
|
11
|
+
const id = DISPOSAL_MODES.indexOf(mode);
|
|
12
|
+
if (id < 0)
|
|
23
13
|
throw new RangeError('Invalid disposal mode');
|
|
24
14
|
return id;
|
|
25
15
|
}
|
|
26
|
-
constructor(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
super(width, height);
|
|
16
|
+
constructor(image, options = {}) {
|
|
17
|
+
if (!(image instanceof Image))
|
|
18
|
+
throw new TypeError('A frame takes an Image, like new Frame(image, { duration: 100 })');
|
|
19
|
+
checkOptions(options, 'Frame(image, { duration: 100 })');
|
|
20
|
+
const { duration = 100, xOffset: x = 0, yOffset: y = 0, disposalMode: disposal = 'keep' } = options;
|
|
21
|
+
this.__image__ = image;
|
|
33
22
|
this.duration = duration;
|
|
34
23
|
this.xOffset = x;
|
|
35
24
|
this.yOffset = y;
|
|
36
25
|
this.disposalMode = disposal;
|
|
37
26
|
}
|
|
27
|
+
get image() {
|
|
28
|
+
return this.__image__;
|
|
29
|
+
}
|
|
30
|
+
set image(image) {
|
|
31
|
+
if (!(image instanceof Image))
|
|
32
|
+
throw new TypeError('A frame\'s image has to be an Image');
|
|
33
|
+
this.__image__ = image;
|
|
34
|
+
}
|
|
35
|
+
get width() {
|
|
36
|
+
return this.__image__.width;
|
|
37
|
+
}
|
|
38
|
+
get height() {
|
|
39
|
+
return this.__image__.height;
|
|
40
|
+
}
|
|
41
|
+
get duration() {
|
|
42
|
+
return this.__duration__;
|
|
43
|
+
}
|
|
44
|
+
set duration(duration) {
|
|
45
|
+
const value = finite(duration, 'frame duration');
|
|
46
|
+
if (value < 0)
|
|
47
|
+
throw new RangeError('Invalid frame duration');
|
|
48
|
+
this.__duration__ = value;
|
|
49
|
+
}
|
|
50
|
+
get xOffset() {
|
|
51
|
+
return this.__x__;
|
|
52
|
+
}
|
|
53
|
+
set xOffset(x) {
|
|
54
|
+
this.__x__ = finite(x, 'x offset');
|
|
55
|
+
}
|
|
56
|
+
get yOffset() {
|
|
57
|
+
return this.__y__;
|
|
58
|
+
}
|
|
59
|
+
set yOffset(y) {
|
|
60
|
+
this.__y__ = finite(y, 'y offset');
|
|
61
|
+
}
|
|
38
62
|
get disposalMode() {
|
|
39
63
|
return DISPOSAL_MODES[this.__disposalMode__];
|
|
40
64
|
}
|
|
@@ -47,44 +71,47 @@ export class Frame extends Image {
|
|
|
47
71
|
toString() {
|
|
48
72
|
return `Frame<${this.width}x${this.height}x${this.duration}ms>`;
|
|
49
73
|
}
|
|
50
|
-
static from(image, durationOrOptions, xOffset, yOffset, disposalMode) {
|
|
51
|
-
if (!(image instanceof Image))
|
|
52
|
-
throw new TypeError('Invalid image passed');
|
|
53
|
-
const options = isOptions(durationOrOptions) ? durationOrOptions : { duration: durationOrOptions, xOffset, yOffset, disposalMode };
|
|
54
|
-
const frame = new Frame(image.width, image.height, options);
|
|
55
|
-
frame.bitmap.set(image.bitmap);
|
|
56
|
-
return frame;
|
|
57
|
-
}
|
|
58
74
|
clone() {
|
|
59
|
-
return Frame.
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.xOffset += bounds[0];
|
|
74
|
-
this.yOffset += bounds[1];
|
|
75
|
-
return this.__apply__(this.__crop__(...bounds));
|
|
76
|
-
}
|
|
77
|
-
resize(widthOrOptions, heightArgument, modeArgument) {
|
|
78
|
-
const [width, height, modeOrOptions] = resizeArguments(widthOrOptions, heightArgument, modeArgument);
|
|
79
|
-
const originalWidth = this.width;
|
|
80
|
-
const originalHeight = this.height;
|
|
81
|
-
super.resize(width, height, modeOrOptions);
|
|
82
|
-
this.xOffset = Math.round(this.xOffset * this.width / originalWidth);
|
|
83
|
-
this.yOffset = Math.round(this.yOffset * this.height / originalHeight);
|
|
75
|
+
return new Frame(this.__image__.clone(), { duration: this.duration, xOffset: this.xOffset, yOffset: this.yOffset, disposalMode: this.disposalMode });
|
|
76
|
+
}
|
|
77
|
+
__tracked__(change) {
|
|
78
|
+
const image = this.__image__;
|
|
79
|
+
image.__moved__ = (scaleX, scaleY, x, y) => {
|
|
80
|
+
this.xOffset = Math.round(this.xOffset * scaleX + x);
|
|
81
|
+
this.yOffset = Math.round(this.yOffset * scaleY + y);
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
change(image);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
delete image.__moved__;
|
|
88
|
+
}
|
|
84
89
|
return this;
|
|
85
90
|
}
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
|
|
91
|
+
resize(widthOrOptions, heightArgument, optionsArgument) {
|
|
92
|
+
return this.__tracked__(image => typeof widthOrOptions === 'number'
|
|
93
|
+
? image.resize(widthOrOptions, heightArgument, optionsArgument)
|
|
94
|
+
: image.resize(widthOrOptions));
|
|
95
|
+
}
|
|
96
|
+
scale(factor, options) {
|
|
97
|
+
return this.__tracked__(image => image.scale(factor, options));
|
|
98
|
+
}
|
|
99
|
+
crop(x, y, width, height) {
|
|
100
|
+
return this.__tracked__(image => image.crop(x, y, width, height));
|
|
101
|
+
}
|
|
102
|
+
trim(options) {
|
|
103
|
+
return this.__tracked__(image => image.trim(options));
|
|
104
|
+
}
|
|
105
|
+
rotate(angle, options) {
|
|
106
|
+
return this.__tracked__(image => image.rotate(angle, options));
|
|
107
|
+
}
|
|
108
|
+
transform(matrix, options) {
|
|
109
|
+
return this.__tracked__(image => image.transform(matrix, options));
|
|
110
|
+
}
|
|
111
|
+
dropShadow(options) {
|
|
112
|
+
return this.__tracked__(image => image.dropShadow(options));
|
|
113
|
+
}
|
|
114
|
+
outline(options) {
|
|
115
|
+
return this.__tracked__(image => image.outline(options));
|
|
89
116
|
}
|
|
90
117
|
}
|
package/dist/gainmap.d.ts
CHANGED
|
@@ -5,56 +5,105 @@ export interface GainMapEncodeOptions {
|
|
|
5
5
|
/** The JPEG quality (1-100). Default: `90` */
|
|
6
6
|
quality?: number;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
8
|
+
/** A gain-map parameter shared across channels or specified as `[red, green, blue]` */
|
|
9
|
+
export type GainMapChannelValues = number | readonly [red: number, green: number, blue: number];
|
|
10
|
+
/** Options of the {@link GainMap} constructor */
|
|
9
11
|
export interface GainMapOptions {
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
gamma?:
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
/** Extra brightness at the map's darkest value (0); `-1` means half as bright. Default: `0` (no change) */
|
|
13
|
+
min?: GainMapChannelValues;
|
|
14
|
+
/** Extra brightness at the map's brightest value (255); `2` means four times as bright. Default: `2` */
|
|
15
|
+
max?: GainMapChannelValues;
|
|
16
|
+
/** How quickly the brightness changes between `min` and `max`; `1` changes it evenly. Default: `1` */
|
|
17
|
+
gamma?: GainMapChannelValues;
|
|
18
|
+
/**
|
|
19
|
+
* Small brightness offset added before applying the boost, to keep black from being boosted indefinitely.
|
|
20
|
+
* Default: `1/64`
|
|
21
|
+
*/
|
|
22
|
+
offsetSDR?: GainMapChannelValues;
|
|
23
|
+
/** Small brightness offset subtracted from the result. Default: `1/64` */
|
|
24
|
+
offsetHDR?: GainMapChannelValues;
|
|
25
|
+
/** How bright a display must be before the map starts to apply; `0` is standard-screen brightness. Default: `0` */
|
|
21
26
|
hdrCapacityMin?: number;
|
|
22
|
-
/**
|
|
27
|
+
/** How bright a display must be for the map to apply fully. Default: the largest value in `max` */
|
|
23
28
|
hdrCapacityMax?: number;
|
|
24
|
-
/**
|
|
29
|
+
/** Whether the boost uses the original image's colors (`false`: the brighter HDR colors). Default: `true` */
|
|
25
30
|
useBaseColorSpace?: boolean;
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
|
-
* A gain map
|
|
29
|
-
*
|
|
33
|
+
* A gain map is a small companion image that tells a high-dynamic-range (HDR) display how much brighter to show each
|
|
34
|
+
* part of a photo. Standard displays ignore it and show the regular-brightness image.
|
|
35
|
+
*
|
|
36
|
+
* {@link Image.decode} reads gain maps from supported JPEG, AVIF and JPEG XL images into {@link Image.gainMap};
|
|
37
|
+
* {@link Image.encodeJPEG}, {@link Image.encodeAVIF} and {@link Image.encodeJXL} can write them. The map covers the
|
|
38
|
+
* whole image, at any resolution. Each pixel's value (0-255) controls how much extra brightness to add at that
|
|
39
|
+
* location. For developers who need the exact calculation, the boost is
|
|
40
|
+
* `2^(min + (max - min) * (v / 255)^(1 / gamma))`, per color channel.
|
|
30
41
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* write a quarter of the width and height). Its value `v` (0-255, per channel or one for all) boosts the linear
|
|
34
|
-
* light of the image by `2^(gainMapMin + (gainMapMax - gainMapMin) * (v / 255)^(1 / gamma))`
|
|
42
|
+
* The parameters are checked when they are set: a value that isn't finite (or an array of other than 1 or 3 of them)
|
|
43
|
+
* throws, and the map keeps its value
|
|
35
44
|
*/
|
|
36
45
|
export declare class GainMap {
|
|
37
|
-
/** log2 of the boost of the map's value 0, per channel (red, green, blue) */
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
|
|
46
|
+
/** log2 of the boost of the map's value 0, per channel (red, green, blue; a copy: assign to change it) */
|
|
47
|
+
get min(): readonly [red: number, green: number, blue: number];
|
|
48
|
+
/**
|
|
49
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
50
|
+
* @param value One number for all channels or [r, g, b]
|
|
51
|
+
*/
|
|
52
|
+
set min(value: GainMapChannelValues);
|
|
53
|
+
/** log2 of the boost of the map's value 255, per channel (a copy: assign to change it) */
|
|
54
|
+
get max(): readonly [red: number, green: number, blue: number];
|
|
55
|
+
/**
|
|
56
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
57
|
+
* @param value One number for all channels or [r, g, b]
|
|
58
|
+
*/
|
|
59
|
+
set max(value: GainMapChannelValues);
|
|
60
|
+
/** The gamma the map's values are stored with, per channel (a copy: assign to change it) */
|
|
61
|
+
get gamma(): readonly [red: number, green: number, blue: number];
|
|
62
|
+
/**
|
|
63
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
64
|
+
* @param value One number above 0 for all channels or [r, g, b]
|
|
65
|
+
*/
|
|
66
|
+
set gamma(value: GainMapChannelValues);
|
|
67
|
+
/** Added to the SDR image's linear values before the boost, per channel (a copy: assign to change it) */
|
|
68
|
+
get offsetSDR(): readonly [red: number, green: number, blue: number];
|
|
69
|
+
/**
|
|
70
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
71
|
+
* @param value One number for all channels or [r, g, b]
|
|
72
|
+
*/
|
|
73
|
+
set offsetSDR(value: GainMapChannelValues);
|
|
74
|
+
/** Subtracted from the HDR result, per channel (a copy: assign to change it) */
|
|
75
|
+
get offsetHDR(): readonly [red: number, green: number, blue: number];
|
|
76
|
+
/**
|
|
77
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
78
|
+
* @param value One number for all channels or [r, g, b]
|
|
79
|
+
*/
|
|
80
|
+
set offsetHDR(value: GainMapChannelValues);
|
|
81
|
+
/** log2 of the display headroom from which on the map starts to apply (from 0) */
|
|
82
|
+
get hdrCapacityMin(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
85
|
+
* @param value A finite number from 0
|
|
86
|
+
*/
|
|
87
|
+
set hdrCapacityMin(value: number);
|
|
88
|
+
/** log2 of the display headroom at which it applies fully (above `hdrCapacityMin`) */
|
|
89
|
+
get hdrCapacityMax(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
92
|
+
* @param value A finite number
|
|
93
|
+
*/
|
|
94
|
+
set hdrCapacityMax(value: number);
|
|
95
|
+
/** Whether the boost applies in the SDR image's color space (else in the HDR image's) */
|
|
96
|
+
get useBaseColorSpace(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Replaces the value (checked: an invalid one throws and the old one stays)
|
|
99
|
+
* @param value Whether the boost applies in the SDR image's color space
|
|
100
|
+
*/
|
|
101
|
+
set useBaseColorSpace(value: boolean);
|
|
53
102
|
/** its pixels */
|
|
54
103
|
private __pixels__;
|
|
55
104
|
/**
|
|
56
105
|
* Creates a gain map
|
|
57
|
-
* @param image The map's pixels:
|
|
106
|
+
* @param image The map's pixels: gray (red, green and blue the same) for one map for all channels. Its alpha is
|
|
58
107
|
* ignored
|
|
59
108
|
* @param options See {@link GainMapOptions}
|
|
60
109
|
*/
|
|
@@ -72,7 +121,7 @@ export declare class GainMap {
|
|
|
72
121
|
get width(): number;
|
|
73
122
|
/** The map's height */
|
|
74
123
|
get height(): number;
|
|
75
|
-
/** `1` for a
|
|
124
|
+
/** `1` for a gray map (one boost for red, green and blue), `3` for one per channel */
|
|
76
125
|
get channels(): 1 | 3;
|
|
77
126
|
/** Clones the gain map (its pixels too) */
|
|
78
127
|
clone(): GainMap;
|
|
@@ -81,14 +130,7 @@ export declare class GainMap {
|
|
|
81
130
|
* Ultra HDR JPEG
|
|
82
131
|
* @param options See {@link GainMapEncodeOptions}
|
|
83
132
|
*/
|
|
84
|
-
encode(options?: GainMapEncodeOptions): Promise<Uint8Array
|
|
85
|
-
/**
|
|
86
|
-
* Encodes the gain map alone: a JPEG with its parameters (hdrgm XMP and ISO 21496-1), like the second image in an
|
|
87
|
-
* Ultra HDR JPEG
|
|
88
|
-
* @param quality The JPEG quality (1-100). Default: `90`
|
|
89
|
-
* @deprecated Pass {@link GainMapEncodeOptions} instead, the positional arguments will be removed in 4.0
|
|
90
|
-
*/
|
|
91
|
-
encode(quality?: number): Promise<Uint8Array>;
|
|
133
|
+
encode(options?: GainMapEncodeOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
92
134
|
/**
|
|
93
135
|
* Decodes a gain map JPEG with its parameters (hdrgm XMP or ISO 21496-1), like the second image in an Ultra HDR
|
|
94
136
|
* JPEG, or the gain map of an Ultra HDR JPEG (or an iPhone's JPEG: its values converted to these parameters)
|