From: Lutz M?l. <lu...@us...> - 2004-05-20 10:52:11
|
Update of /cvsroot/libexif/exif/exif In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13917/exif Modified Files: actions.c actions.h main.c Log Message: 2004-05-20 Lutz Mueller <lu...@us...> * exif/*: Support for maker notes. * exif/main.c: Proposal for support of debugging messages. Index: main.c =================================================================== RCS file: /cvsroot/libexif/exif/exif/main.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- main.c 3 Feb 2004 18:32:22 -0000 1.38 +++ main.c 20 May 2004 10:51:58 -0000 1.39 @@ -28,10 +28,7 @@ #include <libexif/exif-data.h> #include <libexif/exif-utils.h> - -#ifdef HAVE_MNOTE -#include <libmnote/mnote-data.h> -#endif +#include <libexif/exif-loader.h> #include "libjpeg/jpeg-data.h" @@ -69,21 +66,6 @@ exif_entry_dump(entry, 0); } -#ifdef HAVE_MNOTE - -static void -show_note_entry (MNoteData *note, MNoteTag tag) -{ - printf (_("MakerNote entry '%s' (0x%x, '%s'):"), - C(mnote_tag_get_title (note, tag)), tag, - C(mnote_tag_get_name (note, tag))); - printf ("\n"); - - mnote_data_dump_entry(note, tag, 0); -} - -#endif - static void search_entry (ExifData *ed, ExifTag tag) { @@ -210,13 +192,44 @@ return (0); } +#define COL_BLUE "\033[34m" +#define COL_GREEN "\033[32m" +#define COL_RED "\033[31m" +#define COL_NORMAL "\033[0m" + +static void +log_func (ExifLog *log, ExifLogCode code, const char *domain, + const char *format, va_list args, void *data) +{ + switch (code) { + case EXIF_LOG_CODE_DEBUG: + printf (COL_GREEN); + printf ("%s: ", domain); + vprintf (format, args); + printf (COL_NORMAL); + printf ("\n"); + break; + case EXIF_LOG_CODE_NO_MEMORY: + printf (COL_RED); + printf ("%s: ", domain); + vprintf (format, args); + printf (COL_NORMAL); + printf ("\n"); + break; + default: + printf (COL_BLUE); + printf ("%s: ", domain); + vprintf (format, args); + printf (COL_NORMAL); + printf ("\n"); + break; + } +} + typedef struct _ExifOptions ExifOptions; struct _ExifOptions { unsigned int use_ids; ExifTag tag; -#ifdef HAVE_MNOTE - MNoteTag ntag; -#endif }; /* @@ -228,21 +241,11 @@ static unsigned int list_tags = 0, show_description = 0, machine_readable = 0; static unsigned int extract_thumbnail = 0, remove_thumbnail = 0; static unsigned int remove_tag = 0; -#ifdef HAVE_MNOTE -static unsigned int list_ntags = 0; -#endif +static unsigned int list_mnote = 0, debug = 0; static const char *set_value = NULL, *ifd_string = NULL, *tag_string = NULL; -#ifdef HAVE_MNOTE -static const char *ntag_string = NULL; -#endif static ExifIfd ifd = -1; static ExifTag tag = 0; -#ifdef HAVE_MNOTE -static MNoteTag ntag = 0; -static ExifOptions eo = {0, 0, 0}; -#else static ExifOptions eo = {0, 0}; -#endif int main (int argc, const char **argv) @@ -257,18 +260,12 @@ N_("Show IDs instead of tag names"), NULL}, {"tag", 't', POPT_ARG_STRING, &tag_string, 0, N_("Select tag"), N_("tag")}, -#ifdef HAVE_MNOTE - {"ntag", '\0', POPT_ARG_STRING, &ntag_string, 0, - N_("Select MakerNote tag"), N_("ntag")}, -#endif {"ifd", '\0', POPT_ARG_STRING, &ifd_string, 0, N_("Select IFD"), N_("IFD")}, {"list-tags", 'l', POPT_ARG_NONE, &list_tags, 0, N_("List all EXIF tags"), NULL}, -#ifdef HAVE_MNOTE - {"list-ntags", '\0', POPT_ARG_NONE, &list_ntags, 0, - N_("List all EXIF MakerNote tags"), NULL}, -#endif + {"show-mnote", '|', POPT_ARG_NONE, &list_mnote, 0, + N_("Show contents of tag MakerNote"), NULL}, {"remove", '\0', POPT_ARG_NONE, &remove_tag, 0, N_("Remove tag or ifd"), NULL}, {"show-description", 's', POPT_ARG_NONE, &show_description, 0, @@ -286,14 +283,14 @@ {"machine-readable", 'm', POPT_ARG_NONE, &machine_readable, 0, N_("Output in a machine-readable (tab delimited) format"), NULL}, + {"debug", 'd', POPT_ARG_NONE, &debug, 0, + N_("Show debugging messages"), NULL}, POPT_TABLEEND}; ExifData *ed; ExifEntry *e; -#ifdef HAVE_MNOTE - MNoteData *md = 0; -#endif char fname[1024]; FILE *f; + ExifLog *log = NULL; #ifdef ENABLE_NLS #ifdef HAVE_LOCALE_H @@ -307,6 +304,11 @@ poptSetOtherOptionHelp (ctx, _("[OPTION...] file")); while (poptGetNextOpt (ctx) > 0); + if (debug) { + log = exif_log_new (); + exif_log_set_func (log, log_func, NULL); + } + /* Any option? */ if (argc <= 1) { poptPrintHelp (ctx, stdout, 0); @@ -335,11 +337,7 @@ } } - if (show_description -#ifdef HAVE_MNOTE - && !ntag_string -#endif - ) { + if (show_description) { if (!eo.tag) { fprintf (stderr, _("Please specify a tag!")); fputc ('\n', stderr); @@ -357,12 +355,17 @@ if (args) { while (*args) { + ExifLoader *l; /* * Try to read EXIF data from the file. * If there is no EXIF data, exit. */ - ed = exif_data_new_from_file (*args); + l = exif_loader_new (); + exif_loader_log (l, log); + exif_loader_write_file (l, *args); + ed = exif_loader_get_data (l); + exif_loader_unref (l); if (!ed) { fprintf (stderr, _("'%s' does not " "contain EXIF data!"), *args); @@ -370,26 +373,6 @@ exit (1); } -#ifdef HAVE_MNOTE - if (ntag_string || list_ntags || ntag) { - e = exif_content_get_entry(ed->ifd[EXIF_IFD_EXIF], - EXIF_TAG_MAKER_NOTE); - if (!e) { - fprintf (stderr, _("'%s' does not " - "contain EXIF MakerNote data!"), *args); - fputc ('\n', stderr); - exit (1); - } - - md = mnote_data_new_from_data (e->data, e->size); - if (!md) { - fprintf (stderr, "Could not parse EXIF tag MakerNote in '%s'!", *args); - fputc ('\n', stderr); - exit (1); - } - } -#endif - /* Where do we save the output? */ memset (fname, 0, sizeof (fname)); if (output) @@ -400,39 +383,8 @@ sizeof (fname) - 1); } -#ifdef HAVE_MNOTE - if (ntag_string) { - ntag = mnote_tag_from_string (md, ntag_string); - if (!ntag || !mnote_tag_get_name (md, ntag)) { - fprintf (stderr, _("Invalid MakerNote tag '%s'!"), ntag_string); - fputc ('\n', stderr); - return (1); - } - eo.ntag = ntag; - - } - - if (show_description && ntag_string) { - if (!eo.ntag) { - fprintf (stderr, _("Please specify a MakerNote tag!")); - fputc ('\n', stderr); - return (1); - } - printf (_("Tag '%s' (0x%04x, '%s'): %s"), - mnote_tag_get_title (md, eo.ntag), eo.ntag, - mnote_tag_get_name (md, eo.ntag), - mnote_tag_get_description (md, eo.ntag)); - printf ("\n"); - return (0); - } -#endif - if (list_tags) { action_tag_table (*args, ed); -#ifdef HAVE_MNOTE - } else if (list_ntags) { - action_ntag_table (*args, md); -#endif } else if (tag && !set_value) { if ((ifd >= EXIF_IFD_0) && (ifd < EXIF_IFD_COUNT)) { @@ -451,20 +403,6 @@ } else { search_entry (ed, eo.tag); } -#ifdef HAVE_MNOTE - } else if (ntag && !set_value) { - char *value = mnote_data_get_value (md, ntag); - if (value) - show_note_entry (md, ntag); - else { - fprintf (stderr, _("Makernote " - "does not contain tag " - "'%s'."), - ntag_string); - fputc ('\n', stderr); - return (1); - } -#endif } else if (extract_thumbnail) { /* No thumbnail? Exit. */ @@ -630,6 +568,8 @@ } else if (machine_readable) { action_tag_list_machine (*args, ed, eo.use_ids); + } else if (list_mnote) { + action_mnote_list (*args, ed); } else action_tag_list (*args, ed, eo.use_ids); exif_data_unref (ed); Index: actions.c =================================================================== RCS file: /cvsroot/libexif/exif/exif/actions.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- actions.c 7 Jan 2004 23:38:07 -0000 1.15 +++ actions.c 20 May 2004 10:51:58 -0000 1.16 @@ -59,35 +59,6 @@ } } -#ifdef HAVE_MNOTE - -void -action_ntag_table (const char *filename, MNoteData *en) -{ - unsigned int tag; - const char *name; - char txt[1024]; - - memset (txt, 0, sizeof (txt)); - snprintf (txt, sizeof (txt) - 1, _("EXIF MakerNote tags in '%s':"), filename); - fprintf (stdout, "%-38.38s", txt); - fprintf (stdout, "%-7.7s", "MakerNote"); - fputc ('\n', stdout); - for (tag = 0; tag < 0xffff; tag++) { - name = mnote_tag_get_title (en, tag); - if (!name) - continue; - fprintf (stdout, " 0x%04x %-29.29s", tag, name); - if (mnote_data_get_value (en, tag, txt, 1)) - printf (ENTRY_FOUND); - else - printf (ENTRY_NOT_FOUND); - fputc ('\n', stdout); - } -} - -#endif - static void show_entry (ExifEntry *e, void *data) { @@ -114,30 +85,6 @@ exif_content_foreach_entry (content, show_entry, data); } -#ifdef HAVE_MNOTE - -static void -show_note_entry (MNoteData *note, MNoteTag tag, void *data) -{ - unsigned char *ids = data; - char v[73]; - - if (*ids) - fprintf (stdout, "0x%04x", tag); - else - fprintf (stdout, "%-20.20s", mnote_tag_get_title (note, tag)); - printf ("|"); - if (*ids) - fprintf (stdout, "%-72.72s", - mnote_data_get_value (note, tag, v, 73)); - else - fprintf (stdout, "%-58.58s", - mnote_data_get_value (note, tag, v, 58)); - fputc ('\n', stdout); -} - -#endif - static void print_hline (unsigned char ids) { @@ -151,6 +98,36 @@ } void +action_mnote_list (const char *filename, ExifData *ed) +{ + unsigned int i, bs = 1024, c; + char b[1024]; + ExifMnoteData *n; + + n = exif_data_get_mnote_data (ed); + if (!n) { + printf (_("Unknown MakerNote format.")); + return; + } + + c = exif_mnote_data_count (n); + switch (c) { + case 0: + printf (_("MakerNote does not contain any value.\n")); + break; + case 1: + printf (_("MakerNote contains 1 value:\n")); + break; + default: + printf (_("MakerNote contains %i values:\n"), c); + } + for (i = 0; i < c; i++) + printf ("%s: %s\n", C(exif_mnote_data_get_title (n, i)), + C(exif_mnote_data_get_value (n, i, b, bs))); + exif_mnote_data_unref (n); +} + +void action_tag_list (const char *filename, ExifData *ed, unsigned char ids) { ExifByteOrder order; @@ -211,35 +188,3 @@ if (ed->size) fprintf (stdout, _("ThumbnailSize\t%i\n"), ed->size); } - -#ifdef HAVE_MNOTE - -void -action_ntag_list (const char *filename, MNoteData *en, unsigned char ids) -{ - ExifByteOrder order; - - if (!en) - return; - - order = mnote_data_get_byte_order (en); - fprintf (stdout, _("EXIF MakerNote tags in '%s' ('%s' byte order):"), filename, - exif_byte_order_get_name (order)); - fputc ('\n', stdout); - print_hline (ids); - if (ids) - fprintf (stdout, "%-6.6s", _("Tag")); - else - fprintf (stdout, "%-20.20s", _("Tag")); - fputc ('|', stdout); - if (ids) - fprintf (stdout, "%-72.72s", _("Value")); - else - fprintf (stdout, "%-58.58s", _("Value")); - fputc ('\n', stdout); - print_hline (ids); - mnote_data_foreach_entry (en, show_note_entry, &ids); - print_hline (ids); -} - -#endif Index: actions.h =================================================================== RCS file: /cvsroot/libexif/exif/exif/actions.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- actions.h 30 Sep 2003 22:43:00 -0000 1.5 +++ actions.h 20 May 2004 10:51:58 -0000 1.6 @@ -33,9 +33,6 @@ void action_tag_list_machine (const char *filename, ExifData *, unsigned char ids); -#ifdef HAVE_MNOTE -void action_ntag_table (const char *filename, MNoteData *en); -void action_ntag_list (const char *filename, MNoteData *en, unsigned char ids); -#endif +void action_mnote_list (const char *filename, ExifData *); #endif /* __ACTIONS_H__ */ |