@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depup/sharp",
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.5-depup.0",
3
+ "description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images (with updated dependencies)",
4
+ "version": "0.35.4-depup.0",
5
5
  "author": "Lovell Fuller <npm@lovell.info>",
6
6
  "homepage": "https://sharp.pixelplumbing.com",
7
7
  "contributors": [
@@ -89,38 +89,65 @@
89
89
  "Lachlan Newman <lachnewman007@gmail.com>",
90
90
  "Dennis Beatty <dennis@dcbeatty.com>",
91
91
  "Ingvar Stepanyan <me@rreverser.com>",
92
- "Don Denton <don@happycollision.com>"
92
+ "Don Denton <don@happycollision.com>",
93
+ "Dmytro Tiapukhin <cool.gegeg@gmail.com>",
94
+ "Florian Lefebvre <contact@florian-lefebvre.dev>"
93
95
  ],
94
96
  "scripts": {
95
97
  "build": "node install/build.js",
96
- "install": "node install/check.js || npm run build",
97
- "clean": "rm -rf src/build/ .nyc_output/ coverage/ test/fixtures/output.*",
98
+ "build:dist": "node scripts/build.mjs",
99
+ "clean": "rm -rf src/build/ test/fixtures/output.*",
98
100
  "test": "npm run lint && npm run test-unit",
99
- "lint": "npm run lint-cpp && npm run lint-js && npm run lint-types",
101
+ "lint": "npm run lint-cpp && npm run lint-js && npm run lint-types && npm run lint-publish",
100
102
  "lint-cpp": "cpplint --quiet src/*.h src/*.cc",
101
103
  "lint-js": "biome lint",
102
- "lint-types": "tsd --files ./test/types/sharp.test-d.ts",
104
+ "lint-publish": "publint --strict",
105
+ "lint-types": "tsd --files ./test/types/sharp.test-d.{cts,mts}",
103
106
  "test-leak": "./test/leak/leak.sh",
104
107
  "test-unit": "node --experimental-test-coverage test/unit.mjs",
105
108
  "package-from-local-build": "node npm/from-local-build.js",
109
+ "package-wasm-wrappers": "node npm/wasm-wrappers.js",
106
110
  "package-release-notes": "node npm/release-notes.js",
107
111
  "docs-build": "node docs/build.mjs",
108
112
  "docs-serve": "cd docs && npm start",
109
113
  "docs-publish": "cd docs && npm run build && npx firebase-tools deploy --project pixelplumbing --only hosting:pixelplumbing-sharp"
110
114
  },
111
115
  "type": "commonjs",
112
- "main": "lib/index.js",
113
- "types": "lib/index.d.ts",
114
116
  "files": [
117
+ "dist",
115
118
  "install",
116
- "lib",
117
- "src/*.{cc,h,gyp}"
119
+ "lib/index.d.ts",
120
+ "src/*.{cc,h,gyp}",
121
+ "changes.json",
122
+ "README.md"
118
123
  ],
124
+ "main": "./dist/index.cjs",
125
+ "module": "./dist/index.mjs",
126
+ "types": "./dist/index.d.mts",
127
+ "exports": {
128
+ ".": {
129
+ "import": {
130
+ "types": "./dist/index.d.mts",
131
+ "default": "./dist/index.mjs"
132
+ },
133
+ "require": {
134
+ "types": "./dist/index.d.cts",
135
+ "default": "./dist/index.cjs"
136
+ }
137
+ }
138
+ },
139
+ "sideEffects": true,
119
140
  "repository": {
120
141
  "type": "git",
121
- "url": "git://github.com/lovell/sharp.git"
142
+ "url": "git+https://github.com/lovell/sharp.git"
122
143
  },
