mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Options for trim op must be an Object, add lineArt #2363
This commit is contained in:
@@ -265,7 +265,7 @@ namespace sharp {
|
||||
/*
|
||||
Trim an image
|
||||
*/
|
||||
VImage Trim(VImage image, std::vector<double> background, double threshold) {
|
||||
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt) {
|
||||
if (image.width() < 3 && image.height() < 3) {
|
||||
throw VError("Image to trim must be at least 3x3 pixels");
|
||||
}
|
||||
@@ -287,6 +287,7 @@ namespace sharp {
|
||||
int left, top, width, height;
|
||||
left = image.find_trim(&top, &width, &height, VImage::option()
|
||||
->set("background", background)
|
||||
->set("line_art", lineArt)
|
||||
->set("threshold", threshold));
|
||||
if (HasAlpha(image)) {
|
||||
// Search alpha channel (A)
|
||||
@@ -294,6 +295,7 @@ namespace sharp {
|
||||
VImage alpha = image[image.bands() - 1];
|
||||
leftA = alpha.find_trim(&topA, &widthA, &heightA, VImage::option()
|
||||
->set("background", backgroundAlpha)
|
||||
->set("line_art", lineArt)
|
||||
->set("threshold", threshold));
|
||||
if (widthA > 0 && heightA > 0) {
|
||||
if (width > 0 && height > 0) {
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace sharp {
|
||||
/*
|
||||
Trim an image
|
||||
*/
|
||||
VImage Trim(VImage image, std::vector<double> background, double const threshold);
|
||||
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt);
|
||||
|
||||
/*
|
||||
* Linear adjustment (a * in + b)
|
||||
|
||||
@@ -126,10 +126,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
}
|
||||
|
||||
// Trim
|
||||
if (baton->trimThreshold > 0.0) {
|
||||
if (baton->trimThreshold >= 0.0) {
|
||||
MultiPageUnsupported(nPages, "Trim");
|
||||
image = sharp::StaySequential(image, access);
|
||||
image = sharp::Trim(image, baton->trimBackground, baton->trimThreshold);
|
||||
image = sharp::Trim(image, baton->trimBackground, baton->trimThreshold, baton->trimLineArt);
|
||||
baton->trimOffsetLeft = image.xoffset();
|
||||
baton->trimOffsetTop = image.yoffset();
|
||||
}
|
||||
@@ -182,7 +182,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
// - trimming or pre-resize extract isn't required;
|
||||
// - input colourspace is not specified;
|
||||
bool const shouldPreShrink = (targetResizeWidth > 0 || targetResizeHeight > 0) &&
|
||||
baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimThreshold == 0.0 &&
|
||||
baton->gamma == 0 && baton->topOffsetPre == -1 && baton->trimThreshold < 0.0 &&
|
||||
baton->colourspaceInput == VIPS_INTERPRETATION_LAST && !shouldRotateBefore;
|
||||
|
||||
if (shouldPreShrink) {
|
||||
@@ -1248,11 +1248,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
info.Set("attentionX", static_cast<int32_t>(baton->attentionX));
|
||||
info.Set("attentionY", static_cast<int32_t>(baton->attentionY));
|
||||
}
|
||||
if (baton->trimThreshold > 0.0) {
|
||||
if (baton->trimThreshold >= 0.0) {
|
||||
info.Set("trimOffsetLeft", static_cast<int32_t>(baton->trimOffsetLeft));
|
||||
info.Set("trimOffsetTop", static_cast<int32_t>(baton->trimOffsetTop));
|
||||
}
|
||||
|
||||
if (baton->input->textAutofitDpi) {
|
||||
info.Set("textAutofitDpi", static_cast<uint32_t>(baton->input->textAutofitDpi));
|
||||
}
|
||||
@@ -1519,6 +1518,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
||||
baton->thresholdGrayscale = sharp::AttrAsBool(options, "thresholdGrayscale");
|
||||
baton->trimBackground = sharp::AttrAsVectorOfDouble(options, "trimBackground");
|
||||
baton->trimThreshold = sharp::AttrAsDouble(options, "trimThreshold");
|
||||
baton->trimLineArt = sharp::AttrAsBool(options, "trimLineArt");
|
||||
baton->gamma = sharp::AttrAsDouble(options, "gamma");
|
||||
baton->gammaOut = sharp::AttrAsDouble(options, "gammaOut");
|
||||
baton->linearA = sharp::AttrAsVectorOfDouble(options, "linearA");
|
||||
|
||||
@@ -92,6 +92,7 @@ struct PipelineBaton {
|
||||
bool thresholdGrayscale;
|
||||
std::vector<double> trimBackground;
|
||||
double trimThreshold;
|
||||
bool trimLineArt;
|
||||
int trimOffsetLeft;
|
||||
int trimOffsetTop;
|
||||
std::vector<double> linearA;
|
||||
@@ -260,7 +261,8 @@ struct PipelineBaton {
|
||||
threshold(0),
|
||||
thresholdGrayscale(true),
|
||||
trimBackground{},
|
||||
trimThreshold(0.0),
|
||||
trimThreshold(-1.0),
|
||||
trimLineArt(false),
|
||||
trimOffsetLeft(0),
|
||||
trimOffsetTop(0),
|
||||
linearA{},
|
||||
|
||||
Reference in New Issue
Block a user