From: Lutz M?l. <lu...@us...> - 2003-10-26 22:34:20
|
Update of /cvsroot/libexif/libexif/libexif In directory sc8-pr-cvs1:/tmp/cvs-serv21845/libexif Modified Files: Makefile.am exif-content.c exif-data.c exif-mnote-data-priv.h exif-mnote-data.c Log Message: 2003-10-26 Lutz Mueller <lu...@us...> * test/test-mnote.c: New. * libexif: The code now both compiles and doesn't crash, but at least the canon maker note still doesn't get parsed. Index: exif-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-data.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- exif-data.c 26 Oct 2003 10:06:17 -0000 1.29 +++ exif-data.c 26 Oct 2003 22:30:26 -0000 1.30 @@ -50,8 +50,17 @@ ExifMnoteData *md; unsigned int ref_count; + + /* Temporarily used while loading data */ + unsigned int offset_mnote; }; +ExifMnoteData * +exif_data_get_mnote_data (ExifData *d) +{ + return (d && d->priv) ? d->priv->md : NULL; +} + ExifData * exif_data_new (void) { @@ -124,6 +133,10 @@ return; entry->size = s; memcpy (entry->data, d + doff, s); + + /* If this is the MakerNote, remember the offset */ + if (entry->tag == EXIF_TAG_MAKER_NOTE) + data->priv->offset_mnote = doff; } static void @@ -484,22 +497,22 @@ ExifShort n; ExifEntry *e, *em; const unsigned char *d = d_orig; - unsigned int size = ds_orig, len; + unsigned int ds = ds_orig, len; if (!data) return; - if (!d || !size) + if (!d || !ds) return; #ifdef DEBUG - printf ("Parsing %i byte(s) EXIF data...\n", size); + printf ("Parsing %i byte(s) EXIF data...\n", ds); #endif /* * It can be that the data starts with the EXIF header. If it does * not, search the EXIF marker. */ - if (size < 6) { + if (ds < 6) { #ifdef DEBUG printf ("Size too small.\n"); #endif @@ -515,27 +528,27 @@ "0x%x...\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6]); #endif while (1) { - while ((d[0] == 0xff) && size) { + while ((d[0] == 0xff) && ds) { d++; - size--; + ds--; } /* JPEG_MARKER_SOI */ if (d[0] == JPEG_MARKER_SOI) { d++; - size--; + ds--; continue; } /* JPEG_MARKER_APP0 */ if (d[0] == JPEG_MARKER_APP0) { d++; - size--; + ds--; l = (d[0] << 8) | d[1]; - if (l > size) + if (l > ds) return; d += l; - size -= l; + ds -= l; continue; } @@ -550,8 +563,8 @@ return; } d++; - size--; - if (size < 2) { + ds--; + if (ds < 2) { #ifdef DEBUG printf ("Size too small.\n"); #endif @@ -562,14 +575,14 @@ printf ("We have to deal with %i byte(s) of EXIF data.\n", len); #endif d += 2; - size -= 2; + ds -= 2; } /* * Verify the exif header * (offset 2, length 6). */ - if (size < 6) { + if (ds < 6) { #ifdef DEBUG printf ("Size too small.\n"); #endif @@ -587,7 +600,7 @@ #endif /* Byte order (offset 6, length 2) */ - if (size < 12) + if (ds < 12) return; if (!memcmp (d + 6, "II", 2)) data->priv->order = EXIF_BYTE_ORDER_INTEL; @@ -608,7 +621,7 @@ /* Parse the actual exif data (offset 14) */ exif_data_load_data_content (data, data->ifd[EXIF_IFD_0], d + 6, - size - 6, offset); + ds - 6, offset); /* IFD 1 offset */ n = exif_get_short (d + 6 + offset, data->priv->order); @@ -619,7 +632,7 @@ #endif /* Sanity check. */ - if (offset > size - 6) { + if (offset > ds - 6) { #ifdef DEBUG printf ("Bogus offset!\n"); #endif @@ -627,7 +640,7 @@ } exif_data_load_data_content (data, data->ifd[EXIF_IFD_1], d + 6, - size - 6, offset); + ds - 6, offset); } /* @@ -641,14 +654,12 @@ /* Olympus */ if ((e->size >= 5) && (!memcmp (e->data, "OLYMP", 5))) - data->priv->md = exif_mnote_data_olympus_new ( - data->priv->order); + data->priv->md = exif_mnote_data_olympus_new (); /* Pentax */ else if ((e->size >= 2) && (e->data[0] == 0x00) && (e->data[1] == 0x1b)) - data->priv->md = exif_mnote_data_pentax_new ( - data->priv->order); + data->priv->md = exif_mnote_data_pentax_new (); else { em = exif_data_get_entry (data, EXIF_TAG_MAKE); @@ -656,8 +667,7 @@ /* Canon */ if (!strcmp (exif_entry_get_value (em), "Canon")) - data->priv->md = exif_mnote_data_canon_new ( - data->priv->order); + data->priv->md = exif_mnote_data_canon_new (); } } @@ -667,7 +677,11 @@ * pointers after this function here returns. */ if (data->priv->md) { - exif_mnote_data_load (data->priv->md, d_orig, ds_orig); + exif_mnote_data_set_byte_order (data->priv->md, + data->priv->order); + exif_mnote_data_set_offset (data->priv->md, + data->priv->offset_mnote); + exif_mnote_data_load (data->priv->md, d, ds); exif_data_remove_entry (data, EXIF_TAG_MAKER_NOTE); } } Index: exif-mnote-data-priv.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mnote-data-priv.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- exif-mnote-data-priv.h 26 Oct 2003 10:06:17 -0000 1.1 +++ exif-mnote-data-priv.h 26 Oct 2003 22:30:26 -0000 1.2 @@ -26,6 +26,7 @@ #endif /* __cplusplus */ #include <libexif/exif-mnote-data.h> +#include <libexif/exif-byte-order.h> typedef struct _ExifMnoteDataMethods ExifMnoteDataMethods; struct _ExifMnoteDataMethods { @@ -36,6 +37,8 @@ /* Modification */ void (* save) (ExifMnoteData *, unsigned char **, unsigned int *); void (* load) (ExifMnoteData *, const unsigned char *, unsigned int); + void (* set_offset) (ExifMnoteData *, unsigned int); + void (* set_byte_order) (ExifMnoteData *, ExifByteOrder); /* Query */ unsigned int (* count) (ExifMnoteData *); @@ -54,7 +57,9 @@ ExifMnoteDataPriv *priv; }; -void exif_mnote_data_construct (ExifMnoteData *); +void exif_mnote_data_construct (ExifMnoteData *); +void exif_mnote_data_set_byte_order (ExifMnoteData *, ExifByteOrder); +void exif_mnote_data_set_offset (ExifMnoteData *, unsigned int); #ifdef __cplusplus } Index: exif-content.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-content.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- exif-content.c 17 Sep 2003 11:31:06 -0000 1.8 +++ exif-content.c 26 Oct 2003 22:30:26 -0000 1.9 @@ -115,25 +115,23 @@ } void -exif_content_remove_entry (ExifContent *content, ExifEntry *entry) +exif_content_remove_entry (ExifContent *c, ExifEntry *e) { unsigned int i; - if (entry->parent != content) - return; - - for (i = 0; i < content->count; i++) - if (content->entries[i] == entry) - break; - if (i == content->count) - return; + if (!c || !e) return; + if (e->parent != c) return; - memmove (&content->entries[i], &content->entries[i + 1], - sizeof (ExifEntry) * (content->count - i - 1)); - content->count--; + /* Search the entry */ + for (i = 0; i < c->count; i++) if (c->entries[i] == e) break; + if (i == c->count) return; - entry->parent = NULL; - exif_entry_unref (entry); + /* Remove the entry */ + memmove (&c->entries[i], &c->entries[i + 1], + sizeof (ExifEntry) * (c->count - i - 1)); + c->count--; + e->parent = NULL; + exif_entry_unref (e); } ExifEntry * Index: Makefile.am =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/Makefile.am,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- Makefile.am 26 Oct 2003 10:11:31 -0000 1.22 +++ Makefile.am 26 Oct 2003 22:30:26 -0000 1.23 @@ -23,9 +23,9 @@ exif-utils.c \ i18n.h libexif_la_LIBADD = -lm \ - canon/libmnote-canon.a \ - olympus/libmnote-olympus.a \ - pentax/libmnote-pentax.a + canon/libmnote-canon.la \ + olympus/libmnote-olympus.la \ + pentax/libmnote-pentax.la libexifincludedir = $(includedir)/libexif libexifinclude_HEADERS = \ Index: exif-mnote-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mnote-data.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- exif-mnote-data.c 26 Oct 2003 10:06:17 -0000 1.1 +++ exif-mnote-data.c 26 Oct 2003 22:30:26 -0000 1.2 @@ -86,6 +86,20 @@ d->methods.save (d, buf, buf_size); } +void +exif_mnote_data_set_byte_order (ExifMnoteData *d, ExifByteOrder o) +{ + if (!d || !d->methods.set_byte_order) return; + d->methods.set_byte_order (d, o); +} + +void +exif_mnote_data_set_offset (ExifMnoteData *d, unsigned int o) +{ + if (!d || !d->methods.set_offset) return; + d->methods.set_offset (d, o); +} + unsigned int exif_mnote_data_count (ExifMnoteData *d) { |