3 * Copyright (C) 2001 Lutz Müller <lutz@users.sourceforge.net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include "exif-content.h"
29 static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
31 struct _ExifContentPrivate
33 unsigned int ref_count;
37 exif_content_new (void)
41 content = malloc (sizeof (ExifContent));
44 memset (content, 0, sizeof (ExifContent));
45 content->priv = malloc (sizeof (ExifContentPrivate));
50 memset (content->priv, 0, sizeof (ExifContentPrivate));
51 content->priv->ref_count = 1;
57 exif_content_ref (ExifContent *content)
59 content->priv->ref_count++;
63 exif_content_unref (ExifContent *content)
65 content->priv->ref_count--;
66 if (!content->priv->ref_count)
67 exif_content_free (content);
71 exif_content_free (ExifContent *content)
75 for (i = 0; i < content->count; i++)
76 exif_entry_unref (content->entries[i]);
77 free (content->entries);
83 exif_content_parse (ExifContent *content, const unsigned char *data,
84 unsigned int size, unsigned int offset,
94 content->order = order;
96 /* Read number of entries */
97 if (size < offset + 2)
99 n = exif_get_short (data + offset, order);
101 printf ("Parsing directory with %i entries...\n", n);
104 for (i = 0; i < n; i++) {
105 entry = exif_entry_new ();
106 exif_content_add_entry (content, entry);
107 exif_entry_parse (content->entries[i], data, size,
108 offset + 2 + 12 * i, order);
109 exif_entry_unref (entry);
114 exif_content_dump (ExifContent *content, unsigned int indent)
119 for (i = 0; i < 2 * indent; i++)
126 printf ("%sDumping exif content (%i entries)...\n", buf,
128 for (i = 0; i < content->count; i++)
129 exif_entry_dump (content->entries[i], indent + 1);
133 exif_content_add_entry (ExifContent *content, ExifEntry *entry)
138 entry->parent = content;
139 content->entries = realloc (content->entries,
140 sizeof (ExifEntry) * (content->count + 1));
141 content->entries[content->count] = entry;
142 exif_entry_ref (entry);
147 exif_content_remove_entry (ExifContent *content, ExifEntry *entry)
151 if (entry->parent != content)
154 for (i = 0; i < content->count; i++)
155 if (content->entries[i] == entry)
157 if (i == content->count)
160 memmove (&content->entries[i], &content->entries[i + 1],
161 sizeof (ExifEntry) * (content->count - i - 1));
164 entry->parent = NULL;
165 exif_entry_unref (entry);
169 exif_content_get_entry (ExifContent *content, ExifTag tag)
176 for (i = 0; i < content->count; i++)
177 if (content->entries[i]->tag == tag)
178 return (content->entries[i]);