loaders: Added Exif to MetaData parser.
[gfxprim.git] / include / loaders / GP_MetaData.h
blob2c529d2adbd8db4fcec940f7eb30e84f623c677e
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #ifndef LOADERS_METADATA_H
24 #define LOADERS_METADATA_H
26 #define GP_META_RECORD_ID_MAX 32
28 enum GP_MetaType {
29 GP_META_INT,
30 GP_META_STRING,
31 GP_META_DOUBLE,
32 GP_META_RATIONAL,
35 struct GP_MetaRational {
36 int num;
37 int den;
40 union GP_MetaValue {
41 int i;
42 double d;
43 const char *str;
44 struct GP_MetaRational r;
47 typedef struct GP_MetaRecord {
48 char id[GP_META_RECORD_ID_MAX];
49 unsigned int hash;
50 enum GP_MetaType type;
51 struct GP_MetaRecord *next;
52 union GP_MetaValue val;
53 } GP_MetaRecord;
55 typedef struct GP_MetaData GP_MetaData;
58 * Creates a metadata storage for at least expected_records values.
60 * Returns NULL if allocation has failed.
62 GP_MetaData *GP_MetaDataCreate(unsigned int expected_records);
65 * Clears meta-data storage.
67 void GP_MetaDataClear(GP_MetaData *self);
70 * Destroys metadata (frees all alocated memory).
72 void GP_MetaDataDestroy(GP_MetaData *self);
75 * Prints metadata into the stdout.
77 void GP_MetaDataPrint(GP_MetaData *self);
80 * Looks for metadata record with id.
82 GP_MetaRecord *GP_MetaDataGetRecord(GP_MetaData *self, const char *id);
85 * Looks for integer metadata with id. Returns 0 on success and res is set to
86 * found metadata value.
88 int GP_MetaDataGetInt(GP_MetaData *self, const char *id, int *res);
91 * Looks for string metadata by id. Returns pointe to found string, or NULL if
92 * there was no such value.
94 const char *GP_MetaDataGetString(GP_MetaData *self, const char *id);
97 * Creates an record and returns pointer to it.
99 * May return NULL if allocation has failed.
101 GP_MetaRecord *GP_MetaDataCreateRecord(GP_MetaData *self, const char *id);
104 * Creates an integer record and returns pointer to it.
106 GP_MetaRecord *GP_MetaDataCreateInt(GP_MetaData *self, const char *id, int val);
108 GP_MetaRecord *GP_MetaDataCreateRat(GP_MetaData *self, const char *id,
109 int num, int den);
112 * Creates an double record and returns pointer to it.
114 GP_MetaRecord *GP_MetaDataCreateDouble(GP_MetaData *self, const char *id,
115 double val);
118 * Creates an string record and returns pointer to it.
120 * If len == 0, string is copied to the terminating '\0', otherwise len
121 * characters is copied. This has no effect if dup == 0.
123 * If dup is set to 1, the string is duplicated inside of the MetaData
124 * structure, otherwise only the pointer is saved.
126 GP_MetaRecord *GP_MetaDataCreateString(GP_MetaData *self, const char *id,
127 const char *str, int len, int dup);
130 * Parses Exif data from passed buffer. The start of the buffer must point to
131 * the ASCII 'Exif' string.
133 int GP_MetaDataFromExif(GP_MetaData *self, void *buf, size_t buf_len);
135 #endif /* LOADERS_GP_METADATA_H */