Use shrink-on-load for WebP input

This commit is contained in:
Lovell Fuller 2016-03-31 20:53:15 +01:00
parent f8eab49962
commit ee21d2991c
2 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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<VipsArea*>(blob));
} else {
image = VImage::jpegload(
const_cast<char*>((baton->fileIn).data()),
VImage::option()->set("shrink", shrink_on_load)
);
if (inputImageType == ImageType::JPEG) {
// Reload JPEG file
image = VImage::jpegload(const_cast<char*>((baton->fileIn).data()), option);
} else {
// Reload WebP file
image = VImage::webpload(const_cast<char*>((baton->fileIn).data()), option);
}
}
}