diff --git a/docs/changelog.md b/docs/changelog.md index 62ab2dc5..c95cff0e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -22,6 +22,10 @@ Requires libvips v8.6.0. [#977](https://github.com/lovell/sharp/pull/977) [@jardakotesovec](https://github.com/jardakotesovec) +* Add tilecache before smartcrop to avoid over-computation of previous operations. + [#1028](https://github.com/lovell/sharp/issues/1028) + [@coffeebite](https://github.com/coffeebite) + * TIFF output: switch default predictor from 'none' to 'horizontal' to match libvips' behaviour. ### v0.18 - "*ridge*" diff --git a/src/operations.cc b/src/operations.cc index 274ec911..2ab69cf5 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -267,23 +267,6 @@ namespace sharp { } } - /* - Insert a tile cache to prevent over-computation of any previous operations in the pipeline - */ - VImage TileCache(VImage image, double const factor) { - int tile_width; - int tile_height; - int scanline_count; - vips_get_tile_size(image.get_image(), &tile_width, &tile_height, &scanline_count); - double const need_lines = 1.2 * scanline_count / factor; - return image.tilecache(VImage::option() - ->set("tile_width", image.width()) - ->set("tile_height", 10) - ->set("max_tiles", static_cast(round(1.0 + need_lines / 10.0))) - ->set("access", VIPS_ACCESS_SEQUENTIAL) - ->set("threaded", TRUE)); - } - VImage Threshold(VImage image, double const threshold, bool const thresholdGrayscale) { if (!thresholdGrayscale) { return image >= threshold; diff --git a/src/operations.h b/src/operations.h index 529bca44..1493d519 100644 --- a/src/operations.h +++ b/src/operations.h @@ -72,11 +72,6 @@ namespace sharp { */ VImage Sharpen(VImage image, double const sigma, double const flat, double const jagged); - /* - Insert a tile cache to prevent over-computation of any previous operations in the pipeline - */ - VImage TileCache(VImage image, double const factor); - /* Threshold an image */ diff --git a/src/pipeline.cc b/src/pipeline.cc index bcf1d394..58102ccd 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -466,6 +466,9 @@ class PipelineWorker : public Nan::AsyncWorker { image = image.extract_area(left, top, width, height); } else { // Attention-based or Entropy-based crop + image = image.tilecache(VImage::option() + ->set("access", baton->accessMethod) + ->set("threaded", TRUE)); image = image.smartcrop(baton->width, baton->height, VImage::option() ->set("interesting", baton->crop == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION)); baton->hasCropOffset = true;