mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add coords to output when using attention based crop (#3470)
This commit is contained in:
@@ -456,6 +456,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
// Gravity-based crop
|
||||
int left;
|
||||
int top;
|
||||
|
||||
std::tie(left, top) = sharp::CalculateCrop(
|
||||
inputWidth, inputHeight, baton->width, baton->height, baton->position);
|
||||
int width = std::min(inputWidth, baton->width);
|
||||
@@ -466,16 +467,25 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
left, top, width, height, nPages, &targetPageHeight)
|
||||
: image.extract_area(left, top, width, height);
|
||||
} else {
|
||||
int attention_x;
|
||||
int attention_y;
|
||||
|
||||
// Attention-based or Entropy-based crop
|
||||
MultiPageUnsupported(nPages, "Resize strategy");
|
||||
image = image.tilecache(VImage::option()
|
||||
->set("access", VIPS_ACCESS_RANDOM)
|
||||
->set("threaded", TRUE));
|
||||
|
||||
image = image.smartcrop(baton->width, baton->height, VImage::option()
|
||||
->set("interesting", baton->position == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION));
|
||||
->set("interesting", baton->position == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION)
|
||||
->set("attention_x", &attention_x)
|
||||
->set("attention_y", &attention_y));
|
||||
baton->hasCropOffset = true;
|
||||
baton->cropOffsetLeft = static_cast<int>(image.xoffset());
|
||||
baton->cropOffsetTop = static_cast<int>(image.yoffset());
|
||||
baton->hasAttentionCenter = true;
|
||||
baton->attentionX = static_cast<int>(attention_x * jpegShrinkOnLoad / scale);
|
||||
baton->attentionY = static_cast<int>(attention_y * jpegShrinkOnLoad / scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1198,6 +1208,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
info.Set("cropOffsetLeft", static_cast<int32_t>(baton->cropOffsetLeft));
|
||||
info.Set("cropOffsetTop", static_cast<int32_t>(baton->cropOffsetTop));
|
||||
}
|
||||
if (baton->hasAttentionCenter) {
|
||||
info.Set("attentionX", static_cast<int32_t>(baton->attentionX));
|
||||
info.Set("attentionY", static_cast<int32_t>(baton->attentionY));
|
||||
}
|
||||
if (baton->trimThreshold > 0.0) {
|
||||
info.Set("trimOffsetLeft", static_cast<int32_t>(baton->trimOffsetLeft));
|
||||
info.Set("trimOffsetTop", static_cast<int32_t>(baton->trimOffsetTop));
|
||||
|
||||
@@ -74,6 +74,9 @@ struct PipelineBaton {
|
||||
bool hasCropOffset;
|
||||
int cropOffsetLeft;
|
||||
int cropOffsetTop;
|
||||
bool hasAttentionCenter;
|
||||
int attentionX;
|
||||
int attentionY;
|
||||
bool premultiplied;
|
||||
bool tileCentre;
|
||||
bool fastShrinkOnLoad;
|
||||
@@ -236,6 +239,9 @@ struct PipelineBaton {
|
||||
hasCropOffset(false),
|
||||
cropOffsetLeft(0),
|
||||
cropOffsetTop(0),
|
||||
hasAttentionCenter(false),
|
||||
attentionX(0),
|
||||
attentionY(0),
|
||||
premultiplied(false),
|
||||
tintA(128.0),
|
||||
tintB(128.0),
|
||||
|
||||
Reference in New Issue
Block a user