123
144
  "keywords": [
145
+ "sharp",
146
+ "depup",
147
+ "updated-dependencies",
148
+ "security",
149
+ "latest",
150
+ "patched",
124
151
  "jpeg",
125
152
  "png",
126
153
  "webp",
@@ -141,62 +168,76 @@
141
168
  "dependencies": {
142
169
  "@img/colour": "^1.1.0",
143
170
  "detect-libc": "^2.1.2",
144
- "semver": "^7.7.4"
171
+ "semver": "^7.8.5"
145
172
  },
146
173
  "optionalDependencies": {
147
- "@img/sharp-darwin-arm64": "0.34.5",
148
- "@img/sharp-darwin-x64": "0.34.5",
149
- "@img/sharp-libvips-darwin-arm64": "1.2.4",
150
- "@img/sharp-libvips-darwin-x64": "1.2.4",
151
- "@img/sharp-libvips-linux-arm": "1.2.4",
152
- "@img/sharp-libvips-linux-arm64": "1.2.4",
153
- "@img/sharp-libvips-linux-ppc64": "1.2.4",
154
- "@img/sharp-libvips-linux-riscv64": "1.2.4",
155
- "@img/sharp-libvips-linux-s390x": "1.2.4",
156
- "@img/sharp-libvips-linux-x64": "1.2.4",
157
- "@img/sharp-libvips-linuxmusl-arm64": "1.2.4",
158
- "@img/sharp-libvips-linuxmusl-x64": "1.2.4",
159
- "@img/sharp-linux-arm": "0.34.5",
160
- "@img/sharp-linux-arm64": "0.34.5",
161
- "@img/sharp-linux-ppc64": "0.34.5",
162
- "@img/sharp-linux-riscv64": "0.34.5",
163
- "@img/sharp-linux-s390x": "0.34.5",
164
- "@img/sharp-linux-x64": "0.34.5",
165
- "@img/sharp-linuxmusl-arm64": "0.34.5",
166
- "@img/sharp-linuxmusl-x64": "0.34.5",
167
- "@img/sharp-wasm32": "0.34.5",
168
- "@img/sharp-win32-arm64": "0.34.5",
169
- "@img/sharp-win32-ia32": "0.34.5",
170
- "@img/sharp-win32-x64": "0.34.5"
174
+ "@img/sharp-darwin-arm64": "0.35.4",
175
+ "@img/sharp-darwin-x64": "0.35.4",
176
+ "@img/sharp-freebsd-wasm32": "0.35.4",
177
+ "@img/sharp-libvips-darwin-arm64": "1.3.3",
178
+ "@img/sharp-libvips-darwin-x64": "1.3.3",
179
+ "@img/sharp-libvips-linux-arm": "1.3.3",
180
+ "@img/sharp-libvips-linux-arm64": "1.3.3",
181
+ "@img/sharp-libvips-linux-ppc64": "1.3.3",
182
+ "@img/sharp-libvips-linux-riscv64": "1.3.3",
183
+ "@img/sharp-libvips-linux-s390x": "1.3.3",
184
+ "@img/sharp-libvips-linux-x64": "1.3.3",
185
+ "@img/sharp-libvips-linuxmusl-arm64": "1.3.3",
186
+ "@img/sharp-libvips-linuxmusl-x64": "1.3.3",
187
+ "@img/sharp-linux-arm": "0.35.4",
188
+ "@img/sharp-linux-arm64": "0.35.4",
189
+ "@img/sharp-linux-ppc64": "0.35.4",
190
+ "@img/sharp-linux-riscv64": "0.35.4",
191
+ "@img/sharp-linux-s390x": "0.35.4",
192
+ "@img/sharp-linux-x64": "0.35.4",
193
+ "@img/sharp-linuxmusl-arm64": "0.35.4",
194
+ "@img/sharp-linuxmusl-x64": "0.35.4",
195
+ "@img/sharp-webcontainers-wasm32": "0.35.4",
196
+ "@img/sharp-win32-arm64": "0.35.4",
197
+ "@img/sharp-win32-ia32": "0.35.4",
198
+ "@img/sharp-win32-x64": "0.35.4"
199
+ },
200
+ "peerDependenciesMeta": {
201
+ "@types/node": {
202
+ "optional": true
203
+ }
171
204
  },
172
205
  "devDependencies": {
173
- "@biomejs/biome": "^2.3.4",
206
+ "@biomejs/biome": "^2.5.10",
174
207
  "@cpplint/cli": "^0.1.0",
175
- "@emnapi/runtime": "^1.7.0",
176
- "@img/sharp-libvips-dev": "1.2.4",
177
- "@img/sharp-libvips-dev-wasm32": "1.2.4",
178
- "@img/sharp-libvips-win32-arm64": "1.2.4",
179
- "@img/sharp-libvips-win32-ia32": "1.2.4",
180
- "@img/sharp-libvips-win32-x64": "1.2.4",
208
+ "@emnapi/runtime": "^1.11.3",
209
+ "@img/sharp-libvips-dev": "1.3.3",
210
+ "@img/sharp-libvips-dev-wasm32": "1.3.3",
211
+ "@img/sharp-libvips-win32-arm64": "1.3.3",
212
+ "@img/sharp-libvips-win32-ia32": "1.3.3",
213
+ "@img/sharp-libvips-win32-x64": "1.3.3",
181
214
  "@types/node": "*",
182
- "emnapi": "^1.7.0",
183
- "exif-reader": "^2.0.2",
184
- "extract-zip": "^2.0.1",
185
- "icc": "^3.0.0",
186
- "jsdoc-to-markdown": "^9.1.3",
187
- "node-addon-api": "^8.5.0",
188
- "node-gyp": "^11.5.0",
189
- "tar-fs": "^3.1.1",
215
+ "emnapi": "^1.11.3",
216
+ "exif-reader": "^2.0.3",
217
+ "yauzl": "^3.4.0",
218
+ "icc": "^4.0.0",
219
+ "node-addon-api": "^8.9.2",
220
+ "node-gyp": "^12.4.0",
221
+ "publint": "^0.3.24",
222
+ "tar-fs": "^3.1.3",
190
223
  "tsd": "^0.33.0"
191
224
  },
192
225
  "license": "Apache-2.0",
193
226
  "engines": {
194
- "node": "^18.17.0 || ^20.3.0 || >=21.0.0"
227
+ "node": ">=20.9.0"
195
228
  },
196
229
  "config": {
197
- "libvips": ">=8.17.3"
230
+ "libvips": ">=8.18.6"
198
231
  },
199
232
  "funding": {
200
233
  "url": "https://opencollective.com/libvips"
234
+ },
235
+ "depup": {
236
+ "changes": {},
237
+ "depsUpdated": 0,
238
+ "originalPackage": "sharp",
239
+ "originalVersion": "0.35.4",
240
+ "processedAt": "2026-08-30T00:59:02.521Z",
241
+ "smokeTest": "passed"
201
242
  }
202
243
  }
