Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vips resize corrupts image #1499

Closed
angelmixu opened this issue Dec 13, 2019 · 10 comments
Closed

vips resize corrupts image #1499

angelmixu opened this issue Dec 13, 2019 · 10 comments

Comments

@angelmixu
Copy link

angelmixu commented Dec 13, 2019

Hi!

While using the C interface I came to an strange behaviour, when resizing an image with a text (it's a LAB file with black text inside) it generates a bigger image, but with the insides of the text filled with random pixels.

It doesn't happen only when using nearest or linear interpolator, on the others, the image is corrupted.

I have taken a look at the interpolators, and it's a little difficult for me understanding the behaviour to fix it.

I have tested it on macOS Mojave, using libvips homebrew commandline:

$ vips -v
vips-8.8.4-Thu Dec  5 16:24:34 UTC 2019

The command lines I used:

$ vips resize failing_vips_resize_8bit.tif failing_vips_resize_8bit-out.tif 3.0 --kernel lanczos3
$ vips resize failing_vips_resize_16bit.tif failing_vips_resize_16bit-out.tif 3.0 --kernel lanczos3

Here it is attached the two original files, and the output of the command
vips_resize_corruption.zip

If using the 16bit LAB image, the output image gets the text corrupted, and the 8bit one, can't be opened in Photoshop, it says the TIFF file uses an unsupported bit depth.

This is a screenshot of how Photoshop shows the 16bit output image:
Screenshot 2019-12-13 at 10 26 34

EDIT: I tested the 8bit image converted to RGB and it's working correctly.

@jcupitt
Copy link
Member

jcupitt commented Dec 13, 2019

The 8-bit one is fine, but the 16-bit one is not saving LABS back to 16-bit TIF correctly.

I'll have a look, thanks for the report.

jcupitt added a commit that referenced this issue Dec 13, 2019
Negative L in LABS needs to be trimmed off before savingf as TIFF.
Thanks angelmixu.

See #1499
@jcupitt
Copy link
Member

jcupitt commented Dec 13, 2019

OK, fixed in master, thanks for the report!

@angelmixu
Copy link
Author

angelmixu commented Dec 13, 2019

Thanks for the quick fix! :)

For me, the failing_vips_resize_8bit-out.tif file, was the one I can't open on Photoshop.

@jcupitt
Copy link
Member

jcupitt commented Dec 14, 2019

The 8-bit one is saved as float TIFF, which photoshop does not support.

@jcupitt
Copy link
Member

jcupitt commented Dec 14, 2019

You can turn float LAB into 8-bit LAB like this:

vips lab2labq failing_vips_resize_8bit-out.tif x.tif

@angelmixu
Copy link
Author

Oh :/
I could do that, but from a user's point of view, shouldn't a resize maintain the same bit depth of the original image?

angelmixu pushed a commit to angelmixu/libvips that referenced this issue Dec 16, 2019
Negative L in LABS needs to be trimmed off before savingf as TIFF.
Thanks angelmixu.

See libvips#1499
@jcupitt
Copy link
Member

jcupitt commented Dec 18, 2019

libvips does not usually recode explicitly -- it's done by the savers and only when needed.

This case is odd because TIFF supports both 8-bit and 32-bit LAB, so there's an ambiguity. Let's add a recode as a nasty and hacky special case just for resize, since that must be the most common case.

@angelmixu
Copy link
Author

Thanks!

The other issue is this one: #1473

I'm wondering if there could be a generic solution to both cases, but can't think of one right now :/
Maybe a tag for maintaining the output format that should be, or alike.

jcupitt added a commit that referenced this issue Dec 18, 2019
The "squash" option to tiffsave now also squashes 32-bit 3-band float
CIELAB images down to 8 bits.

See #1499
@jcupitt
Copy link
Member

jcupitt commented Dec 18, 2019

I changed my mind -- it was too hacky.

Instead, the "squash" option to tiffsave turns 3-band float LAB into 8-bit, eg.:

$ vips resize failing_vips_resize_8bit.tif x.tif[squash] 2
$ vipsheader x.tif
x.tif: 5400x240, labq, tiffload_stream

@jcupitt
Copy link
Member

jcupitt commented Jan 24, 2020

I think (?) this is done now, I'll close.

@jcupitt jcupitt closed this as completed Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants