@napi-rs/image 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +601 -22
- package/index.d.ts +334 -13
- package/index.js +69 -25
- package/package.json +20 -39
- package/.gitattributes +0 -13
- package/Cargo.toml +0 -35
- package/__test__/lossless.spec.mjs +0 -18
- package/build.rs +0 -5
- package/optimize-test.js +0 -7
- package/src/lib.rs +0 -185
- package/un-optimized.jpg +0 -0
- package/un-optimized.png +0 -0
package/index.d.ts
CHANGED
|
@@ -3,11 +3,108 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export interface AvifConfig {
|
|
7
|
+
/** 0-100 scale, 100 is lossless */
|
|
8
|
+
quality?: number | undefined | null
|
|
9
|
+
/** 0-100 scale */
|
|
10
|
+
alphaQuality?: number | undefined | null
|
|
11
|
+
/** rav1e preset 1 (slow) 10 (fast but crappy), default is 4 */
|
|
12
|
+
speed?: number | undefined | null
|
|
13
|
+
/** How many threads should be used (0 = match core count) */
|
|
14
|
+
threads?: number | undefined | null
|
|
15
|
+
/** set to '4:2:0' to use chroma subsampling, default '4:4:4' */
|
|
16
|
+
chromaSubsampling?: ChromaSubsampling | undefined | null
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* https://en.wikipedia.org/wiki/Chroma_subsampling#Types_of_sampling_and_subsampling
|
|
20
|
+
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
|
|
21
|
+
*/
|
|
22
|
+
export const enum ChromaSubsampling {
|
|
23
|
+
/**
|
|
24
|
+
* Each of the three Y'CbCr components has the same sample rate, thus there is no chroma subsampling. This scheme is sometimes used in high-end film scanners and cinematic post-production.
|
|
25
|
+
* Note that "4:4:4" may instead be wrongly referring to R'G'B' color space, which implicitly also does not have any chroma subsampling (except in JPEG R'G'B' can be subsampled).
|
|
26
|
+
* Formats such as HDCAM SR can record 4:4:4 R'G'B' over dual-link HD-SDI.
|
|
27
|
+
*/
|
|
28
|
+
Yuv444 = 0,
|
|
29
|
+
/**
|
|
30
|
+
* The two chroma components are sampled at half the horizontal sample rate of luma: the horizontal chroma resolution is halved. This reduces the bandwidth of an uncompressed video signal by one-third.
|
|
31
|
+
* Many high-end digital video formats and interfaces use this scheme:
|
|
32
|
+
* - [AVC-Intra 100](https://en.wikipedia.org/wiki/AVC-Intra)
|
|
33
|
+
* - [Digital Betacam](https://en.wikipedia.org/wiki/Betacam#Digital_Betacam)
|
|
34
|
+
* - [Betacam SX](https://en.wikipedia.org/wiki/Betacam#Betacam_SX)
|
|
35
|
+
* - [DVCPRO50](https://en.wikipedia.org/wiki/DV#DVCPRO) and [DVCPRO HD](https://en.wikipedia.org/wiki/DV#DVCPRO_HD)
|
|
36
|
+
* - [Digital-S](https://en.wikipedia.org/wiki/Digital-S)
|
|
37
|
+
* - [CCIR 601](https://en.wikipedia.org/wiki/Rec._601) / [Serial Digital Interface](https://en.wikipedia.org/wiki/Serial_digital_interface) / [D1](https://en.wikipedia.org/wiki/D-1_(Sony))
|
|
38
|
+
* - [ProRes (HQ, 422, LT, and Proxy)](https://en.wikipedia.org/wiki/Apple_ProRes)
|
|
39
|
+
* - [XDCAM HD422](https://en.wikipedia.org/wiki/XDCAM)
|
|
40
|
+
* - [Canon MXF HD422](https://en.wikipedia.org/wiki/Canon_XF-300)
|
|
41
|
+
*/
|
|
42
|
+
Yuv422 = 1,
|
|
43
|
+
/**
|
|
44
|
+
* n 4:2:0, the horizontal sampling is doubled compared to 4:1:1,
|
|
45
|
+
* but as the **Cb** and **Cr** channels are only sampled on each alternate line in this scheme, the vertical resolution is halved.
|
|
46
|
+
* The data rate is thus the same.
|
|
47
|
+
* This fits reasonably well with the PAL color encoding system, since this has only half the vertical chrominance resolution of [NTSC](https://en.wikipedia.org/wiki/NTSC).
|
|
48
|
+
* It would also fit extremely well with the [SECAM](https://en.wikipedia.org/wiki/SECAM) color encoding system,
|
|
49
|
+
* since like that format, 4:2:0 only stores and transmits one color channel per line (the other channel being recovered from the previous line).
|
|
50
|
+
* However, little equipment has actually been produced that outputs a SECAM analogue video signal.
|
|
51
|
+
* In general, SECAM territories either have to use a PAL-capable display or a [transcoder](https://en.wikipedia.org/wiki/Transcoding) to convert the PAL signal to SECAM for display.
|
|
52
|
+
*/
|
|
53
|
+
Yuv420 = 2,
|
|
54
|
+
/**
|
|
55
|
+
* What if the chroma subsampling model is 4:0:0?
|
|
56
|
+
* That says to use every pixel of luma data, but that each row has 0 chroma samples applied to it. The resulting image, then, is comprised solely of the luminance data—a greyscale image.
|
|
57
|
+
*/
|
|
58
|
+
Yuv400 = 3
|
|
59
|
+
}
|
|
60
|
+
export interface JpegCompressOptions {
|
|
61
|
+
/** Output quality, default is 100 (lossless) */
|
|
62
|
+
quality?: number | undefined | null
|
|
63
|
+
/**
|
|
64
|
+
* If true, it will use MozJPEG’s scan optimization. Makes progressive image files smaller.
|
|
65
|
+
* Default is `true`
|
|
66
|
+
*/
|
|
67
|
+
optimizeScans?: boolean | undefined | null
|
|
68
|
+
}
|
|
69
|
+
export function compressJpegSync(input: Buffer, options?: JpegCompressOptions | undefined | null): Buffer
|
|
70
|
+
export function compressJpeg(input: Buffer, options?: JpegCompressOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
71
|
+
export const enum CompressionType {
|
|
72
|
+
/** Default compression level */
|
|
73
|
+
Default = 0,
|
|
74
|
+
/** Fast, minimal compression */
|
|
75
|
+
Fast = 1,
|
|
76
|
+
/** High compression level */
|
|
77
|
+
Best = 2,
|
|
78
|
+
/** Huffman coding compression */
|
|
79
|
+
Huffman = 3,
|
|
80
|
+
/** Run-length encoding compression */
|
|
81
|
+
Rle = 4
|
|
82
|
+
}
|
|
83
|
+
export const enum FilterType {
|
|
84
|
+
/**
|
|
85
|
+
* No processing done, best used for low bit depth greyscale or data with a
|
|
86
|
+
* low color count
|
|
87
|
+
*/
|
|
88
|
+
NoFilter = 0,
|
|
89
|
+
/** Filters based on previous pixel in the same scanline */
|
|
90
|
+
Sub = 1,
|
|
91
|
+
/** Filters based on the scanline above */
|
|
92
|
+
Up = 2,
|
|
93
|
+
/** Filters based on the average of left and right neighbor pixels */
|
|
94
|
+
Avg = 3,
|
|
95
|
+
/** Algorithm that takes into account the left, upper left, and above pixels */
|
|
96
|
+
Paeth = 4,
|
|
97
|
+
/**
|
|
98
|
+
* Uses a heuristic to select one of the preceding filters for each
|
|
99
|
+
* scanline rather than one filter for the entire image
|
|
100
|
+
*/
|
|
101
|
+
Adaptive = 5
|
|
102
|
+
}
|
|
103
|
+
export interface PngEncodeOptions {
|
|
104
|
+
/** Default is `CompressionType::Default` */
|
|
105
|
+
compressionType?: CompressionType | undefined | null
|
|
106
|
+
/** Default is `FilterType::NoFilter` */
|
|
107
|
+
filterType?: FilterType | undefined | null
|
|
11
108
|
}
|
|
12
109
|
export interface PNGLosslessOptions {
|
|
13
110
|
/**
|
|
@@ -53,14 +150,238 @@ export interface PNGLosslessOptions {
|
|
|
53
150
|
/** Whether to use heuristics to pick the best filter and compression */
|
|
54
151
|
useHeuristics?: boolean | undefined | null
|
|
55
152
|
}
|
|
56
|
-
export function
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
153
|
+
export function losslessCompressPngSync(input: Buffer, options?: PNGLosslessOptions | undefined | null): Buffer
|
|
154
|
+
export function losslessCompressPng(input: Buffer, options?: PNGLosslessOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
155
|
+
export interface PngQuantOptions {
|
|
156
|
+
/** default is 70 */
|
|
157
|
+
minQuality?: number | undefined | null
|
|
158
|
+
/** default is 99 */
|
|
159
|
+
maxQuality?: number | undefined | null
|
|
60
160
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
161
|
+
* 1- 10
|
|
162
|
+
* Faster speeds generate images of lower quality, but may be useful for real-time generation of images.
|
|
163
|
+
* default: 5
|
|
63
164
|
*/
|
|
64
|
-
|
|
165
|
+
speed?: number | undefined | null
|
|
166
|
+
/**
|
|
167
|
+
* Number of least significant bits to ignore.
|
|
168
|
+
* Useful for generating palettes for VGA, 15-bit textures, or other retro platforms.
|
|
169
|
+
*/
|
|
170
|
+
posterization?: number | undefined | null
|
|
171
|
+
}
|
|
172
|
+
export function pngQuantizeSync(input: Buffer, options?: PngQuantOptions | undefined | null): Buffer
|
|
173
|
+
export function pngQuantize(input: Buffer, options?: PngQuantOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
174
|
+
export const enum Orientation {
|
|
175
|
+
/** Normal */
|
|
176
|
+
Horizontal = 1,
|
|
177
|
+
MirrorHorizontal = 2,
|
|
178
|
+
Rotate180 = 3,
|
|
179
|
+
MirrorVertical = 4,
|
|
180
|
+
MirrorHorizontalAndRotate270Cw = 5,
|
|
181
|
+
Rotate90Cw = 6,
|
|
182
|
+
MirrorHorizontalAndRotate90Cw = 7,
|
|
183
|
+
Rotate270Cw = 8
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Available Sampling Filters.
|
|
187
|
+
*
|
|
188
|
+
* ## Examples
|
|
189
|
+
*
|
|
190
|
+
* To test the different sampling filters on a real example, you can find two
|
|
191
|
+
* examples called
|
|
192
|
+
* [`scaledown`](https://github.com/image-rs/image/tree/master/examples/scaledown)
|
|
193
|
+
* and
|
|
194
|
+
* [`scaleup`](https://github.com/image-rs/image/tree/master/examples/scaleup)
|
|
195
|
+
* in the `examples` directory of the crate source code.
|
|
196
|
+
*
|
|
197
|
+
* Here is a 3.58 MiB
|
|
198
|
+
* [test image](https://github.com/image-rs/image/blob/master/examples/scaledown/test.jpg)
|
|
199
|
+
* that has been scaled down to 300x225 px:
|
|
200
|
+
*
|
|
201
|
+
* <!-- NOTE: To test new test images locally, replace the GitHub path with `../../../docs/` -->
|
|
202
|
+
* <div style="display: flex; flex-wrap: wrap; align-items: flex-start;">
|
|
203
|
+
* <div style="margin: 0 8px 8px 0;">
|
|
204
|
+
* <img src="https://raw.githubusercontent.com/image-rs/image/master/examples/scaledown/scaledown-test-near.png" title="Nearest"><br>
|
|
205
|
+
* Nearest Neighbor
|
|
206
|
+
* </div>
|
|
207
|
+
* <div style="margin: 0 8px 8px 0;">
|
|
208
|
+
* <img src="https://raw.githubusercontent.com/image-rs/image/master/examples/scaledown/scaledown-test-tri.png" title="Triangle"><br>
|
|
209
|
+
* Linear: Triangle
|
|
210
|
+
* </div>
|
|
211
|
+
* <div style="margin: 0 8px 8px 0;">
|
|
212
|
+
* <img src="https://raw.githubusercontent.com/image-rs/image/master/examples/scaledown/scaledown-test-cmr.png" title="CatmullRom"><br>
|
|
213
|
+
* Cubic: Catmull-Rom
|
|
214
|
+
* </div>
|
|
215
|
+
* <div style="margin: 0 8px 8px 0;">
|
|
216
|
+
* <img src="https://raw.githubusercontent.com/image-rs/image/master/examples/scaledown/scaledown-test-gauss.png" title="Gaussian"><br>
|
|
217
|
+
* Gaussian
|
|
218
|
+
* </div>
|
|
219
|
+
* <div style="margin: 0 8px 8px 0;">
|
|
220
|
+
* <img src="https://raw.githubusercontent.com/image-rs/image/master/examples/scaledown/scaledown-test-lcz2.png" title="Lanczos3"><br>
|
|
221
|
+
* Lanczos with window 3
|
|
222
|
+
* </div>
|
|
223
|
+
* </div>
|
|
224
|
+
*
|
|
225
|
+
* ## Speed
|
|
226
|
+
*
|
|
227
|
+
* Time required to create each of the examples above, tested on an Intel
|
|
228
|
+
* i7-4770 CPU with Rust 1.37 in release mode:
|
|
229
|
+
*
|
|
230
|
+
* <table style="width: auto;">
|
|
231
|
+
* <tr>
|
|
232
|
+
* <th>Nearest</th>
|
|
233
|
+
* <td>31 ms</td>
|
|
234
|
+
* </tr>
|
|
235
|
+
* <tr>
|
|
236
|
+
* <th>Triangle</th>
|
|
237
|
+
* <td>414 ms</td>
|
|
238
|
+
* </tr>
|
|
239
|
+
* <tr>
|
|
240
|
+
* <th>CatmullRom</th>
|
|
241
|
+
* <td>817 ms</td>
|
|
242
|
+
* </tr>
|
|
243
|
+
* <tr>
|
|
244
|
+
* <th>Gaussian</th>
|
|
245
|
+
* <td>1180 ms</td>
|
|
246
|
+
* </tr>
|
|
247
|
+
* <tr>
|
|
248
|
+
* <th>Lanczos3</th>
|
|
249
|
+
* <td>1170 ms</td>
|
|
250
|
+
* </tr>
|
|
251
|
+
* </table>
|
|
252
|
+
*/
|
|
253
|
+
export const enum ResizeFilterType {
|
|
254
|
+
/** Nearest Neighbor */
|
|
255
|
+
Nearest = 0,
|
|
256
|
+
/** Linear Filter */
|
|
257
|
+
Triangle = 1,
|
|
258
|
+
/** Cubic Filter */
|
|
259
|
+
CatmullRom = 2,
|
|
260
|
+
/** Gaussian Filter */
|
|
261
|
+
Gaussian = 3,
|
|
262
|
+
/** Lanczos with window 3 */
|
|
263
|
+
Lanczos3 = 4
|
|
264
|
+
}
|
|
265
|
+
export const enum JsColorType {
|
|
266
|
+
/** Pixel is 8-bit luminance */
|
|
267
|
+
L8 = 0,
|
|
268
|
+
/** Pixel is 8-bit luminance with an alpha channel */
|
|
269
|
+
La8 = 1,
|
|
270
|
+
/** Pixel contains 8-bit R, G and B channels */
|
|
271
|
+
Rgb8 = 2,
|
|
272
|
+
/** Pixel is 8-bit RGB with an alpha channel */
|
|
273
|
+
Rgba8 = 3,
|
|
274
|
+
/** Pixel is 16-bit luminance */
|
|
275
|
+
L16 = 4,
|
|
276
|
+
/** Pixel is 16-bit luminance with an alpha channel */
|
|
277
|
+
La16 = 5,
|
|
278
|
+
/** Pixel is 16-bit RGB */
|
|
279
|
+
Rgb16 = 6,
|
|
280
|
+
/** Pixel is 16-bit RGBA */
|
|
281
|
+
Rgba16 = 7,
|
|
282
|
+
/** Pixel is 32-bit float RGB */
|
|
283
|
+
Rgb32F = 8,
|
|
284
|
+
/** Pixel is 32-bit float RGBA */
|
|
285
|
+
Rgba32F = 9
|
|
286
|
+
}
|
|
287
|
+
export interface Metadata {
|
|
288
|
+
width: number
|
|
289
|
+
height: number
|
|
290
|
+
exif?: Record<string, string> | undefined | null
|
|
291
|
+
orientation?: number | undefined | null
|
|
292
|
+
format: string
|
|
293
|
+
colorType: JsColorType
|
|
294
|
+
}
|
|
295
|
+
export class Transformer {
|
|
296
|
+
constructor(input: Buffer)
|
|
297
|
+
static fromRgbaPixels(input: Buffer | Uint8ClampedArray, width: number, height: number): Transformer
|
|
298
|
+
metadata(withExif?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<Metadata>
|
|
299
|
+
/**
|
|
300
|
+
* Rotate with exif orientation
|
|
301
|
+
* If the orientation param is not null,
|
|
302
|
+
* the new orientation value will override the exif orientation value
|
|
303
|
+
*/
|
|
304
|
+
rotate(orientation?: Orientation | undefined | null): this
|
|
305
|
+
/**
|
|
306
|
+
* Return a grayscale version of this image.
|
|
307
|
+
* Returns `Luma` images in most cases. However, for `f32` images,
|
|
308
|
+
* this will return a greyscale `Rgb/Rgba` image instead.
|
|
309
|
+
*/
|
|
310
|
+
grayscale(): this
|
|
311
|
+
/** Invert the colors of this image. */
|
|
312
|
+
invert(): this
|
|
313
|
+
/**
|
|
314
|
+
* Resize this image using the specified filter algorithm.
|
|
315
|
+
* The image is scaled to the maximum possible size that fits
|
|
316
|
+
* within the bounds specified by `width` and `height`.
|
|
317
|
+
*/
|
|
318
|
+
resize(width: number, height?: number | undefined | null, filterType?: ResizeFilterType | undefined | null): this
|
|
319
|
+
/**
|
|
320
|
+
* Performs a Gaussian blur on this image.
|
|
321
|
+
* `sigma` is a measure of how much to blur by.
|
|
322
|
+
*/
|
|
323
|
+
blur(sigma: number): this
|
|
324
|
+
/**
|
|
325
|
+
* Performs an unsharpen mask on this image.
|
|
326
|
+
* `sigma` is the amount to blur the image by.
|
|
327
|
+
* `threshold` is a control of how much to sharpen.
|
|
328
|
+
*
|
|
329
|
+
* See <https://en.wikipedia.org/wiki/Unsharp_masking#Digital_unsharp_masking>
|
|
330
|
+
*/
|
|
331
|
+
unsharpen(sigma: number, threshold: number): this
|
|
332
|
+
/** Filters this image with the specified 3x3 kernel. */
|
|
333
|
+
filter3x3(kernel: Array<number>): this
|
|
334
|
+
/**
|
|
335
|
+
* Adjust the contrast of this image.
|
|
336
|
+
* `contrast` is the amount to adjust the contrast by.
|
|
337
|
+
* Negative values decrease the contrast and positive values increase the contrast.
|
|
338
|
+
*/
|
|
339
|
+
adjustContrast(contrast: number): this
|
|
340
|
+
/**
|
|
341
|
+
* Brighten the pixels of this image.
|
|
342
|
+
* `value` is the amount to brighten each pixel by.
|
|
343
|
+
* Negative values decrease the brightness and positive values increase it.
|
|
344
|
+
*/
|
|
345
|
+
brighten(brightness: number): this
|
|
346
|
+
/**
|
|
347
|
+
* Hue rotate the supplied image.
|
|
348
|
+
* `value` is the degrees to rotate each pixel by.
|
|
349
|
+
* 0 and 360 do nothing, the rest rotates by the given degree value.
|
|
350
|
+
* just like the css webkit filter hue-rotate(180)
|
|
351
|
+
*/
|
|
352
|
+
huerotate(hue: number): this
|
|
353
|
+
/**
|
|
354
|
+
* The quality factor `quality_factor` ranges from 0 to 100 and controls the loss and quality during compression.
|
|
355
|
+
* The value 0 corresponds to low quality and small output sizes, whereas 100 is the highest quality and largest output size.
|
|
356
|
+
* https://developers.google.com/speed/webp/docs/api#simple_encoding_api
|
|
357
|
+
*/
|
|
358
|
+
webp(qualityFactor?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
359
|
+
/**
|
|
360
|
+
* The quality factor `quality_factor` ranges from 0 to 100 and controls the loss and quality during compression.
|
|
361
|
+
* The value 0 corresponds to low quality and small output sizes, whereas 100 is the highest quality and largest output size.
|
|
362
|
+
* https://developers.google.com/speed/webp/docs/api#simple_encoding_api
|
|
363
|
+
*/
|
|
364
|
+
webpSync(qualityFactor?: number | undefined | null): Buffer
|
|
365
|
+
webpLossless(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
366
|
+
webpLosslessSync(): Buffer
|
|
367
|
+
avif(options?: AvifConfig | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
368
|
+
avifSync(options?: AvifConfig | undefined | null): Buffer
|
|
369
|
+
png(options?: PngEncodeOptions | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
370
|
+
pngSync(options?: PngEncodeOptions | undefined | null): Buffer
|
|
371
|
+
/** default `quality` is 90 */
|
|
372
|
+
jpeg(quality?: number | undefined | null, signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
373
|
+
/** default `quality` is 90 */
|
|
374
|
+
jpegSync(quality?: number | undefined | null): Buffer
|
|
375
|
+
bmp(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
376
|
+
bmpSync(): Buffer
|
|
377
|
+
ico(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
378
|
+
icoSync(): Buffer
|
|
379
|
+
tiff(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
380
|
+
tiffSync(): Buffer
|
|
381
|
+
pnm(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
382
|
+
pnmSync(): Buffer
|
|
383
|
+
tga(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
384
|
+
tgaSync(): Buffer
|
|
385
|
+
farbfeld(signal?: AbortSignal | undefined | null): Promise<Buffer>
|
|
386
|
+
farbfeldSync(): Buffer
|
|
65
387
|
}
|
|
66
|
-
export function compressJpeg(input: Buffer, options?: JpegCompressOptions | undefined | null): Buffer
|
package/index.js
CHANGED
|
@@ -13,34 +13,51 @@ function isMusl() {
|
|
|
13
13
|
try {
|
|
14
14
|
return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
|
|
15
15
|
} catch (e) {
|
|
16
|
-
return
|
|
16
|
+
return true
|
|
17
17
|
}
|
|
18
18
|
} else {
|
|
19
19
|
const { glibcVersionRuntime } = process.report.getReport().header
|
|
20
|
-
return !
|
|
20
|
+
return !glibcVersionRuntime
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
switch (platform) {
|
|
25
25
|
case 'android':
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
switch (arch) {
|
|
27
|
+
case 'arm64':
|
|
28
|
+
localFileExisted = existsSync(join(__dirname, 'image.android-arm64.node'))
|
|
29
|
+
try {
|
|
30
|
+
if (localFileExisted) {
|
|
31
|
+
nativeBinding = require('./image.android-arm64.node')
|
|
32
|
+
} else {
|
|
33
|
+
nativeBinding = require('@napi-rs/image-android-arm64')
|
|
34
|
+
}
|
|
35
|
+
} catch (e) {
|
|
36
|
+
loadError = e
|
|
37
|
+
}
|
|
38
|
+
break
|
|
39
|
+
case 'arm':
|
|
40
|
+
localFileExisted = existsSync(join(__dirname, 'image.android-arm-eabi.node'))
|
|
41
|
+
try {
|
|
42
|
+
if (localFileExisted) {
|
|
43
|
+
nativeBinding = require('./image.android-arm-eabi.node')
|
|
44
|
+
} else {
|
|
45
|
+
nativeBinding = require('@napi-rs/image-android-arm-eabi')
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
loadError = e
|
|
49
|
+
}
|
|
50
|
+
break
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
38
53
|
}
|
|
39
54
|
break
|
|
40
55
|
case 'win32':
|
|
41
56
|
switch (arch) {
|
|
42
57
|
case 'x64':
|
|
43
|
-
localFileExisted = existsSync(
|
|
58
|
+
localFileExisted = existsSync(
|
|
59
|
+
join(__dirname, 'image.win32-x64-msvc.node')
|
|
60
|
+
)
|
|
44
61
|
try {
|
|
45
62
|
if (localFileExisted) {
|
|
46
63
|
nativeBinding = require('./image.win32-x64-msvc.node')
|
|
@@ -52,7 +69,9 @@ switch (platform) {
|
|
|
52
69
|
}
|
|
53
70
|
break
|
|
54
71
|
case 'ia32':
|
|
55
|
-
localFileExisted = existsSync(
|
|
72
|
+
localFileExisted = existsSync(
|
|
73
|
+
join(__dirname, 'image.win32-ia32-msvc.node')
|
|
74
|
+
)
|
|
56
75
|
try {
|
|
57
76
|
if (localFileExisted) {
|
|
58
77
|
nativeBinding = require('./image.win32-ia32-msvc.node')
|
|
@@ -64,7 +83,9 @@ switch (platform) {
|
|
|
64
83
|
}
|
|
65
84
|
break
|
|
66
85
|
case 'arm64':
|
|
67
|
-
localFileExisted = existsSync(
|
|
86
|
+
localFileExisted = existsSync(
|
|
87
|
+
join(__dirname, 'image.win32-arm64-msvc.node')
|
|
88
|
+
)
|
|
68
89
|
try {
|
|
69
90
|
if (localFileExisted) {
|
|
70
91
|
nativeBinding = require('./image.win32-arm64-msvc.node')
|
|
@@ -94,7 +115,9 @@ switch (platform) {
|
|
|
94
115
|
}
|
|
95
116
|
break
|
|
96
117
|
case 'arm64':
|
|
97
|
-
localFileExisted = existsSync(
|
|
118
|
+
localFileExisted = existsSync(
|
|
119
|
+
join(__dirname, 'image.darwin-arm64.node')
|
|
120
|
+
)
|
|
98
121
|
try {
|
|
99
122
|
if (localFileExisted) {
|
|
100
123
|
nativeBinding = require('./image.darwin-arm64.node')
|
|
@@ -128,7 +151,9 @@ switch (platform) {
|
|
|
128
151
|
switch (arch) {
|
|
129
152
|
case 'x64':
|
|
130
153
|
if (isMusl()) {
|
|
131
|
-
localFileExisted = existsSync(
|
|
154
|
+
localFileExisted = existsSync(
|
|
155
|
+
join(__dirname, 'image.linux-x64-musl.node')
|
|
156
|
+
)
|
|
132
157
|
try {
|
|
133
158
|
if (localFileExisted) {
|
|
134
159
|
nativeBinding = require('./image.linux-x64-musl.node')
|
|
@@ -139,7 +164,9 @@ switch (platform) {
|
|
|
139
164
|
loadError = e
|
|
140
165
|
}
|
|
141
166
|
} else {
|
|
142
|
-
localFileExisted = existsSync(
|
|
167
|
+
localFileExisted = existsSync(
|
|
168
|
+
join(__dirname, 'image.linux-x64-gnu.node')
|
|
169
|
+
)
|
|
143
170
|
try {
|
|
144
171
|
if (localFileExisted) {
|
|
145
172
|
nativeBinding = require('./image.linux-x64-gnu.node')
|
|
@@ -153,7 +180,9 @@ switch (platform) {
|
|
|
153
180
|
break
|
|
154
181
|
case 'arm64':
|
|
155
182
|
if (isMusl()) {
|
|
156
|
-
localFileExisted = existsSync(
|
|
183
|
+
localFileExisted = existsSync(
|
|
184
|
+
join(__dirname, 'image.linux-arm64-musl.node')
|
|
185
|
+
)
|
|
157
186
|
try {
|
|
158
187
|
if (localFileExisted) {
|
|
159
188
|
nativeBinding = require('./image.linux-arm64-musl.node')
|
|
@@ -164,7 +193,9 @@ switch (platform) {
|
|
|
164
193
|
loadError = e
|
|
165
194
|
}
|
|
166
195
|
} else {
|
|
167
|
-
localFileExisted = existsSync(
|
|
196
|
+
localFileExisted = existsSync(
|
|
197
|
+
join(__dirname, 'image.linux-arm64-gnu.node')
|
|
198
|
+
)
|
|
168
199
|
try {
|
|
169
200
|
if (localFileExisted) {
|
|
170
201
|
nativeBinding = require('./image.linux-arm64-gnu.node')
|
|
@@ -177,7 +208,9 @@ switch (platform) {
|
|
|
177
208
|
}
|
|
178
209
|
break
|
|
179
210
|
case 'arm':
|
|
180
|
-
localFileExisted = existsSync(
|
|
211
|
+
localFileExisted = existsSync(
|
|
212
|
+
join(__dirname, 'image.linux-arm-gnueabihf.node')
|
|
213
|
+
)
|
|
181
214
|
try {
|
|
182
215
|
if (localFileExisted) {
|
|
183
216
|
nativeBinding = require('./image.linux-arm-gnueabihf.node')
|
|
@@ -203,7 +236,18 @@ if (!nativeBinding) {
|
|
|
203
236
|
throw new Error(`Failed to load native binding`)
|
|
204
237
|
}
|
|
205
238
|
|
|
206
|
-
const {
|
|
239
|
+
const { ChromaSubsampling, compressJpegSync, compressJpeg, CompressionType, FilterType, losslessCompressPngSync, losslessCompressPng, pngQuantizeSync, pngQuantize, Orientation, ResizeFilterType, JsColorType, Transformer } = nativeBinding
|
|
207
240
|
|
|
208
|
-
module.exports.
|
|
241
|
+
module.exports.ChromaSubsampling = ChromaSubsampling
|
|
242
|
+
module.exports.compressJpegSync = compressJpegSync
|
|
209
243
|
module.exports.compressJpeg = compressJpeg
|
|
244
|
+
module.exports.CompressionType = CompressionType
|
|
245
|
+
module.exports.FilterType = FilterType
|
|
246
|
+
module.exports.losslessCompressPngSync = losslessCompressPngSync
|
|
247
|
+
module.exports.losslessCompressPng = losslessCompressPng
|
|
248
|
+
module.exports.pngQuantizeSync = pngQuantizeSync
|
|
249
|
+
module.exports.pngQuantize = pngQuantize
|
|
250
|
+
module.exports.Orientation = Orientation
|
|
251
|
+
module.exports.ResizeFilterType = ResizeFilterType
|
|
252
|
+
module.exports.JsColorType = JsColorType
|
|
253
|
+
module.exports.Transformer = Transformer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/image",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"description": "Image processing library",
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"jpg",
|
|
18
18
|
"png"
|
|
19
19
|
],
|
|
20
|
+
"files": [
|
|
21
|
+
"index.js",
|
|
22
|
+
"index.d.ts"
|
|
23
|
+
],
|
|
20
24
|
"publishConfig": {
|
|
21
25
|
"registry": "https://registry.npmjs.org/",
|
|
22
26
|
"access": "public"
|
|
@@ -38,22 +42,6 @@
|
|
|
38
42
|
}
|
|
39
43
|
},
|
|
40
44
|
"license": "MIT",
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@napi-rs/cli": "^2.2.1",
|
|
43
|
-
"@types/node": "^17.0.8",
|
|
44
|
-
"ava": "^4.0.1",
|
|
45
|
-
"npm-run-all": "^4.1.5",
|
|
46
|
-
"prettier": "^2.5.1"
|
|
47
|
-
},
|
|
48
|
-
"ava": {
|
|
49
|
-
"extensions": [
|
|
50
|
-
"mjs"
|
|
51
|
-
],
|
|
52
|
-
"timeout": "3m",
|
|
53
|
-
"environmentVariables": {
|
|
54
|
-
"NODE_ENV": "ava"
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
45
|
"engines": {
|
|
58
46
|
"node": ">= 10"
|
|
59
47
|
},
|
|
@@ -62,36 +50,29 @@
|
|
|
62
50
|
"url": "https://github.com/sponsors/Brooooooklyn"
|
|
63
51
|
},
|
|
64
52
|
"scripts": {
|
|
65
|
-
"artifacts": "napi artifacts",
|
|
53
|
+
"artifacts": "napi artifacts -d ../../artifacts",
|
|
66
54
|
"build": "napi build --platform --release",
|
|
67
55
|
"build:debug": "napi build --platform",
|
|
68
56
|
"format": "run-p format:prettier format:rs",
|
|
69
57
|
"format:prettier": "prettier --config ./package.json -w .",
|
|
70
58
|
"format:rs": "cargo fmt --all",
|
|
71
59
|
"prepublishOnly": "napi prepublish -t npm",
|
|
72
|
-
"test": "ava",
|
|
73
60
|
"version": "napi version"
|
|
74
61
|
},
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
"semi": false,
|
|
78
|
-
"trailingComma": "all",
|
|
79
|
-
"singleQuote": true,
|
|
80
|
-
"arrowParens": "always"
|
|
81
|
-
},
|
|
82
|
-
"repository": "git@github.com:Brooooooklyn/imgquant.git",
|
|
62
|
+
"repository": "git@github.com:Brooooooklyn/Image.git",
|
|
63
|
+
"gitHead": "0aa7effa90873c50d9cd418b873fde5b07d670d6",
|
|
83
64
|
"optionalDependencies": {
|
|
84
|
-
"@napi-rs/image-win32-x64-msvc": "1.
|
|
85
|
-
"@napi-rs/image-darwin-x64": "1.
|
|
86
|
-
"@napi-rs/image-linux-x64-gnu": "1.
|
|
87
|
-
"@napi-rs/image-darwin-arm64": "1.
|
|
88
|
-
"@napi-rs/image-android-arm64": "1.
|
|
89
|
-
"@napi-rs/image-linux-arm64-gnu": "1.
|
|
90
|
-
"@napi-rs/image-linux-arm64-musl": "1.
|
|
91
|
-
"@napi-rs/image-linux-arm-gnueabihf": "1.
|
|
92
|
-
"@napi-rs/image-linux-x64-musl": "1.
|
|
93
|
-
"@napi-rs/image-freebsd-x64": "1.
|
|
94
|
-
"@napi-rs/image-win32-ia32-msvc": "1.
|
|
95
|
-
"@napi-rs/image-android-arm-eabi": "1.
|
|
65
|
+
"@napi-rs/image-win32-x64-msvc": "1.1.0",
|
|
66
|
+
"@napi-rs/image-darwin-x64": "1.1.0",
|
|
67
|
+
"@napi-rs/image-linux-x64-gnu": "1.1.0",
|
|
68
|
+
"@napi-rs/image-darwin-arm64": "1.1.0",
|
|
69
|
+
"@napi-rs/image-android-arm64": "1.1.0",
|
|
70
|
+
"@napi-rs/image-linux-arm64-gnu": "1.1.0",
|
|
71
|
+
"@napi-rs/image-linux-arm64-musl": "1.1.0",
|
|
72
|
+
"@napi-rs/image-linux-arm-gnueabihf": "1.1.0",
|
|
73
|
+
"@napi-rs/image-linux-x64-musl": "1.1.0",
|
|
74
|
+
"@napi-rs/image-freebsd-x64": "1.1.0",
|
|
75
|
+
"@napi-rs/image-win32-ia32-msvc": "1.1.0",
|
|
76
|
+
"@napi-rs/image-android-arm-eabi": "1.1.0"
|
|
96
77
|
}
|
|
97
78
|
}
|
package/.gitattributes
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Auto detect text files and perform LF normalization
|
|
2
|
-
* text=auto
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*.ts text eol=lf merge=union
|
|
6
|
-
*.tsx text eol=lf merge=union
|
|
7
|
-
*.rs text eol=lf merge=union
|
|
8
|
-
*.js text eol=lf merge=union
|
|
9
|
-
*.json text eol=lf merge=union
|
|
10
|
-
*.debug text eol=lf merge=union
|
|
11
|
-
|
|
12
|
-
index.js linguist-detectable=false
|
|
13
|
-
index.d.ts inguist-detectable=false
|
package/Cargo.toml
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
edition = "2021"
|
|
3
|
-
name = "napi-rs_pngquant"
|
|
4
|
-
version = "0.0.0"
|
|
5
|
-
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["cdylib"]
|
|
8
|
-
|
|
9
|
-
[dependencies]
|
|
10
|
-
libc = "0.2"
|
|
11
|
-
napi = {version = "2", default-features = false, features = ["napi3"]}
|
|
12
|
-
napi-derive = {version = "2", default-features = false, features = ["type-def"]}
|
|
13
|
-
|
|
14
|
-
[target.'cfg(not(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64")))'.dependencies.oxipng]
|
|
15
|
-
default-features = false
|
|
16
|
-
features = ["parallel", "libdeflater"]
|
|
17
|
-
version = "5"
|
|
18
|
-
|
|
19
|
-
[target.'cfg(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"))'.dependencies.oxipng]
|
|
20
|
-
default-features = false
|
|
21
|
-
features = ["parallel"]
|
|
22
|
-
version = "5"
|
|
23
|
-
|
|
24
|
-
[target.'cfg(not(all(target_os = "linux", target_arch = "arm")))'.dependencies.mozjpeg-sys]
|
|
25
|
-
version = "1"
|
|
26
|
-
|
|
27
|
-
[target.'cfg(all(target_os = "linux", target_arch = "arm"))'.dependencies.mozjpeg-sys]
|
|
28
|
-
default-features = false
|
|
29
|
-
version = "1"
|
|
30
|
-
|
|
31
|
-
[build-dependencies]
|
|
32
|
-
napi-build = "1"
|
|
33
|
-
|
|
34
|
-
[profile.release]
|
|
35
|
-
lto = true
|