mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Allow for negative top/left offsets in composite overlays
A top or left offset value of -1 will no longer mean that the value is not set, but will now be an actual offset of -1. INT_MIN for left & top will mean that the values are not set. Co-authored-by: Christian Flintrup <chr@gigahost.dk>
This commit is contained in:
committed by
Lovell Fuller
parent
182beaa4a1
commit
02676140e8
@@ -658,26 +658,18 @@ namespace sharp {
|
||||
int top = 0;
|
||||
|
||||
// assign only if valid
|
||||
if (x >= 0 && x < (inWidth - outWidth)) {
|
||||
if (x < (inWidth - outWidth)) {
|
||||
left = x;
|
||||
} else if (x >= (inWidth - outWidth)) {
|
||||
left = inWidth - outWidth;
|
||||
}
|
||||
|
||||
if (y >= 0 && y < (inHeight - outHeight)) {
|
||||
if (y < (inHeight - outHeight)) {
|
||||
top = y;
|
||||
} else if (y >= (inHeight - outHeight)) {
|
||||
top = inHeight - outHeight;
|
||||
}
|
||||
|
||||
// the resulting left and top could have been outside the image after calculation from bottom/right edges
|
||||
if (left < 0) {
|
||||
left = 0;
|
||||
}
|
||||
if (top < 0) {
|
||||
top = 0;
|
||||
}
|
||||
|
||||
return std::make_tuple(left, top);
|
||||
}
|
||||
|
||||
|
||||
@@ -570,7 +570,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
int left;
|
||||
int top;
|
||||
compositeImage = compositeImage.replicate(across, down);
|
||||
if (composite->left >= 0 && composite->top >= 0) {
|
||||
if (composite->hasOffset) {
|
||||
std::tie(left, top) = sharp::CalculateCrop(
|
||||
compositeImage.width(), compositeImage.height(), image.width(), image.height(),
|
||||
composite->left, composite->top);
|
||||
@@ -592,7 +592,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
// Calculate position
|
||||
int left;
|
||||
int top;
|
||||
if (composite->left >= 0 && composite->top >= 0) {
|
||||
if (composite->hasOffset) {
|
||||
// Composite image at given offsets
|
||||
std::tie(left, top) = sharp::CalculateCrop(image.width(), image.height(),
|
||||
compositeImage.width(), compositeImage.height(), composite->left, composite->top);
|
||||
@@ -1253,6 +1253,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
||||
composite->gravity = sharp::AttrAsUint32(compositeObject, "gravity");
|
||||
composite->left = sharp::AttrAsInt32(compositeObject, "left");
|
||||
composite->top = sharp::AttrAsInt32(compositeObject, "top");
|
||||
composite->hasOffset = sharp::AttrAsBool(compositeObject, "hasOffset");
|
||||
composite->tile = sharp::AttrAsBool(compositeObject, "tile");
|
||||
composite->premultiplied = sharp::AttrAsBool(compositeObject, "premultiplied");
|
||||
baton->composite.push_back(composite);
|
||||
|
||||
@@ -40,6 +40,7 @@ struct Composite {
|
||||
int gravity;
|
||||
int left;
|
||||
int top;
|
||||
bool hasOffset;
|
||||
bool tile;
|
||||
bool premultiplied;
|
||||
|
||||
@@ -47,8 +48,9 @@ struct Composite {
|
||||
input(nullptr),
|
||||
mode(VIPS_BLEND_MODE_OVER),
|
||||
gravity(0),
|
||||
left(-1),
|
||||
top(-1),
|
||||
left(0),
|
||||
top(0),
|
||||
hasOffset(false),
|
||||
tile(false),
|
||||
premultiplied(false) {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user