@revizly/sharp 0.35.0-revizly4 → 0.35.0-revizly41

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.
Files changed (46) hide show
  1. package/README.md +12 -18
  2. package/{lib/channel.js → dist/channel.cjs} +1 -1
  3. package/dist/channel.mjs +177 -0
  4. package/{lib/colour.js → dist/colour.cjs} +11 -7
  5. package/dist/colour.mjs +199 -0
  6. package/{lib/composite.js → dist/composite.cjs} +2 -1
  7. package/dist/composite.mjs +213 -0
  8. package/{lib/constructor.js → dist/constructor.cjs} +42 -29
  9. package/dist/constructor.mjs +512 -0
  10. package/dist/index.cjs +25 -0
  11. package/dist/index.d.cts +2001 -0
  12. package/dist/index.d.mts +2048 -0
  13. package/dist/index.mjs +25 -0
  14. package/{lib/input.js → dist/input.cjs} +26 -21
  15. package/dist/input.mjs +814 -0
  16. package/{lib/is.js → dist/is.cjs} +1 -1
  17. package/dist/is.mjs +143 -0
  18. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  19. package/dist/libvips.mjs +212 -0
  20. package/{lib/operation.js → dist/operation.cjs} +33 -51
  21. package/dist/operation.mjs +998 -0
  22. package/{lib/output.js → dist/output.cjs} +161 -28
  23. package/dist/output.mjs +1799 -0
  24. package/{lib/resize.js → dist/resize.cjs} +46 -24
  25. package/dist/resize.mjs +617 -0
  26. package/dist/sharp.cjs +125 -0
  27. package/dist/sharp.mjs +125 -0
  28. package/{lib/utility.js → dist/utility.cjs} +18 -8
  29. package/dist/utility.mjs +301 -0
  30. package/install/build.js +3 -3
  31. package/lib/index.d.ts +105 -75
  32. package/package.json +46 -27
  33. package/src/binding.gyp +18 -13
  34. package/src/common.cc +70 -17
  35. package/src/common.h +22 -3
  36. package/src/metadata.cc +66 -8
  37. package/src/metadata.h +6 -1
  38. package/src/operations.cc +25 -8
  39. package/src/operations.h +1 -1
  40. package/src/pipeline.cc +206 -69
  41. package/src/pipeline.h +16 -1
  42. package/src/stats.cc +6 -6
  43. package/src/utilities.cc +7 -6
  44. package/install/check.js +0 -14
  45. package/lib/index.js +0 -16
  46. package/lib/sharp.js +0 -121
