3 * Copyright © 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.
22 #include "exif-content.h"
30 static const unsigned char ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
32 struct _ExifContentPrivate
34 unsigned int ref_count;
38 exif_content_new (void)
42 content = malloc (sizeof (ExifContent));
45 memset (content, 0, sizeof (ExifContent));
46 content->priv = malloc (sizeof (ExifContentPrivate));
51 memset (content->priv, 0, sizeof (ExifContentPrivate));
53 content->priv->ref_count = 1;
59 exif_content_ref (ExifContent *content)
61 content->priv->ref_count++;
65 exif_content_unref (ExifContent *content)
67 content->priv->ref_count--;
68 if (!content->priv->ref_count)
69 exif_content_free (content);
73 exif_content_free (ExifContent *content)
77 for (i = 0; i < content->count; i++)
78 exif_entry_unref (content->entries[i]);
79 free (content->entries);
85 exif_content_dump (ExifContent *content, unsigned int indent)
90 for (i = 0; i < 2 * indent; i++)
97 printf ("%sDumping exif content (%i entries)...\n", buf,
99 for (i = 0; i < content->count; i++)
100 exif_entry_dump (content->entries[i], indent + 1);
104 exif_content_add_entry (ExifContent *content, ExifEntry *entry)
109 entry->parent = content;
110 content->entries = realloc (content->entries,
111 sizeof (ExifEntry) * (content->count + 1));
112 if (!content->entries)
114 content->entries[content->count] = entry;
115 exif_entry_ref (entry);
120 exif_content_remove_entry (ExifContent *c, ExifEntry *e)
124 if (!c || !e) return;
125 if (e->parent != c) return;
127 /* Search the entry */
128 for (i = 0; i < c->count; i++) if (c->entries[i] == e) break;
129 if (i == c->count) return;
131 /* Remove the entry */
132 memmove (&c->entries[i], &c->entries[i + 1],
133 sizeof (ExifEntry) * (c->count - i - 1));
136 exif_entry_unref (e);
137 c->entries = realloc(c->entries,sizeof(ExifEntry) * c->count);
141 exif_content_get_entry (ExifContent *content, ExifTag tag)
148 for (i = 0; i < content->count; i++)
149 if (content->entries[i]->tag == tag)
150 return (content->entries[i]);
155 exif_content_foreach_entry (ExifContent *content,
156 ExifContentForeachEntryFunc func, void *data)
160 if (!content || !func)
163 for (i = 0; i < content->count; i++)
164 func (content->entries[i], data);