sharp 0.35.2 → 0.35.3-rc.2

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/pipeline.cc CHANGED
@@ -608,38 +608,25 @@ class PipelineWorker : public Napi::AsyncWorker {
608
608
  baton->width = image.width() + baton->extendLeft + baton->extendRight;
609
609
  baton->height = (nPages > 1 ? targetPageHeight : image.height()) + baton->extendTop + baton->extendBottom;
610
610
 
611
+ std::vector<double> background;
611
612
  if (baton->extendWith == VIPS_EXTEND_BACKGROUND) {
612
- std::vector<double> background;
613
613
  std::tie(image, background) = sharp::ApplyAlpha(image, baton->extendBackground, shouldPremultiplyAlpha);
614
-
615
- image = sharp::StaySequential(image, nPages > 1);
616
- image = nPages > 1
617
- ? sharp::EmbedMultiPage(image,
618
- baton->extendLeft, baton->extendTop, baton->width, baton->height,
619
- baton->extendWith, background, nPages, &targetPageHeight)
620
- : image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
621
- VImage::option()->set("extend", baton->extendWith)->set("background", background));
622
- if (baton->keepGainMap) {
623
- gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
624
- baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
625
- ->set("extend", baton->extendWith)
626
- ->set("background", 0));
627
- }
628
- } else {
629
- std::vector<double> ignoredBackground(1);
630
- image = sharp::StaySequential(image);
631
- image = nPages > 1
632
- ? sharp::EmbedMultiPage(image,
633
- baton->extendLeft, baton->extendTop, baton->width, baton->height,
634
- baton->extendWith, ignoredBackground, nPages, &targetPageHeight)
635
- : image.embed(baton->extendLeft, baton->extendTop, baton->width, baton->height,
636
- VImage::option()->set("extend", baton->extendWith));
637
- if (baton->keepGainMap) {
638
- gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
639
- baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
640
- ->set("extend", baton->extendWith)
641
- ->set("background", 0));
642
- }
614
+ }
615
+ 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);
619
+ }
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
+ if (baton->keepGainMap) {
626
+ gainMap = gainMap.embed(baton->extendLeft / gainMapScaleFactor, baton->extendTop / gainMapScaleFactor,
627
+ baton->width / gainMapScaleFactor, baton->height / gainMapScaleFactor, VImage::option()
628
+ ->set("extend", baton->extendWith)
629
+ ->set("background", 0));
643
630
  }
644
631
  }
645
632
  // Median - must happen before blurring, due to the utility of blurring after thresholding
@@ -957,6 +944,7 @@ class PipelineWorker : public Napi::AsyncWorker {
957
944
  baton->pageHeightOut = image.get_int(VIPS_META_PAGE_HEIGHT);
958
945
  baton->pagesOut = image.get_int(VIPS_META_N_PAGES);
959
946
  }
947
+ baton->hasAlphaOut = image.has_alpha();
960
948
 
961
949
  // Output
962
950
  sharp::SetTimeout(image, baton->timeoutSeconds);
@@ -996,6 +984,7 @@ class PipelineWorker : public Napi::AsyncWorker {
996
984
  } else {
997
985
  baton->channels = std::min(baton->channels, 3);
998
986
  }
987
+ baton->hasAlphaOut = false;
999
988
  } else if (baton->formatOut == "jp2" || (baton->formatOut == "input"
1000
989
  && inputImageType == sharp::ImageType::JP2)) {
1001
990
  // Write JP2 to Buffer
@@ -1078,6 +1067,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1078
1067
  if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
1079
1068
  sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
1080
1069
  baton->channels = std::min(baton->channels, 3);
1070
+ baton->hasAlphaOut = false;
1081
1071
  }
1082
1072
  // Cast pixel values to float, if required
1083
1073
  if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
@@ -1137,6 +1127,9 @@ class PipelineWorker : public Napi::AsyncWorker {
1137
1127
  area->free_fn = nullptr;
1138
1128
  vips_area_unref(area);
1139
1129
  baton->formatOut = "dz";
1130
+ if (baton->tileFormat == "jpeg") {
1131
+ baton->hasAlphaOut = false;
1132
+ }
1140
1133
  } else if (baton->formatOut == "jxl" ||
1141
1134
  (baton->formatOut == "input" && inputImageType == sharp::ImageType::JXL)) {
1142
1135
  // Write JXL to buffer
@@ -1224,6 +1217,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1224
1217
  }
