@revizly/sharp 0.35.0-revizly4 → 0.35.0-revizly40
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 +12 -18
- package/{lib/channel.js → dist/channel.cjs} +1 -1
- package/dist/channel.mjs +177 -0
- package/{lib/colour.js → dist/colour.cjs} +1 -1
- package/dist/colour.mjs +195 -0
- package/{lib/composite.js → dist/composite.cjs} +2 -1
- package/dist/composite.mjs +213 -0
- package/{lib/constructor.js → dist/constructor.cjs} +42 -29
- package/dist/constructor.mjs +512 -0
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +1999 -0
- package/dist/index.d.mts +2046 -0
- package/dist/index.mjs +25 -0
- package/{lib/input.js → dist/input.cjs} +22 -17
- package/dist/input.mjs +814 -0
- package/{lib/is.js → dist/is.cjs} +1 -1
- package/dist/is.mjs +143 -0
- package/{lib/libvips.js → dist/libvips.cjs} +35 -30
- package/dist/libvips.mjs +212 -0
- package/{lib/operation.js → dist/operation.cjs} +22 -47
- package/dist/operation.mjs +991 -0
- package/{lib/output.js → dist/output.cjs} +161 -28
- package/dist/output.mjs +1799 -0
- package/{lib/resize.js → dist/resize.cjs} +40 -18
- package/dist/resize.mjs +617 -0
- package/dist/sharp.cjs +119 -0
- package/dist/sharp.mjs +119 -0
- package/{lib/utility.js → dist/utility.cjs} +11 -7
- package/dist/utility.mjs +295 -0
- package/install/build.js +3 -3
- package/lib/index.d.ts +99 -71
- package/package.json +46 -27
- package/src/binding.gyp +18 -13
- package/src/common.cc +70 -17
- package/src/common.h +22 -3
- package/src/metadata.cc +66 -8
- package/src/metadata.h +6 -1
- package/src/operations.cc +25 -8
- package/src/operations.h +1 -1
- package/src/pipeline.cc +194 -69
- package/src/pipeline.h +14 -1
- package/src/stats.cc +6 -6
- package/src/utilities.cc +4 -3
- package/install/check.js +0 -14
- package/lib/index.js +0 -16
- package/lib/sharp.js +0 -121
package/src/pipeline.h
CHANGED
|
@@ -48,6 +48,7 @@ struct PipelineBaton {
|
|
|
48
48
|
size_t bufferOutLength;
|
|
49
49
|
int pageHeightOut;
|
|
50
50
|
int pagesOut;
|
|
51
|
+
bool typedArrayOut;
|
|
51
52
|
std::vector<Composite *> composite;
|
|
52
53
|
std::vector<sharp::InputDescriptor *> joinChannelIn;
|
|
53
54
|
int topOffsetPre;
|
|
@@ -101,6 +102,7 @@ struct PipelineBaton {
|
|
|
101
102
|
bool trimLineArt;
|
|
102
103
|
int trimOffsetLeft;
|
|
103
104
|
int trimOffsetTop;
|
|
105
|
+
int trimMargin;
|
|
104
106
|
std::vector<double> linearA;
|
|
105
107
|
std::vector<double> linearB;
|
|
106
108
|
int dilateWidth;
|
|
@@ -167,6 +169,7 @@ struct PipelineBaton {
|
|
|
167
169
|
int webpEffort;
|
|
168
170
|
bool webpMinSize;
|
|
169
171
|
bool webpMixed;
|
|
172
|
+
bool webpExact;
|
|
170
173
|
int gifBitdepth;
|
|
171
174
|
int gifEffort;
|
|
172
175
|
double gifDither;
|
|
@@ -194,6 +197,8 @@ struct PipelineBaton {
|
|
|
194
197
|
std::string heifChromaSubsampling;
|
|
195
198
|
bool heifLossless;
|
|
196
199
|
int heifBitdepth;
|
|
200
|
+
std::string heifTune;
|
|
201
|
+
std::string heifEncoder;
|
|
197
202
|
double jxlDistance;
|
|
198
203
|
int jxlDecodingTier;
|
|
199
204
|
int jxlEffort;
|
|
@@ -208,6 +213,8 @@ struct PipelineBaton {
|
|
|
208
213
|
std::unordered_map<std::string, std::string> withExif;
|
|
209
214
|
bool withExifMerge;
|
|
210
215
|
std::string withXmp;
|
|
216
|
+
bool withGainMap;
|
|
217
|
+
bool keepGainMap;
|
|
211
218
|
int timeoutSeconds;
|
|
212
219
|
std::vector<double> convKernel;
|
|
213
220
|
int convKernelWidth;
|
|
@@ -242,6 +249,7 @@ struct PipelineBaton {
|
|
|
242
249
|
bufferOutLength(0),
|
|
243
250
|
pageHeightOut(0),
|
|
244
251
|
pagesOut(0),
|
|
252
|
+
typedArrayOut(false),
|
|
245
253
|
topOffsetPre(-1),
|
|
246
254
|
topOffsetPost(-1),
|
|
247
255
|
channels(0),
|
|
@@ -281,6 +289,7 @@ struct PipelineBaton {
|
|
|
281
289
|
trimLineArt(false),
|
|
282
290
|
trimOffsetLeft(0),
|
|
283
291
|
trimOffsetTop(0),
|
|
292
|
+
trimMargin(0),
|
|
284
293
|
linearA{},
|
|
285
294
|
linearB{},
|
|
286
295
|
dilateWidth(0),
|
|
@@ -344,6 +353,7 @@ struct PipelineBaton {
|
|
|
344
353
|
webpEffort(4),
|
|
345
354
|
webpMinSize(false),
|
|
346
355
|
webpMixed(false),
|
|
356
|
+
webpExact(false),
|
|
347
357
|
gifBitdepth(8),
|
|
348
358
|
gifEffort(7),
|
|
349
359
|
gifDither(1.0),
|
|
@@ -357,7 +367,7 @@ struct PipelineBaton {
|
|
|
357
367
|
tiffBigtiff(false),
|
|
358
368
|
tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
|
|
359
369
|
tiffPyramid(false),
|
|
360
|
-
tiffBitdepth(
|
|
370
|
+
tiffBitdepth(0),
|
|
361
371
|
tiffMiniswhite(false),
|
|
362
372
|
tiffTile(false),
|
|
363
373
|
tiffTileHeight(256),
|
|
@@ -371,6 +381,7 @@ struct PipelineBaton {
|
|
|
371
381
|
heifChromaSubsampling("4:4:4"),
|
|
372
382
|
heifLossless(false),
|
|
373
383
|
heifBitdepth(8),
|
|
384
|
+
heifTune("auto"),
|
|
374
385
|
jxlDistance(1.0),
|
|
375
386
|
jxlDecodingTier(0),
|
|
376
387
|
jxlEffort(7),
|
|
@@ -381,6 +392,8 @@ struct PipelineBaton {
|
|
|
381
392
|
withMetadataOrientation(-1),
|
|
382
393
|
withMetadataDensity(0.0),
|
|
383
394
|
withExifMerge(true),
|
|
395
|
+
withGainMap(false),
|
|
396
|
+
keepGainMap(false),
|
|
384
397
|
timeoutSeconds(0),
|
|
385
398
|
convKernelWidth(0),
|
|
386
399
|
convKernelHeight(0),
|
package/src/stats.cc
CHANGED
|
@@ -39,7 +39,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
39
39
|
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
|
40
40
|
try {
|
|
41
41
|
std::tie(image, imageType) = OpenInput(baton->input);
|
|
42
|
-
} catch (
|
|
42
|
+
} catch (std::runtime_error const &err) {
|
|
43
43
|
(baton->err).append(err.what());
|
|
44
44
|
}
|
|
45
45
|
if (imageType != sharp::ImageType::UNKNOWN) {
|
|
@@ -92,7 +92,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
92
92
|
baton->dominantRed = dx * 16 + 8;
|
|
93
93
|
baton->dominantGreen = dy * 16 + 8;
|
|
94
94
|
baton->dominantBlue = dz * 16 + 8;
|
|
95
|
-
} catch (
|
|
95
|
+
} catch (std::runtime_error const &err) {
|
|
96
96
|
(baton->err).append(err.what());
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -109,10 +109,9 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
109
109
|
// Handle warnings
|
|
110
110
|
std::string warning = sharp::VipsWarningPop();
|
|
111
111
|
while (!warning.empty()) {
|
|
112
|
-
debuglog.
|
|
112
|
+
debuglog.SHARP_CALLBACK_FN_NAME(Receiver().Value(), { Napi::String::New(env, warning) });
|
|
113
113
|
warning = sharp::VipsWarningPop();
|
|
114
114
|
}
|
|
115
|
-
|
|
116
115
|
if (baton->err.empty()) {
|
|
117
116
|
// Stats Object
|
|
118
117
|
Napi::Object info = Napi::Object::New(env);
|
|
@@ -144,9 +143,10 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
144
143
|
dominant.Set("g", baton->dominantGreen);
|
|
145
144
|
dominant.Set("b", baton->dominantBlue);
|
|
146
145
|
info.Set("dominant", dominant);
|
|
147
|
-
Callback().
|
|
146
|
+
Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(), { env.Null(), info });
|
|
148
147
|
} else {
|
|
149
|
-
Callback().
|
|
148
|
+
Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(),
|
|
149
|
+
{ Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
delete baton->input;
|
package/src/utilities.cc
CHANGED
|
@@ -123,6 +123,7 @@ Napi::Value format(const Napi::CallbackInfo& info) {
|
|
|
123
123
|
"jpeg", "png", "webp", "tiff", "magick", "openslide", "dz",
|
|
124
124
|
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k", "jxl", "rad", "dcraw"
|
|
125
125
|
}) {
|
|
126
|
+
std::string id = f == "jp2k" ? "jp2" : f;
|
|
126
127
|
// Input
|
|
127
128
|
const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str());
|
|
128
129
|
Napi::Boolean hasInputFile = Napi::Boolean::New(env, oc);
|
|
@@ -154,11 +155,11 @@ Napi::Value format(const Napi::CallbackInfo& info) {
|
|
|
154
155
|
output.Set("stream", hasOutputBuffer);
|
|
155
156
|
// Other attributes
|
|
156
157
|
Napi::Object container = Napi::Object::New(env);
|
|
157
|
-
container.Set("id",
|
|
158
|
+
container.Set("id", id);
|
|
158
159
|
container.Set("input", input);
|
|
159
160
|
container.Set("output", output);
|
|
160
161
|
// Add to set of formats
|
|
161
|
-
format.Set(
|
|
162
|
+
format.Set(id, container);
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
// Raw, uncompressed data
|
|
@@ -243,7 +244,7 @@ Napi::Value _maxColourDistance(const Napi::CallbackInfo& info) {
|
|
|
243
244
|
}
|
|
244
245
|
// Calculate colour distance
|
|
245
246
|
maxColourDistance = image1.dE00(image2).max();
|
|
246
|
-
} catch (
|
|
247
|
+
} catch (std::runtime_error const &err) {
|
|
247
248
|
throw Napi::Error::New(env, err.what());
|
|
248
249
|
}
|
|
249
250
|
|
package/install/check.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
Copyright 2013 Lovell Fuller and others.
|
|
3
|
-
SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
const { useGlobalLibvips } = require('../lib/libvips');
|
|
8
|
-
if (useGlobalLibvips() || process.env.npm_config_build_from_source) {
|
|
9
|
-
process.exit(1);
|
|
10
|
-
}
|
|
11
|
-
} catch (err) {
|
|
12
|
-
const summary = err.message.split(/\n/).slice(0, 1);
|
|
13
|
-
console.log(`sharp: skipping install check: ${summary}`);
|
|
14
|
-
}
|
package/lib/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
Copyright 2013 Lovell Fuller and others.
|
|
3
|
-
SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const Sharp = require('./constructor');
|
|
7
|
-
require('./input')(Sharp);
|
|
8
|
-
require('./resize')(Sharp);
|
|
9
|
-
require('./composite')(Sharp);
|
|
10
|
-
require('./operation')(Sharp);
|
|
11
|
-
require('./colour')(Sharp);
|
|
12
|
-
require('./channel')(Sharp);
|
|
13
|
-
require('./output')(Sharp);
|
|
14
|
-
require('./utility')(Sharp);
|
|
15
|
-
|
|
16
|
-
module.exports = Sharp;
|
package/lib/sharp.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
Copyright 2013 Lovell Fuller and others.
|
|
3
|
-
SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// Inspects the runtime environment and exports the relevant sharp.node binary
|
|
7
|
-
|
|
8
|
-
const { familySync, versionSync } = require('detect-libc');
|
|
9
|
-
|
|
10
|
-
const { runtimePlatformArch, isUnsupportedNodeRuntime, prebuiltPlatforms, minimumLibvipsVersion } = require('./libvips');
|
|
11
|
-
const runtimePlatform = runtimePlatformArch();
|
|
12
|
-
|
|
13
|
-
const paths = [
|
|
14
|
-
`../src/build/Release/sharp-${runtimePlatform}.node`,
|
|
15
|
-
'../src/build/Release/sharp-wasm32.node',
|
|
16
|
-
`@revizly/sharp-${runtimePlatform}/sharp.node`,
|
|
17
|
-
'@revizly/sharp-wasm32/sharp.node'
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
/* node:coverage disable */
|
|
21
|
-
|
|
22
|
-
let path, sharp;
|
|
23
|
-
const errors = [];
|
|
24
|
-
for (path of paths) {
|
|
25
|
-
try {
|
|
26
|
-
sharp = require(path);
|
|
27
|
-
break;
|
|
28
|
-
} catch (err) {
|
|
29
|
-
errors.push(err);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (sharp && path.startsWith('@img/sharp-linux-x64') && !sharp._isUsingX64V2()) {
|
|
34
|
-
const err = new Error('Prebuilt binaries for linux-x64 require v2 microarchitecture');
|
|
35
|
-
err.code = 'Unsupported CPU';
|
|
36
|
-
errors.push(err);
|
|
37
|
-
sharp = null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (sharp) {
|
|
41
|
-
module.exports = sharp;
|
|
42
|
-
} else {
|
|
43
|
-
const [isLinux, isMacOs, isWindows] = ['linux', 'darwin', 'win32'].map(os => runtimePlatform.startsWith(os));
|
|
44
|
-
|
|
45
|
-
const help = [`Could not load the "sharp" module using the ${runtimePlatform} runtime`];
|
|
46
|
-
errors.forEach(err => {
|
|
47
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
48
|
-
help.push(`${err.code}: ${err.message}`);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const messages = errors.map(err => err.message).join(' ');
|
|
52
|
-
help.push('Possible solutions:');
|
|
53
|
-
// Common error messages
|
|
54
|
-
if (isUnsupportedNodeRuntime()) {
|
|
55
|
-
const { found, expected } = isUnsupportedNodeRuntime();
|
|
56
|
-
help.push(
|
|
57
|
-
'- Please upgrade Node.js:',
|
|
58
|
-
` Found ${found}`,
|
|
59
|
-
` Requires ${expected}`
|
|
60
|
-
);
|
|
61
|
-
} else if (prebuiltPlatforms.includes(runtimePlatform)) {
|
|
62
|
-
const [os, cpu] = runtimePlatform.split('-');
|
|
63
|
-
const libc = os.endsWith('musl') ? ' --libc=musl' : '';
|
|
64
|
-
help.push(
|
|
65
|
-
'- Ensure optional dependencies can be installed:',
|
|
66
|
-
' npm install --include=optional sharp',
|
|
67
|
-
'- Ensure your package manager supports multi-platform installation:',
|
|
68
|
-
' See https://sharp.pixelplumbing.com/install#cross-platform',
|
|
69
|
-
'- Add platform-specific dependencies:',
|
|
70
|
-
` npm install --os=${os.replace('musl', '')}${libc} --cpu=${cpu} @revizly/sharp`
|
|
71
|
-
);
|
|
72
|
-
} else {
|
|
73
|
-
help.push(
|
|
74
|
-
`- Manually install libvips >= ${minimumLibvipsVersion}`,
|
|
75
|
-
'- Add experimental WebAssembly-based dependencies:',
|
|
76
|
-
' npm install --cpu=wasm32 sharp',
|
|
77
|
-
' npm install @revizly/sharp-wasm32'
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
|
|
81
|
-
try {
|
|
82
|
-
const { config } = require(`@revizly/sharp-libvips-${runtimePlatform}/package`);
|
|
83
|
-
const libcFound = `${familySync()} ${versionSync()}`;
|
|
84
|
-
const libcRequires = `${config.musl ? 'musl' : 'glibc'} ${config.musl || config.glibc}`;
|
|
85
|
-
help.push(
|
|
86
|
-
'- Update your OS:',
|
|
87
|
-
` Found ${libcFound}`,
|
|
88
|
-
` Requires ${libcRequires}`
|
|
89
|
-
);
|
|
90
|
-
} catch (_errEngines) {}
|
|
91
|
-
}
|
|
92
|
-
if (isLinux && /\/snap\/core[0-9]{2}/.test(messages)) {
|
|
93
|
-
help.push(
|
|
94
|
-
'- Remove the Node.js Snap, which does not support native modules',
|
|
95
|
-
' snap remove node'
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
if (isMacOs && /Incompatible library version/.test(messages)) {
|
|
99
|
-
help.push(
|
|
100
|
-
'- Update Homebrew:',
|
|
101
|
-
' brew update && brew upgrade vips'
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
if (errors.some(err => err.code === 'ERR_DLOPEN_DISABLED')) {
|
|
105
|
-
help.push('- Run Node.js without using the --no-addons flag');
|
|
106
|
-
}
|
|
107
|
-
// Link to installation docs
|
|
108
|
-
if (isWindows && /The specified procedure could not be found/.test(messages)) {
|
|
109
|
-
help.push(
|
|
110
|
-
'- Using the canvas package on Windows?',
|
|
111
|
-
' See https://sharp.pixelplumbing.com/install#canvas-and-windows',
|
|
112
|
-
'- Check for outdated versions of sharp in the dependency tree:',
|
|
113
|
-
' npm ls sharp'
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
help.push(
|
|
117
|
-
'- Consult the installation documentation:',
|
|
118
|
-
' See https://sharp.pixelplumbing.com/install'
|
|
119
|
-
);
|
|
120
|
-
throw new Error(help.join('\n'));
|
|
121
|
-
}
|