sharp 0.34.4 → 0.34.5-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.
package/src/common.h CHANGED
@@ -1,13 +1,16 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_COMMON_H_
5
7
  #define SRC_COMMON_H_
6
8
 
9
+ #include <atomic>
7
10
  #include <string>
8
11
  #include <tuple>
12
+ #include <utility>
9
13
  #include <vector>
10
- #include <atomic>
11
14
 
12
15
  #include <napi.h>
13
16
  #include <vips/vips8>
@@ -16,8 +19,8 @@
16
19
 
17
20
  #if (VIPS_MAJOR_VERSION < 8) || \
18
21
  (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION < 17) || \
19
- (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION == 17 && VIPS_MICRO_VERSION < 2)
20
- #error "libvips version 8.17.2+ is required - please see https://sharp.pixelplumbing.com/install"
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
24
  #endif
22
25
 
23
26
  #if defined(__has_include)
@@ -30,7 +33,7 @@ using vips::VImage;
30
33
 
31
34
  namespace sharp {
32
35
 
33
- struct InputDescriptor { // NOLINT(runtime/indentation_namespace)
36
+ struct InputDescriptor {
34
37
  std::string name;
35
38
  std::string file;
36
39
  bool autoOrient;
package/src/metadata.cc CHANGED
@@ -1,15 +1,19 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
6
+ #include <cmath>
4
7
  #include <numeric>
8
+ #include <string>
9
+ #include <utility>
5
10
  #include <vector>
6
- #include <cmath>
7
11
 
8
12
  #include <napi.h>
9
13
  #include <vips/vips8>
10
14
 
11
- #include "common.h"
12
- #include "metadata.h"
15
+ #include "./common.h"
16
+ #include "./metadata.h"
13
17
 
14
18
  static void* readPNGComment(VipsImage *image, const char *field, GValue *value, void *p);
15
19
 
@@ -215,10 +219,10 @@ class MetadataWorker : public Napi::AsyncWorker {
215
219
  if (!baton->levels.empty()) {
216
220
  int i = 0;
217
221
  Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
218
- for (std::pair<int, int> const &l : baton->levels) {
222
+ for (const auto& [width, height] : baton->levels) {
219
223
  Napi::Object level = Napi::Object::New(env);
220
- level.Set("width", l.first);
221
- level.Set("height", l.second);
224
+ level.Set("width", width);
225
+ level.Set("height", height);
222
226
  levels.Set(i++, level);
223
227
  }
224
228
  info.Set("levels", levels);
@@ -275,10 +279,10 @@ class MetadataWorker : public Napi::AsyncWorker {
275
279
  if (baton->comments.size() > 0) {
276
280
  int i = 0;
277
281
  Napi::Array comments = Napi::Array::New(env, baton->comments.size());
278
- for (auto &c : baton->comments) {
282
+ for (const auto& [keyword, text] : baton->comments) {
279
283
  Napi::Object comment = Napi::Object::New(env);
280
- comment.Set("keyword", c.first);
281
- comment.Set("text", c.second);
284
+ comment.Set("keyword", keyword);
285
+ comment.Set("text", text);
282
286
  comments.Set(i++, comment);
283
287
  }
284
288
  info.Set("comments", comments);
package/src/metadata.h CHANGED
@@ -1,10 +1,13 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_METADATA_H_
5
7
  #define SRC_METADATA_H_
6
8
 
7
9
  #include <string>
10
+ #include <vector>
8
11
  #include <napi.h>
9
12
 
10
13
  #include "./common.h"
package/src/operations.cc CHANGED
@@ -1,5 +1,7 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #include <algorithm>
5
7
  #include <functional>
@@ -8,8 +10,8 @@
8
10
  #include <vector>
9
11
  #include <vips/vips8>
10
12
 
11
- #include "common.h"
12
- #include "operations.h"
13
+ #include "./common.h"
14
+ #include "./operations.h"
13
15
 
14
16
  using vips::VImage;
15
17
  using vips::VError;
package/src/operations.h CHANGED
@@ -1,5 +1,7 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_OPERATIONS_H_
5
7
  #define SRC_OPERATIONS_H_
@@ -8,6 +10,7 @@
8
10
  #include <functional>
9
11
  #include <memory>
10
12
  #include <tuple>
13
+ #include <vector>
11
14
  #include <vips/vips8>
12
15
 
13
16
  using vips::VImage;
package/src/pipeline.cc CHANGED
@@ -1,9 +1,11 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #include <algorithm>
5
7
  #include <cmath>
6
- #include <filesystem>
8
+ #include <filesystem> // NOLINT(build/c++17)
7
9
  #include <map>
8
10
  #include <memory>
9
11
  #include <numeric>
@@ -17,9 +19,9 @@
17
19
  #include <vips/vips8>
18
20
  #include <napi.h>
19
21
 
20
- #include "common.h"
21
- #include "operations.h"
22
- #include "pipeline.h"
22
+ #include "./common.h"
23
+ #include "./operations.h"
24
+ #include "./pipeline.h"
23
25
 
24
26
  class PipelineWorker : public Napi::AsyncWorker {
25
27
  public:
@@ -453,12 +455,10 @@ class PipelineWorker : public Napi::AsyncWorker {
453
455
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->resizeBackground, shouldPremultiplyAlpha);
454
456
 
455
457
  // Embed
456
- int left;
457
- int top;
458
- std::tie(left, top) = sharp::CalculateEmbedPosition(
458
+ const auto& [left, top] = sharp::CalculateEmbedPosition(
459
459
  inputWidth, inputHeight, baton->width, baton->height, baton->position);
460
- int width = std::max(inputWidth, baton->width);
461
- int height = std::max(inputHeight, baton->height);
460
+ const int width = std::max(inputWidth, baton->width);
461
+ const int height = std::max(inputHeight, baton->height);
462
462
 
463
463
  image = nPages > 1
464
464
  ? sharp::EmbedMultiPage(image,
@@ -477,13 +477,10 @@ class PipelineWorker : public Napi::AsyncWorker {
477
477
  // Crop
478
478
  if (baton->position < 9) {
479
479
  // Gravity-based crop
480
- int left;
481
- int top;
482
-
483
- std::tie(left, top) = sharp::CalculateCrop(
480
+ const auto& [left, top] = sharp::CalculateCrop(
484
481
  inputWidth, inputHeight, baton->width, baton->height, baton->position);
485
- int width = std::min(inputWidth, baton->width);
486
- int height = std::min(inputHeight, baton->height);
482
+ const int width = std::min(inputWidth, baton->width);
483
+ const int height = std::min(inputHeight, baton->height);
487
484
 
488
485
  image = nPages > 1
489
486
  ? sharp::CropMultiPage(image,
@@ -795,20 +792,14 @@ class PipelineWorker : public Napi::AsyncWorker {
795
792
  image = sharp::EnsureAlpha(image, baton->ensureAlpha);
796
793
  }
797
794
 
798
- // Convert image to sRGB, if not already
795
+ // Ensure output colour space
799
796
  if (sharp::Is16Bit(image.interpretation())) {
800
797
  image = image.cast(VIPS_FORMAT_USHORT);
801
798
  }
802
799
  if (image.interpretation() != baton->colourspace) {
803
- // Convert colourspace, pass the current known interpretation so libvips doesn't have to guess
804
800
  image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
805
- // Transform colours from embedded profile to output profile
806
- if ((baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) && baton->colourspacePipeline != VIPS_INTERPRETATION_CMYK &&
807
- baton->withIccProfile.empty() && sharp::HasProfile(image)) {
808
- image = image.icc_transform(processingProfile, VImage::option()
809
- ->set("embedded", true)
810
- ->set("depth", sharp::Is16Bit(image.interpretation()) ? 16 : 8)
811
- ->set("intent", VIPS_INTENT_PERCEPTUAL));
801
+ if (inputProfile.first != nullptr && baton->withIccProfile.empty()) {
802
+ image = sharp::SetProfile(image, inputProfile);
812
803
  }
813
804
  }
814
805
 
@@ -843,8 +834,6 @@ class PipelineWorker : public Napi::AsyncWorker {
843
834
  } catch(...) {
844
835
  sharp::VipsWarningCallback(nullptr, G_LOG_LEVEL_WARNING, "Invalid profile", nullptr);
845
836
  }
846
- } else if (baton->keepMetadata & VIPS_FOREIGN_KEEP_ICC) {
847
- image = sharp::SetProfile(image, inputProfile);
848
837
  }
849
838
 
850
839
  // Negate the colours in the image
@@ -866,8 +855,8 @@ class PipelineWorker : public Napi::AsyncWorker {
866
855
  if (!baton->withExifMerge) {
867
856
  image = sharp::RemoveExif(image);
868
857
  }
869
- for (const auto& s : baton->withExif) {
870
- image.set(s.first.data(), s.second.data());
858
+ for (const auto& [key, value] : baton->withExif) {
859
+ image.set(key.c_str(), value.c_str());
871
860
  }
872
861
  }
873
862
  // XMP buffer
@@ -1009,6 +998,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1009
998
  ->set("Q", baton->tiffQuality)
1010
999
  ->set("bitdepth", baton->tiffBitdepth)
1011
1000
  ->set("compression", baton->tiffCompression)
1001
+ ->set("bigtiff", baton->tiffBigtiff)
1012
1002
  ->set("miniswhite", baton->tiffMiniswhite)
1013
1003
  ->set("predictor", baton->tiffPredictor)
1014
1004
  ->set("pyramid", baton->tiffPyramid)
@@ -1211,6 +1201,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1211
1201
  ->set("Q", baton->tiffQuality)
1212
1202
  ->set("bitdepth", baton->tiffBitdepth)
1213
1203
  ->set("compression", baton->tiffCompression)
1204
+ ->set("bigtiff", baton->tiffBigtiff)
1214
1205
  ->set("miniswhite", baton->tiffMiniswhite)
1215
1206
  ->set("predictor", baton->tiffPredictor)
1216
1207
  ->set("pyramid", baton->tiffPyramid)
@@ -1276,7 +1267,12 @@ class PipelineWorker : public Napi::AsyncWorker {
1276
1267
  if (what && what[0]) {
1277
1268
  (baton->err).append(what);
1278
1269
  } else {
1279
- (baton->err).append("Unknown error");
1270
+ if (baton->input->failOn == VIPS_FAIL_ON_WARNING) {
1271
+ (baton->err).append("Warning treated as error due to failOn setting");
1272
+ baton->errUseWarning = true;
1273
+ } else {
1274
+ (baton->err).append("Unknown error");
1275
+ }
1280
1276
  }
1281
1277
  }
1282
1278
  // Clean up libvips' per-request data and threads
@@ -1291,7 +1287,11 @@ class PipelineWorker : public Napi::AsyncWorker {
1291
1287
  // Handle warnings
1292
1288
  std::string warning = sharp::VipsWarningPop();
1293
1289
  while (!warning.empty()) {
1294
- debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
1290
+ if (baton->errUseWarning) {
1291
+ (baton->err).append("\n").append(warning);
1292
+ } else {
1293
+ debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
1294
+ }
1295
1295
  warning = sharp::VipsWarningPop();
1296
1296
  }
1297
1297
 
@@ -1435,11 +1435,11 @@ class PipelineWorker : public Napi::AsyncWorker {
1435
1435
  std::string
1436
1436
  AssembleSuffixString(std::string extname, std::vector<std::pair<std::string, std::string>> options) {
1437
1437
  std::string argument;
1438
- for (auto const &option : options) {
1438
+ for (const auto& [key, value] : options) {
1439
1439
  if (!argument.empty()) {
1440
1440
  argument += ",";
1441
1441
  }
1442
- argument += option.first + "=" + option.second;
1442
+ argument += key + "=" + value;
1443
1443
  }
1444
1444
  return extname + "[" + argument + "]";
1445
1445
  }
@@ -1750,6 +1750,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
1750
1750
  baton->gifReuse = sharp::AttrAsBool(options, "gifReuse");
1751
1751
  baton->gifProgressive = sharp::AttrAsBool(options, "gifProgressive");
1752
1752
  baton->tiffQuality = sharp::AttrAsUint32(options, "tiffQuality");
1753
+ baton->tiffBigtiff = sharp::AttrAsBool(options, "tiffBigtiff");
1753
1754
  baton->tiffPyramid = sharp::AttrAsBool(options, "tiffPyramid");
1754
1755
  baton->tiffMiniswhite = sharp::AttrAsBool(options, "tiffMiniswhite");
1755
1756
  baton->tiffBitdepth = sharp::AttrAsUint32(options, "tiffBitdepth");
package/src/pipeline.h CHANGED
@@ -1,13 +1,15 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_PIPELINE_H_
5
7
  #define SRC_PIPELINE_H_
6
8
 
7
9
  #include <memory>
8
10
  #include <string>
9
- #include <vector>
10
11
  #include <unordered_map>
12
+ #include <vector>
11
13
 
12
14
  #include <napi.h>
13
15
  #include <vips/vips8>
@@ -175,6 +177,7 @@ struct PipelineBaton {
175
177
  bool gifProgressive;
176
178
  int tiffQuality;
177
179
  VipsForeignTiffCompression tiffCompression;
180
+ bool tiffBigtiff;
178
181
  VipsForeignTiffPredictor tiffPredictor;
179
182
  bool tiffPyramid;
180
183
  int tiffBitdepth;
@@ -197,6 +200,7 @@ struct PipelineBaton {
197
200
  bool jxlLossless;
198
201
  VipsBandFormat rawDepth;
199
202
  std::string err;
203
+ bool errUseWarning;
200
204
  int keepMetadata;
201
205
  int withMetadataOrientation;
202
206
  double withMetadataDensity;
@@ -350,6 +354,7 @@ struct PipelineBaton {
350
354
  gifProgressive(false),
351
355
  tiffQuality(80),
352
356
  tiffCompression(VIPS_FOREIGN_TIFF_COMPRESSION_JPEG),
357
+ tiffBigtiff(false),
353
358
  tiffPredictor(VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL),
354
359
  tiffPyramid(false),
355
360
  tiffBitdepth(8),
@@ -371,6 +376,7 @@ struct PipelineBaton {
371
376
  jxlEffort(7),
372
377
  jxlLossless(false),
373
378
  rawDepth(VIPS_FORMAT_UCHAR),
379
+ errUseWarning(false),
374
380
  keepMetadata(0),
375
381
  withMetadataOrientation(-1),
376
382
  withMetadataDensity(0.0),
package/src/sharp.cc CHANGED
@@ -1,16 +1,18 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
- #include <mutex> // NOLINT(build/c++11)
6
+ #include <mutex>
5
7
 
6
8
  #include <napi.h>
7
9
  #include <vips/vips8>
8
10
 
9
- #include "common.h"
10
- #include "metadata.h"
11
- #include "pipeline.h"
12
- #include "utilities.h"
13
- #include "stats.h"
11
+ #include "./common.h"
12
+ #include "./metadata.h"
13
+ #include "./pipeline.h"
14
+ #include "./stats.h"
15
+ #include "./utilities.h"
14
16
 
15
17
  Napi::Object init(Napi::Env env, Napi::Object exports) {
16
18
  static std::once_flag sharp_vips_init_once;
package/src/stats.cc CHANGED
@@ -1,15 +1,18 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
6
+ #include <iostream>
4
7
  #include <numeric>
8
+ #include <string>
5
9
  #include <vector>
6
- #include <iostream>
7
10
 
8
11
  #include <napi.h>
9
12
  #include <vips/vips8>
10
13
 
11
- #include "common.h"
12
- #include "stats.h"
14
+ #include "./common.h"
15
+ #include "./stats.h"
13
16
 
14
17
  class StatsWorker : public Napi::AsyncWorker {
15
18
  public:
package/src/stats.h CHANGED
@@ -1,10 +1,13 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_STATS_H_
5
7
  #define SRC_STATS_H_
6
8
 
7
9
  #include <string>
10
+ #include <vector>
8
11
  #include <napi.h>
9
12
 
10
13
  #include "./common.h"
@@ -24,7 +27,7 @@ struct ChannelStats {
24
27
 
25
28
  ChannelStats(int minVal, int maxVal, double sumVal, double squaresSumVal,
26
29
  double meanVal, double stdevVal, int minXVal, int minYVal, int maxXVal, int maxYVal):
27
- min(minVal), max(maxVal), sum(sumVal), squaresSum(squaresSumVal),
30
+ min(minVal), max(maxVal), sum(sumVal), squaresSum(squaresSumVal), // NOLINT(build/include_what_you_use)
28
31
  mean(meanVal), stdev(stdevVal), minX(minXVal), minY(minYVal), maxX(maxXVal), maxY(maxYVal) {}
29
32
  };
30
33
 
package/src/utilities.cc CHANGED
@@ -1,17 +1,19 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #include <cmath>
5
- #include <string>
6
7
  #include <cstdio>
8
+ #include <string>
7
9
 
8
10
  #include <napi.h>
9
11
  #include <vips/vips8>
10
12
  #include <vips/vector.h>
11
13
 
12
- #include "common.h"
13
- #include "operations.h"
14
- #include "utilities.h"
14
+ #include "./common.h"
15
+ #include "./operations.h"
16
+ #include "./utilities.h"
15
17
 
16
18
  /*
17
19
  Get and set cache limits
package/src/utilities.h CHANGED
@@ -1,5 +1,7 @@
1
- // Copyright 2013 Lovell Fuller and others.
2
- // SPDX-License-Identifier: Apache-2.0
1
+ /*!
2
+ Copyright 2013 Lovell Fuller and others.
3
+ SPDX-License-Identifier: Apache-2.0
4
+ */
3
5
 
4
6
  #ifndef SRC_UTILITIES_H_
5
7
  #define SRC_UTILITIES_H_