@revizly/sharp 0.33.6-revizly2 → 0.34.0-revizly2
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/constructor.js +1 -0
- package/lib/index.d.ts +6 -2
- package/lib/input.js +3 -2
- package/lib/output.js +10 -5
- package/lib/resize.js +3 -1
- package/package.json +7 -7
- package/src/binding.gyp +11 -4
- package/src/common.h +3 -7
- package/src/metadata.cc +16 -7
- package/src/metadata.h +4 -2
- package/src/pipeline.cc +10 -14
- package/src/pipeline.h +2 -0
package/lib/constructor.js
CHANGED
package/lib/index.d.ts
CHANGED
@@ -1076,6 +1076,10 @@ declare namespace sharp {
|
|
1076
1076
|
chromaSubsampling?: string | undefined;
|
1077
1077
|
/** Boolean indicating whether the image is interlaced using a progressive scan */
|
1078
1078
|
isProgressive?: boolean | undefined;
|
1079
|
+
/** Boolean indicating whether the image is palette-based (GIF, PNG). */
|
1080
|
+
isPalette?: boolean | undefined;
|
1081
|
+
/** Number of bits per sample for each channel (GIF, PNG). */
|
1082
|
+
bitsPerSample?: number | undefined;
|
1079
1083
|
/** Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP */
|
1080
1084
|
pages?: number | undefined;
|
1081
1085
|
/** Number of pixels high each page in a multi-page image will be. */
|
@@ -1102,8 +1106,8 @@ declare namespace sharp {
|
|
1102
1106
|
tifftagPhotoshop?: Buffer | undefined;
|
1103
1107
|
/** The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC) */
|
1104
1108
|
compression?: 'av1' | 'hevc';
|
1105
|
-
/** Default background colour, if present, for PNG (bKGD) and GIF images
|
1106
|
-
background?: { r: number; g: number; b: number } | number;
|
1109
|
+
/** Default background colour, if present, for PNG (bKGD) and GIF images */
|
1110
|
+
background?: { r: number; g: number; b: number } | { gray: number };
|
1107
1111
|
/** Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide */
|
1108
1112
|
levels?: LevelMetadata[] | undefined;
|
1109
1113
|
/** Number of Sub Image File Directories in an OME-TIFF image */
|
package/lib/input.js
CHANGED
@@ -434,15 +434,16 @@ function _isStreamInput () {
|
|
434
434
|
* - `density`: Number of pixels per inch (DPI), if present
|
435
435
|
* - `chromaSubsampling`: String containing JPEG chroma subsampling, `4:2:0` or `4:4:4` for RGB, `4:2:0:4` or `4:4:4:4` for CMYK
|
436
436
|
* - `isProgressive`: Boolean indicating whether the image is interlaced using a progressive scan
|
437
|
+
* - `isPalette`: Boolean indicating whether the image is palette-based (GIF, PNG).
|
438
|
+
* - `bitsPerSample`: Number of bits per sample for each channel (GIF, PNG, HEIF).
|
437
439
|
* - `pages`: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebP
|
438
440
|
* - `pageHeight`: Number of pixels high each page in a multi-page image will be.
|
439
|
-
* - `paletteBitDepth`: Bit depth of palette-based image (GIF, PNG).
|
440
441
|
* - `loop`: Number of times to loop an animated image, zero refers to a continuous loop.
|
441
442
|
* - `delay`: Delay in ms between each page in an animated image, provided as an array of integers.
|
442
443
|
* - `pagePrimary`: Number of the primary page in a HEIF image
|
443
444
|
* - `levels`: Details of each level in a multi-level image provided as an array of objects, requires libvips compiled with support for OpenSlide
|
444
445
|
* - `subifds`: Number of Sub Image File Directories in an OME-TIFF image
|
445
|
-
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images
|
446
|
+
* - `background`: Default background colour, if present, for PNG (bKGD) and GIF images
|
446
447
|
* - `compression`: The encoder used to compress an HEIF file, `av1` (AVIF) or `hevc` (HEIC)
|
447
448
|
* - `resolutionUnit`: The unit of resolution (density), either `inch` or `cm`, if present
|
448
449
|
* - `hasProfile`: Boolean indicating the presence of an embedded ICC profile
|
package/lib/output.js
CHANGED
@@ -623,6 +623,7 @@ function png (options) {
|
|
623
623
|
* @param {boolean} [options.lossless=false] - use lossless compression mode
|
624
624
|
* @param {boolean} [options.nearLossless=false] - use near_lossless compression mode
|
625
625
|
* @param {boolean} [options.smartSubsample=false] - use high quality chroma subsampling
|
626
|
+
* @param {boolean} [options.smartDeblock=false] - auto-adjust the deblocking filter, can improve low contrast edges (slow)
|
626
627
|
* @param {string} [options.preset='default'] - named preset for preprocessing/filtering, one of: default, photo, picture, drawing, icon, text
|
627
628
|
* @param {number} [options.effort=4] - CPU effort, between 0 (fastest) and 6 (slowest)
|
628
629
|
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
@@ -658,6 +659,9 @@ function webp (options) {
|
|
658
659
|
if (is.defined(options.smartSubsample)) {
|
659
660
|
this._setBooleanOption('webpSmartSubsample', options.smartSubsample);
|
660
661
|
}
|
662
|
+
if (is.defined(options.smartDeblock)) {
|
663
|
+
this._setBooleanOption('webpSmartDeblock', options.smartDeblock);
|
664
|
+
}
|
661
665
|
if (is.defined(options.preset)) {
|
662
666
|
if (is.string(options.preset) && is.inArray(options.preset, ['default', 'photo', 'picture', 'drawing', 'icon', 'text'])) {
|
663
667
|
this.options.webpPreset = options.preset;
|
@@ -1123,8 +1127,6 @@ function heif (options) {
|
|
1123
1127
|
* The prebuilt binaries do not include this - see
|
1124
1128
|
* {@link https://sharp.pixelplumbing.com/install#custom-libvips installing a custom libvips}.
|
1125
1129
|
*
|
1126
|
-
* Image metadata (EXIF, XMP) is unsupported.
|
1127
|
-
*
|
1128
1130
|
* @since 0.31.3
|
1129
1131
|
*
|
1130
1132
|
* @param {Object} [options] - output options
|
@@ -1132,7 +1134,9 @@ function heif (options) {
|
|
1132
1134
|
* @param {number} [options.quality] - calculate `distance` based on JPEG-like quality, between 1 and 100, overrides distance if specified
|
1133
1135
|
* @param {number} [options.decodingTier=0] - target decode speed tier, between 0 (highest quality) and 4 (lowest quality)
|
1134
1136
|
* @param {boolean} [options.lossless=false] - use lossless compression
|
1135
|
-
* @param {number} [options.effort=7] - CPU effort, between
|
1137
|
+
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 9 (slowest)
|
1138
|
+
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
1139
|
+
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
1136
1140
|
* @returns {Sharp}
|
1137
1141
|
* @throws {Error} Invalid options
|
1138
1142
|
*/
|
@@ -1169,13 +1173,14 @@ function jxl (options) {
|
|
1169
1173
|
}
|
1170
1174
|
}
|
1171
1175
|
if (is.defined(options.effort)) {
|
1172
|
-
if (is.integer(options.effort) && is.inRange(options.effort,
|
1176
|
+
if (is.integer(options.effort) && is.inRange(options.effort, 1, 9)) {
|
1173
1177
|
this.options.jxlEffort = options.effort;
|
1174
1178
|
} else {
|
1175
|
-
throw is.invalidParameterError('effort', 'integer between
|
1179
|
+
throw is.invalidParameterError('effort', 'integer between 1 and 9', options.effort);
|
1176
1180
|
}
|
1177
1181
|
}
|
1178
1182
|
}
|
1183
|
+
trySetAnimationOptions(options, this.options);
|
1179
1184
|
return this._updateFormatOut('jxl', options);
|
1180
1185
|
}
|
1181
1186
|
|
package/lib/resize.js
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@revizly/sharp",
|
3
3
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.34.0-revizly2",
|
5
5
|
"author": "Lovell Fuller <npm@lovell.info>",
|
6
6
|
"homepage": "https://sharp.pixelplumbing.com",
|
7
7
|
"contributors": [
|
@@ -148,19 +148,19 @@
|
|
148
148
|
"@revizly/sharp-linux-x64": "0.33.6-revizly1"
|
149
149
|
},
|
150
150
|
"devDependencies": {
|
151
|
-
"@emnapi/runtime": "^1.
|
151
|
+
"@emnapi/runtime": "^1.3.1",
|
152
152
|
"@revizly/sharp-libvips-dev": "1.0.9",
|
153
153
|
"@types/node": "*",
|
154
154
|
"cc": "^3.0.1",
|
155
|
-
"emnapi": "^1.
|
155
|
+
"emnapi": "^1.3.1",
|
156
156
|
"exif-reader": "^2.0.1",
|
157
157
|
"extract-zip": "^2.0.1",
|
158
158
|
"icc": "^3.0.0",
|
159
|
-
"jsdoc-to-markdown": "^9.0.
|
159
|
+
"jsdoc-to-markdown": "^9.0.5",
|
160
160
|
"license-checker": "^25.0.1",
|
161
|
-
"mocha": "^10.
|
162
|
-
"node-addon-api": "^8.1
|
163
|
-
"nyc": "^17.
|
161
|
+
"mocha": "^10.8.2",
|
162
|
+
"node-addon-api": "^8.2.1",
|
163
|
+
"nyc": "^17.1.0",
|
164
164
|
"prebuild": "^13.0.1",
|
165
165
|
"semistandard": "^17.0.0",
|
166
166
|
"tar-fs": "^3.0.6",
|
package/src/binding.gyp
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
|
19
19
|
'type': 'shared_library',
|
20
20
|
'defines': [
|
21
|
-
'
|
21
|
+
'_VIPS_PUBLIC=__declspec(dllexport)',
|
22
22
|
'_ALLOW_KEYWORD_MACROS'
|
23
23
|
],
|
24
24
|
'sources': [
|
@@ -45,6 +45,9 @@
|
|
45
45
|
'Release': {
|
46
46
|
'msvs_settings': {
|
47
47
|
'VCCLCompilerTool': {
|
48
|
+
"AdditionalOptions": [
|
49
|
+
"/std:c++17"
|
50
|
+
],
|
48
51
|
'ExceptionHandling': 1,
|
49
52
|
'Optimization': 1,
|
50
53
|
'WholeProgramOptimization': 'true'
|
@@ -172,6 +175,7 @@
|
|
172
175
|
'-l:libvips-cpp.so.<(vips_version)'
|
173
176
|
],
|
174
177
|
'ldflags': [
|
178
|
+
'-lstdc++fs',
|
175
179
|
'-Wl,-s',
|
176
180
|
'-Wl,--disable-new-dtags',
|
177
181
|
'-Wl,-z,nodelete',
|
@@ -207,14 +211,14 @@
|
|
207
211
|
}]
|
208
212
|
],
|
209
213
|
'cflags_cc': [
|
210
|
-
'-std=c++
|
214
|
+
'-std=c++17',
|
211
215
|
'-fexceptions',
|
212
216
|
'-Wall',
|
213
217
|
'-Os'
|
214
218
|
],
|
215
219
|
'xcode_settings': {
|
216
|
-
'CLANG_CXX_LANGUAGE_STANDARD': 'c++
|
217
|
-
'MACOSX_DEPLOYMENT_TARGET': '10.
|
220
|
+
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',
|
221
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.15',
|
218
222
|
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
219
223
|
'GCC_ENABLE_CPP_RTTI': 'YES',
|
220
224
|
'OTHER_CPLUSPLUSFLAGS': [
|
@@ -234,6 +238,9 @@
|
|
234
238
|
['OS == "win"', {
|
235
239
|
'msvs_settings': {
|
236
240
|
'VCCLCompilerTool': {
|
241
|
+
"AdditionalOptions": [
|
242
|
+
"/std:c++17"
|
243
|
+
],
|
237
244
|
'ExceptionHandling': 1,
|
238
245
|
'Optimization': 1,
|
239
246
|
'WholeProgramOptimization': 'true'
|
package/src/common.h
CHANGED
@@ -20,13 +20,9 @@
|
|
20
20
|
#error "libvips version 8.16.0+ is required - please see https://sharp.pixelplumbing.com/install"
|
21
21
|
#endif
|
22
22
|
|
23
|
-
#if
|
24
|
-
#
|
25
|
-
#
|
26
|
-
|
27
|
-
#if (defined(__clang__) && defined(__has_feature))
|
28
|
-
#if (!__has_feature(cxx_range_for))
|
29
|
-
#error "clang version 3.0+ is required for C++11 features - please see https://sharp.pixelplumbing.com/install"
|
23
|
+
#if defined(__has_include)
|
24
|
+
#if !__has_include(<filesystem>)
|
25
|
+
#error "C++17 compiler required - please see https://sharp.pixelplumbing.com/install"
|
30
26
|
#endif
|
31
27
|
#endif
|
32
28
|
|
package/src/metadata.cc
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
#include <numeric>
|
5
5
|
#include <vector>
|
6
|
+
#include <cmath>
|
6
7
|
|
7
8
|
#include <napi.h>
|
8
9
|
#include <vips/vips8>
|
@@ -47,8 +48,11 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
47
48
|
if (image.get_typeof("interlaced") == G_TYPE_INT) {
|
48
49
|
baton->isProgressive = image.get_int("interlaced") == 1;
|
49
50
|
}
|
50
|
-
if (image.get_typeof(
|
51
|
-
baton->
|
51
|
+
if (image.get_typeof(VIPS_META_PALETTE) == G_TYPE_INT) {
|
52
|
+
baton->isPalette = image.get_int(VIPS_META_PALETTE);
|
53
|
+
}
|
54
|
+
if (image.get_typeof(VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT) {
|
55
|
+
baton->bitsPerSample = image.get_int(VIPS_META_BITS_PER_SAMPLE);
|
52
56
|
}
|
53
57
|
if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT) {
|
54
58
|
baton->pages = image.get_int(VIPS_META_N_PAGES);
|
@@ -171,8 +175,13 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
171
175
|
info.Set("chromaSubsampling", baton->chromaSubsampling);
|
172
176
|
}
|
173
177
|
info.Set("isProgressive", baton->isProgressive);
|
174
|
-
|
175
|
-
|
178
|
+
info.Set("isPalette", baton->isPalette);
|
179
|
+
if (baton->bitsPerSample > 0) {
|
180
|
+
info.Set("bitsPerSample", baton->bitsPerSample);
|
181
|
+
if (baton->isPalette) {
|
182
|
+
// Deprecated, remove with libvips 8.17.0
|
183
|
+
info.Set("paletteBitDepth", baton->bitsPerSample);
|
184
|
+
}
|
176
185
|
}
|
177
186
|
if (baton->pages > 0) {
|
178
187
|
info.Set("pages", baton->pages);
|
@@ -218,15 +227,15 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|
218
227
|
info.Set("subifds", baton->subifds);
|
219
228
|
}
|
220
229
|
if (!baton->background.empty()) {
|
230
|
+
Napi::Object background = Napi::Object::New(env);
|
221
231
|
if (baton->background.size() == 3) {
|
222
|
-
Napi::Object background = Napi::Object::New(env);
|
223
232
|
background.Set("r", baton->background[0]);
|
224
233
|
background.Set("g", baton->background[1]);
|
225
234
|
background.Set("b", baton->background[2]);
|
226
|
-
info.Set("background", background);
|
227
235
|
} else {
|
228
|
-
|
236
|
+
background.Set("gray", round(baton->background[0] * 100 / 255));
|
229
237
|
}
|
238
|
+
info.Set("background", background);
|
230
239
|
}
|
231
240
|
info.Set("hasProfile", baton->hasProfile);
|
232
241
|
info.Set("hasAlpha", baton->hasAlpha);
|
package/src/metadata.h
CHANGED
@@ -24,7 +24,8 @@ struct MetadataBaton {
|
|
24
24
|
int density;
|
25
25
|
std::string chromaSubsampling;
|
26
26
|
bool isProgressive;
|
27
|
-
|
27
|
+
bool isPalette;
|
28
|
+
int bitsPerSample;
|
28
29
|
int pages;
|
29
30
|
int pageHeight;
|
30
31
|
int loop;
|
@@ -59,7 +60,8 @@ struct MetadataBaton {
|
|
59
60
|
channels(0),
|
60
61
|
density(0),
|
61
62
|
isProgressive(false),
|
62
|
-
|
63
|
+
isPalette(false),
|
64
|
+
bitsPerSample(0),
|
63
65
|
pages(0),
|
64
66
|
pageHeight(0),
|
65
67
|
loop(-1),
|
package/src/pipeline.cc
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
#include <algorithm>
|
5
5
|
#include <cmath>
|
6
|
+
#include <filesystem>
|
6
7
|
#include <map>
|
7
8
|
#include <memory>
|
8
9
|
#include <numeric>
|
@@ -20,17 +21,6 @@
|
|
20
21
|
#include "operations.h"
|
21
22
|
#include "pipeline.h"
|
22
23
|
|
23
|
-
#ifdef _WIN32
|
24
|
-
#define STAT64_STRUCT __stat64
|
25
|
-
#define STAT64_FUNCTION _stat64
|
26
|
-
#elif defined(_LARGEFILE64_SOURCE)
|
27
|
-
#define STAT64_STRUCT stat64
|
28
|
-
#define STAT64_FUNCTION stat64
|
29
|
-
#else
|
30
|
-
#define STAT64_STRUCT stat
|
31
|
-
#define STAT64_FUNCTION stat
|
32
|
-
#endif
|
33
|
-
|
34
24
|
class PipelineWorker : public Napi::AsyncWorker {
|
35
25
|
public:
|
36
26
|
PipelineWorker(Napi::Function callback, PipelineBaton *baton,
|
@@ -929,6 +919,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
929
919
|
->set("lossless", baton->webpLossless)
|
930
920
|
->set("near_lossless", baton->webpNearLossless)
|
931
921
|
->set("smart_subsample", baton->webpSmartSubsample)
|
922
|
+
->set("smart_deblock", baton->webpSmartDeblock)
|
932
923
|
->set("preset", baton->webpPreset)
|
933
924
|
->set("effort", baton->webpEffort)
|
934
925
|
->set("min_size", baton->webpMinSize)
|
@@ -1136,6 +1127,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
1136
1127
|
->set("lossless", baton->webpLossless)
|
1137
1128
|
->set("near_lossless", baton->webpNearLossless)
|
1138
1129
|
->set("smart_subsample", baton->webpSmartSubsample)
|
1130
|
+
->set("smart_deblock", baton->webpSmartDeblock)
|
1139
1131
|
->set("preset", baton->webpPreset)
|
1140
1132
|
->set("effort", baton->webpEffort)
|
1141
1133
|
->set("min_size", baton->webpMinSize)
|
@@ -1304,9 +1296,11 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
1304
1296
|
Callback().Call(Receiver().Value(), { env.Null(), data, info });
|
1305
1297
|
} else {
|
1306
1298
|
// Add file size to info
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1299
|
+
if (baton->formatOut != "dz" || sharp::IsDzZip(baton->fileOut)) {
|
1300
|
+
try {
|
1301
|
+
uint32_t const size = static_cast<uint32_t>(std::filesystem::file_size(baton->fileOut));
|
1302
|
+
info.Set("size", size);
|
1303
|
+
} catch (...) {}
|
1310
1304
|
}
|
1311
1305
|
Callback().Call(Receiver().Value(), { env.Null(), info });
|
1312
1306
|
}
|
@@ -1419,6 +1413,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
1419
1413
|
{"lossless", baton->webpLossless ? "true" : "false"},
|
1420
1414
|
{"near_lossless", baton->webpNearLossless ? "true" : "false"},
|
1421
1415
|
{"smart_subsample", baton->webpSmartSubsample ? "true" : "false"},
|
1416
|
+
{"smart_deblock", baton->webpSmartDeblock ? "true" : "false"},
|
1422
1417
|
{"preset", vips_enum_nick(VIPS_TYPE_FOREIGN_WEBP_PRESET, baton->webpPreset)},
|
1423
1418
|
{"min_size", baton->webpMinSize ? "true" : "false"},
|
1424
1419
|
{"mixed", baton->webpMixed ? "true" : "false"},
|
@@ -1676,6 +1671,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|
1676
1671
|
baton->webpLossless = sharp::AttrAsBool(options, "webpLossless");
|
1677
1672
|
baton->webpNearLossless = sharp::AttrAsBool(options, "webpNearLossless");
|
1678
1673
|
baton->webpSmartSubsample = sharp::AttrAsBool(options, "webpSmartSubsample");
|
1674
|
+
baton->webpSmartDeblock = sharp::AttrAsBool(options, "webpSmartDeblock");
|
1679
1675
|
baton->webpPreset = sharp::AttrAsEnum<VipsForeignWebpPreset>(options, "webpPreset", VIPS_TYPE_FOREIGN_WEBP_PRESET);
|
1680
1676
|
baton->webpEffort = sharp::AttrAsUint32(options, "webpEffort");
|
1681
1677
|
baton->webpMinSize = sharp::AttrAsBool(options, "webpMinSize");
|
package/src/pipeline.h
CHANGED
@@ -157,6 +157,7 @@ struct PipelineBaton {
|
|
157
157
|
bool webpNearLossless;
|
158
158
|
bool webpLossless;
|
159
159
|
bool webpSmartSubsample;
|
160
|
+
bool webpSmartDeblock;
|
160
161
|
VipsForeignWebpPreset webpPreset;
|
161
162
|
int webpEffort;
|
162
163
|
bool webpMinSize;
|
@@ -328,6 +329,7 @@ struct PipelineBaton {
|
|
328
329
|
webpNearLossless(false),
|
329
330
|
webpLossless(false),
|
330
331
|
webpSmartSubsample(false),
|
332
|
+
webpSmartDeblock(false),
|
331
333
|
webpPreset(VIPS_FOREIGN_WEBP_PRESET_DEFAULT),
|
332
334
|
webpEffort(4),
|
333
335
|
webpMinSize(false),
|