sharp 0.34.2-rc.0 → 0.34.3-rc.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.
@@ -156,6 +156,7 @@ const debuglog = util.debuglog('sharp');
156
156
  * @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
157
157
  * @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
158
158
  * @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
159
+ * @param {boolean} [options.jp2Oneshot=false] - Set to `true` to decode tiled JPEG 2000 images in a single operation, improving compatibility.
159
160
  * @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
160
161
  * @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
161
162
  * @param {number} [options.raw.width] - integral number of pixels wide.
package/lib/index.d.ts CHANGED
@@ -1009,6 +1009,8 @@ declare namespace sharp {
1009
1009
  level?: number | undefined;
1010
1010
  /** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
1011
1011
  pdfBackground?: Colour | Color | undefined;
1012
+ /** Set to `true` to load JPEG 2000 images using [oneshot mode](https://github.com/libvips/libvips/issues/4205) */
1013
+ jp2Oneshot?: boolean | undefined;
1012
1014
  /** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
1013
1015
  animated?: boolean | undefined;
1014
1016
  /** Describes raw pixel input image data. See raw() for pixel ordering. */
package/lib/input.js CHANGED
@@ -27,9 +27,9 @@ const align = {
27
27
  * @private
28
28
  */
29
29
  function _inputOptionsFromObject (obj) {
30
- const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient } = obj;
31
- return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient].some(is.defined)
32
- ? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient }
30
+ const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot } = obj;
31
+ return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot].some(is.defined)
32
+ ? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot }
33
33
  : undefined;
34
34
  }
35
35
 
@@ -250,6 +250,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
250
250
  if (is.defined(inputOptions.pdfBackground)) {
251
251
  inputDescriptor.pdfBackground = this._getBackgroundColourOption(inputOptions.pdfBackground);
252
252
  }
253
+ // JP2 oneshot
254
+ if (is.defined(inputOptions.jp2Oneshot)) {
255
+ if (is.bool(inputOptions.jp2Oneshot)) {
256
+ inputDescriptor.jp2Oneshot = inputOptions.jp2Oneshot;
257
+ } else {
258
+ throw is.invalidParameterError('jp2Oneshot', 'boolean', inputOptions.jp2Oneshot);
259
+ }
260
+ }
253
261
  // Create new image
