-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
192 lines (190 loc) · 9.7 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */
export function sum(a: number, b: number): number
/** A wrapper around `ImageWrapper` that can be exposed to JavaScript */
export class CommonImage {
dimensions(): [width: number, height: number]
/**
* Get the color type of the image
*
* ---
* Return value is one of the following (there may be other values, use it with caution):
* - `l8`: 8-bit luminance
* - `la8`: 8-bit luminance with alpha channel
* - `rgb8`: 8-bit with R, G and B channels
* - `rgba8`: 8-bit with R, G, B and alpha channels
* - `l16`: 16-bit luminance
* - `la16`: 16-bit luminance with alpha channel
* - `rgb16`: 16-bit with R, G and B channels
* - `rgba16`: 16-bit with R, G, B and alpha channels
* - `rgb32f`: 32-bit floating point with R, G and B channels
* - `rgba32f`: 32-bit floating point with R, G, B and alpha channels
* - `unknown_since_non_exhaustive`: unknown color type, this should never happen
*/
colorType(): 'l8'|'la8'|'rgb8'|'rgba8'|'l16'|'la16'|'rgb16'|'rgba16'|'rgb32f'|'rgba32f'|'unknown_since_non_exhaustive'
/** Bits per pixel (bpp) refers to the number of bits of information stored per pixel of the image */
bpp(): number
/**
* Resize this image using the specified filter algorithm. Returns a new image. The image's aspect ratio is preserved. The image is scaled to the maximum possible size that fits within the bounds specified by `nw` and `nh`.
*
* ---
* 'filter' can be one of the following (arranged from fastest to slowest):
* - `nearest`: Nearest Neighbor -- default
* - `triangle`: Linear Filter
* - `catmullRom`: Cubic Filter
* - `gaussian`: Gaussian Filter
* - `lanczos3`: Lanczos with window 3
*
* ---
* see {@link resizeToCover} and {@link resizeExact} for other resize strategies
*/
resizeToFit(nw: number, nh: number, filter?: 'nearest'|'triangle'|'catmullRom'|'gaussian'|'lanczos3'): CommonImage
/**
* Resize this image using the specified filter algorithm. Returns a new image. The image's aspect ratio is preserved. The image is scaled to the maximum possible size that fits within the larger (relative to aspect ratio) of the bounds specified by `nw` and `nh`, then cropped to fit within the bounds specified by `nw` and `nh`.
*
* ---
* 'filter' can be one of the following (arranged from fastest to slowest):
* - `nearest`: Nearest Neighbor -- default
* - `triangle`: Linear Filter
* - `catmullRom`: Cubic Filter
* - `gaussian`: Gaussian Filter
* - `lanczos3`: Lanczos with window 3
*
* ---
* see {@link resizeToFit} and {@link resizeExact} for other resize strategies
*/
resizeToCover(nw: number, nh: number, filter?: 'nearest'|'triangle'|'catmullRom'|'gaussian'|'lanczos3'): CommonImage
/**
* Resize this image using the specified filter algorithm. Returns a new image. Does not preserve aspect ratio. nw and nh are the new image's dimensions.
*
* ---
* 'filter' can be one of the following (arranged from fastest to slowest):
* - `nearest`: Nearest Neighbor -- default
* - `triangle`: Linear Filter
* - `catmullRom`: Cubic Filter
* - `gaussian`: Gaussian Filter
* - `lanczos3`: Lanczos with window 3
*
* ---
* see {@link resizeToFit} and {@link resizeToCover} for other resize strategies
*/
resizeExact(nw: number, nh: number, filter?: 'nearest'|'triangle'|'catmullRom'|'gaussian'|'lanczos3'): CommonImage
/**
* Rotate this image by 90 degrees clockwise. Returns a new image
*
* ---
* `quarter`: The number of 90-degree clockwise rotations to apply. Valid within `0-3` and should be a `u8`, otherwise it will cause a panic
*/
rotateQuarter(quarter: number): CommonImage
/**
* Flip this image horizontally or vertically. Returns a new image
*
* ---
* `horizontal`: whether to flip horizontally, otherwise it will flip vertically. default is `true`
*/
flip(horizontal?: boolean | undefined | null): CommonImage
/** Crop this image. Returns a new image */
crop(x: number, y: number, width: number, height: number): CommonImage
/** Encode this image as a PNG and return the encoded bytes */
toPng(): Array<number>
/**
* Encode this image as a JPEG(with specified quality) and return the encoded bytes
*
* ---
* `quality`: Valid within `1-100` and should be a `u8`, otherwise it will cause a panic
*/
toJpeg(quality: number): Array<number>
/**
* Encode this image as a PNM(in variant PBM) and return the encoded bytes
*
* ---
* `binary_sample`: whether to use binary sample encoding, otherwise it will use ascii sample encoding. default is `true` for smaller size
*/
toPbm(binarySample?: boolean | undefined | null): Array<number>
/**
* Encode this image as a PNM(in variant PGM) and return the encoded bytes
*
* ---
* `binary_sample`: whether to use binary sample encoding, otherwise it will use ascii sample encoding. default is `true` for smaller size
*/
toPgm(binarySample?: boolean | undefined | null): Array<number>
/**
* Encode this image as a PNM(in variant PPM) and return the encoded bytes
*
* ---
* `binary_sample`: whether to use binary sample encoding, otherwise it will use ascii sample encoding. default is `true` for smaller size
*/
toPpm(binarySample?: boolean | undefined | null): Array<number>
/** Encode this image as a PNM(extended as PAM) and return the encoded bytes */
toPam(): Array<number>
/** Encode this image as a GIF and return the encoded bytes */
toGif(): Array<number>
/**
* Encode this image as a ICO and return the encoded bytes
*
* ---
* `strategy`: The strategy used when the width or height of the image exceeds 256. Its value is in the format of '<mode>_<filter>'.
* - `undefined`: No conversion is used, will cause a panic if the width or height of the image exceeds 256
*
* 'mode' can be one of the following:
* - `fit`: The image's aspect ratio is preserved. The image is scaled to the maximum possible size that fits within **256x256**.
* - `cover`: The image's aspect ratio is preserved. The image is scaled to the maximum possible size that fits within **256x256** (relative to aspect ratio), then cropped to fit within **256x256**.
* - `exact`: Does not preserve aspect ratio. **256x256** the new image's dimension.
*
* 'filter' can be one of the following (arranged from fastest to slowest):
* - `nearest`: Nearest Neighbor
* - `triangle`: Linear Filter
* - `catmullRom`: Cubic Filter
* - `gaussian`: Gaussian Filter
* - `lanczos3`: Lanczos with window 3
*/
toIco(strategy?: 'fit_nearest'|'fit_triangle'|'fit_catmullRom'|'fit_gaussian'|'fit_lanczos3'|'cover_nearest'|'cover_triangle'|'cover_catmullRom'|'cover_gaussian'|'cover_lanczos3'|'exact_nearest'|'exact_triangle'|'exact_catmullRom'|'exact_gaussian'|'exact_lanczos3'): Array<number>
/** Encode this image as a BMP and return the encoded bytes */
toBmp(): Array<number>
/** Encode this image as a Farbfeld and return the encoded bytes */
toFarbfeld(): Array<number>
/** Encode this image as a TGA and return the encoded bytes */
toTga(): Array<number>
/** Encode this image as a OpenExr and return the encoded bytes */
toOpenExr(): Array<number>
/** Encode this image as a TIFF and return the encoded bytes */
toTiff(): Array<number>
/** Encode this image as a QOI and return the encoded bytes */
toQoi(): Array<number>
}
/** `ImageLoader` provides several way to load image binary into a `CommonImage` */
export class ImageLoader {
/** Create a `CommonImage` instance from a byte slice. Makes an educated guess about the image format */
static autoGuess(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a PNG */
static fromPng(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a JPEG */
static fromJpeg(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a GIF */
static fromGif(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a WEBP */
static fromWebp(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a PNM */
static fromPnm(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a TIFF */
static fromTiff(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a TGA */
static fromTga(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a DDS */
static fromDds(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a BMP */
static fromBmp(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a ICO */
static fromIco(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a Radiance HDR */
static fromHdr(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a OpenEXR */
static fromOpenEXR(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a Farbfeld */
static fromFarbfeld(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a AVIF */
static fromAvif(buffer: Array<number>): CommonImage
/** Create a `CommonImage` instance from a byte slice. Assumes the image is a QOI */
static fromQoi(buffer: Array<number>): CommonImage
}