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));
52 content->priv->ref_count = 1;
58 exif_content_ref (ExifContent *content)
60 content->priv->ref_count++;
64 exif_content_unref (ExifContent *content)
66 content->priv->ref_count--;
67 if (!content->priv->ref_count)
68 exif_content_free (content);
72 exif_content_free (ExifContent *content)
76 for (i = 0; i < content->count; i++)
77 exif_entry_unref (content->entries[i]);
78 free (content->entries);
84 exif_content_dump (ExifContent *content, unsigned int indent)
89 for (i = 0; i < 2 * indent; i++)
96 printf ("%sDumping exif content (%i entries)...\n", buf,
98 for (i = 0; i < content->count; i++)
99 exif_entry_dump (content->entries[i], indent + 1);
103 exif_content_add_entry (ExifContent *content, ExifEntry *entry)
108 entry->parent = content;
109 content->entries = realloc (content->entries,
110 sizeof (ExifEntry) * (content->count + 1));
111 content->entries[content->count] = entry;
112 exif_entry_ref (entry);
117 exif_content_remove_entry (ExifContent *content, ExifEntry *entry)
121 if (entry->parent != content)
124 for (i = 0; i < content->count; i++)
125 if (content->entries[i] == entry)
127 if (i == content->count)
130 memmove (&content->entries[i], &content->entries[i + 1],
131 sizeof (ExifEntry) * (content->count - i - 1));
134 entry->parent = NULL;
135 exif_entry_unref (entry);
139 exif_content_get_entry (ExifContent *content, ExifTag tag)
146 for (i = 0; i < content->count; i++)
147 if (content->entries[i]->tag == tag)
148 return (content->entries[i]);
153 exif_content_foreach_entry (ExifContent *content,
154 ExifContentForeachEntryFunc func, void *data)
158 if (!content || !func)
161 for (i = 0; i < content->count; i++)
162 func (content->entries[i], data);