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 tiffsave doesn't set predictor correctly #2128

Closed
Adios opened this issue Mar 3, 2021 · 1 comment
Closed

vips tiffsave doesn't set predictor correctly #2128

Adios opened this issue Mar 3, 2021 · 1 comment

Comments

@Adios
Copy link
Contributor

Adios commented Mar 3, 2021

Bug report

Describe the bug

I try to re-compress an image in zip with --predictor set to horizontal as in

vips tiffsave GitHub-Mark.png vips_horizontal.tif --compression deflate --predictor horizontal

but it's seems to be ignored in the output image:

$ tiffinfo vips_horizontal.tif 
TIFF Directory at offset 0x3b3c (15164)
  Image Width: 560 Image Length: 560
  Resolution: 28.34, 28.34 pixels/cm
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Rows/Strip: 128
  Planar Configuration: single image plane

And no matter --predictor horizontal or --predictor none, they output the same file size, as if they were compressed without setting a predictor.

To Reproduce

Steps to reproduce the behavior:

  1. use image: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
  2. vips tiffsave GitHub-Mark.png vips_horizontal.tif --compression deflate --predictor horizontal
  3. tiffinfo vips_horizontal.tif
  4. vips tiffsave GitHub-Mark.png vips_none.tif --compression deflate --predictor none

Expected behavior

  1. Should see Predictor: horizontal differencing 2 (0x2) in the tiffinfo output
  2. vips_horizontal.tif & vips_none.tif should have different sizes (in most cases)

Actual behavior

  1. No Predictor: horizontal differencing 2 (0x2) in the tiffinfo output
  2. vips_horizontal.tif & vips_none.tif have the same size

Environment

  • Linux 5.11.2-arch1-1
$ pacman -Q libtiff libvips imagemagick
libtiff 4.2.0-1
libvips 8.10.3-1
imagemagick 7.0.11.2-1

Additional context

As a comparison, use ImageMagick:

magick convert GitHub-Mark.png -compress zip -define tiff:predictor=2 gm_horizontal.tif

Could see the Predictor filed is set,

$ tiffinfo gm_horizontal.tif 
TIFF Directory at offset 0x2494 (9364)
  Image Width: 560 Image Length: 560
  Bits/Sample: 8
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: palette color (RGB from colormap)
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 560
  Planar Configuration: single image plane
  Page Number: 0-1
  Color Map: (present)
  White Point: 0.3127-0.329
  PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000
  Predictor: horizontal differencing 2 (0x2)

And the generated image sizes are different: (with respect to -define tiff:predictor=1)

$ ls -l gm_horizontal.tif gm_none.tif 
-rw-r--r-- 1 adios adios 11174 Mar  4 04:18 gm_horizontal.tif
-rw-r--r-- 1 adios adios  9892 Mar  4 04:29 gm_none.tif

Additional context 2

I encountered this issue on Ubuntu (with homebrew) at beginning, and then I started a VM to install Arch to test and report the issue.

@jcupitt
Copy link
Member

jcupitt commented Mar 4, 2021

Hi @Adios, you're right, there was a mixup in enum values in the tiff saver which prevented it from setting the predictor correctly.

I now see:

$ vips tiffsave k2.jpg x.tif --compression deflate --predictor horizontal
$ tiffinfo x.tif
TIFF Directory at offset 0x38fa56 (3734102)
  Image Width: 1450 Image Length: 2048
  Resolution: 72.009, 72.009 pixels/inch
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: RGB color
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 3
  Rows/Strip: 128
  Planar Configuration: single image plane
  Predictor: horizontal differencing 2 (0x2)

This fix will be in 8.10.6, and I've credited you in the changelog.

Thank you very much for reporting this dumb thing!

jcupitt added a commit that referenced this issue Mar 4, 2021
the enums were mixed up, thanks Adios

see #2128
@jcupitt jcupitt closed this as completed Mar 4, 2021
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