Sharp: outline getting removed on resize

Created on 13 Oct 2020  路  9Comments  路  Source: lovell/sharp

we have an issue with black outlines of images getting removed in the current version (0.26.1). In 0.24.1 we still had the outline, though it was more grey than black.
What are the steps to reproduce?

sharp("test.jpg").resize({width: 1400}).toFile("test2.jpg")

What is the expected behaviour?
the outline is still visible after resizing the image
test image:

test

test result in 0.26.1
test0 26

test result in 0.24.1:
test2

any ideas?

blocked-upstream-dependency

Most helpful comment

I could reproduce this on libvips master with:

vips resize x.jpg tn_x.jpg 0.929615

This small + 0.5-patch in the libvips mask calculations seems to resolve this.


Patch

diff --git a/libvips/resample/templates.h b/libvips/resample/templates.h
index 1111111..2222222 100644
--- a/libvips/resample/templates.h
+++ b/libvips/resample/templates.h
@@ -329,7 +329,7 @@ calculate_coefficients_triangle( double *c,

    sum = 0;
    for( i = 0; i < n_points; i++ ) {
-       const double xp = (i - half) / shrink;
+       const double xp = (i - half + 0.5) / shrink;

        double l;

@@ -367,7 +367,7 @@ calculate_coefficients_cubic( double *c,

    sum = 0;
    for( i = 0; i < n_points; i++ ) {
-       const double xp = (i - half) / shrink;
+       const double xp = (i - half + 0.5) / shrink;
        const double axp = VIPS_FABS( xp ); 
        const double axp2 = axp * axp;
        const double axp3 = axp2 * axp;
@@ -416,7 +416,7 @@ calculate_coefficients_lanczos( double *c,

    sum = 0;
    for( i = 0; i < n_points; i++ ) {
-       const double xp = (i - half) / shrink;
+       const double xp = (i - half + 0.5) / shrink;

        double l;

(I'm not sure if this patch could cause regressions, I'll have to check this against this and this repository)

I now see:


Output image

tn_x

/cc @jcupitt as he recently did https://github.com/libvips/libvips/pull/1647.

All 9 comments

Hi, did you see the fastShrinkOnLoad option?

https://sharp.pixelplumbing.com/api-resize#parameters

unfortunately this doesn't work
sharp("test.jpg").resize({width: 1400,fastShrinkOnLoad:true}).toFile("test0.26_fast.jpg")
test0 26_fast

I could reproduce this on libvips master with:

vips resize x.jpg tn_x.jpg 0.929615

This small + 0.5-patch in the libvips mask calculations seems to resolve this.


Patch

diff --git a/libvips/resample/templates.h b/libvips/resample/templates.h
index 1111111..2222222 100644
--- a/libvips/resample/templates.h
+++ b/libvips/resample/templates.h
@@ -329,7 +329,7 @@ calculate_coefficients_triangle( double *c,

    sum = 0;
    for( i = 0; i < n_points; i++ ) {
-       const double xp = (i - half) / shrink;
+       const double xp = (i - half + 0.5) / shrink;

        double l;

@@ -367,7 +367,7 @@ calculate_coefficients_cubic( double *c,

    sum = 0;
    for( i = 0; i < n_points; i++ ) {
-       const double xp = (i - half) / shrink;
+       const double xp = (i - half + 0.5) / shrink;
        const double axp = VIPS_FABS( xp ); 
        const double axp2 = axp * axp;
        const double axp3 = axp2 * axp;
@@ -416,7 +416,7 @@ calculate_coefficients_lanczos( double *c,

    sum = 0;
    for( i = 0; i < n_points; i++ ) {
-       const double xp = (i - half) / shrink;
+       const double xp = (i - half + 0.5) / shrink;

        double l;

(I'm not sure if this patch could cause regressions, I'll have to check this against this and this repository)

I now see:


Output image

tn_x

/cc @jcupitt as he recently did https://github.com/libvips/libvips/pull/1647.

With commit https://github.com/kleisauke/libvips/commit/18eebf7a9491163d72e07f9c674a9af1c9517a90 (included in PR https://github.com/libvips/libvips/pull/1769), I now see:


Output image

tn_x

Which looks to be the correct output for this image. This change causes no regressions on the above linked repositories. It also seems to improve the 9.4x resize on the pyvips-issue-148 repository, see:
| VIPS before | VIPS after |
| :---: | :---: |
| 8x_vips_resize.png | 8x_vips_resize.png |
| Above border is missing | No missing borders |

This sounds great! How ist your process now? will there be a bugfix version?

@markusmoormann Please subscribe to https://github.com/libvips/libvips/pull/1769 for updates.

This is fixed in libvips 8.10.4, which will be included in the prebuilt binaries provided by sharp v0.27.0.

Great! @lovell when will v0.27.0 be released?

sharp v0.27.0 now available with a prebuilt libvips v8.10.5 - thanks for reporting this.

Was this page helpful?
0 / 5 - 0 ratings