@revizly/sharp 0.35.0-revizly50 → 0.35.0-revizly52

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/dist/channel.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/channel.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/colour.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/colour.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/input.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/input.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/is.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -107,9 +107,15 @@ const inArray = (val, list) => list.includes(val);
107
107
  * @returns {Error} Containing the formatted message.
108
108
  * @private
109
109
  */
110
- const invalidParameterError = (name, expected, actual) => new Error(
111
- `Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
110
+ const invalidParameterError = (name, expected, actual) => {
111
+ let actualString;
112
+ try {
113
+ actualString = String(actual).slice(0, 100);
114
+ } catch {}
115
+ return new Error(
116
+ `Expected ${expected} for ${name} but received ${actualString} of type ${typeof actual}`
112
117
  );
118
+ };
113
119
 
114
120
  /**
115
121
  * Ensures an Error from C++ contains a JS stack.
package/dist/is.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -107,9 +107,15 @@ const inArray = (val, list) => list.includes(val);
107
107
  * @returns {Error} Containing the formatted message.
108
108
  * @private
109
109
  */
110
- const invalidParameterError = (name, expected, actual) => new Error(
111
- `Expected ${expected} for ${name} but received ${actual} of type ${typeof actual}`
110
+ const invalidParameterError = (name, expected, actual) => {
111
+ let actualString;
112
+ try {
113
+ actualString = String(actual).slice(0, 100);
114
+ } catch {}
115
+ return new Error(
116
+ `Expected ${expected} for ${name} but received ${actualString} of type ${typeof actual}`
112
117
  );
118
+ };
113
119
 
114
120
  /**
115
121
  * Ensures an Error from C++ contains a JS stack.
package/dist/libvips.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/libvips.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -824,7 +824,7 @@ function linear (a, b) {
824
824
  this.options.linearA = [];
825
825
  } else if (is.number(a)) {
826
826
  this.options.linearA = [a];
827
- } else if (Array.isArray(a) && a.length && a.every(is.number)) {
827
+ } else if (Array.isArray(a) && is.inRange(a.length, 1, 1000000) && a.every(is.number)) {
828
828
  this.options.linearA = a;
829
829
  } else {
830
830
  throw is.invalidParameterError('a', 'number or array of numbers', a);
@@ -833,7 +833,7 @@ function linear (a, b) {
833
833
  this.options.linearB = [];
834
834
  } else if (is.number(b)) {
835
835
  this.options.linearB = [b];
836
- } else if (Array.isArray(b) && b.length && b.every(is.number)) {
836
+ } else if (Array.isArray(b) && is.inRange(b.length, 1, 1000000) && b.every(is.number)) {
837
837
  this.options.linearB = b;
838
838
  } else {
839
839
  throw is.invalidParameterError('b', 'number or array of numbers', b);
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -824,7 +824,7 @@ function linear (a, b) {
824
824
  this.options.linearA = [];
825
825
  } else if (is.number(a)) {
826
826
  this.options.linearA = [a];
827
- } else if (Array.isArray(a) && a.length && a.every(is.number)) {
827
+ } else if (Array.isArray(a) && is.inRange(a.length, 1, 1000000) && a.every(is.number)) {
828
828
  this.options.linearA = a;
829
829
  } else {
830
830
  throw is.invalidParameterError('a', 'number or array of numbers', a);
@@ -833,7 +833,7 @@ function linear (a, b) {
833
833
  this.options.linearB = [];
834
834
  } else if (is.number(b)) {
835
835
  this.options.linearB = [b];
836
- } else if (Array.isArray(b) && b.length && b.every(is.number)) {
836
+ } else if (Array.isArray(b) && is.inRange(b.length, 1, 1000000) && b.every(is.number)) {
837
837
  this.options.linearB = b;
838
838
  } else {
839
839
  throw is.invalidParameterError('b', 'number or array of numbers', b);
package/dist/output.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1066,6 +1066,7 @@ function trySetAnimationOptions (source, target) {
1066
1066
  target.delay = [source.delay];
1067
1067
  } else if (
1068
1068
  Array.isArray(source.delay) &&
1069
+ is.inRange(source.delay.length, 1, 1000000) &&
1069
1070
  source.delay.every(is.integer) &&
1070
1071
  source.delay.every(v => is.inRange(v, 0, 65535))) {
1071
1072
  target.delay = source.delay;
package/dist/output.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -1066,6 +1066,7 @@ function trySetAnimationOptions (source, target) {
1066
1066
  target.delay = [source.delay];
1067
1067
  } else if (
1068
1068
  Array.isArray(source.delay) &&
1069
+ is.inRange(source.delay.length, 1, 1000000) &&
1069
1070
  source.delay.every(is.integer) &&
1070
1071
  source.delay.every(v => is.inRange(v, 0, 65535))) {
1071
1072
  target.delay = source.delay;
package/dist/resize.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/resize.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/sharp.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -75,7 +75,7 @@ if (!sharp) {
75
75
  if (isUnsupportedNodeRuntime()) {
76
76
  const { found, expected } = isUnsupportedNodeRuntime();
77
77
  help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
78
- } else if (prebuiltPlatforms.includes(runtimePlatform)) {
78
+ } else if (prebuiltPlatforms.includes(runtimePlatform) && !/libstdc\+\+\.so/.test(messages)) {
79
79
  const [os, cpu] = runtimePlatform.split("-");
80
80
  const libc = os.endsWith("musl") ? " --libc=musl" : "";
81
81
  help.push(
package/dist/sharp.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -75,7 +75,7 @@ if (!sharp) {
75
75
  if (isUnsupportedNodeRuntime()) {
76
76
  const { found, expected } = isUnsupportedNodeRuntime();
77
77
  help.push("- Please upgrade Node.js:", ` Found ${found}`, ` Requires ${expected}`);
78
- } else if (prebuiltPlatforms.includes(runtimePlatform)) {
78
+ } else if (prebuiltPlatforms.includes(runtimePlatform) && !/libstdc\+\+\.so/.test(messages)) {
79
79
  const [os, cpu] = runtimePlatform.split("-");
80
80
  const libc = os.endsWith("musl") ? " --libc=musl" : "";
81
81
  help.push(
package/dist/utility.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/dist/utility.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/install/build.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
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.35.0-revizly50",
4
+ "version": "0.35.0-revizly52",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -163,10 +163,10 @@
163
163
  "semver": "^7.8.5"
164
164
  },
165
165
  "optionalDependencies": {
166
- "@revizly/sharp-libvips-linux-arm64": "1.0.51",
167
- "@revizly/sharp-libvips-linux-x64": "1.0.51",
168
- "@revizly/sharp-linux-arm64": "0.35.0-revizly50",
169
- "@revizly/sharp-linux-x64": "0.35.0-revizly50"
166
+ "@revizly/sharp-libvips-linux-arm64": "1.0.53",
167
+ "@revizly/sharp-libvips-linux-x64": "1.0.53",
168
+ "@revizly/sharp-linux-arm64": "0.35.0-revizly52",
169
+ "@revizly/sharp-linux-x64": "0.35.0-revizly52"
170
170
  },
171
171
  "peerDependenciesMeta": {
172
172
  "@types/node": {
@@ -174,27 +174,27 @@
174
174
  }
175
175
  },
176
176
  "devDependencies": {
177
- "@biomejs/biome": "^2.5.10",
177
+ "@biomejs/biome": "^2.5.14",
178
178
  "@cpplint/cli": "^0.1.0",
179
179
  "@emnapi/runtime": "^1.11.3",
180
- "@revizly/sharp-libvips-dev": "1.0.51",
180
+ "@revizly/sharp-libvips-dev": "1.0.53",
181
181
  "@types/node": "*",
182
182
  "emnapi": "^1.11.3",
183
183
  "exif-reader": "^2.0.3",
184
- "yauzl": "^3.4.0",
185
184
  "icc": "^4.0.0",
186
185
  "node-addon-api": "^8.9.2",
187
186
  "node-gyp": "^12.4.0",
188
187
  "publint": "^0.3.24",
189
188
  "tar-fs": "^3.1.3",
190
- "tsd": "^0.33.0"
189
+ "tsd": "^0.33.0",
190
+ "yauzl": "^3.4.0"
191
191
  },
192
192
  "license": "Apache-2.0",
193
193
  "engines": {
194
194
  "node": ">=20.9.0"
195
195
  },
196
196
  "config": {
197
- "libvips": ">=8.18.6"
197
+ "libvips": ">=8.18.7"
198
198
  },
199
199
  "funding": {
200
200
  "url": "https://opencollective.com/libvips"
package/src/binding.gyp CHANGED
@@ -1,7 +1,7 @@
1
- # Copyright 2013 Lovell Fuller and others.
1
+ # SPDX-FileCopyrightText: 2013 Lovell Fuller and others
2
2
  # SPDX-License-Identifier: Apache-2.0
3
3
 
4
- {
4
+ { # noqa: B018
5
5
  'variables': {
6
6
  'vips_version': '<!(node -p "require(\'../dist/libvips.cjs\').minimumLibvipsVersion")',
7
7
  'platform_and_arch': '<!(node -p "require(\'../dist/libvips.cjs\').buildPlatformArch()")',
package/src/common.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -635,7 +635,7 @@ namespace sharp {
635
635
  if (HasProfile(image)) {
636
636
  size_t length;
637
637
  const void *data = image.get_blob(VIPS_META_ICC_NAME, &length);
638
- icc.first = static_cast<char*>(vips_malloc(reinterpret_cast<VipsObject*>(image.get_image()), length));
638
+ icc.first = static_cast<char*>(g_malloc(length));
639
639
  icc.second = length;
640
640
  memcpy(icc.first, data, length);
641
641
  }
@@ -648,7 +648,7 @@ namespace sharp {
648
648
  VImage SetProfile(VImage image, std::pair<char*, size_t> icc) {
649
649
  if (icc.first != nullptr) {
650
650
  image = image.copy();
651
- image.set(VIPS_META_ICC_NAME, nullptr, icc.first, icc.second);
651
+ image.set(VIPS_META_ICC_NAME, reinterpret_cast<VipsCallbackFn>(vips_area_free_cb), icc.first, icc.second);
652
652
  }
653
653
  return image;
654
654
  }
@@ -720,7 +720,7 @@ namespace sharp {
720
720
  if (hasDelay) {
721
721
  if (delay.size() == 1) {
722
722
  // We have just one delay, repeat that value for all frames.
723
- delay.insert(delay.end(), nPages - 1, delay[0]);
723
+ delay.insert(delay.end(), std::max(0, nPages - 1), delay[0]);
724
724
  }
725
725
  copy.set("delay", delay);
726
726
  }
package/src/common.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -19,8 +19,8 @@
19
19
 
20
20
  #if (VIPS_MAJOR_VERSION < 8) || \
21
21
  (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 18) || \
22
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 6)
23
- #error "libvips version 8.18.6+ is required - please see https://sharp.pixelplumbing.com/install"
22
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 18 && VIPS_MICRO_VERSION < 7)
23
+ #error "libvips version 8.18.7+ is required - please see https://sharp.pixelplumbing.com/install"
24
24
  #endif
25
25
 
26
26
  #if defined(__has_include)
package/src/metadata.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/metadata.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/operations.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/operations.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/pipeline.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -56,9 +56,9 @@ class PipelineWorker : public Napi::AsyncWorker {
56
56
  hasAlpha |= image.has_alpha();
57
57
  }
58
58
  if (hasAlpha) {
59
- for (auto &image : images) {
60
- if (!image.has_alpha()) {
61
- image = sharp::EnsureAlpha(image, 1);
59
+ for (size_t i = 0; i < images.size(); i++) {
60
+ if (!images[i].has_alpha()) {
61
+ images[i] = sharp::EnsureAlpha(images[i], 1);
62
62
  }
63
63
  }
64
64
  } else {
@@ -94,7 +94,10 @@ class PipelineWorker : public Napi::AsyncWorker {
94
94
  // Calculate angle of rotation
95
95
  VipsAngle rotation = VIPS_ANGLE_D0;
96
96
  VipsAngle autoRotation = VIPS_ANGLE_D0;
97
+ VipsAngle gainMapRotation = VIPS_ANGLE_D0;
97
98
  bool autoFlop = false;
99
+ bool gainMapFlip = false;
100
+ bool gainMapFlop = false;
98
101
 
99
102
  if (baton->input->autoOrient) {
100
103
  // Rotate and flip image according to Exif orientation
@@ -115,11 +118,13 @@ class PipelineWorker : public Napi::AsyncWorker {
115
118
  MultiPageUnsupported(nPages, "Rotate");
116
119
  }
117
120
  image = image.rot(autoRotation);
121
+ gainMapRotation = autoRotation;
118
122
  autoRotation = VIPS_ANGLE_D0;
119
123
  }
120
124
  if (autoFlop) {
121
125
  image = image.flip(VIPS_DIRECTION_HORIZONTAL);
122
126
  autoFlop = false;
127
+ gainMapFlop = true;
123
128
  }
124
129
  }
125
130
 
@@ -128,20 +133,24 @@ class PipelineWorker : public Napi::AsyncWorker {
128
133
  if (baton->flip) {
129
134
  image = image.flip(VIPS_DIRECTION_VERTICAL);
130
135
  baton->flip = false;
136
+ gainMapFlip = true;
131
137
  }
132
138
  if (baton->flop) {
133
139
  image = image.flip(VIPS_DIRECTION_HORIZONTAL);
134
140
  baton->flop = false;
141
+ gainMapFlop = true;
135
142
  }
136
143
  if (rotation != VIPS_ANGLE_D0) {
137
144
  if (rotation != VIPS_ANGLE_D180) {
138
145
  MultiPageUnsupported(nPages, "Rotate");
139
146
  }
140
147
  image = image.rot(rotation);
148
+ gainMapRotation = rotation;
141
149
  rotation = VIPS_ANGLE_D0;
142
150
  }
143
151
  if (baton->rotationAngle != 0.0) {
144
152
  MultiPageUnsupported(nPages, "Rotate");
153
+ KeepGainMapUnsupported(baton->keepGainMap, "Rotate");
145
154
  std::vector<double> background;
146
155
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, false);
147
156
  image = image.rotate(baton->rotationAngle, VImage::option()->set("background", background)).copy_memory();
@@ -152,6 +161,7 @@ class PipelineWorker : public Napi::AsyncWorker {
152
161
  // Trim
153
162
  if (baton->trimThreshold >= 0.0) {
154
163
  MultiPageUnsupported(nPages, "Trim");
164
+ KeepGainMapUnsupported(baton->keepGainMap, "Trim");
155
165
  image = sharp::StaySequential(image);
156
166
  image = sharp::Trim(image, baton->trimBackground, baton->trimThreshold, baton->trimLineArt, baton->trimMargin);
157
167
  baton->trimOffsetLeft = image.xoffset();
@@ -306,6 +316,20 @@ class PipelineWorker : public Napi::AsyncWorker {
306
316
  if (image.get_typeof("gainmap-scale-factor") == G_TYPE_INT) {
307
317
  gainMapScaleFactor = image.get_int("gainmap-scale-factor");
308
318
  }
319
+ if (gainMapFlip) {
320
+ gainMap = gainMap.flip(VIPS_DIRECTION_VERTICAL);
321
+ }
322
+ if (gainMapFlop) {
323
+ gainMap = gainMap.flip(VIPS_DIRECTION_HORIZONTAL);
324
+ }
325
+ if (gainMapRotation != VIPS_ANGLE_D0) {
326
+ gainMap = gainMap.rot(gainMapRotation);
327
+ }
328
+ if (baton->topOffsetPre != -1) {
329
+ gainMap = gainMap.extract_area(
330
+ baton->leftOffsetPre / gainMapScaleFactor, baton->topOffsetPre / gainMapScaleFactor,
331
+ baton->widthPre / gainMapScaleFactor, baton->heightPre / gainMapScaleFactor);
332
+ }
309
333
  } else if (baton->withGainMap) {
310
334
  image = image.uhdr2scRGB();
311
335
  }
@@ -429,14 +453,14 @@ class PipelineWorker : public Napi::AsyncWorker {
429
453
  }
430
454
  image = image.rot(autoRotation);
431
455
  if (baton->keepGainMap) {
432
- gainMap = gainMap.rot(autoRotation);
456
+ gainMap = sharp::StaySequential(gainMap).rot(autoRotation);
433
457
  }
434
458
  }
435
459
  // Mirror vertically (up-down) about the x-axis
436
460
  if (baton->flip) {
437
461
  image = image.flip(VIPS_DIRECTION_VERTICAL);
438
462
  if (baton->keepGainMap) {
439
- gainMap = gainMap.flip(VIPS_DIRECTION_VERTICAL);
463
+ gainMap = sharp::StaySequential(gainMap).flip(VIPS_DIRECTION_VERTICAL);
440
464
  }
441
465
  }
442
466
  // Mirror horizontally (left-right) about the y-axis
@@ -453,7 +477,7 @@ class PipelineWorker : public Napi::AsyncWorker {
453
477
  }
454
478
  image = image.rot(rotation);
455
479
  if (baton->keepGainMap) {
456
- gainMap = gainMap.rot(rotation);
480
+ gainMap = sharp::StaySequential(gainMap).rot(rotation);
457
481
  }
458
482
  }
459
483
 
@@ -557,6 +581,7 @@ class PipelineWorker : public Napi::AsyncWorker {
557
581
  // Rotate post-extract non-90 angle
558
582
  if (!baton->rotateBefore && baton->rotationAngle != 0.0) {
559
583
  MultiPageUnsupported(nPages, "Rotate");
584
+ KeepGainMapUnsupported(baton->keepGainMap, "Rotate");
560
585
  image = sharp::StaySequential(image);
561
586
  std::vector<double> background;
562
587
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->rotationBackground, shouldPremultiplyAlpha);
@@ -613,15 +638,17 @@ class PipelineWorker : public Napi::AsyncWorker {
613
638
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->extendBackground, shouldPremultiplyAlpha);
614
639
  }
615
640
  image = sharp::StaySequential(image, nPages > 1 || baton->extendWith != VIPS_EXTEND_BACKGROUND);
616
- auto options = VImage::option()->set("extend", baton->extendWith);
617
- if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
618
- options->set("background", background);
641
+ if (nPages > 1) {
642
+ image = sharp::EmbedMultiPage(image,
643
+ baton->extendLeft, baton->extendTop, baton->width, baton->height,
644
+ baton->extendWith, background, nPages, &targetPageHeight);
645
+ } else {
646
+ auto options = VImage::option()->set("extend", baton->extendWith);
647
+ if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
648
+ options->set("background", background);
649
+ }
650
+ image = image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height, options);
619
651
  }
620
- image = nPages > 1
621
- ? sharp::EmbedMultiPage(image,
622
- baton->extendLeft, baton->extendTop, baton->width, baton->height,
623
- baton->extendWith, background, nPages, &targetPageHeight)
624
- : image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height, options);
625
652
  if (baton->keepGainMap) {
626
653
  gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
627
654
  baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
@@ -863,7 +890,11 @@ class PipelineWorker : public Napi::AsyncWorker {
863
890
  image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
864
891
  if (inputProfile.first != nullptr && baton->withIccProfile.empty()) {
865
892
  image = sharp::SetProfile(image, inputProfile);
893
+ } else {
894
+ g_free(inputProfile.first);
866
895
  }
896
+ } else {
897
+ g_free(inputProfile.first);
867
898
  }
868
899
 
869
900
  // Extract channel
@@ -1358,8 +1389,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1358
1389
  baton->formatOut = "v";
1359
1390
  } else {
1360
1391
  // Unsupported output format
1361
- (baton->err).append("Unsupported output format " + baton->fileOut);
1362
- return Error();
1392
+ throw std::runtime_error("Unsupported output format " + baton->fileOut);
1363
1393
  }
1364
1394
  }
1365
1395
  } catch (std::runtime_error const &err) {
@@ -1442,7 +1472,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1442
1472
  // ECMAScript ArrayBuffer with Uint8Array view
1443
1473
  Napi::TypedArrayOf<uint8_t> data = Napi::Buffer<char>::Copy(env,
1444
1474
  static_cast<char*>(baton->bufferOut), baton->bufferOutLength);
1445
- sharp::FreeCallback(static_cast<char*>(baton->bufferOut), nullptr);
1475
+ sharp::FreeCallback(nullptr, static_cast<char*>(baton->bufferOut));
1446
1476
  Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(), { env.Null(), data, info });
1447
1477
  } else {
1448
1478
  // Node.js Buffer
@@ -1634,6 +1664,8 @@ class PipelineWorker : public Napi::AsyncWorker {
1634
1664
  image = image.copy();
1635
1665
  image.set("gainmap-data", reinterpret_cast<VipsCallbackFn>(vips_area_free_cb),
1636
1666
  gainMapJpeg->data, gainMapJpeg->length);
1667
+ gainMapJpeg->free_fn = nullptr;
1668
+ vips_area_unref(gainMapJpeg);
1637
1669
  return image;
1638
1670
  }
1639
1671
 
package/src/pipeline.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/sharp.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/stats.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/stats.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
package/src/utilities.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -133,7 +133,7 @@ Napi::Value format(const Napi::CallbackInfo& info) {
133
133
  input.Set("file", hasInputFile);
134
134
  input.Set("buffer", hasInputBuffer);
135
135
  input.Set("stream", hasInputBuffer);
136
- if (hasInputFile) {
136
+ if (oc) {
137
137
  const VipsForeignClass *fc = VIPS_FOREIGN_CLASS(oc);
138
138
  if (fc->suffs) {
139
139
  Napi::Array fileSuffix = Napi::Array::New(env);
package/src/utilities.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Copyright 2013 Lovell Fuller and others.
2
+ SPDX-FileCopyrightText: 2013 Lovell Fuller and others
3
3
  SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5