GNOME Bugzilla – Bug 147328
CMYK TIFF channels reversed on big-endian host
Last modified: 2004-07-14 10:57:38 UTC
When loading a CMYK TIFF file into Gimp, an RGBA conversion is applied by libtiff. Unfortunately libtiff puts the pixels in an endian-sensitive uint32 buffer, and on a big-endian host such as PowerPC the result is an ugly ABGR image. A simple run through GUINT32_TO_LE over the pixels before shoving them at gimp_pixel_rgb_set_rect() fixes this. (Patch to current CVS to be attached.)
Created attachment 29435 [details] A small CMYK TIFF image exhibiting the bug if loaded on big-endian host
Created attachment 29436 [details] Image as saved from broken Gimp, showing reversed ABGR channels
Created attachment 29437 [details] [review] Quick fix patch
Shouldn't libtiff be doing this?
Libtiff is behaving according to spec; see the man page for TIFFReadRGBAImage. It could perhaps be rewritten to use the TIFFRGBAImage* functions... this could probably save memory during load, too, by putting lines into gimp as they're loaded instead of the extra image buffer it uses now. I'll give that a try. Anyway the majority of images (RGB(A) and grayscale) go through different code paths already.
OK, confirming this bug then. It would be nice to see the load routine changed in the way you suggested because a plug-in should avoid to allocate a buffer of the full image size. If you can come up with such a patch, that would be appreciated. Otherwise your simple patch should be committed before 2.0.3 is released (scheduled for next weekend).
Created attachment 29518 [details] [review] optimized quick-fix Sorry to nitpick, but this sort of thing bothers me.
Created attachment 29525 [details] [review] Possible alternate patch to load with smaller buffers As per comment #5; sticks a callback in which cheats using smaller intermediate buffers instead of loading everything into an image-sized buffer and then slurping it into gimp. I'm not really sure I like this; it feels kind of fragile and might be making unwarranted assumptions that could break if libtiff changes, etc.
Yeah, it doesn't look straight-forward so we should better stick with the first patch or rather the optimized version of it. Should be committed to both branches.
Applied to HEAD and stable branch: 2004-07-14 Sven Neumann <sven@gimp.org> * plug-ins/common/tiff.c: applied a patch done by Brion Vibber and Philip Lafleur that fixes loading of CMYK TIFF images on big-endian hardware (bug #147328).