GNOME Bugzilla – Bug 66886
Add support for multiple page TIFF images
Last modified: 2004-12-22 21:47:04 UTC
http://www.efax.com/ sends out multiple page .tiff files. As far as I can tell, gimp can view only the first page of these. It would be nice to see the rest.
The multiple pages could be loaded (and saved) as separate layers.
Multipage TIFFS are supported by the standard libtiff utiltites, available for almost all *nix and even Win32, and can be viewed with the GNU HaliFAX viewer, so the code to handle them is out there. A short term solution is to use tiffsplit to break the multipage image into single pages and edit them one at a time. However, the GIMP's 1 bit per pixel black and white palette option does not create a true BILEVEL image as needed by Group 3/4 Fax for multipage TIFFs. G3/4 faxes are highly compressed as runs of 0s and 1s, rather than individual bytes containing only 0 or 1 values. It would be nice to have an option to export true BILEVEL TIFFs, even as single pages, and this would be part of the solution to your request to load multiplage TIFFs too. Richard Nolde rnolde@ltgc.com
Changes at the request of Dave Neary on the developer mailing list. I am changing many of the bugzilla reports that have not specified a target milestone to Future milestone. Hope that is acceptable.
If libtiff supports this, I suspect that this should be relatively easy to implement. If someone who knows the libtiff library better than me can back this up, please add the "easy-fix" keyword. Raising priority since this is a frequently requested feature.
There is a patch against tiff.c plug-in to add ability to load multipage TIFF as an image with sevearl layers. I'm not fluent with GIMP plug-in API, so I don't know how to save the multilayer file in form of multipage TIFF, likely I shall try to figure out how it may be done and prepare additional patch. There are a few lines of new code only, but patch looks long because of tabulation changes: the large block of the code goes into loop brackets. You can prepare multipage TIFF for testing with the tiffcp utility: $ tiffcp in1.tiff in2.tiff ... out.tif
Created attachment 21935 [details] [review] Patch to load multipage TIFF
Looks good from a quick glimpse at the patch. Perhaps I can later today find the time to review the patch more thoroughly.
Created attachment 22006 [details] [review] updated patch
There were a few minor problems that I tried to address. For example, GIMP wants you to add an alpha channel to all layers but the Background layer. I tried to address these issues. My new patch also contains some more code cleanup in the tiff plug-in. I would appreciate some testing before I commit this.
I'm committing this change because I believe it is correct but needs testing. The only way to get it tested is to get it out to the people. If this change breaks the plug-in, it should be backed out and postponed until after the 2.0 release. 2003-12-02 Sven Neumann <sven@gimp.org> * plug-ins/common/tiff.c: applied a modified version of a patch submitted by Andrey Kiselev. Implements loading of TIFF files with multiple pages (bug #66886).
Adding a searchable comment to this bug. Several panorama stitching tools based on the 'panotools' library also support multiple-image "layered" tiff formats. Note that like xcf, the tiff layers do not need to have the same bounds as the full image area. It looks like this is not active in the 1.3.23 .rpm I have, so I won't reopen this unless it doesn't appear to work in the 1.3.24 or so.
Multi-page tiff files now are loading here (gimp-2 pre1). There are some remaining issues: Layer offsets are ignored, all layers are placed at the top left. The canvas is sized to the dimensions of the bottom layer. Layer masks are loaded as alpha channels rather than masks. This loses information where transparency is 100%.
Created attachment 23116 [details] [review] Added support for non-premultiplied alpha channels, and layer offsets
I uploaded a patch to tiff.c by Pablo D'Angelo. This adds support for reading layer offsets in tiff files and for reading non-premultiplied alpha channels properly. Tested ok on a photoshop6 (single layer) tiff file, a multi-layer FAX format tiff file and various tiff files generated by hugin/nona.
This looks good (except some style issues and // comments). However I think that while the fix for layer offsets should be applied before 2.0, the masks patch should wait until 2.0.1 or 2.2 (that would have to be decided still). It would be very much appreciated if you could open two new bug reports. One about layer offsets in multi-page TIFF files, the other about the mask fix. Please attach the patch there then. Or, and that would be very nice, create individual patches for each bug report.
About the alpha channel stuff. Currently the tiff plugin violates the tiff specification, by always assuming premultiplied alpha, even if the tiff file explicitly states otherwise. Maybe the current behaviour while saving might be expected by some people (although I would rate it counterintitive). However, I expect that valid tiff files should be read properly. Or are there important tiff writers that save the alpha channel in a way that does not confirm to the TIFF spec? See the current tiff spec, available at http://partners.adobe.com/ asn/developer/PDFS/TN/TIFF6.pdf page 31,32 and 77 Pablo d'Angelo
It would really help us a lot if you could file two bug reports for these two issues.
New reports have been opened as bug #131016 and bug #131030.