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

Converting 1-bpp PNG into TIFF does not preserve depth #277

Closed
ppisar opened this issue Sep 29, 2016 · 8 comments
Closed

Converting 1-bpp PNG into TIFF does not preserve depth #277

ppisar opened this issue Sep 29, 2016 · 8 comments

Comments

@ppisar
Copy link

ppisar commented Sep 29, 2016

After upgrading from 6.9.2-7 to 6.9.3-0 I found that conversion from PNG into TIFF stopped preserving image depth. The same issue is with latest 6.9.5-5:

$ convert -version
Version: ImageMagick 6.9.2-7 Q16 x86_64 2016-09-29 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib

$ convert in.png out.tiff && file in.png out.tiff 
in.png:   PNG image data, 157 x 196, 1-bit grayscale, non-interlaced
out.tiff: TIFF image data, little-endian, direntries=16, height=196, bps=1, compression=deflate, PhotometricIntepretation=BlackIsZero, orientation=upper-left, width=157

$ convert -version
Version: ImageMagick 6.9.5-5 Q16 x86_64 2016-09-29 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib

$ convert in.png out.tiff && file in.png out.tiff 
in.png:   PNG image data, 157 x 196, 1-bit grayscale, non-interlaced
out.tiff: TIFF image data, little-endian, direntries=17, height=196, bps=8, compression=deflate, PhotometricIntepretation=BlackIsZero, orientation=upper-left, width=157
@ppisar
Copy link
Author

ppisar commented Sep 29, 2016

This is the input in.png
in.

@ppisar
Copy link
Author

ppisar commented Sep 29, 2016

I also tried 6.9.5-10. The bug is there too.

marschap pushed a commit to marschap/gscan2pdf that referenced this issue Mar 26, 2017
When saving an imported PDF 1-bpp images are corrupted
<https://bugzilla.redhat.com/show_bug.cgi?id=1369984>.

This due to bug in PDF::API2
<https://rt.cpan.org/Public/Bug/Display.html?id=118047> and a change
in ImageMagick
<ImageMagick/ImageMagick#277>.

This patch makes sure the image depth is preserved at conversion to
TIFF by Image::Magick. Otherwise 8-bpp TIFFs got broken by PDF::API2.

Signed-off-by: Petr Písař <ppisar@redhat.com>
@dlemstra
Copy link
Member

dlemstra commented Sep 4, 2017

The PNG reader calls png_set_packing and changes the depth of the image from 1 bit to 8 bit. This patch was added a while back. Maybe @glennrp can explain why this was added?

@glennrp
Copy link
Contributor

glennrp commented Sep 5, 2017

We call png_set_packing in the decoder to expand the samples to 8 bits, but we also call png_set_packing in the encoder to pack them into 8-sample bytes again.

@glennrp
Copy link
Contributor

glennrp commented Sep 5, 2017

I don't see anything in the ChangeLog nor is there any difference between 6.9.2-6/coders/png.c and 6.9.3-1/coders/png.c that would explain this.

@dlemstra
Copy link
Member

dlemstra commented Sep 5, 2017

I think the line https://github.com/ImageMagick/ImageMagick/blob/ImageMagick-6/coders/png.c#L2433 is setting the depth to 8 bit instead of 1 bit.

@ppisar
Copy link
Author

ppisar commented May 3, 2019

I can see 6.9.9-38 is still broken.

@ppisar
Copy link
Author

ppisar commented Sep 16, 2019

6.9.10-64 is also broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants