Update of /cvsroot/libexif/libmnote/libmnote
In directory sc8-pr-cvs1:/tmp/cvs-serv3220/libmnote
Modified Files:
mnote-data.c mnote-data.h
Log Message:
2003-08-25 Lutz Mueller <lu...@us...>
* libmnote/mnote-data.c (mnote_data_new_from_path): New
(mnote_data_new_from_data): Now handles EXIF data, too (instead
of only MakerNote data).
Index: mnote-data.c
===================================================================
RCS file: /cvsroot/libexif/libmnote/libmnote/mnote-data.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mnote-data.c 24 Jul 2003 20:18:10 -0000 1.4
+++ mnote-data.c 25 Aug 2003 21:00:23 -0000 1.5
@@ -30,6 +30,10 @@
#include <olympus/mnote-olympus-data.h>
#include <pentax/mnote-pentax-data.h>
+#include <libexif/exif-data.h>
+
+#define DEBUG
+
struct _MNoteDataPrivate {
ExifByteOrder order;
@@ -98,30 +102,81 @@
note->methods.load_data (note, data, size);
}
+static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
+
MNoteData *
mnote_data_new_from_data (const unsigned char *data, unsigned int size)
{
MNoteData *note = NULL;
+ ExifData *d = NULL;
+ ExifEntry *e = NULL;
+ const unsigned char *p = data;
if (!size || !data) return NULL;
+ /*
+ * If we got the full EXIF data, goto the tag MakerNote in order
+ * to figure out which parser to use.
+ */
+ d = exif_data_new_from_data (data, size);
+ if (d) e = exif_content_get_entry (d->ifd[EXIF_IFD_EXIF],
+ EXIF_TAG_MAKER_NOTE);
+ if (e) p = e->data;
+
/* Canon notes begin with 0x0000 */
- if ((size > 1) && (data[0] == 0x00) && (data[1] == 0x00))
+ if ((size > 1) && (p[0] == 0x00) && (p[1] == 0x00)) {
+#ifdef DEBUG
+ printf ("Detected Canon maker note.\n");
+#endif
note = mnote_canon_data_new ();
+ }
/* Olympus notes begin with "OLYMP" */
- else if ((size >= 5) && !memcmp (data, "OLYMP", 5)) {
+ else if ((size >= 5) && !memcmp (p, "OLYMP", 5)) {
note = mnote_olympus_data_new ();
/* Pentax notes have 27 tag entries */
- } else if (size >= 2 && (data[0] == 0x00) && (data[1] == 0x1b)) {
+ } else if (size >= 2 && (p[0] == 0x00) && (p[1] == 0x1b)) {
note = mnote_pentax_data_new ();
} else note = NULL;
+ if (d) exif_data_unref (d);
+
if (note) mnote_data_load_data (note, data, size);
return (note);
+}
+
+MNoteData *
+mnote_data_new_from_file (const char *path)
+{
+ FILE *f;
+ int size = 0, s;
+ unsigned char *data = NULL;
+ MNoteData *d;
+
+#ifdef DEBUG
+ printf ("Reading file...\n");
+#endif
+ f = fopen (path, "rb");
+ if (!f) return NULL;
+ while (1) {
+ data = realloc (data, sizeof (char) * (size + 1024));
+ if (!data) {fclose (f); return NULL;}
+ s = fread (data + size, 1, 1024, f);
+ if (s <= 0) break;
+ size += s;
+ if (size > 200000) break;
+ }
+ fclose (f);
+#ifdef DEBUG
+ printf ("%i byte(s) read.\n", size);
+#endif
+ d = mnote_data_new_from_data (data, size);
+ free (data);
+
+ return d;
}
void
Index: mnote-data.h
===================================================================
RCS file: /cvsroot/libexif/libmnote/libmnote/mnote-data.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mnote-data.h 15 Dec 2002 11:44:18 -0000 1.2
+++ mnote-data.h 25 Aug 2003 21:00:23 -0000 1.3
@@ -65,12 +65,6 @@
MNoteDataPrivate *priv;
};
-void mnote_data_construct (MNoteData *note);
-
-void mnote_data_ref (MNoteData *note);
-void mnote_data_unref (MNoteData *note);
-void mnote_data_free (MNoteData *note);
-
const char *mnote_tag_get_name (MNoteData *note, MNoteTag tag);
const char *mnote_tag_get_title (MNoteData *note, MNoteTag tag);
const char *mnote_tag_get_description (MNoteData *note, MNoteTag tag);
@@ -81,11 +75,16 @@
void mnote_data_dump (MNoteData *note, unsigned int indent);
-MNoteData *mnote_data_new_from_data (const unsigned char *data,
- unsigned int size);
+/* Life-cycle */
+void mnote_data_construct (MNoteData *note);
+void mnote_data_ref (MNoteData *note);
+void mnote_data_unref (MNoteData *note);
+void mnote_data_free (MNoteData *note); /* Do not use! */
-void mnote_data_save_to_data (MNoteData *note,
- unsigned char **data, unsigned int *size);
+MNoteData *mnote_data_new_from_data (const unsigned char *, unsigned int);
+MNoteData *mnote_data_new_from_file (const char *path);
+void mnote_data_save_to_data (MNoteData *note,
+ unsigned char **, unsigned int *);
void mnote_data_set_byte_order (MNoteData *note, ExifByteOrder order);
ExifByteOrder mnote_data_get_byte_order (MNoteData *note);
|