From: Lutz M?l. <lu...@us...> - 2003-10-27 22:38:06
|
Update of /cvsroot/libexif/libexif/libexif/canon In directory sc8-pr-cvs1:/tmp/cvs-serv7105/libexif/canon Modified Files: exif-mnote-data-canon.c mnote-canon-entry.c Log Message: 2003-10-27 Lutz Mueller <lu...@us...> * libexif: Canon maker notes seem to work now (both loading and saving). Index: mnote-canon-entry.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/canon/mnote-canon-entry.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- mnote-canon-entry.c 27 Oct 2003 20:07:11 -0000 1.2 +++ mnote-canon-entry.c 27 Oct 2003 22:34:30 -0000 1.3 @@ -69,13 +69,13 @@ switch (entry->tag) { case MNOTE_CANON_TAG_SETTINGS_1: CF (entry->format, EXIF_FORMAT_SHORT, v); - n = exif_get_short (data, entry->order)/2; - data+=2; + n = exif_get_short (data, entry->order) / 2; + data += 2; CC (entry->components, n, v); for (i = 1; i < n; i++) { vs = exif_get_short (data, entry->order); data += 2; - switch(i) { + switch (i) { case 1: strncpy (v, _("Macro mode : "), sizeof (v) - 1); switch (vs) { Index: exif-mnote-data-canon.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/canon/exif-mnote-data-canon.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- exif-mnote-data-canon.c 27 Oct 2003 20:07:11 -0000 1.3 +++ exif-mnote-data-canon.c 27 Oct 2003 22:34:30 -0000 1.4 @@ -65,7 +65,7 @@ ExifMnoteDataCanon *cnote = (ExifMnoteDataCanon *) note; if (!note) return NULL; - if (cnote->count >= n) return NULL; + if (cnote->count <= n) return NULL; return mnote_canon_entry_get_value (&cnote->entries[n]); } @@ -146,6 +146,52 @@ } static void +exif_mnote_data_canon_save (ExifMnoteData *ne, + unsigned char **buf, unsigned int *buf_size) +{ + ExifMnoteDataCanon *n = (ExifMnoteDataCanon *) ne; + unsigned int i, o, s, doff; + + if (!n || !buf || !buf_size) return; + + /* + * Allocate enough memory for all entries and the number + * of entries. + */ + *buf_size = 2 + n->count * 12 + 4; + *buf = malloc (sizeof (char) * *buf_size); + if (!*buf) return; + memset (*buf, 0, sizeof (char) * *buf_size); + + /* Save the number of entries */ + exif_set_short (*buf, n->order, n->count); + + /* Save each entry */ + for (i = 0; i < n->count; i++) { + o = 2 + i * 12; + exif_set_short (*buf + o + 0, n->order, n->entries[i].tag); + exif_set_short (*buf + o + 2, n->order, n->entries[i].format); + exif_set_long (*buf + o + 4, n->order, + n->entries[i].components); + o += 8; + s = exif_format_get_size (n->entries[i].format) * + n->entries[i].components; + if (s > 4) { + *buf_size += s; + *buf = realloc (*buf, sizeof (char) * *buf_size); + if (!*buf) return; + doff = *buf_size - s; + exif_set_long (*buf + o, n->order, n->offset + doff); + } else + doff = o; + + /* Write the data. Fill unneeded bytes with 0. */ + memcpy (*buf + doff, n->entries[i].data, s); + if (s < 4) memset (*buf + doff + s, 0, (4 - s)); + } +} + +static void exif_mnote_data_canon_load (ExifMnoteData *ne, const unsigned char *buf, unsigned int buf_size) { @@ -186,13 +232,10 @@ /* Sanity check */ n->entries[i].data = malloc (sizeof (char) * s); if (!n->entries[i].data) return; + memset (n->entries[i].data, 0, sizeof (char) * s); n->entries[i].size = s; memcpy (n->entries[i].data, buf + o, s); } - -#ifdef DEBUG - printf ("Loaded %i entries.\n", n->count); -#endif } static unsigned int @@ -246,6 +289,7 @@ d->methods.set_byte_order = exif_mnote_data_canon_set_byte_order; d->methods.set_offset = exif_mnote_data_canon_set_offset; d->methods.load = exif_mnote_data_canon_load; + d->methods.save = exif_mnote_data_canon_save; d->methods.count = exif_mnote_data_canon_count; d->methods.get_name = exif_mnote_data_canon_get_name; d->methods.get_title = exif_mnote_data_canon_get_title; |