254
262
  if (is.defined(inputOptions.create)) {
255
263
  if (
package/lib/output.js CHANGED
@@ -1019,6 +1019,9 @@ function tiff (options) {
1019
1019
  * AVIF image sequences are not supported.
1020
1020
  * Prebuilt binaries support a bitdepth of 8 only.
1021
1021
  *
1022
+ * This feature is experimental on the Windows ARM64 platform
1023
+ * and requires a CPU with ARM64v8.4 or later.
1024
+ *
1022
1025
  * @example
1023
1026
  * const data = await sharp(input)
1024
1027
  * .avif({ effort: 2 })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "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.34.2-rc.0",
4
+ "version": "0.34.3-rc.0",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -92,7 +92,7 @@
92
92
  "Don Denton <don@happycollision.com>"
93
93
  ],
94
94
  "scripts": {
95
- "install": "node install/check",
95
+ "install": "node install/check.js",
96
96
  "clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*",
97
97
  "test": "npm run test-lint && npm run test-unit && npm run test-licensing && npm run test-types",
98
98
  "test-lint": "semistandard && cpplint",
@@ -100,8 +100,7 @@
100
100
  "test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;LGPL-3.0-or-later;MIT\"",
101
101
  "test-leak": "./test/leak/leak.sh",
102
102
  "test-types": "tsd",
103
- "package-from-local-build": "node npm/from-local-build",
104
- "package-from-github-release": "node npm/from-github-release",
103
+ "package-from-local-build": "node npm/from-local-build.js",
105
104
  "docs-build": "node docs/build.mjs",
106
105
  "docs-serve": "cd docs && npm start",
107
106
  "docs-publish": "cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
@@ -142,35 +141,36 @@
142
141
  "semver": "^7.7.2"
143
142
  },
144
143
  "optionalDependencies": {
145
- "@img/sharp-darwin-arm64": "0.34.2-rc.0",
146
- "@img/sharp-darwin-x64": "0.34.2-rc.0",
147
- "@img/sharp-libvips-darwin-arm64": "1.1.0",
148
- "@img/sharp-libvips-darwin-x64": "1.1.0",
149
- "@img/sharp-libvips-linux-arm": "1.1.0",
150
- "@img/sharp-libvips-linux-arm64": "1.1.0",
151
- "@img/sharp-libvips-linux-ppc64": "1.1.0",
152
- "@img/sharp-libvips-linux-s390x": "1.1.0",
153
- "@img/sharp-libvips-linux-x64": "1.1.0",
154
- "@img/sharp-libvips-linuxmusl-arm64": "1.1.0",
155
- "@img/sharp-libvips-linuxmusl-x64": "1.1.0",
156
- "@img/sharp-linux-arm": "0.34.2-rc.0",
157
- "@img/sharp-linux-arm64": "0.34.2-rc.0",
158
- "@img/sharp-linux-s390x": "0.34.2-rc.0",
159
- "@img/sharp-linux-x64": "0.34.2-rc.0",
160
- "@img/sharp-linuxmusl-arm64": "0.34.2-rc.0",
161
- "@img/sharp-linuxmusl-x64": "0.34.2-rc.0",
162
- "@img/sharp-wasm32": "0.34.2-rc.0",
163
- "@img/sharp-win32-arm64": "0.34.2-rc.0",
164
- "@img/sharp-win32-ia32": "0.34.2-rc.0",
165
- "@img/sharp-win32-x64": "0.34.2-rc.0"
144
+ "@img/sharp-darwin-arm64": "0.34.3-rc.0",
145
+ "@img/sharp-darwin-x64": "0.34.3-rc.0",
146
+ "@img/sharp-libvips-darwin-arm64": "1.2.0-rc.2",
147
+ "@img/sharp-libvips-darwin-x64": "1.2.0-rc.2",
148
+ "@img/sharp-libvips-linux-arm": "1.2.0-rc.2",
149
+ "@img/sharp-libvips-linux-arm64": "1.2.0-rc.2",
150
+ "@img/sharp-libvips-linux-ppc64": "1.2.0-rc.2",
151
+ "@img/sharp-libvips-linux-s390x": "1.2.0-rc.2",
152
+ "@img/sharp-libvips-linux-x64": "1.2.0-rc.2",
153
+ "@img/sharp-libvips-linuxmusl-arm64": "1.2.0-rc.2",
154
+ "@img/sharp-libvips-linuxmusl-x64": "1.2.0-rc.2",
155
+ "@img/sharp-linux-arm": "0.34.3-rc.0",
156
+ "@img/sharp-linux-arm64": "0.34.3-rc.0",
157
+ "@img/sharp-linux-ppc64": "0.34.3-rc.0",
158
+ "@img/sharp-linux-s390x": "0.34.3-rc.0",
159
+ "@img/sharp-linux-x64": "0.34.3-rc.0",
160
+ "@img/sharp-linuxmusl-arm64": "0.34.3-rc.0",
161
+ "@img/sharp-linuxmusl-x64": "0.34.3-rc.0",
162
+ "@img/sharp-wasm32": "0.34.3-rc.0",
163
+ "@img/sharp-win32-arm64": "0.34.3-rc.0",
164
+ "@img/sharp-win32-ia32": "0.34.3-rc.0",
165
+ "@img/sharp-win32-x64": "0.34.3-rc.0"
166
166
  },
167
167
  "devDependencies": {
168
168
  "@emnapi/runtime": "^1.4.3",
169
- "@img/sharp-libvips-dev": "1.1.0",
170
- "@img/sharp-libvips-dev-wasm32": "1.1.0",
171
- "@img/sharp-libvips-win32-arm64": "1.1.0",
172
- "@img/sharp-libvips-win32-ia32": "1.1.0",
173
- "@img/sharp-libvips-win32-x64": "1.1.0",
169
+ "@img/sharp-libvips-dev": "1.2.0-rc.2",
170
+ "@img/sharp-libvips-dev-wasm32": "1.2.0-rc.2",
171
+ "@img/sharp-libvips-win32-arm64": "1.2.0-rc.2",
172
+ "@img/sharp-libvips-win32-ia32": "1.2.0-rc.2",
173
+ "@img/sharp-libvips-win32-x64": "1.2.0-rc.2",
174
174
  "@types/node": "*",
175
175
  "cc": "^3.0.1",
176
176
  "emnapi": "^1.4.3",
@@ -179,12 +179,12 @@
179
179
  "icc": "^3.0.0",
180
180
  "jsdoc-to-markdown": "^9.1.1",
181
181
  "license-checker": "^25.0.1",
182
- "mocha": "^11.2.2",
182
+ "mocha": "^11.6.0",
183
183
  "node-addon-api": "^8.3.1",
184
+ "node-gyp": "^11.2.0",
184
185
  "nyc": "^17.1.0",
185
- "prebuild": "^13.0.1",
186
186
  "semistandard": "^17.0.0",
187
- "tar-fs": "^3.0.8",
187
+ "tar-fs": "^3.0.9",
188
188
  "tsd": "^0.32.0"
189
189
  },
190
190
  "license": "Apache-2.0",
@@ -192,16 +192,11 @@
192
192
  "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
193
193
  },
194
194
  "config": {
195
- "libvips": ">=8.16.1"
195
+ "libvips": ">=8.17.0"
196
196
  },
197
197
  "funding": {
198
198
  "url": "https://opencollective.com/libvips"
199
199
  },
200
- "binary": {
201
- "napi_versions": [
202
- 9
203
- ]
204
- },
205
200
  "semistandard": {
206
201
  "env": [
207
202
  "mocha"
package/src/binding.gyp CHANGED
@@ -163,6 +163,8 @@
163
163
  },
164
164
  'xcode_settings': {
165
165
  'OTHER_LDFLAGS': [
166
+ '-Wl,-s',
167
+ '-Wl,-dead_strip',
166
168
  # Ensure runtime linking is relative to sharp.node
167
169
  '-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'',
168
170
  '-Wl,-rpath,\'@loader_path/../../../sharp-libvips-<(platform_and_arch)/<(sharp_libvips_version)/lib\'',
@@ -176,6 +178,9 @@
176
178
  'defines': [
177
179
  '_GLIBCXX_USE_CXX11_ABI=1'
178
180
  ],
181
+ 'cflags_cc': [
182
+ '<!(node -p "require(\'detect-libc\').isNonGlibcLinuxSync() ? \'\' : \'-flto=auto\'")'
183
+ ],
179
184
  'link_settings': {
180
185
  'libraries': [
181
186
  '-l:libvips-cpp.so.<(vips_version)'
package/src/common.cc CHANGED
@@ -113,6 +113,10 @@ namespace sharp {
113
113
  if (HasAttr(input, "pdfBackground")) {
114
114
  descriptor->pdfBackground = AttrAsVectorOfDouble(input, "pdfBackground");
115
115
  }
116
+ // Use JPEG 2000 oneshot mode?
117
+ if (HasAttr(input, "jp2Oneshot")) {
118
+ descriptor->jp2Oneshot = AttrAsBool(input, "jp2Oneshot");
119
+ }
116
120
  // Create new image
117
121
  if (HasAttr(input, "createChannels")) {
118
122
  descriptor->createChannels = AttrAsUint32(input, "createChannels");
@@ -434,6 +438,9 @@ namespace sharp {
434
438
  if (imageType == ImageType::PDF) {
435
439
  option->set("background", descriptor->pdfBackground);
436
440
  }
441
+ if (imageType == ImageType::JP2) {
442
+ option->set("oneshot", descriptor->jp2Oneshot);
443
+ }
437
444
  image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
438
445
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
439
446
  image = SetDensity(image, descriptor->density);
@@ -541,6 +548,9 @@ namespace sharp {
541
548
  if (imageType == ImageType::PDF) {
542
549
  option->set("background", descriptor->pdfBackground);
543
550
  }
551
+ if (imageType == ImageType::JP2) {
552
+ option->set("oneshot", descriptor->jp2Oneshot);
553
+ }
544
554
  image = VImage::new_from_file(descriptor->file.data(), option);
545
555
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
546
556
  image = SetDensity(image, descriptor->density);
package/src/common.h CHANGED
@@ -15,9 +15,9 @@
15
15
  // Verify platform and compiler compatibility
16
16
 
17
17
  #if (VIPS_MAJOR_VERSION < 8) || \
18
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 16) || \
19
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 16 && VIPS_MICRO_VERSION < 1)
20
- #error "libvips version 8.16.1+ is required - please see https://sharp.pixelplumbing.com/install"
18
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 17) || \
19
+ (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 17 && VIPS_MICRO_VERSION < 0)
20
+ #error "libvips version 8.17.0+ is required - please see https://sharp.pixelplumbing.com/install"
21
21
  #endif
22
22
 
23
23
  #if defined(__has_include)
@@ -78,6 +78,7 @@ namespace sharp {
78
78
  VipsAlign joinHalign;
79
79
  VipsAlign joinValign;
80
80
  std::vector<double> pdfBackground;
81
+ bool jp2Oneshot;
81
82
 
82
83
  InputDescriptor():
83
84
  autoOrient(false),
@@ -120,7 +121,8 @@ namespace sharp {
120
121
  joinBackground{ 0.0, 0.0, 0.0, 255.0 },
121
122
  joinHalign(VIPS_ALIGN_LOW),
122
123
  joinValign(VIPS_ALIGN_LOW),
123
- pdfBackground{ 255.0, 255.0, 255.0, 255.0 } {}
124
+ pdfBackground{ 255.0, 255.0, 255.0, 255.0 },
125
+ jp2Oneshot(false) {}
124
126
  };
125
127
 
126
128
  // Convenience methods to access the attributes of a Napi::Object
package/src/pipeline.cc CHANGED
@@ -294,6 +294,7 @@ class PipelineWorker : public Napi::AsyncWorker {
294
294
  option->set("n", baton->input->pages);
295
295
  option->set("page", baton->input->page);
296
296
  option->set("dpi", baton->input->density);
297
+ option->set("background", baton->input->pdfBackground);
297
298
 
298
299
  if (baton->input->buffer != nullptr) {
299
300
  // Reload PDF buffer
@@ -668,7 +669,6 @@ class PipelineWorker : public Napi::AsyncWorker {
668
669
  sharp::ImageType compositeImageType = sharp::ImageType::UNKNOWN;
669
670
  composite->input->access = access;
670
671
  std::tie(compositeImage, compositeImageType) = sharp::OpenInput(composite->input);
671
- compositeImage = sharp::EnsureColourspace(compositeImage, baton->colourspacePipeline);
672
672
 
673
673
  if (composite->input->autoOrient) {
674
674
  // Respect EXIF Orientation
@@ -733,8 +733,7 @@ class PipelineWorker : public Napi::AsyncWorker {
733
733
  // gravity was used for extract_area, set it back to its default value of 0
734
734
  composite->gravity = 0;
735
735
  }
736
- // Ensure image to composite is sRGB with unpremultiplied alpha
737
- compositeImage = compositeImage.colourspace(VIPS_INTERPRETATION_sRGB);
736
+ // Ensure image to composite is with unpremultiplied alpha
738
737
  compositeImage = sharp::EnsureAlpha(compositeImage, 1);
739
738
  if (composite->premultiplied) compositeImage = compositeImage.unpremultiply();
740
739
  // Calculate position
@@ -759,7 +758,12 @@ class PipelineWorker : public Napi::AsyncWorker {
759
758
  xs.push_back(left);
760
759
  ys.push_back(top);
761
760
  }
762
- image = VImage::composite(images, modes, VImage::option()->set("x", xs)->set("y", ys));
761
+ image = VImage::composite(images, modes, VImage::option()
762
+ ->set("compositing_space", baton->colourspacePipeline == VIPS_INTERPRETATION_LAST
763
+ ? VIPS_INTERPRETATION_sRGB
764
+ : baton->colourspacePipeline)
765
+ ->set("x", xs)
766
+ ->set("y", ys));
763
767
  image = sharp::RemoveGifPalette(image);
764
768
  }
765
769
 
package/src/sharp.cc CHANGED
@@ -18,8 +18,10 @@ Napi::Object init(Napi::Env env, Napi::Object exports) {
18
18
  vips_init("sharp");
19
19
  });
20
20
 
21
- g_log_set_handler("VIPS", static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING),
22
- static_cast<GLogFunc>(sharp::VipsWarningCallback), nullptr);
21
+ for (auto domain : { "VIPS", "vips2tiff" }) {
22
+ g_log_set_handler(domain, static_cast<GLogLevelFlags>(G_LOG_LEVEL_WARNING),
23
+ static_cast<GLogFunc>(sharp::VipsWarningCallback), nullptr);
24
+ }
23
25
 
24
26
  // Methods available to JavaScript
25
27
  exports.Set("metadata", Napi::Function::New(env, metadata));