package/src/binding.gyp CHANGED
@@ -3,13 +3,14 @@
3
3
 
4
4
  {
5
5
  'variables': {
6
- 'vips_version': '<!(node -p "require(\'../lib/libvips\').minimumLibvipsVersion")',
7
- 'platform_and_arch': '<!(node -p "require(\'../lib/libvips\').buildPlatformArch()")',
6
+ 'vips_version': '<!(node -p "require(\'../dist/libvips.cjs\').minimumLibvipsVersion")',
7
+ 'platform_and_arch': '<!(node -p "require(\'../dist/libvips.cjs\').buildPlatformArch()")',
8
+ 'sharp_version': '<!(node -p "require(\'../package.json\').version")',
8
9
  'sharp_libvips_version': '<!(node -p "require(\'../package.json\').optionalDependencies[\'@img/sharp-libvips-<(platform_and_arch)\']")',
9
- 'sharp_libvips_yarn_locator': '<!(node -p "require(\'../lib/libvips\').yarnLocator()")',
10
- 'sharp_libvips_include_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsIncludeDir()")',
11
- 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
12
- 'sharp_libvips_lib_dir': '<!(node -p "require(\'../lib/libvips\').buildSharpLibvipsLibDir()")'
10
+ 'sharp_libvips_yarn_locator': '<!(node -p "require(\'../dist/libvips.cjs\').yarnLocator()")',
11
+ 'sharp_libvips_include_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsIncludeDir()")',
12
+ 'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsCPlusPlusDir()")',
13
+ 'sharp_libvips_lib_dir': '<!(node -p "require(\'../dist/libvips.cjs\').buildSharpLibvipsLibDir()")'
13
14
  },
14
15
  'targets': [{
15
16
  'target_name': 'libvips-cpp-<(vips_version)',
@@ -20,6 +21,7 @@
20
21
  'defines': [
21
22
  '_VIPS_PUBLIC=__declspec(dllexport)',
22
23
  '_ALLOW_KEYWORD_MACROS',
24
+ '_HAS_EXCEPTIONS=1',
23
25
  'G_DISABLE_ASSERT',
24
26
  'G_DISABLE_CAST_CHECKS',
25
27
  'G_DISABLE_CHECKS'
@@ -81,7 +83,7 @@
81
83
  }]
82
84
  ]
83
85
  }, {
84
- 'target_name': 'sharp-<(platform_and_arch)',
86
+ 'target_name': 'sharp-<(platform_and_arch)-<(sharp_version)',
85
87
  'defines': [
86
88
  'G_DISABLE_ASSERT',
87
89
  'G_DISABLE_CAST_CHECKS',
@@ -97,8 +99,8 @@
97
99
  'variables': {
98
100
  'conditions': [
99
101
  ['OS != "win"', {
100
- 'pkg_config_path': '<!(node -p "require(\'../lib/libvips\').pkgConfigPath()")',
101
- 'use_global_libvips': '<!(node -p "Boolean(require(\'../lib/libvips\').useGlobalLibvips()).toString()")'
102
+ 'pkg_config_path': '<!(node -p "require(\'../dist/libvips.cjs\').pkgConfigPath()")',
103
+ 'use_global_libvips': '<!(node -p "Boolean(require(\'../dist/libvips.cjs\').useGlobalLibvips()).toString()")'
102
104
  }, {
103
105
  'pkg_config_path': '',
104
106
  'use_global_libvips': ''
@@ -120,7 +122,7 @@
120
122
  'conditions': [
121
123
  ['use_global_libvips == "true"', {
122
124
  # Use pkg-config for include and lib
123
- 'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
125
+ 'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s/-I//g)'],
124
126
  'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)'],
125
127
  'defines': [
126
128
  'SHARP_USE_GLOBAL_LIBVIPS'
@@ -147,7 +149,8 @@
147
149
  ['OS == "win"', {
148
150
  'defines': [
149
151
  '_ALLOW_KEYWORD_MACROS',
150
- '_FILE_OFFSET_BITS=64'
152
+ '_FILE_OFFSET_BITS=64',
153
+ '_HAS_EXCEPTIONS=1'
151
154
  ],
152
155
  'link_settings': {
153
156
  'libraries': [
@@ -202,14 +205,16 @@
202
205
  }],
203
206
  ['OS == "emscripten"', {
204
207
  'product_extension': 'node.js',
208
+ 'cflags_cc': [
209
+ '-fwasm-exceptions'
210
+ ],
205
211
  'link_settings': {
206
212
  'ldflags': [
207
- '-fexceptions',
213
+ '-fwasm-exceptions',
208
214
  '--pre-js=<!(node -p "require.resolve(\'./emscripten/pre.js\')")',
209
215
  '-Oz',
210
216
  '-sALLOW_MEMORY_GROWTH',
211
217
  '-sENVIRONMENT=node',
212
- '-sEXPORTED_FUNCTIONS=emnapiInit,_vips_shutdown,_uv_library_shutdown',
213
218
  '-sNODERAWFS',
214
219
  '-sWASM_ASYNC_COMPILATION=0'
215
220
  ],
@@ -282,7 +287,7 @@
282
287
  'target_name': 'copy-dll',
283
288
  'type': 'none',
284
289
  'dependencies': [
285
- 'sharp-<(platform_and_arch)'
290
+ 'sharp-<(platform_and_arch)-<(sharp_version)'
286
291
  ],
287
292
  'conditions': [
288
293
  ['OS == "win"', {
package/src/common.cc CHANGED
@@ -118,7 +118,7 @@ namespace sharp {
118
118
  descriptor->openSlideLevel = AttrAsUint32(input, "openSlideLevel");
119
119
  }
120
120
  // subIFD (OME-TIFF)
121
- if (HasAttr(input, "subifd")) {
121
+ if (HasAttr(input, "tiffSubifd")) {
122
122
  descriptor->tiffSubifd = AttrAsInt32(input, "tiffSubifd");
123
123
  }
124
124
  // // PDF background color
@@ -196,8 +196,8 @@ namespace sharp {
196
196
  if (HasAttr(input, "joinValign")) {
197
197
  descriptor->joinValign = AttrAsEnum<VipsAlign>(input, "joinValign", VIPS_TYPE_ALIGN);
198
198
  }
199
- // Limit input images to a given number of pixels, where pixels = width * height
200
199
  descriptor->limitInputPixels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputPixels"));
200
+ descriptor->limitInputChannels = static_cast<uint64_t>(AttrAsInt64(input, "limitInputChannels"));
201
201
  if (HasAttr(input, "access")) {
202
202
  descriptor->access = AttrAsBool(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
203
203
  }
@@ -289,6 +289,7 @@ namespace sharp {
289
289
  case ImageType::JXL: id = "jxl"; break;
290
290
  case ImageType::RAD: id = "rad"; break;
291
291
  case ImageType::DCRAW: id = "dcraw"; break;
292
+ case ImageType::UHDR: id = "uhdr"; break;
292
293
  case ImageType::VIPS: id = "vips"; break;
293
294
  case ImageType::RAW: id = "raw"; break;
294
295
  case ImageType::UNKNOWN: id = "unknown"; break;
@@ -339,6 +340,9 @@ namespace sharp {
339
340
  { "VipsForeignLoadRadBuffer", ImageType::RAD },
340
341
  { "VipsForeignLoadDcRawFile", ImageType::DCRAW },
341
342
  { "VipsForeignLoadDcRawBuffer", ImageType::DCRAW },
343
+ { "VipsForeignLoadUhdr", ImageType::UHDR },
344
+ { "VipsForeignLoadUhdrFile", ImageType::UHDR },
345
+ { "VipsForeignLoadUhdrBuffer", ImageType::UHDR },
342
346
  { "VipsForeignLoadVips", ImageType::VIPS },
343
347
  { "VipsForeignLoadVipsFile", ImageType::VIPS },
344
348
  { "VipsForeignLoadRaw", ImageType::RAW }
@@ -356,6 +360,9 @@ namespace sharp {
356
360
  imageType = it->second;
357
361
  }
358
362
  }
363
+ if (imageType == ImageType::UHDR) {
364
+ imageType = ImageType::JPEG;
365
+ }
359
366
  return imageType;
360
367
  }
361
368
 
@@ -375,6 +382,9 @@ namespace sharp {
375
382
  imageType = ImageType::MISSING;
376
383
  }
377
384
  }
385
+ if (imageType == ImageType::UHDR) {
386
+ imageType = ImageType::JPEG;
387
+ }
378
388
  return imageType;
379
389
  }
380
390
 
@@ -416,7 +426,7 @@ namespace sharp {
416
426
  }
417
427
  if (ImageTypeSupportsPage(imageType)) {
418
428
  option->set("n", descriptor->pages);
419
- option->set("page", descriptor->page);
429
+ option->set("page", std::max(0, descriptor->page));
420
430
  }
421
431
  switch (imageType) {
422
432
  case ImageType::SVG:
@@ -446,6 +456,22 @@ namespace sharp {
446
456
  return option;
447
457
  }
448
458
 
459
+ /*
460
+ Should HEIF image be re-opened using the primary item?
461
+ */
462
+ static bool HeifPrimaryPageReopen(VImage image, InputDescriptor *descriptor) {
463
+ if (image.get_typeof(VIPS_META_N_PAGES) == G_TYPE_INT && image.get_typeof("heif-primary") == G_TYPE_INT) {
464
+ if (image.get_int(VIPS_META_N_PAGES) > 1 && descriptor->pages == 1 && descriptor->page == -1) {
465
+ int const pagePrimary = image.get_int("heif-primary");
466
+ if (pagePrimary != 0) {
467
+ descriptor->page = pagePrimary;
468
+ return true;
469
+ }
470
+ }
471
+ }
472
+ return false;
473
+ }
474
+
449
475
  /*
450
476
  Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
451
477
  */
@@ -480,12 +506,15 @@ namespace sharp {
480
506
  image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
481
507
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
482
508
  image = SetDensity(image, descriptor->density);
509
+ } else if (imageType == ImageType::HEIF && HeifPrimaryPageReopen(image, descriptor)) {
510
+ option = GetOptionsForImageType(imageType, descriptor);
511
+ image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
483
512
  }
484
- } catch (vips::VError const &err) {
485
- throw vips::VError(std::string("Input buffer has corrupt header: ") + err.what());
513
+ } catch (std::runtime_error const &err) {
514
+ throw std::runtime_error(std::string("Input buffer has corrupt header: ") + err.what());
486
515
  }
487
516
  } else {
488
- throw vips::VError("Input buffer contains unsupported image format");
517
+ throw std::runtime_error("Input buffer contains unsupported image format");
489
518
  }
490
519
  }
491
520
  } else {
@@ -556,10 +585,10 @@ namespace sharp {
556
585
  imageType = DetermineImageType(descriptor->file.data());
557
586
  if (imageType == ImageType::MISSING) {
558
587
  if (descriptor->file.find("<svg") != std::string::npos) {
559
- throw vips::VError("Input file is missing, did you mean "
588
+ throw std::runtime_error("Input file is missing, did you mean "
560
589
  "sharp(Buffer.from('" + descriptor->file.substr(0, 8) + "...')?");
561
590
  }
562
- throw vips::VError("Input file is missing: " + descriptor->file);
591
+ throw std::runtime_error("Input file is missing: " + descriptor->file);
563
592
  }
564
593
  if (imageType != ImageType::UNKNOWN) {
565
594
  try {
@@ -567,12 +596,15 @@ namespace sharp {
567
596
  image = VImage::new_from_file(descriptor->file.data(), option);
568
597
  if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
569
598
  image = SetDensity(image, descriptor->density);
599
+ } else if (imageType == ImageType::HEIF && HeifPrimaryPageReopen(image, descriptor)) {
600
+ option = GetOptionsForImageType(imageType, descriptor);
601
+ image = VImage::new_from_file(descriptor->file.data(), option);
570
602
  }
571
- } catch (vips::VError const &err) {
572
- throw vips::VError(std::string("Input file has corrupt header: ") + err.what());
603
+ } catch (std::runtime_error const &err) {
604
+ throw std::runtime_error(std::string("Input file has corrupt header: ") + err.what());
573
605
  }
574
606
  } else {
575
- throw vips::VError("Input file contains unsupported image format");
607
+ throw std::runtime_error("Input file contains unsupported image format");
576
608
  }
577
609
  }
578
610
  }
@@ -580,7 +612,10 @@ namespace sharp {
580
612
  // Limit input images to a given number of pixels, where pixels = width * height
581
613
  if (descriptor->limitInputPixels > 0 &&
582
614
  static_cast<uint64_t>(image.width()) * image.height() > descriptor->limitInputPixels) {
583
- throw vips::VError("Input image exceeds pixel limit");
615
+ throw std::runtime_error("Input image exceeds pixel limit");
616
+ }
617
+ if (descriptor->limitInputChannels > 0 && static_cast<uint64_t>(image.bands()) > descriptor->limitInputChannels) {
618
+ throw std::runtime_error("Input image exceeds channel limit");
584
619
  }
585
620
  return std::make_tuple(image, imageType);
586
621
  }
@@ -600,7 +635,7 @@ namespace sharp {
600
635
  if (HasProfile(image)) {
601
636
  size_t length;
602
637
  const void *data = image.get_blob(VIPS_META_ICC_NAME, &length);
603
- icc.first = static_cast<char*>(g_malloc(length));
638
+ icc.first = static_cast<char*>(vips_malloc(reinterpret_cast<VipsObject*>(image.get_image()), length));
604
639
  icc.second = length;
605
640
  memcpy(icc.first, data, length);
606
641
  }
@@ -613,7 +648,7 @@ namespace sharp {
613
648
  VImage SetProfile(VImage image, std::pair<char*, size_t> icc) {
614
649
  if (icc.first != nullptr) {
615
650
  image = image.copy();
616
- image.set(VIPS_META_ICC_NAME, reinterpret_cast<VipsCallbackFn>(vips_area_free_cb), icc.first, icc.second);
651
+ image.set(VIPS_META_ICC_NAME, nullptr, icc.first, icc.second);
617
652
  }
618
653
  return image;
619
654
  }
@@ -676,9 +711,12 @@ namespace sharp {
676
711
  bool hasDelay = !delay.empty();
677
712
  VImage copy = image.copy();
678
713
 
679
- // Only set page-height if we have more than one page, or this could
680
- // accidentally turn into an animated image later.
681
- if (nPages > 1) copy.set(VIPS_META_PAGE_HEIGHT, pageHeight);
714
+ // Only set page-height and n-pages if we have more than one page, or this
715
+ // could accidentally turn into an animated image later.
716
+ if (nPages > 1) {
717
+ copy.set(VIPS_META_PAGE_HEIGHT, pageHeight);
718
+ copy.set(VIPS_META_N_PAGES, nPages);
719
+ }
682
720
  if (hasDelay) {
683
721
  if (delay.size() == 1) {
684
722
  // We have just one delay, repeat that value for all frames.
@@ -756,19 +794,19 @@ namespace sharp {
756
794
  : image.height();
757
795
  if (imageType == ImageType::JPEG) {
758
796
  if (image.width() > 65535 || height > 65535) {
759
- throw vips::VError("Processed image is too large for the JPEG format");
797
+ throw std::runtime_error("Processed image is too large for the JPEG format");
760
798
  }
761
799
  } else if (imageType == ImageType::WEBP) {
762
800
  if (image.width() > 16383 || height > 16383) {
763
- throw vips::VError("Processed image is too large for the WebP format");
801
+ throw std::runtime_error("Processed image is too large for the WebP format");
764
802
  }
765
803
  } else if (imageType == ImageType::GIF) {
766
804
  if (image.width() > 65535 || height > 65535) {
767
- throw vips::VError("Processed image is too large for the GIF format");
805
+ throw std::runtime_error("Processed image is too large for the GIF format");
768
806
  }
769
807
  } else if (imageType == ImageType::HEIF) {
770
808
  if (image.width() > 16384 || height > 16384) {
771
- throw vips::VError("Processed image is too large for the HEIF format");
809
+ throw std::runtime_error("Processed image is too large for the HEIF format");
772
810
  }
773
811
  }
774
812
  }
@@ -1127,4 +1165,22 @@ namespace sharp {
1127
1165
  }
1128
1166
  return image;
1129
1167
  }
1168
+
1169
+ /*
1170
+ Does this image have a gain map?
1171
+ */
1172
+ bool HasGainMap(VImage image) {
1173
+ return image.get_typeof("gainmap") == VIPS_TYPE_BLOB ||
1174
+ image.get_typeof("gainmap-data") == VIPS_TYPE_BLOB;
1175
+ }
1176
+
1177
+ /*
1178
+ Removes gain map, if any.
1179
+ */
1180
+ VImage RemoveGainMap(VImage image) {
1181
+ VImage copy = image.copy();
1182
+ copy.remove("gainmap");
1183
+ copy.remove("gainmap-data");
1184
+ return copy;
1185
+ }
1130
1186
  } // namespace sharp
package/src/common.h CHANGED
@@ -18,9 +18,9 @@
18
18
  // Verify platform and compiler compatibility
19
19
 
20
20
  #if (VIPS_MAJOR_VERSION < 8) || \
21
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 17) || \
22
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 17 && VIPS_MICRO_VERSION < 3)
23
- #error "libvips version 8.17.3+ is required - please see https://sharp.pixelplumbing.com/install"
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"
24
24
  #endif
25
25
 
26
26
  #if defined(__has_include)
@@ -29,6 +29,12 @@
29
29
  #endif
30
30
  #endif
31
31
 
32
+ #ifdef __EMSCRIPTEN__
33
+ #define SHARP_CALLBACK_FN_NAME Call
34
+ #else
35
+ #define SHARP_CALLBACK_FN_NAME MakeCallback
36
+ #endif
37
+
32
38
  using vips::VImage;
33
39
 
34
40
  namespace sharp {
@@ -40,6 +46,7 @@ namespace sharp {
40
46
  char *buffer;
41
47
  VipsFailOn failOn;
42
48
  uint64_t limitInputPixels;
49
+ uint64_t limitInputChannels;
43
50
  bool unlimited;
44
51
  VipsAccess access;
45
52
  size_t bufferLength;
@@ -92,6 +99,7 @@ namespace sharp {
92
99
  buffer(nullptr),
93
100
  failOn(VIPS_FAIL_ON_WARNING),
94
101
  limitInputPixels(0x3FFF * 0x3FFF),
102
+ limitInputChannels(5),
95
103
  unlimited(false),
96
104
  access(VIPS_ACCESS_SEQUENTIAL),
97
105
  bufferLength(0),
@@ -105,7 +113,7 @@ namespace sharp {
105
113
  rawPremultiplied(false),
106
114
  rawPageHeight(0),
107
115
  pages(1),
108
- page(0),
116
+ page(-1),
109
117
  createChannels(0),
110
118
  createWidth(0),
111
119
  createHeight(0),
@@ -173,6 +181,7 @@ namespace sharp {
173
181
  JXL,
174
182
  RAD,
175
183
  DCRAW,
184
+ UHDR,
176
185
  VIPS,
177
186
  RAW,
178
187
  UNKNOWN,
@@ -397,6 +406,16 @@ namespace sharp {
397
406
  */
398
407
  VImage StaySequential(VImage image, bool condition = true);
399
408
 
409
+ /*
410
+ Does this image have a gain map?
411
+ */
412
+ bool HasGainMap(VImage image);
413
+
414
+ /*
415
+ Removes gain map, if any.
416
+ */
417
+ VImage RemoveGainMap(VImage image);
418
+
400
419
  } // namespace sharp
401
420
 
402
421
  #endif // SRC_COMMON_H_