sharp 0.35.5 → 0.35.6
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 +1 -1
- package/dist/channel.mjs +1 -1
- package/dist/colour.cjs +2 -2
- package/dist/colour.mjs +2 -2
- package/dist/composite.cjs +1 -1
- package/dist/composite.mjs +1 -1
- package/dist/constructor.cjs +3 -3
- package/dist/constructor.mjs +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.mts +10 -8
- package/dist/index.mjs +1 -1
- package/dist/input.cjs +9 -2
- package/dist/input.mjs +9 -2
- package/dist/is.cjs +2 -2
- package/dist/is.mjs +2 -2
- package/dist/libvips.cjs +1 -1
- package/dist/libvips.mjs +1 -1
- package/dist/operation.cjs +4 -4
- package/dist/operation.mjs +4 -4
- package/dist/output.cjs +39 -23
- package/dist/output.mjs +39 -23
- package/dist/resize.cjs +14 -10
- package/dist/resize.mjs +14 -10
- package/dist/sharp.cjs +1 -1
- package/dist/sharp.mjs +1 -1
- package/dist/utility.cjs +1 -1
- package/dist/utility.mjs +1 -1
- package/install/build.js +1 -1
- package/lib/index.d.ts +10 -8
- package/package.json +39 -37
- package/src/binding.gyp +1 -1
- package/src/common.cc +6 -22
- package/src/common.h +3 -13
- package/src/metadata.cc +17 -3
- package/src/metadata.h +5 -2
- package/src/operations.cc +2 -2
- package/src/operations.h +2 -2
- package/src/pipeline.cc +121 -41
- package/src/pipeline.h +1 -1
- package/src/sharp.cc +1 -1
- package/src/stats.cc +20 -6
- package/src/stats.h +7 -5
- package/src/utilities.cc +1 -1
- package/src/utilities.h +1 -1
package/src/metadata.h
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
2
|
+
SPDX-FileCopyrightText: 2013 Lovell Fuller and others
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -58,6 +58,7 @@ struct MetadataBaton {
|
|
|
58
58
|
size_t gainMapLength;
|
|
59
59
|
MetadataComments comments;
|
|
60
60
|
std::string err;
|
|
61
|
+
bool errUseWarning;
|
|
61
62
|
|
|
62
63
|
MetadataBaton():
|
|
63
64
|
input(nullptr),
|
|
@@ -87,7 +88,9 @@ struct MetadataBaton {
|
|
|
87
88
|
tifftagPhotoshop(nullptr),
|
|
88
89
|
tifftagPhotoshopLength(0),
|
|
89
90
|
gainMap(nullptr),
|
|
90
|
-
gainMapLength(0)
|
|
91
|
+
gainMapLength(0),
|
|
92
|
+
errUseWarning(false)
|
|
93
|
+
{}
|
|
91
94
|
};
|
|
92
95
|
|
|
93
96
|
Napi::Value metadata(const Napi::CallbackInfo& info);
|
package/src/operations.cc
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
2
|
+
SPDX-FileCopyrightText: 2013 Lovell Fuller and others
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -97,7 +97,7 @@ namespace sharp {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/*
|
|
100
|
-
* Contrast limiting
|
|
100
|
+
* Contrast limiting adaptive histogram equalization (CLAHE)
|
|
101
101
|
*/
|
|
102
102
|
VImage Clahe(VImage image, int const width, int const height, int const maxSlope) {
|
|
103
103
|
return image.hist_local(width, height, VImage::option()->set("max_slope", maxSlope));
|
package/src/operations.h
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
2
|
+
SPDX-FileCopyrightText: 2013 Lovell Fuller and others
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -28,7 +28,7 @@ namespace sharp {
|
|
|
28
28
|
VImage Normalise(VImage image, int const lower, int const upper);
|
|
29
29
|
|
|
30
30
|
/*
|
|
31
|
-
* Contrast limiting
|
|
31
|
+
* Contrast limiting adaptive histogram equalization (CLAHE)
|
|
32
32
|
*/
|
|
33
33
|
VImage Clahe(VImage image, int const width, int const height, int const maxSlope);
|
|
34
34
|
|
package/src/pipeline.cc
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
2
|
+
SPDX-FileCopyrightText: 2013 Lovell Fuller and others
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -40,6 +40,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
40
40
|
// Increment processing task counter
|
|
41
41
|
sharp::counterProcess++;
|
|
42
42
|
|
|
43
|
+
std::pair<char*, size_t> inputProfile(nullptr, 0);
|
|
43
44
|
try {
|
|
44
45
|
// Open input
|
|
45
46
|
vips::VImage image;
|
|
@@ -78,7 +79,20 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
VipsAccess access = baton->input->access;
|
|
81
|
-
|
|
82
|
+
// A device-independent colourspace is reached through the ICC profile connection space, either Lab or XYZ
|
|
83
|
+
bool const labPcs =
|
|
84
|
+
baton->colourspacePipeline == VIPS_INTERPRETATION_LAB ||
|
|
85
|
+
baton->colourspacePipeline == VIPS_INTERPRETATION_LABS ||
|
|
86
|
+
baton->colourspacePipeline == VIPS_INTERPRETATION_LCH;
|
|
87
|
+
bool const xyzPcs =
|
|
88
|
+
baton->colourspacePipeline == VIPS_INTERPRETATION_scRGB ||
|
|
89
|
+
baton->colourspacePipeline == VIPS_INTERPRETATION_XYZ ||
|
|
90
|
+
baton->colourspacePipeline == VIPS_INTERPRETATION_YXY;
|
|
91
|
+
// lcms needs 8/16-bit device values, so the conversion must wait for the import
|
|
92
|
+
bool const deferColourspace = sharp::HasProfile(image) && (labPcs || xyzPcs);
|
|
93
|
+
if (!deferColourspace) {
|
|
94
|
+
image = sharp::EnsureColourspace(image, baton->colourspacePipeline);
|
|
95
|
+
}
|
|
82
96
|
|
|
83
97
|
int nPages = baton->input->pages;
|
|
84
98
|
if (nPages == -1) {
|
|
@@ -256,7 +270,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
256
270
|
if (baton->input->buffer != nullptr) {
|
|
257
271
|
// Reload JPEG buffer
|
|
258
272
|
VipsBlob *blob = vips_blob_new(nullptr, baton->input->buffer, baton->input->bufferLength);
|
|
259
|
-
|
|
273
|
+
try {
|
|
274
|
+
image = VImage::jpegload_buffer(blob, option);
|
|
275
|
+
} catch (...) {
|
|
276
|
+
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
277
|
+
throw;
|
|
278
|
+
}
|
|
260
279
|
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
261
280
|
} else {
|
|
262
281
|
// Reload JPEG file
|
|
@@ -268,7 +287,12 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
268
287
|
if (baton->input->buffer != nullptr) {
|
|
269
288
|
// Reload WebP buffer
|
|
270
289
|
VipsBlob *blob = vips_blob_new(nullptr, baton->input->buffer, baton->input->bufferLength);
|
|
271
|
-
|
|
290
|
+
try {
|
|
291
|
+
image = VImage::webpload_buffer(blob, option);
|
|
292
|
+
} catch (...) {
|
|
293
|
+
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
294
|
+
throw;
|
|
295
|
+
}
|
|
272
296
|
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
273
297
|
} else {
|
|
274
298
|
// Reload WebP file
|
|
@@ -278,13 +302,17 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
278
302
|
if (baton->input->buffer != nullptr) {
|
|
279
303
|
// Reload SVG buffer
|
|
280
304
|
VipsBlob *blob = vips_blob_new(nullptr, baton->input->buffer, baton->input->bufferLength);
|
|
281
|
-
|
|
305
|
+
try {
|
|
306
|
+
image = VImage::svgload_buffer(blob, option);
|
|
307
|
+
} catch (...) {
|
|
308
|
+
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
309
|
+
throw;
|
|
310
|
+
}
|
|
282
311
|
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
283
312
|
} else {
|
|
284
313
|
// Reload SVG file
|
|
285
314
|
image = VImage::svgload(const_cast<char*>(baton->input->file.data()), option);
|
|
286
315
|
}
|
|
287
|
-
sharp::SetDensity(image, baton->input->density);
|
|
288
316
|
if (image.width() > 32767 || image.height() > 32767) {
|
|
289
317
|
throw std::runtime_error("Input SVG image will exceed 32767x32767 pixel limit when scaled");
|
|
290
318
|
}
|
|
@@ -292,13 +320,17 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
292
320
|
if (baton->input->buffer != nullptr) {
|
|
293
321
|
// Reload PDF buffer
|
|
294
322
|
VipsBlob *blob = vips_blob_new(nullptr, baton->input->buffer, baton->input->bufferLength);
|
|
295
|
-
|
|
323
|
+
try {
|
|
324
|
+
image = VImage::pdfload_buffer(blob, option);
|
|
325
|
+
} catch (...) {
|
|
326
|
+
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
327
|
+
throw;
|
|
328
|
+
}
|
|
296
329
|
vips_area_unref(reinterpret_cast<VipsArea*>(blob));
|
|
297
330
|
} else {
|
|
298
331
|
// Reload PDF file
|
|
299
332
|
image = VImage::pdfload(const_cast<char*>(baton->input->file.data()), option);
|
|
300
333
|
}
|
|
301
|
-
sharp::SetDensity(image, baton->input->density);
|
|
302
334
|
}
|
|
303
335
|
} else {
|
|
304
336
|
if (inputImageType == sharp::ImageType::SVG && (image.width() > 32767 || image.height() > 32767)) {
|
|
@@ -310,9 +342,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
310
342
|
}
|
|
311
343
|
VImage gainMap;
|
|
312
344
|
int gainMapScaleFactor = 1;
|
|
313
|
-
if (
|
|
345
|
+
if (!image.gainmap().is_null()) {
|
|
314
346
|
if (baton->keepGainMap) {
|
|
315
|
-
gainMap = image.gainmap();
|
|
347
|
+
gainMap = image.gainmap().copy_memory();
|
|
316
348
|
if (image.get_typeof("gainmap-scale-factor") == G_TYPE_INT) {
|
|
317
349
|
gainMapScaleFactor = image.get_int("gainmap-scale-factor");
|
|
318
350
|
}
|
|
@@ -333,7 +365,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
333
365
|
} else if (baton->withGainMap) {
|
|
334
366
|
image = image.uhdr2scRGB();
|
|
335
367
|
}
|
|
336
|
-
image =
|
|
368
|
+
image = image.copy();
|
|
369
|
+
image.remove("gainmap");
|
|
370
|
+
image.remove("gainmap-data");
|
|
337
371
|
} else {
|
|
338
372
|
baton->keepGainMap = false;
|
|
339
373
|
baton->withGainMap = false;
|
|
@@ -360,18 +394,22 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
360
394
|
// In toilet-roll mode, we must adjust vshrink so that we exactly hit
|
|
361
395
|
// pageHeight or we'll have pixels straddling pixel boundaries
|
|
362
396
|
if (inputHeight > pageHeight) {
|
|
397
|
+
if (nPages == 0 || targetHeight > INT_MAX / nPages) {
|
|
398
|
+
throw std::runtime_error("Invalid dimensions");
|
|
399
|
+
}
|
|
363
400
|
targetHeight *= nPages;
|
|
364
401
|
vshrink = static_cast<double>(inputHeight) / targetHeight;
|
|
365
402
|
}
|
|
366
403
|
|
|
367
404
|
// Ensure we're using a device-independent colour space
|
|
368
|
-
std::pair<char*, size_t> inputProfile(nullptr, 0);
|
|
369
405
|
if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->withIccProfile.empty()) {
|
|
370
406
|
// Cache input profile for use with output
|
|
371
407
|
inputProfile = sharp::GetProfile(image);
|
|
372
408
|
baton->input->ignoreIcc = true;
|
|
373
409
|
}
|
|
374
410
|
char const *processingProfile = image.interpretation() == VIPS_INTERPRETATION_RGB16 ? "p3" : "srgb";
|
|
411
|
+
bool importedToPcs = false;
|
|
412
|
+
bool importedToP3 = false;
|
|
375
413
|
if (
|
|
376
414
|
sharp::HasProfile(image) &&
|
|
377
415
|
image.interpretation() != VIPS_INTERPRETATION_LABS &&
|
|
@@ -381,10 +419,21 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
381
419
|
) {
|
|
382
420
|
// Convert to sRGB/P3 using embedded profile
|
|
383
421
|
try {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
422
|
+
if (deferColourspace &&
|
|
423
|
+
(image.format() == VIPS_FORMAT_UCHAR || image.format() == VIPS_FORMAT_USHORT)) {
|
|
424
|
+
// XYZ PCS is linear and device-independent, so colour management and linearisation are a single operation
|
|
425
|
+
image = image.icc_import(VImage::option()
|
|
426
|
+
->set("embedded", true)
|
|
427
|
+
->set("pcs", labPcs ? VIPS_PCS_LAB : VIPS_PCS_XYZ)
|
|
428
|
+
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
|
429
|
+
importedToPcs = true;
|
|
430
|
+
} else {
|
|
431
|
+
image = image.icc_transform(processingProfile, VImage::option()
|
|
432
|
+
->set("embedded", true)
|
|
433
|
+
->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
|
|
434
|
+
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
|
435
|
+
importedToP3 = image.interpretation() == VIPS_INTERPRETATION_RGB16;
|
|
436
|
+
}
|
|
388
437
|
} catch(...) {
|
|
389
438
|
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid embedded profile", nullptr);
|
|
390
439
|
}
|
|
@@ -397,6 +446,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
397
446
|
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
|
398
447
|
}
|
|
399
448
|
|
|
449
|
+
if (deferColourspace) {
|
|
450
|
+
image = sharp::EnsureColourspace(image, baton->colourspacePipeline);
|
|
451
|
+
}
|
|
452
|
+
|
|
400
453
|
// Flatten image to remove alpha channel
|
|
401
454
|
if (baton->flatten && image.has_alpha()) {
|
|
402
455
|
image = sharp::Flatten(image, baton->flattenBackground);
|
|
@@ -453,14 +506,14 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
453
506
|
}
|
|
454
507
|
image = image.rot(autoRotation);
|
|
455
508
|
if (baton->keepGainMap) {
|
|
456
|
-
gainMap =
|
|
509
|
+
gainMap = gainMap.rot(autoRotation);
|
|
457
510
|
}
|
|
458
511
|
}
|
|
459
512
|
// Mirror vertically (up-down) about the x-axis
|
|
460
513
|
if (baton->flip) {
|
|
461
514
|
image = image.flip(VIPS_DIRECTION_VERTICAL);
|
|
462
515
|
if (baton->keepGainMap) {
|
|
463
|
-
gainMap =
|
|
516
|
+
gainMap = gainMap.flip(VIPS_DIRECTION_VERTICAL);
|
|
464
517
|
}
|
|
465
518
|
}
|
|
466
519
|
// Mirror horizontally (left-right) about the y-axis
|
|
@@ -477,7 +530,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
477
530
|
}
|
|
478
531
|
image = image.rot(rotation);
|
|
479
532
|
if (baton->keepGainMap) {
|
|
480
|
-
gainMap =
|
|
533
|
+
gainMap = gainMap.rot(rotation);
|
|
481
534
|
}
|
|
482
535
|
}
|
|
483
536
|
|
|
@@ -638,15 +691,17 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
638
691
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->extendBackground, shouldPremultiplyAlpha);
|
|
639
692
|
}
|
|
640
693
|
image = sharp::StaySequential(image, nPages > 1 || baton->extendWith != VIPS_EXTEND_BACKGROUND);
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
694
|
+
if (nPages > 1) {
|
|
695
|
+
image = sharp::EmbedMultiPage(image,
|
|
696
|
+
baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
|
697
|
+
baton->extendWith, background, nPages, &targetPageHeight);
|
|
698
|
+
} else {
|
|
699
|
+
auto options = VImage::option()->set("extend", baton->extendWith);
|
|
700
|
+
if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
|
|
701
|
+
options->set("background", background);
|
|
702
|
+
}
|
|
703
|
+
image = image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height, options);
|
|
644
704
|
}
|
|
645
|
-
image = nPages > 1
|
|
646
|
-
? sharp::EmbedMultiPage(image,
|
|
647
|
-
baton->extendLeft, baton->extendTop, baton->width, baton->height,
|
|
648
|
-
baton->extendWith, background, nPages, &targetPageHeight)
|
|
649
|
-
: image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height, options);
|
|
650
705
|
if (baton->keepGainMap) {
|
|
651
706
|
gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
|
|
652
707
|
baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
|
|
@@ -880,14 +935,33 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
880
935
|
image = sharp::EnsureAlpha(image, baton->ensureAlpha);
|
|
881
936
|
}
|
|
882
937
|
|
|
938
|
+
// Leave PCS before the output colourspace is applied, which would gamut-clip
|
|
939
|
+
if (importedToPcs) {
|
|
940
|
+
try {
|
|
941
|
+
image = image.colourspace(VIPS_INTERPRETATION_XYZ).icc_export(VImage::option()
|
|
942
|
+
->set("output_profile", baton->withIccProfile.empty()
|
|
943
|
+
? (sharp::Is16Bit(baton->colourspace) ? processingProfile : "srgb")
|
|
944
|
+
: const_cast<char*>(baton->withIccProfile.data()))
|
|
945
|
+
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
|
946
|
+
} catch(...) {
|
|
947
|
+
sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid profile", nullptr);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
883
951
|
// Ensure output colour space
|
|
884
952
|
if (sharp::Is16Bit(image.interpretation())) {
|
|
885
953
|
image = image.cast(VIPS_FORMAT_USHORT);
|
|
886
954
|
}
|
|
955
|
+
if (importedToP3 && !sharp::Is16Bit(baton->colourspace) && baton->withIccProfile.empty()) {
|
|
956
|
+
image = image.icc_transform("srgb", VImage::option()
|
|
957
|
+
->set("input_profile", "p3")
|
|
958
|
+
->set("intent", VIPS_INTENT_PERCEPTUAL));
|
|
959
|
+
}
|
|
887
960
|
if (image.interpretation() != baton->colourspace) {
|
|
888
961
|
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
|
889
962
|
if (inputProfile.first != nullptr && baton->withIccProfile.empty()) {
|
|
890
963
|
image = sharp::SetProfile(image, inputProfile);
|
|
964
|
+
inputProfile.first = nullptr;
|
|
891
965
|
}
|
|
892
966
|
}
|
|
893
967
|
|
|
@@ -898,10 +972,9 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
898
972
|
if (baton->extractChannel == 3 && image.has_alpha()) {
|
|
899
973
|
baton->extractChannel = image.bands() - 1;
|
|
900
974
|
} else {
|
|
901
|
-
(
|
|
902
|
-
|
|
903
|
-
.append(" from image with channels 0-").append(std::to_string(image.bands() - 1));
|
|
904
|
-
return Error();
|
|
975
|
+
throw std::runtime_error(
|
|
976
|
+
std::string("Cannot extract channel ").append(std::to_string(baton->extractChannel))
|
|
977
|
+
.append(" from image with channels 0-").append(std::to_string(image.bands() - 1)));
|
|
905
978
|
}
|
|
906
979
|
}
|
|
907
980
|
VipsInterpretation colourspace = sharp::Is16Bit(image.interpretation())
|
|
@@ -913,7 +986,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
913
986
|
}
|
|
914
987
|
|
|
915
988
|
// Apply output ICC profile
|
|
916
|
-
if (!baton->withIccProfile.empty()) {
|
|
989
|
+
if (!importedToPcs && !baton->withIccProfile.empty()) {
|
|
917
990
|
try {
|
|
918
991
|
image = image.icc_transform(const_cast<char*>(baton->withIccProfile.data()), VImage::option()
|
|
919
992
|
->set("input_profile", processingProfile)
|
|
@@ -1015,6 +1088,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1015
1088
|
// Write JP2 to Buffer
|
|
1016
1089
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JP2);
|
|
1017
1090
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.jp2ksave_buffer(VImage::option()
|
|
1091
|
+
->set("keep", baton->keepMetadata)
|
|
1018
1092
|
->set("Q", baton->jp2Quality)
|
|
1019
1093
|
->set("lossless", baton->jp2Lossless)
|
|
1020
1094
|
->set("subsample_mode", baton->jp2ChromaSubsampling == "4:4:4"
|
|
@@ -1158,7 +1232,6 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1158
1232
|
} else if (baton->formatOut == "jxl" ||
|
|
1159
1233
|
(baton->formatOut == "input" && inputImageType == sharp::ImageType::JXL)) {
|
|
1160
1234
|
// Write JXL to buffer
|
|
1161
|
-
image = sharp::RemoveAnimationProperties(image);
|
|
1162
1235
|
VipsArea *area = reinterpret_cast<VipsArea*>(image.jxlsave_buffer(VImage::option()
|
|
1163
1236
|
->set("keep", baton->keepMetadata)
|
|
1164
1237
|
->set("distance", baton->jxlDistance)
|
|
@@ -1214,7 +1287,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1214
1287
|
bool const isV = sharp::IsV(baton->fileOut);
|
|
1215
1288
|
bool const mightMatchInput = baton->formatOut == "input";
|
|
1216
1289
|
bool const willMatchInput = mightMatchInput &&
|
|
1217
|
-
!(isJpeg || isPng || isWebp || isGif || isTiff || isJp2 || isHeif || isDz || isDzZip || isV);
|
|
1290
|
+
!(isJpeg || isPng || isWebp || isGif || isTiff || isJp2 || isJxl || isHeif || isDz || isDzZip || isV);
|
|
1218
1291
|
|
|
1219
1292
|
if (baton->formatOut == "jpeg" || (mightMatchInput && isJpeg) ||
|
|
1220
1293
|
(willMatchInput && inputImageType == sharp::ImageType::JPEG)) {
|
|
@@ -1241,13 +1314,18 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1241
1314
|
->set("optimize_coding", baton->jpegOptimiseCoding));
|
|
1242
1315
|
}
|
|
1243
1316
|
baton->formatOut = "jpeg";
|
|
1244
|
-
|
|
1317
|
+
if (baton->colourspace == VIPS_INTERPRETATION_CMYK) {
|
|
1318
|
+
baton->channels = std::min(baton->channels, 4);
|
|
1319
|
+
} else {
|
|
1320
|
+
baton->channels = std::min(baton->channels, 3);
|
|
1321
|
+
}
|
|
1245
1322
|
baton->hasAlphaOut = false;
|
|
1246
1323
|
} else if (baton->formatOut == "jp2" || (mightMatchInput && isJp2) ||
|
|
1247
1324
|
(willMatchInput && (inputImageType == sharp::ImageType::JP2))) {
|
|
1248
1325
|
// Write JP2 to file
|
|
1249
1326
|
sharp::AssertImageTypeDimensions(image, sharp::ImageType::JP2);
|
|
1250
1327
|
image.jp2ksave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
|
1328
|
+
->set("keep", baton->keepMetadata)
|
|
1251
1329
|
->set("Q", baton->jp2Quality)
|
|
1252
1330
|
->set("lossless", baton->jp2Lossless)
|
|
1253
1331
|
->set("subsample_mode", baton->jp2ChromaSubsampling == "4:4:4"
|
|
@@ -1350,7 +1428,6 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1350
1428
|
} else if (baton->formatOut == "jxl" || (mightMatchInput && isJxl) ||
|
|
1351
1429
|
(willMatchInput && inputImageType == sharp::ImageType::JXL)) {
|
|
1352
1430
|
// Write JXL to file
|
|
1353
|
-
image = sharp::RemoveAnimationProperties(image);
|
|
1354
1431
|
image.jxlsave(const_cast<char*>(baton->fileOut.data()), VImage::option()
|
|
1355
1432
|
->set("keep", baton->keepMetadata)
|
|
1356
1433
|
->set("distance", baton->jxlDistance)
|
|
@@ -1381,8 +1458,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1381
1458
|
baton->formatOut = "v";
|
|
1382
1459
|
} else {
|
|
1383
1460
|
// Unsupported output format
|
|
1384
|
-
(
|
|
1385
|
-
return Error();
|
|
1461
|
+
throw std::runtime_error("Unsupported output format " + baton->fileOut);
|
|
1386
1462
|
}
|
|
1387
1463
|
}
|
|
1388
1464
|
} catch (std::runtime_error const &err) {
|
|
@@ -1398,6 +1474,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1398
1474
|
}
|
|
1399
1475
|
}
|
|
1400
1476
|
}
|
|
1477
|
+
g_free(inputProfile.first);
|
|
1478
|
+
|
|
1401
1479
|
// Clean up libvips' per-request data and threads
|
|
1402
1480
|
vips_error_clear();
|
|
1403
1481
|
vips_thread_shutdown();
|
|
@@ -1465,7 +1543,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1465
1543
|
// ECMAScript ArrayBuffer with Uint8Array view
|
|
1466
1544
|
Napi::TypedArrayOf<uint8_t> data = Napi::Buffer<char>::Copy(env,
|
|
1467
1545
|
static_cast<char*>(baton->bufferOut), baton->bufferOutLength);
|
|
1468
|
-
sharp::FreeCallback(static_cast<char*>(baton->bufferOut)
|
|
1546
|
+
sharp::FreeCallback(nullptr, static_cast<char*>(baton->bufferOut));
|
|
1469
1547
|
Callback().SHARP_CALLBACK_FN_NAME(Receiver().Value(), { env.Null(), data, info });
|
|
1470
1548
|
} else {
|
|
1471
1549
|
// Node.js Buffer
|
|
@@ -1657,6 +1735,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|
|
1657
1735
|
image = image.copy();
|
|
1658
1736
|
image.set("gainmap-data", reinterpret_cast<VipsCallbackFn>(vips_area_free_cb),
|
|
1659
1737
|
gainMapJpeg->data, gainMapJpeg->length);
|
|
1738
|
+
gainMapJpeg->free_fn = nullptr;
|
|
1739
|
+
vips_area_unref(gainMapJpeg);
|
|
1660
1740
|
return image;
|
|
1661
1741
|
}
|
|
1662
1742
|
|
|
@@ -1821,9 +1901,9 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
|
|
1821
1901
|
baton->convKernelOffset = sharp::AttrAsDouble(kernel, "offset");
|
|
1822
1902
|
size_t const kernelSize = static_cast<size_t>(baton->convKernelWidth * baton->convKernelHeight);
|
|
1823
1903
|
baton->convKernel.resize(kernelSize);
|
|
1824
|
-
Napi::Array
|
|
1904
|
+
Napi::Array kernelData = kernel.Get("kernel").As<Napi::Array>();
|
|
1825
1905
|
for (unsigned int i = 0; i < kernelSize; i++) {
|
|
1826
|
-
baton->convKernel[i] = sharp::AttrAsDouble(
|
|
1906
|
+
baton->convKernel[i] = sharp::AttrAsDouble(kernelData, i);
|
|
1827
1907
|
}
|
|
1828
1908
|
}
|
|
1829
1909
|
if (options.Has("recombMatrix")) {
|
package/src/pipeline.h
CHANGED
package/src/sharp.cc
CHANGED
package/src/stats.cc
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
2
|
+
SPDX-FileCopyrightText: 2013 Lovell Fuller and others
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -48,8 +48,8 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
48
48
|
int const bands = image.bands();
|
|
49
49
|
for (int b = 1; b <= bands; b++) {
|
|
50
50
|
ChannelStats cStats(
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
stats.getpoint(STAT_MIN_INDEX, b).front(),
|
|
52
|
+
stats.getpoint(STAT_MAX_INDEX, b).front(),
|
|
53
53
|
stats.getpoint(STAT_SUM_INDEX, b).front(),
|
|
54
54
|
stats.getpoint(STAT_SQ_SUM_INDEX, b).front(),
|
|
55
55
|
stats.getpoint(STAT_MEAN_INDEX, b).front(),
|
|
@@ -60,7 +60,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
60
60
|
static_cast<int>(stats.getpoint(STAT_MAXY_INDEX, b).front()));
|
|
61
61
|
baton->channelStats.push_back(cStats);
|
|
62
62
|
}
|
|
63
|
-
// Image is not opaque when alpha layer is present and contains a non-
|
|
63
|
+
// Image is not opaque when alpha layer is present and contains a non-maxima value
|
|
64
64
|
if (image.has_alpha()) {
|
|
65
65
|
double const minAlpha = static_cast<double>(stats.getpoint(STAT_MIN_INDEX, bands).front());
|
|
66
66
|
if (minAlpha != vips_interpretation_max_alpha(image.interpretation())) {
|
|
@@ -93,7 +93,17 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
93
93
|
baton->dominantGreen = dy * 16 + 8;
|
|
94
94
|
baton->dominantBlue = dz * 16 + 8;
|
|
95
95
|
} catch (std::runtime_error const &err) {
|
|
96
|
-
|
|
96
|
+
char const *what = err.what();
|
|
97
|
+
if (what && what[0]) {
|
|
98
|
+
(baton->err).append(what);
|
|
99
|
+
} else {
|
|
100
|
+
if (baton->input->failOn == VIPS_FAIL_ON_WARNING) {
|
|
101
|
+
(baton->err).append("Warning treated as error due to failOn setting");
|
|
102
|
+
baton->errUseWarning = true;
|
|
103
|
+
} else {
|
|
104
|
+
(baton->err).append("Unknown error");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
97
107
|
}
|
|
98
108
|
}
|
|
99
109
|
|
|
@@ -109,7 +119,11 @@ class StatsWorker : public Napi::AsyncWorker {
|
|
|
109
119
|
// Handle warnings
|
|
110
120
|
std::string warning = sharp::VipsWarningPop();
|
|
111
121
|
while (!warning.empty()) {
|
|
112
|
-
|
|
122
|
+
if (baton->errUseWarning) {
|
|
123
|
+
(baton->err).append("\n").append(warning);
|
|
124
|
+
} else {
|
|
125
|
+
debuglog.SHARP_CALLBACK_FN_NAME(Receiver().Value(), { Napi::String::New(env, warning) });
|
|
126
|
+
}
|
|
113
127
|
warning = sharp::VipsWarningPop();
|
|
114
128
|
}
|
|
115
129
|
if (baton->err.empty()) {
|
package/src/stats.h
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
2
|
+
SPDX-FileCopyrightText: 2013 Lovell Fuller and others
|
|
3
3
|
SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
struct ChannelStats {
|
|
16
16
|
// stats per channel
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
double min;
|
|
18
|
+
double max;
|
|
19
19
|
double sum;
|
|
20
20
|
double squaresSum;
|
|
21
21
|
double mean;
|
|
@@ -25,7 +25,7 @@ struct ChannelStats {
|
|
|
25
25
|
int maxX;
|
|
26
26
|
int maxY;
|
|
27
27
|
|
|
28
|
-
ChannelStats(
|
|
28
|
+
ChannelStats(double minVal, double maxVal, double sumVal, double squaresSumVal,
|
|
29
29
|
double meanVal, double stdevVal, int minXVal, int minYVal, int maxXVal, int maxYVal):
|
|
30
30
|
min(minVal), max(maxVal), sum(sumVal), squaresSum(squaresSumVal), // NOLINT(build/include_what_you_use)
|
|
31
31
|
mean(meanVal), stdev(stdevVal), minX(minXVal), minY(minYVal), maxX(maxXVal), maxY(maxYVal) {}
|
|
@@ -45,6 +45,7 @@ struct StatsBaton {
|
|
|
45
45
|
int dominantBlue;
|
|
46
46
|
|
|
47
47
|
std::string err;
|
|
48
|
+
bool errUseWarning;
|
|
48
49
|
|
|
49
50
|
StatsBaton():
|
|
50
51
|
input(nullptr),
|
|
@@ -53,7 +54,8 @@ struct StatsBaton {
|
|
|
53
54
|
sharpness(0.0),
|
|
54
55
|
dominantRed(0),
|
|
55
56
|
dominantGreen(0),
|
|
56
|
-
dominantBlue(0)
|
|
57
|
+
dominantBlue(0),
|
|
58
|
+
errUseWarning(false)
|
|
57
59
|
{}
|
|
58
60
|
};
|
|
59
61
|
|
package/src/utilities.cc
CHANGED
package/src/utilities.h
CHANGED