#34 libexif needs JPEG wrapping

open
libexif (61)
5
2006-01-26
2005-05-06
No

The EXIF specification actually describes two different tile
formats: one for compressed images and one for
uncompressed images. The former includes the EXIF IFDs
inside a JFIF APP1 marker right at the start of the file; libexif
seems to deal with this just fine. But uncompressed data is to
be stored in an extended TIFF format, which libexif can't deal
with.

The following code in exif_data_load_data() is the culprit: it
looks for either the APP1 marker or the header for its
contents (starting with "Exif"). But a TIFF-based EXIF file
has neither.

This is important to me because I'm writing gphoto2 support
for Canon cameras. The latest models use a new raw image
format, CR2, which is EXIF with a few oddities. I can dump
these files with tiffdump, but libexif won't parse the EXIF
information. Since the JPEG preview inside the file lacks the
EXIF information, I must either parse the file myself or hand
it to higher-level software that will extract the important
information. I'd like to use libexif to do this.

I'm attaching a sample CR2 file for testing.

if (!memcmp (d, ExifHeader, 6)) {
exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG,
"ExifData",
"Found EXIF header.");
} else {
while (1) {
while ((d[0] == 0xff) && ds) {
d++;
ds--;
}

/* JPEG_MARKER_SOI */
if (d[0] == JPEG_MARKER_SOI) {
d++;
ds--;
continue;
}

/* JPEG_MARKER_APP0 */
if (d[0] == JPEG_MARKER_APP0) {
d++;
ds--;
l = (d[0] << 8) | d[1];
if (l > ds)
return;
d += l;
ds -= l;
continue;
}

/* JPEG_MARKER_APP1 */
if (d[0] == JPEG_MARKER_APP1)
break;

/* Unknown marker or data. Give up. */
exif_log (data->priv->log,
EXIF_LOG_CODE_CORRUPT_DATA,
"ExifData", _("EXIF marker not found."));
return;
}
d++;
ds--;
if (ds < 2) {
LOG_TOO_SMALL;
return;
}
len = (d[0] << 8) | d[1];
exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG,
"ExifData",
"We have to deal with %i byte(s) of EXIF data.",
len);
d += 2;
ds -= 2;
}

Discussion

  • Logged In: YES
    user_id=59853

    There is no sample CR2 file attached.

    When there is, I'll be glad to add it to libexif-testsuite
    with any number of testcases.

     
  • Logged In: YES
    user_id=682763

    Well, I get

    "Error

    Invalid filename"

    when I attempt to attach. It's a local file here on a Windows
    system. Does SourceForge assume a Linux host or something?
    My local file name, as found by browsing via the "Choose" button,
    is

    "C:\Documents and Settings\westin\My
    Documents\archive\camera-raw-formats\Canon\GL6C0031.CR2"

     
  • Logged In: YES
    user_id=27487

    still want a CR2 sample file ? I can provide from 20D.

     
  • Logged In: YES
    user_id=27487

    provided a CR2 file to ndim

     
    • assigned_to: nobody --> hfiguiere
     
  • Logged In: YES
    user_id=27487

    I have posted a patch to support TIFF file and that will
    work with CR2 and NEF.

    Taking that bug.

     
  • Andrew Jackson
    Andrew Jackson
    2007-12-28

    Logged In: YES
    user_id=1811026
    Originator: NO

    Any movement on this? AFAICS the current code still doesn't work with .CR2 files despite the claim to a patch in this thread.

     
  • Dan Fandrich
    Dan Fandrich
    2008-02-10

    Logged In: YES
    user_id=236775
    Originator: NO

    So far noone has attached a .CR2 file to this bug report, so there's no way to test the patch.

     
  • Logged In: YES
    user_id=27487
    Originator: NO

    Attaching one won't work as they are BIG.

    There are several samples there:

    http://www.rawsamples.ch/html/en/canon.html