Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering or logging in.

CTS 33 - TIFF with alpha channel not correct

  • 3 Replies
  • 50 Views
*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 749
    • View Profile
CTS 33 - TIFF with alpha channel not correct
« October 24, 2020, 01:34:09 PM »
opened by carygravel on GitHub:

In the attached zip file are a TIFF with alpha layer, created by imagemagick with:
Code: [Select]
convert -depth 1 -gravity center -pointsize 78 -size 1000x568 caption:'Lorem ipsum etc etc' alpha.tif
and a PDF created by the following Perl code (also in the zip file as alpha.pl

The PDF is corrupt, and the Perl code produce the warning: Don't know what to do with alpha layer in TIFF

This is tested with Graphics::TIFF.
Code: [Select]
#!/usr/bin/perl
use warnings;
use strict;
use PDF::Builder;

my $width = 1000;
my $height = 568;
my $pdf = PDF::Builder->new(-file => 'alpha.pdf');
my $page = $pdf->page();
$page->mediabox($width, $height);
my $gfx = $page->gfx();
my $img = $pdf->image_tiff('alpha.tif');
$gfx->image($img, 0, 0, $width, $height);
$pdf->save();
$pdf->end();

reply by carygravel
Without Graphics::TIFF, the warning becomes Your system does not have Graphics::TIFF installed, so some TIFF functions may not run correctly. and the PDF is blank.
« Last Edit: October 24, 2020, 01:52:53 PM by Phil »

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 749
    • View Profile
Re: CTS 33 - TIFF with alpha channel not correct
« Reply #1: October 24, 2020, 01:52:17 PM »
PhilterPaper replied

Thank you for the report. I am able to replicate the problem and hope to have time to look at it very soon. I presume that the second PDF you sent was from alpha.pl without Graphics::TIFF. It is reported as corrupt when attempting to open it.

When I look at alpha.tif in GIMP, all I see is an empty transparent canvas, so it may not be handling it correctly. Windows Photo Viewer, Photos, Paint, and Paint 3D; as well as AutoDesk Sketchbook report that it's damaged or an unsupported format, I'll have to find a TIFF viewer for Windows, to make sure the original alpha.tif is uncorrupted.

I need to do some research on TIFF and alpha channels, but a quick look suggests that TIFF does support an alpha channel. Now to see if libtiff and Graphics::TIFF officially support alpha. By any chance can you quote chapter and verse that says it's supposed to support an alpha channel?

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 749
    • View Profile
Re: CTS 33 - TIFF with alpha channel not correct
« Reply #2: October 24, 2020, 05:32:09 PM »
carygravel replied:

http://www.libtiff.org/libtiff.html, section "TIFFRGBAImage Support". A stands for Alpha.

ImageMagick displays alpha.tif without problem.

However, tiff2pdf, which is a utility which is part of libtiff, produces the same corrupt image as in the original report.

PhilterPaper replied:

It looks like I may have to install the Windows version of ImageMagick, in order to get a good TIFF viewer. Recall that tiff2pdf was mentioned in the original skip message for Test 9 -- I guess that matters haven't improved in many years. Perhaps TIFF + Alpha channel is so unusual that most viewers don't bother supporting it?

A quick look at the TIFF_GT module in PDF::Builder suggests that it's aware of Gray+Alpha and RGBA, but the author never went very far in writing for it. I need to find some documentation for libtiff/Graphics::TIFF that explains why bitsPerSample only has a value of 1 (just black & white image?) and how it relates to SamplesPerPixel. Hopefully it will be in the libtiff link above. Once I can get the Alpha layer separated out cleanly, I should be able to borrow some code from the PNG module to handle it properly for the PDF.

*

Offline Phil

  • Global Moderator
  • Hero Member
  • *****
  • 749
    • View Profile
Re: CTS 33 - TIFF with alpha channel not correct
« Reply #3: October 31, 2020, 08:56:53 AM »
carygravel on 25 October 2020 replied:

I've had gscan2pdf users complain about TIFF+Alpha not working, but I agree that it's not very common.