package/src/pipeline.h CHANGED
@@ -48,6 +48,8 @@ struct PipelineBaton {
48
48
  size_t bufferOutLength;
49
49
  int pageHeightOut;
50
50
  int pagesOut;
51
+ bool typedArrayOut;
52
+ bool hasAlphaOut;
51
53
  std::vector<Composite *> composite;
52
54
  std::vector<sharp::InputDescriptor *> joinChannelIn;
53
55
  int topOffsetPre;
@@ -101,6 +103,7 @@ struct PipelineBaton {
101
103
  bool trimLineArt;
102
104
  int trimOffsetLeft;
103
105
  int trimOffsetTop;
106
+ int trimMargin;
104
107
  std::vector<double> linearA;
105
108
  std::vector<double> linearB;
106
109
  int dilateWidth;
@@ -167,6 +170,7 @@ struct PipelineBaton {
167
170
  int webpEffort;
168
171
  bool webpMinSize;
169
172
  bool webpMixed;
173
+ bool webpExact;
170
174
  int gifBitdepth;
171
175
  int gifEffort;
172
176
  double gifDither;
@@ -194,6 +198,8 @@ struct PipelineBaton {
194
198
  std::string heifChromaSubsampling;
195
199
  bool heifLossless;
196
200
  int heifBitdepth;
201
+ std::string heifTune;
202
+ std::string heifEncoder;
197
203
  double jxlDistance;
198
204
  int jxlDecodingTier;
199
205
  int jxlEffort;
@@ -208,6 +214,8 @@ struct PipelineBaton {
208
214
  std::unordered_map<std::string, std::string> withExif;
209
215
  bool withExifMerge;
210
216
  std::string withXmp;
217
+ bool withGainMap;
218
+ bool keepGainMap;
211
219
  int timeoutSeconds;
212
220
  std::vector<double> convKernel;
213
221
  int convKernelWidth;
@@ -242,6 +250,8 @@ struct PipelineBaton {
242
250
  bufferOutLength(0),
243
251
  pageHeightOut(0),
244
252
  pagesOut(0),
253
+ typedArrayOut(false),
254
+ hasAlphaOut(false),
245
255
  topOffsetPre(-1),
246
256
  topOffsetPost(-1),
247
257
  channels(0),
@@ -281,6 +291,7 @@ struct PipelineBaton {
281
291
  trimLineArt(false),
282
292
  trimOffsetLeft(0),
283
293
  trimOffsetTop(0),
294
+ trimMargin(0),
284
295
  linearA{},
285
296
  linearB{},
286
297
  dilateWidth(0),
@@ -344,6 +355,7 @@ struct PipelineBaton {
344
355
  webpEffort(4),
345
356
  webpMinSize(false),
346
357
  webpMixed(false),
358
+ webpExact(false),
347
359
  gifBitdepth(8),
348
360
  gifEffort(7),
349
361
  gifDither(1.0),
@@ -357,7 +369,7 @@ struct PipelineBaton {
357
369
  tiffBigtiff(false),
358
370
  tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
359
371
  tiffPyramid(false),
360
- tiffBitdepth(8),
372
+ tiffBitdepth(0),
361
373
  tiffMiniswhite(false),
362
374
  tiffTile(false),
363
375
  tiffTileHeight(256),
@@ -371,6 +383,7 @@ struct PipelineBaton {
371
383
  heifChromaSubsampling("4:4:4"),
372
384
  heifLossless(false),
373
385
  heifBitdepth(8),
386
+ heifTune("auto"),
374
387
  jxlDistance(1.0),
375
388
  jxlDecodingTier(0),
376
389
  jxlEffort(7),
@@ -381,6 +394,8 @@ struct PipelineBaton {
381
394
  withMetadataOrientation(-1),
382
395
  withMetadataDensity(0.0),
383
396
  withExifMerge(true),
397
+ withGainMap(false),
398
+ keepGainMap(false),
384
399
  timeoutSeconds(0),
385
400
  convKernelWidth(0),
386
401
  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 (vips::VError const &err) {
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 (vips::VError const &err) {
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.Call(Receiver().Value(), { Napi::String::New(env, warning) });
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().Call(Receiver().Value(), { env.Null(), info });
146
+ Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(), { env.Null(), info });
148
147
  } else {
149
- Callback().Call(Receiver().Value(), { Napi::Error::New(env, sharp::TrimEnd(baton->err)).Value() });
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
@@ -23,15 +23,15 @@ Napi::Value cache(const Napi::CallbackInfo& info) {
23
23
 
24
24
  // Set memory limit
25
25
  if (info[size_t(0)].IsNumber()) {
26
- vips_cache_set_max_mem(info[size_t(0)].As<Napi::Number>().Int32Value() * 1048576);
26
+ vips_cache_set_max_mem(static_cast<size_t>(info[size_t(0)].As<Napi::Number>().Uint32Value()) * 1048576);
27
27
  }
28
28
  // Set file limit
29
29
  if (info[size_t(1)].IsNumber()) {
30
- vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Int32Value());
30
+ vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Uint32Value());
31
31
  }
32
32
  // Set items limit
33
33
  if (info[size_t(2)].IsNumber()) {
34
- vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Int32Value());
34
+ vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Uint32Value());
35
35
  }
36
36
 
37
37
  // Get memory stats
@@ -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", f);
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(f, container);
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 (vips::VError const &err) {
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
- }