From: Lutz M?l. <lu...@us...> - 2004-05-20 10:50:48
|
Update of /cvsroot/libexif/libexif/libexif In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13633/libexif Modified Files: Makefile.am exif-data.c exif-data.h exif-loader.c exif-loader.h exif-mnote-data-priv.h exif-mnote-data.c exif-mnote-data.h Added Files: exif-log.c exif-log.h Log Message: 2004-05-15 Lutz Mueller <lu...@us...> * libexif/exif-log.[c,h]: New. Proposal for handling of debugging messages. --- NEW FILE: exif-log.c --- (This appears to be a binary file; contents omitted.) Index: exif-mnote-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mnote-data.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- exif-mnote-data.c 7 Jan 2004 15:12:12 -0000 1.4 +++ exif-mnote-data.c 20 May 2004 10:50:35 -0000 1.5 @@ -133,3 +133,12 @@ if (!d || !d->methods.get_value) return NULL; return d->methods.get_value (d, n, val, maxlen); } + +void +exif_mnote_data_log (ExifMnoteData *d, ExifLog *log) +{ + if (!d) return; + exif_log_unref (d->log); + d->log = log; + exif_log_ref (log); +} Index: Makefile.am =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/Makefile.am,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- Makefile.am 7 Apr 2004 00:39:10 -0000 1.25 +++ Makefile.am 20 May 2004 10:50:35 -0000 1.26 @@ -17,6 +17,7 @@ exif-format.c \ exif-ifd.c \ exif-loader.c \ + exif-log.c \ exif-mnote-data.c \ exif-mnote-data-priv.h \ exif-tag.c \ @@ -36,6 +37,7 @@ exif-format.h \ exif-ifd.h \ exif-loader.h \ + exif-log.h \ exif-mnote-data.h \ exif-result.h \ exif-tag.h \ Index: exif-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-data.c,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- exif-data.c 18 May 2004 12:27:38 -0000 1.43 +++ exif-data.c 20 May 2004 10:50:35 -0000 1.44 @@ -27,6 +27,7 @@ #include "exif-utils.h" #include "exif-loader.h" #include "jpeg-marker.h" +#include <libexif/exif-log.h> #include <libexif/olympus/exif-mnote-data-olympus.h> #include <libexif/canon/exif-mnote-data-canon.h> @@ -49,6 +50,8 @@ ExifMnoteData *md; + ExifLog *log; + unsigned int ref_count; /* Temporarily used while loading data */ @@ -112,6 +115,10 @@ entry->format = exif_get_short (d + offset + 2, data->priv->order); entry->components = exif_get_long (d + offset + 4, data->priv->order); + exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", + "Loading entry 0x%x ('%s')...", entry->tag, + exif_tag_get_name (entry->tag)); + /* * Size? If bigger than 4 bytes, the actual data is not * in the entry but somewhere else (offset). @@ -128,20 +135,22 @@ if (size < doff + s) return; - entry->data = malloc (sizeof (char) * s); - if (!entry->data) + entry->data = malloc (s); + if (!entry->data) { + EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", s); 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) { -#ifdef DEBUG - printf ("%02x %02x %02x %02x %02x %02x %02x\n", - entry->data[0], entry->data[1], entry->data[2], - entry->data[3], entry->data[4], entry->data[5], - entry->data[6]); -#endif + exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", + "MakerNote found (%02x %02x %02x %02x " + "%02x %02x %02x...).", + entry->data[0], entry->data[1], entry->data[2], + entry->data[3], entry->data[4], entry->data[5], + entry->data[6]); data->priv->offset_mnote = doff; } } @@ -184,8 +193,10 @@ doff = *ds - 6; *ds += s; *d = realloc (*d, *ds); - if (!*d) + if (!*d) { + EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", *ds); return; + } exif_set_long (*d + 6 + offset + 8, data->priv->order, doff); } else @@ -201,18 +212,19 @@ unsigned int ds, ExifLong offset, ExifLong size) { if (ds < offset + size) { -#ifdef DEBUG - printf ("Bogus thumbnail offset and size: %i < %i + %i.\n", - (int) ds, (int) offset, (int) size); -#endif + exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", + "Bogus thumbnail offset and size: %i < %i + %i.", + (int) ds, (int) offset, (int) size); return; } if (data->data) free (data->data); data->size = size; data->data = malloc (data->size); - if (!data->data) - return; + if (!data->data) { + EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", data->size); + return; + } memcpy (data->data, d + offset, data->size); } @@ -230,9 +242,8 @@ /* Read the number of entries */ if (offset >= ds - 1) return; n = exif_get_short (d + offset, data->priv->order); -#ifdef DEBUG - printf ("Loading %i entries...\n", n); -#endif + exif_log (data->priv->log, EXIF_LOG_CODE_DEBUG, "ExifData", + "Loading %i entries...", n); offset += 2; /* Check if we have enough data. */ @@ -241,10 +252,6 @@ for (i = 0; i < n; i++) { tag = exif_get_short (d + offset + 12 * i, data->priv->order); -#ifdef DEBUG - printf ("Loading entry '%s' (%i of %i)...\n", - exif_tag_get_name (tag), i + 1, n); -#endif switch (tag) { case EXIF_TAG_EXIF_IFD_POINTER: case EXIF_TAG_GPS_INFO_IFD_POINTER: @@ -360,8 +367,10 @@ */ *ds += (2 + (ifd->count + n_ptr + n_thumb) * 12 + 4); *d = realloc (*d, *ds); - if (!*d) + if (!*d) { + EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", *ds); return; + } /* Save the number of entries */ exif_set_short (*d + 6 + offset, data->priv->order, @@ -461,8 +470,11 @@ *ds - 6); *ds += data->size; *d = realloc (*d, *ds); - if (!*d) + if (!*d) { + EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", + *ds); return; + } memcpy (*d + *ds - data->size, data->data, data->size); offset += 12; #ifdef DEBUG @@ -697,11 +709,12 @@ * If we are able to interpret the maker note, do so. */ if (data->priv->md) { - 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_mnote_data_log (data->priv->md, data->priv->log); + 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); } } } @@ -752,24 +765,11 @@ ExifData * exif_data_new_from_file (const char *path) { - FILE *f; - int size; ExifData *edata; ExifLoader *loader; - unsigned char data[1024]; - - f = fopen (path, "rb"); - if (!f) - return (NULL); loader = exif_loader_new (); - while (1) { - size = fread (data, 1, sizeof (data), f); - if (size <= 0) break; - if (!exif_loader_write (loader, data, size)) break; - } - fclose (f); - + exif_loader_write_file (loader, path); edata = exif_loader_get_data (loader); exif_loader_unref (loader); @@ -975,3 +975,12 @@ if (data->priv->md) exif_mnote_data_set_byte_order (data->priv->md, order); } + +void +exif_data_log (ExifData *data, ExifLog *log) +{ + if (!data || !data->priv) return; + exif_log_unref (data->priv->log); + data->priv->log = log; + exif_log_ref (log); +} Index: exif-mnote-data-priv.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mnote-data-priv.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- exif-mnote-data-priv.h 7 Jan 2004 15:12:12 -0000 1.4 +++ exif-mnote-data-priv.h 20 May 2004 10:50:35 -0000 1.5 @@ -27,6 +27,7 @@ #include <libexif/exif-mnote-data.h> #include <libexif/exif-byte-order.h> +#include <libexif/exif-log.h> typedef struct _ExifMnoteDataMethods ExifMnoteDataMethods; struct _ExifMnoteDataMethods { @@ -55,6 +56,9 @@ ExifMnoteDataPriv *priv; ExifMnoteDataMethods methods; + + /* Logging */ + ExifLog *log; }; void exif_mnote_data_construct (ExifMnoteData *); Index: exif-data.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-data.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- exif-data.h 26 Oct 2003 10:06:17 -0000 1.7 +++ exif-data.h 20 May 2004 10:50:35 -0000 1.8 @@ -25,9 +25,10 @@ extern "C" { #endif /* __cplusplus */ -#include <libexif/exif-tag.h> #include <libexif/exif-byte-order.h> #include <libexif/exif-ifd.h> +#include <libexif/exif-log.h> +#include <libexif/exif-tag.h> typedef struct _ExifData ExifData; typedef struct _ExifDataPrivate ExifDataPrivate; @@ -69,7 +70,9 @@ ExifDataForeachContentFunc func, void *user_data); -void exif_data_dump (ExifData *data); +/* For debugging purposes and error reporting */ +void exif_data_dump (ExifData *data); +void exif_data_log (ExifData *data, ExifLog *log); /* For your convenience */ #define exif_data_get_entry(d,t) \ Index: exif-mnote-data.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-mnote-data.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- exif-mnote-data.h 7 Jan 2004 15:12:12 -0000 1.2 +++ exif-mnote-data.h 20 May 2004 10:50:35 -0000 1.3 @@ -25,6 +25,8 @@ extern "C" { #endif /* __cplusplus */ +#include <libexif/exif-log.h> + typedef struct _ExifMnoteData ExifMnoteData; void exif_mnote_data_ref (ExifMnoteData *); @@ -42,6 +44,8 @@ /* Returns NULL or val */ char *exif_mnote_data_get_value (ExifMnoteData *, unsigned int, char *val, unsigned int maxlen); +void exif_mnote_data_log (ExifMnoteData *, ExifLog *); + #ifdef __cplusplus } #endif /* __cplusplus */ --- NEW FILE: exif-log.h --- (This appears to be a binary file; contents omitted.) Index: exif-loader.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-loader.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- exif-loader.c 2 Feb 2004 15:36:40 -0000 1.6 +++ exif-loader.c 20 May 2004 10:50:35 -0000 1.7 @@ -3,6 +3,9 @@ #include <stdlib.h> #include <string.h> +#include <stdio.h> + +#include <libexif/i18n.h> #include <libjpeg/jpeg-marker.h> @@ -24,16 +27,36 @@ unsigned int bytes_read; unsigned int ref_count; + + ExifLog *log; }; #undef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) -/* - * This function imitates code from libexif, written by Lutz - * Müller. See libexif/exif-data.c:exif_data_new_from_file. Here, it - * can cope with a sequence of data chunks. - */ +void +exif_loader_write_file (ExifLoader *l, const char *path) +{ + FILE *f; + int size; + unsigned char data[1024]; + + if (!l) return; + + f = fopen (path, "rb"); + if (!f) { + exif_log (l->log, EXIF_LOG_CODE_NONE, "ExifLoader", + _("The file '%s' could not be opened."), path); + return; + } + while (1) { + size = fread (data, 1, sizeof (data), f); + if (size <= 0) break; + if (!exif_loader_write (l, data, size)) break; + } + fclose (f); +} + unsigned char exif_loader_write (ExifLoader *eld, unsigned char *buf, unsigned int len) { @@ -43,6 +66,9 @@ if (eld->state == EL_FAILED) return 0; if (eld->size && eld->bytes_read == eld->size) return 0; + exif_log (eld->log, EXIF_LOG_CODE_DEBUG, "ExifLoader", + "Scanning %i byte(s) of data...", len); + for (i = 0; (i < len) && (eld->state != EL_EXIF_FOUND) && (eld->state != EL_FAILED); i++) switch (eld->state) { @@ -179,5 +205,22 @@ ExifData * exif_loader_get_data (ExifLoader *loader) { - return exif_data_new_from_data (loader->buf, loader->bytes_read); + ExifData *ed; + + if (!loader) return NULL; + + ed = exif_data_new (); + exif_data_log (ed, loader->log); + exif_data_load_data (ed, loader->buf, loader->bytes_read); + + return ed; +} + +void +exif_loader_log (ExifLoader *loader, ExifLog *log) +{ + if (!loader) return; + exif_log_unref (loader->log); + loader->log = log; + exif_log_ref (log); } Index: exif-loader.h =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-loader.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- exif-loader.h 17 Mar 2003 20:39:20 -0000 1.1 +++ exif-loader.h 20 May 2004 10:50:35 -0000 1.2 @@ -22,6 +22,8 @@ #define __EXIF_LOADER_H__ #include <libexif/exif-data.h> +#include <libexif/exif-loader.h> +#include <libexif/exif-log.h> #ifdef __cplusplus extern "C" { @@ -33,6 +35,8 @@ void exif_loader_ref (ExifLoader *); void exif_loader_unref (ExifLoader *); +void exif_loader_write_file (ExifLoader *, const char *fname); + /* * Returns 1 while EXIF data is read (or while there is still * hope that there will be EXIF data later on), 0 otherwise. @@ -42,6 +46,8 @@ void exif_loader_reset (ExifLoader *); ExifData *exif_loader_get_data (ExifLoader *); +void exif_loader_log (ExifLoader *, ExifLog *); + #ifdef __cplusplus } #endif /* __cplusplus */ |