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;
40 exif_content_new (void)
42 ExifMem *mem = exif_mem_new_default ();
43 ExifContent *content = exif_content_new_mem (mem);
51 exif_content_new_mem (ExifMem *mem)
55 if (!mem) return NULL;
57 content = exif_mem_alloc (mem, (ExifLong) sizeof (ExifContent));
60 content->priv = exif_mem_alloc (mem,
61 (ExifLong) sizeof (ExifContentPrivate));
63 exif_mem_free (mem, content);
67 content->priv->ref_count = 1;
69 content->priv->mem = mem;
76 exif_content_ref (ExifContent *content)
78 content->priv->ref_count++;
82 exif_content_unref (ExifContent *content)
84 content->priv->ref_count--;
85 if (!content->priv->ref_count)
86 exif_content_free (content);
90 exif_content_free (ExifContent *content)
96 for (i = 0; i < content->count; i++)
97 exif_entry_unref (content->entries[i]);
99 ExifMem *mem = content->priv->mem;
100 exif_mem_free (mem, content->entries);
101 exif_mem_free (mem, content->priv);
102 exif_mem_free (mem, content);
103 exif_mem_unref (mem);
108 exif_content_dump (ExifContent *content, unsigned int indent)
113 for (i = 0; i < 2 * indent; i++)
120 printf ("%sDumping exif content (%i entries)...\n", buf,
122 for (i = 0; i < content->count; i++)
123 exif_entry_dump (content->entries[i], indent + 1);
127 exif_content_add_entry (ExifContent *content, ExifEntry *entry)
129 if (!content || !content->priv || !entry || entry->parent) return;
131 entry->parent = content;
132 content->entries = exif_mem_realloc (content->priv->mem,
133 content->entries, sizeof (ExifEntry) * (content->count + 1));
134 if (!content->entries) return;
135 content->entries[content->count] = entry;
136 exif_entry_ref (entry);
141 exif_content_remove_entry (ExifContent *c, ExifEntry *e)
145 if (!c || !c->priv || !e || (e->parent != c)) return;
147 /* Search the entry */
148 for (i = 0; i < c->count; i++) if (c->entries[i] == e) break;
149 if (i == c->count) return;
151 /* Remove the entry */
152 memmove (&c->entries[i], &c->entries[i + 1],
153 sizeof (ExifEntry) * (c->count - i - 1));
156 exif_entry_unref (e);
157 c->entries = exif_mem_realloc (c->priv->mem, c->entries,
158 sizeof(ExifEntry) * c->count);
162 exif_content_get_entry (ExifContent *content, ExifTag tag)
169 for (i = 0; i < content->count; i++)
170 if (content->entries[i]->tag == tag)
171 return (content->entries[i]);
176 exif_content_foreach_entry (ExifContent *content,
177 ExifContentForeachEntryFunc func, void *data)
181 if (!content || !func)
184 for (i = 0; i < content->count; i++)
185 func (content->entries[i], data);