From ee21d2991c798e73e44ea43a06153cbcbf416f13 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 31 Mar 2016 20:53:15 +0100 Subject: [PATCH] Use shrink-on-load for WebP input --- docs/changelog.md | 6 ++++++ src/pipeline.cc | 23 +++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 13756a3b..72e4dc03 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,11 @@ # Changelog +### v0.15 - "*outfit*" + +* Take advantage of libvips 8.3 features. + Use shrink-on-load for WebP input. + [#369](https://github.com/lovell/sharp/issues/369) + ### v0.14 - "*needle*" Requires libvips v8.2.3 diff --git a/src/pipeline.cc b/src/pipeline.cc index 2518c0f5..2fd4fa37 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -303,7 +303,8 @@ class PipelineWorker : public AsyncWorker { // but not when applying gamma correction or pre-resize extract int shrink_on_load = 1; if ( - xshrink == yshrink && inputImageType == ImageType::JPEG && xshrink >= 2 && + xshrink == yshrink && xshrink >= 2 && + (inputImageType == ImageType::JPEG || inputImageType == ImageType::WEBP) && baton->gamma == 0 && baton->topOffsetPre == -1 ) { if (xshrink >= 8) { @@ -329,15 +330,25 @@ class PipelineWorker : public AsyncWorker { xresidual = CalculateResidual(xshrink, xfactor); yresidual = CalculateResidual(yshrink, yfactor); // Reload input using shrink-on-load + VOption *option = VImage::option()->set("shrink", shrink_on_load); if (baton->bufferInLength > 1) { VipsBlob *blob = vips_blob_new(nullptr, baton->bufferIn, baton->bufferInLength); - image = VImage::jpegload_buffer(blob, VImage::option()->set("shrink", shrink_on_load)); + if (inputImageType == ImageType::JPEG) { + // Reload JPEG buffer + image = VImage::jpegload_buffer(blob, option); + } else { + // Reload WebP buffer + image = VImage::webpload_buffer(blob, option); + } vips_area_unref(reinterpret_cast(blob)); } else { - image = VImage::jpegload( - const_cast((baton->fileIn).data()), - VImage::option()->set("shrink", shrink_on_load) - ); + if (inputImageType == ImageType::JPEG) { + // Reload JPEG file + image = VImage::jpegload(const_cast((baton->fileIn).data()), option); + } else { + // Reload WebP file + image = VImage::webpload(const_cast((baton->fileIn).data()), option); + } } }