TIFF with alpha produces a corrupt output when JPG compressed.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
alexcgt
Posts: 11
Joined: 2018-06-14T05:47:35-07:00
Authentication code: 1152

TIFF with alpha produces a corrupt output when JPG compressed.

Post by alexcgt »

Compressing TIFF images containing alpha channel using JPG compression will randomly produce corrupt images.
The very same images without alpha channels will produce the correct output.

Source TIF image:
https://www.dropbox.com/s/3kehra55qw8308q/rgba.tif?dl=0

Screenshot of the compressed source image opened in Photoshop:
Image

Source image has been processed using the following command:

Code: Select all

magick mogrify -compress JPEG -quality 90 rgba.tif
I'm using:
ImageMagick-7.0.8-Q8
Windows 10 Pro
Photoshop 19
Last edited by alexcgt on 2018-06-18T06:56:15-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by snibgo »

With IM v7.0.7-28 Q16 on Windows 8.1, your command works for me, making text "ALPHA" in black on a transparent background.

Please paste the text output from "magick -version".
snibgo's IM pages: im.snibgo.com
alexcgt
Posts: 11
Joined: 2018-06-14T05:47:35-07:00
Authentication code: 1152

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by alexcgt »

Code: Select all

Version: ImageMagick 7.0.8-0 Q8 x64 2018-06-12 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by fmw42 »

It works fine for me also on IM 7.0.8.0 Q16 Mac OSX Sierra. I note that you are using Q8. Perhaps that is the issue. Or perhaps you need to upgrade libtiff?
alexcgt
Posts: 11
Joined: 2018-06-14T05:47:35-07:00
Authentication code: 1152

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by alexcgt »

It didn't work with Q16 either.
Q8, Q16, Dynamic, Static, Win32 -- they all produce corrupt alpha.
Oddly XnView doesn't see the image as corrupted but I don't trust XnView anymore.
And Photoshop shows the image as corrupted.

I was under the impression that IM install has everything that is required. Is libtiff an external library?
Is there any comprehensive upgrade guide?
All I get on the internet is some links to some repositories.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by snibgo »

Yes, the pre-compiled binaries for ImageMagick on Windows includes libtiff. In your "magick -version", the "Delegates (built-in)" line includes "tiff".

What does "magick -list format" say under TIFF lines? My version 7.0.7-28 says:

Code: Select all

     TIFF* TIFF      rw+   Tagged Image File Format (LIBTIFF, Version 4.0.9)
   TIFF64* TIFF      rw-   Tagged Image File Format (64-bit) (LIBTIFF, Version 4
.0.9)
Provided yours says 4.0.9 or greater, that should be okay.

Prior to this post, I didn't know that TIFF with JPEG compression could store alpha. It does, successfully for me.

Can you test with ZIP and LZW compression in TIFF? If they work, is one of those a satisfactory workaround for you?
snibgo's IM pages: im.snibgo.com
alexcgt
Posts: 11
Joined: 2018-06-14T05:47:35-07:00
Authentication code: 1152

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by alexcgt »

Thanks, snibgo.

At first, I thought it might be the libtiff trouble but it turns out to be something entirely different.

I spent many hours just to find out that the Photoshop indeed doesn't support JPEG-compressed TIFF containing alpha channels.
The problem is that it won't notify you about the invalid image format or that it has some troubles reading the format or something like that!
It will just open the image and will mess up the rightmost vertical quarter of the image (as in the screenshot).

You can actually save TIFF with JPEG compression in Photoshop but only if the image doesn't have an alpha channel.
Which is weird since just about every piece of software I have does process the format correctly.
And that includes Windows Explorer and Slack.
LZW or ZIP compression just won't do it for me since I'm processing high-resolution textures for models and they rarely contain data which is well compressed using non-lossy algorithms.

I've lost my trust in Photoshop.

Thanks for your help, folks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by snibgo »

Okay, a Photoshop problem.

Is JP2 an option for you? It compresses photos well, with transparency, and responds to "-quality" in the same way as JPG.

Code: Select all

magick toes_holed.png -quality 40 t.jp2
But JP2 isn't widely supported. I expect current Photoshop supports it, but you'll need to test.
snibgo's IM pages: im.snibgo.com
alexcgt
Posts: 11
Joined: 2018-06-14T05:47:35-07:00
Authentication code: 1152

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by alexcgt »

A very interesting suggestion regarding JP2 and Photoshop seems to be opening it correctly.
Unfortunately, I'm constrained by the formats which are supported by Unity3D and it currently doesn't have a support for JP2.
alexcgt
Posts: 11
Joined: 2018-06-14T05:47:35-07:00
Authentication code: 1152

Re: TIFF with alpha produces a corrupt output when JPG compressed.

Post by alexcgt »

...
Post Reply