After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 147328 - CMYK TIFF channels reversed on big-endian host
CMYK TIFF channels reversed on big-endian host
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
2.0.x
Other All
: High normal
: 2.0
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2004-07-11 06:27 UTC by Brion Vibber
Modified: 2004-07-14 10:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
A small CMYK TIFF image exhibiting the bug if loaded on big-endian host (193.20 KB, image/tiff)
2004-07-11 06:29 UTC, Brion Vibber
  Details
Image as saved from broken Gimp, showing reversed ABGR channels (95.91 KB, image/png)
2004-07-11 06:30 UTC, Brion Vibber
  Details
Quick fix patch (786 bytes, patch)
2004-07-11 06:31 UTC, Brion Vibber
none Details | Review
optimized quick-fix (878 bytes, patch)
2004-07-13 22:42 UTC, Philip L
accepted-commit_now Details | Review
Possible alternate patch to load with smaller buffers (4.71 KB, patch)
2004-07-14 06:03 UTC, Brion Vibber
none Details | Review

Description Brion Vibber 2004-07-11 06:27: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.)
Comment 1 Brion Vibber 2004-07-11 06:29:25 UTC
Created attachment 29435 [details]
A small CMYK TIFF image exhibiting the bug if loaded on big-endian host
Comment 2 Brion Vibber 2004-07-11 06:30:47 UTC
Created attachment 29436 [details]
Image as saved from broken Gimp, showing reversed ABGR channels
Comment 3 Brion Vibber 2004-07-11 06:31:42 UTC
Created attachment 29437 [details] [review]
Quick fix patch
Comment 4 Sven Neumann 2004-07-12 07:13:44 UTC
Shouldn't libtiff be doing this?
Comment 5 Brion Vibber 2004-07-12 07:35:01 UTC
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.
Comment 6 Sven Neumann 2004-07-12 16:15:24 UTC
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).
Comment 7 Philip L 2004-07-13 22:42:58 UTC
Created attachment 29518 [details] [review]
optimized quick-fix

Sorry to nitpick, but this sort of thing bothers me.
Comment 8 Brion Vibber 2004-07-14 06:03:47 UTC
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.
Comment 9 Sven Neumann 2004-07-14 08:52:40 UTC
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. 
Comment 10 Sven Neumann 2004-07-14 10:57:38 UTC
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).