Skip to content

Commit

Permalink
SDL_image jpeg IPTC patch.
Browse files Browse the repository at this point in the history
--ryan.



Date: Mon, 15 Aug 2005 21:24:39 -0700 (PDT)
From: Jeremy Stanley <stanmuffin@yahoo.com>
To: sdl@libsdl.org
Subject: [SDL] SDL_Image: IMG_isJPG() fails on pictures with IPTC information

I found that SDL_Image fails to load JPEG files to
which I have added a caption using Picasa (a free as
in beer picture organization tool;
http://www.picasa.com).  Picasa claims to store its
captions in IPTC format.  Photoshop apparently uses
this format too, but I don't have that program so I
can't verify that.

The problem is that the IPTC information block is
stored between the SOI (FF D8) and APP1 (FF E1)
markers in the JPEG file, so that the "JFIF" or "Exif"
constant is not stored at offset 6.  Instead, the two
bytes at offset 2 store FF ED and the next two bytes
store the size of the block as a big endian word
(including the size field).  The APP1 (FF E1) marker
will immediately follow.

A simple fix could be inserted just after the second
SDL_RWread() in IMG_isJPG().  Instead of throwing
these four bytes away, we can check for the IPTC
header and skip over it.  The following code does the
trick for me.
  • Loading branch information
icculus committed Sep 8, 2005
1 parent 2c74770 commit 5e3c1d4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions IMG_jpg.c
Expand Up @@ -47,6 +47,12 @@ int IMG_isJPG(SDL_RWops *src)
if ( SDL_RWread(src, magic, 2, 1) ) {
if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
SDL_RWread(src, magic, 4, 1);

/* skip IPTC info block if it exists... */
if ( (magic[0] == 0xFF) && (magic[1] == 0xED) ) {
SDL_RWseek(src, (((Uint16)magic[2] << 8) |magic[3]) + 2, SEEK_CUR);
}

SDL_RWread(src, magic, 4, 1);
if ( memcmp((char *)magic, "JFIF", 4) == 0 ||
memcmp((char *)magic, "Exif", 4) == 0 ||
Expand Down

0 comments on commit 5e3c1d4

Please sign in to comment.