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.
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 content->entries[content->count] = entry;
113 exif_entry_ref (entry);
118 exif_content_remove_entry (ExifContent *content, ExifEntry *entry)
122 if (entry->parent != content)
125 for (i = 0; i < content->count; i++)
126 if (content->entries[i] == entry)
128 if (i == content->count)
131 memmove (&content->entries[i], &content->entries[i + 1],
132 sizeof (ExifEntry) * (content->count - i - 1));
135 entry->parent = NULL;
136 exif_entry_unref (entry);
140 exif_content_get_entry (ExifContent *content, ExifTag tag)
147 for (i = 0; i < content->count; i++)
148 if (content->entries[i]->tag == tag)
149 return (content->entries[i]);
154 exif_content_foreach_entry (ExifContent *content,
155 ExifContentForeachEntryFunc func, void *data)
159 if (!content || !func)
162 for (i = 0; i < content->count; i++)
163 func (content->entries[i], data);