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 673315 - raw RGB565 bitmap loader is endian-specific
raw RGB565 bitmap loader is endian-specific
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Plugins
git master
Other All
: High enhancement
: 2.10
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2012-04-01 19:48 UTC by rsaxvc
Modified: 2012-09-26 21:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch against 0ca03e88275 to fix RGB565 portability problems. (8.32 KB, patch)
2012-09-24 02:06 UTC, rsaxvc
none Details | Review
Add support for BGR based 565 raw images (4.74 KB, patch)
2012-09-24 02:43 UTC, rsaxvc
none Details | Review
Patch against 0ca03e88275 to fix RGB565 portability problems, using G_ENDIAN stuff (8.93 KB, patch)
2012-09-25 02:18 UTC, rsaxvc
committed Details | Review

Description rsaxvc 2012-04-01 19:48:21 UTC
A raw RGB565 image loaded on HP-UX/itanium may work correctly, but the same image loaded on Windows/itanium produces garbled results. Similarly with Linux/x86 vs Linux/PA-Risc.

The problem appears to be in plug-ins/common/file-raw.c - when reading/writing 2byte ints, the current endianness must be taken into account.

However, since the RGB565 raw loader means different things on different hardware, I propose we support both, naming one RGB565BE and the other RGB565LE.
Comment 1 Michael Natterer 2012-05-09 22:08:57 UTC
Would you provide a patch for this?
Comment 2 rsaxvc 2012-05-09 22:32:44 UTC
I intend to, but am pretty busy right now. I'd also like to add some common YUV formats too,but again I haven't had time.
Comment 3 rsaxvc 2012-09-24 02:06:54 UTC
Created attachment 225041 [details] [review]
Patch against 0ca03e88275 to fix RGB565 portability problems.

This patch splits 'RGB565' support into two different modes, one to handle each possible endianness of RGB565. I made some test images here: https://github.com/rsaxvc/test-image-files
Comment 4 rsaxvc 2012-09-24 02:43:23 UTC
Created attachment 225042 [details] [review]
Add support for BGR based 565 raw images
Comment 5 rsaxvc 2012-09-24 02:43:52 UTC
The second patch adds BGR565LE and BGR565BE support as well.
Comment 6 Michael Natterer 2012-09-24 19:14:10 UTC
Thanks a lot :) raw seems to be turning into a swiss army knife.

Can you adapt the patches to use the already existing
G_BYTE_ORDER and GUINT16_SWAP_LE_BE() macros please?

Raising priority because this is a straightforward enhancement
with almost ready-to-apply patches.
Comment 7 rsaxvc 2012-09-24 21:18:18 UTC
I'll try to post new patches sometime this week.
Comment 8 rsaxvc 2012-09-25 02:18:00 UTC
Created attachment 225120 [details] [review]
Patch against 0ca03e88275 to fix RGB565 portability problems, using G_ENDIAN stuff

This combines the previous two patches and uses the existing glib framework to detect endianness at compile-time, as well as to swap the endianness on 16-bit pixels. This patch was tested on Linux 3.2.0, and tested against images located here: https://github.com/rsaxvc/test-image-files
Comment 9 Michael Natterer 2012-09-26 21:17:56 UTC
Thanks for the update, pushed to master (not to 2.8 because it
adds new features and translatable strings). Did some cosmetic
cleanup, the patch used foo( bar ) instead of foo (bar).

commit b88f1b04ddcc38a8454e10175177e00c307f97bb
Author: Richard Allen <rsaxvc@gmail.com>
Date:   Sun Sep 23 21:02:40 2012 -0500

    Bug 673315 - raw RGB565 bitmap loader is endian-specific
    
    Split raw RGB565 into RGB565LE/RGB565BE/BGR565LE/BGR565BE
    
    This change splits the raw file importing to handle the two different
    endiannesses natively. This fixes a bug where the same image would
    import different on different CPUs or even on different operating
    systems on the same CPU. This also adds the ability to directly open
    BRG565 files from the raw file import dialog.

 plug-ins/common/file-raw.c |  146 +++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 103 insertions(+), 43 deletions(-)