1225
1218
  baton->formatOut = "jpeg";
1226
1219
  baton->channels = std::min(baton->channels, 3);
1220
+ baton->hasAlphaOut = false;
1227
1221
  } else if (baton->formatOut == "jp2" || (mightMatchInput && isJp2) ||
1228
1222
  (willMatchInput && (inputImageType == sharp::ImageType::JP2))) {
1229
1223
  // Write JP2 to file
@@ -1290,6 +1284,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1290
1284
  if (baton->tiffCompression == VIPS_FOREIGN_TIFF_COMPRESSION_JPEG) {
1291
1285
  sharp::AssertImageTypeDimensions(image, sharp::ImageType::JPEG);
1292
1286
  baton->channels = std::min(baton->channels, 3);
1287
+ baton->hasAlphaOut = false;
1293
1288
  }
1294
1289
  // Cast pixel values to float, if required
1295
1290
  if (baton->tiffPredictor == VIPS_FOREIGN_TIFF_PREDICTOR_FLOAT) {
@@ -1350,6 +1345,9 @@ class PipelineWorker : public Napi::AsyncWorker {
1350
1345
  vips::VOption *options = BuildOptionsDZ(baton);
1351
1346
  image.dzsave(const_cast<char*>(baton->fileOut.data()), options);
1352
1347
  baton->formatOut = "dz";
1348
+ if (baton->tileFormat == "jpeg") {
1349
+ baton->hasAlphaOut = false;
1350
+ }
1353
1351
  } else if (baton->formatOut == "v" || (mightMatchInput && isV) ||
1354
1352
  (willMatchInput && inputImageType == sharp::ImageType::VIPS)) {
1355
1353
  // Write V to file
@@ -1434,6 +1432,7 @@ class PipelineWorker : public Napi::AsyncWorker {
1434
1432
  info.Set("pageHeight", static_cast<int32_t>(baton->pageHeightOut));
1435
1433
  info.Set("pages", static_cast<int32_t>(baton->pagesOut));
1436
1434
  }
1435
+ info.Set("hasAlpha", baton->hasAlphaOut);
1437
1436
 
1438
1437
  if (baton->bufferOutLength > 0) {
1439
1438
  info.Set("size", static_cast<uint32_t>(baton->bufferOutLength));
package/src/pipeline.h CHANGED
@@ -49,6 +49,7 @@ struct PipelineBaton {
49
49
  int pageHeightOut;
50
50
  int pagesOut;
51
51
  bool typedArrayOut;
52
+ bool hasAlphaOut;
52
53
  std::vector<Composite *> composite;
53
54
  std::vector<sharp::InputDescriptor *> joinChannelIn;
54
55
  int topOffsetPre;
@@ -249,6 +250,7 @@ struct PipelineBaton {
249
250
  pageHeightOut(0),
250
251
  pagesOut(0),
251
252
  typedArrayOut(false),
253
+ hasAlphaOut(false),
252
254
  topOffsetPre(-1),
253
255
  topOffsetPost(-1),
254
256
  channels(0),
package/src/utilities.cc CHANGED
@@ -23,15 +23,15 @@ Napi::Value cache(const Napi::CallbackInfo& info) {
23
23
 
24
24
  // Set memory limit
25
25
  if (info[size_t(0)].IsNumber()) {
26
- vips_cache_set_max_mem(info[size_t(0)].As<Napi::Number>().Int32Value() * 1048576);
26
+ vips_cache_set_max_mem(static_cast<size_t>(info[size_t(0)].As<Napi::Number>().Uint32Value()) * 1048576);
27
27
  }
28
28
  // Set file limit
29
29
  if (info[size_t(1)].IsNumber()) {
30
- vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Int32Value());
30
+ vips_cache_set_max_files(info[size_t(1)].As<Napi::Number>().Uint32Value());
31
31
  }
32
32
  // Set items limit
33
33
  if (info[size_t(2)].IsNumber()) {
34
- vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Int32Value());
34
+ vips_cache_set_max(info[size_t(2)].As<Napi::Number>().Uint32Value());
35
35
  }
36
36
 
37
37
  // Get memory stats