@depup/sharp 0.34.5-depup.0 → 0.35.4-depup.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.
Files changed (47) hide show
  1. package/README.md +16 -109
  2. package/changes.json +5 -0
  3. package/{lib/channel.js → dist/channel.cjs} +1 -1
  4. package/dist/channel.mjs +177 -0
  5. package/{lib/colour.js → dist/colour.cjs} +11 -7
  6. package/dist/colour.mjs +199 -0
  7. package/{lib/composite.js → dist/composite.cjs} +8 -7
  8. package/dist/composite.mjs +213 -0
  9. package/{lib/constructor.js → dist/constructor.cjs} +42 -30
  10. package/dist/constructor.mjs +511 -0
  11. package/dist/index.cjs +25 -0
  12. package/dist/index.d.cts +1999 -0
  13. package/dist/index.d.mts +2046 -0
  14. package/dist/index.mjs +25 -0
  15. package/{lib/input.js → dist/input.cjs} +47 -37
  16. package/dist/input.mjs +819 -0
  17. package/{lib/is.js → dist/is.cjs} +1 -1
  18. package/dist/is.mjs +143 -0
  19. package/{lib/libvips.js → dist/libvips.cjs} +35 -30
  20. package/dist/libvips.mjs +212 -0
  21. package/{lib/operation.js → dist/operation.cjs} +37 -51
  22. package/dist/operation.mjs +1002 -0
  23. package/{lib/output.js → dist/output.cjs} +166 -47
  24. package/dist/output.mjs +1785 -0
  25. package/{lib/resize.js → dist/resize.cjs} +54 -32
  26. package/dist/resize.mjs +617 -0
  27. package/dist/sharp.cjs +174 -0
  28. package/dist/sharp.mjs +174 -0
  29. package/{lib/utility.js → dist/utility.cjs} +18 -8
  30. package/dist/utility.mjs +301 -0
  31. package/install/build.js +3 -3
  32. package/lib/index.d.ts +111 -83
  33. package/package.json +95 -54
  34. package/src/binding.gyp +19 -14
  35. package/src/common.cc +77 -21
  36. package/src/common.h +23 -4
  37. package/src/metadata.cc +66 -8
  38. package/src/metadata.h +6 -1
  39. package/src/operations.cc +25 -8
  40. package/src/operations.h +1 -1
  41. package/src/pipeline.cc +203 -69
  42. package/src/pipeline.h +15 -1
  43. package/src/stats.cc +6 -6
  44. package/src/utilities.cc +7 -6
  45. package/install/check.js +0 -14
  46. package/lib/index.js +0 -16
  47. 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,7 @@ struct PipelineBaton {
194
198
  std::string heifChromaSubsampling;
195
199
  bool heifLossless;
196
200
  int heifBitdepth;
201
+ std::string heifTune;
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,8 @@ struct PipelineBaton {
242
249
  bufferOutLength(0),
243
250
  pageHeightOut(0),
244
251
  pagesOut(0),
252
+ typedArrayOut(false),
253
+ hasAlphaOut(false),
245
254
  topOffsetPre(-1),
246
255
  topOffsetPost(-1),
247
256
  channels(0),
@@ -281,6 +290,7 @@ struct PipelineBaton {
281
290
  trimLineArt(false),
282
291
  trimOffsetLeft(0),
283
292
  trimOffsetTop(0),
293
+ trimMargin(0),
284
294
  linearA{},
285
295
  linearB{},
286
296
  dilateWidth(0),
@@ -344,6 +354,7 @@ struct PipelineBaton {
344
354
  webpEffort(4),
345
355
  webpMinSize(false),
346
356
  webpMixed(false),
357
+ webpExact(false),
347
358
  gifBitdepth(8),
348
359
  gifEffort(7),
349
360
  gifDither(1.0),
@@ -357,7 +368,7 @@ struct PipelineBaton {
357
368
  tiffBigtiff(false),
358
369
  tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
359
370
  tiffPyramid(false),
360
- tiffBitdepth(8),
371
+ tiffBitdepth(0),
361
372
  tiffMiniswhite(false),
362
373
  tiffTile(false),
363
374
  tiffTileHeight(256),
@@ -371,6 +382,7 @@ struct PipelineBaton {
371
382
  heifChromaSubsampling("4:4:4"),
372
383
  heifLossless(false),
373
384
  heifBitdepth(8),
385
+ heifTune("auto"),
374
386
  jxlDistance(1.0),
375
387
  jxlDecodingTier(0),
376
388
  jxlEffort(7),
@@ -381,6 +393,8 @@ struct PipelineBaton {
381
393
  withMetadataOrientation(-1),
382
394
  withMetadataDensity(0.0),
383
395
  withExifMerge(true),
396
+ withGainMap(false),
397
+ keepGainMap(false),
384
398
  timeoutSeconds(0),
385
399
  convKernelWidth(0),
386
400
  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
- `@img/sharp-${runtimePlatform}/sharp.node`,
17
- '@img/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} 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 @img/sharp-wasm32'
78
- );
79
- }
80
- if (isLinux && /(symbol not found|CXXABI_)/i.test(messages)) {
81
- try {
82
- const { config } = require(`@img/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
- }