infrastructure for preprocessing of metadata
[geeqie.git] / src / exif.h
1 /*
2  * Geeqie
3  * (C) 2006 John Ellis
4  *  Copyright (C) 2008 The Geeqie Team
5  *
6  *  Authors:
7  *    Support for Exif file format, originally written by Eric Swalens.
8  *    Modified by Quy Tonthat
9  *    Reimplemented with generic data storage by John Ellis
10  *
11
12     This program is free software; you can redistribute it and/or modify
13     it under the terms of the GNU General Public License as published by
14     the Free Software Foundation; either version 2 of the License, or
15     (at your option) any later version.
16
17     This program is distributed in the hope that it will be useful,
18     but WITHOUT ANY WARRANTY; without even the implied warranty of
19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20     GNU General Public License for more details.
21
22     You should have received a copy of the GNU General Public License
23     along with this program; if not, write to the Free Software
24     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27 #ifndef __EXIF_H
28 #define __EXIF_H
29
30
31 /*
32  *-----------------------------------------------------------------------------
33  * Tag formats
34  *-----------------------------------------------------------------------------
35  */
36
37 #define EXIF_FORMAT_COUNT 13
38
39 typedef enum {
40         EXIF_FORMAT_UNKNOWN             = 0,
41         EXIF_FORMAT_BYTE_UNSIGNED       = 1,
42         EXIF_FORMAT_STRING              = 2,
43         EXIF_FORMAT_SHORT_UNSIGNED      = 3,
44         EXIF_FORMAT_LONG_UNSIGNED       = 4,
45         EXIF_FORMAT_RATIONAL_UNSIGNED   = 5,
46         EXIF_FORMAT_BYTE                = 6,
47         EXIF_FORMAT_UNDEFINED           = 7,
48         EXIF_FORMAT_SHORT               = 8,
49         EXIF_FORMAT_LONG                = 9,
50         EXIF_FORMAT_RATIONAL            = 10,
51         EXIF_FORMAT_FLOAT               = 11,
52         EXIF_FORMAT_DOUBLE              = 12
53 } ExifFormatType;
54
55
56 /*
57  *-----------------------------------------------------------------------------
58  * Data storage
59  *-----------------------------------------------------------------------------
60  */
61
62 typedef struct _ExifItem ExifItem;
63
64 typedef struct _ExifRational ExifRational;
65 struct _ExifRational
66 {
67         guint32 num;
68         guint32 den;
69 };
70
71
72 /* enums useful for image manipulation */
73
74 typedef enum {
75         EXIF_ORIENTATION_UNKNOWN        = 0,
76         EXIF_ORIENTATION_TOP_LEFT       = 1,
77         EXIF_ORIENTATION_TOP_RIGHT      = 2,
78         EXIF_ORIENTATION_BOTTOM_RIGHT   = 3,
79         EXIF_ORIENTATION_BOTTOM_LEFT    = 4,
80         EXIF_ORIENTATION_LEFT_TOP       = 5,
81         EXIF_ORIENTATION_RIGHT_TOP      = 6,
82         EXIF_ORIENTATION_RIGHT_BOTTOM   = 7,
83         EXIF_ORIENTATION_LEFT_BOTTOM    = 8
84 } ExifOrientationType;
85
86 typedef enum {
87         EXIF_UNIT_UNKNOWN       = 0,
88         EXIF_UNIT_NOUNIT        = 1,
89         EXIF_UNIT_INCH          = 2,
90         EXIF_UNIT_CENTIMETER    = 3
91 } ExifUnitType;
92
93
94 typedef struct _ExifFormattedText ExifFormattedText;
95 struct _ExifFormattedText
96 {
97         const gchar *key;
98         const gchar *description;
99         gchar *(*build_func)(ExifData *exif);
100 };
101
102 /*
103  *-----------------------------------------------------------------------------
104  * functions
105  *-----------------------------------------------------------------------------
106  */
107
108 ExifData *exif_read(gchar *path, gchar *sidecar_path);
109
110 ExifData *exif_read_fd(FileData *fd);
111 void exif_free_fd(FileData *fd, ExifData *exif);
112
113 /* exif_read returns processed data (merged from image and sidecar, etc.)
114    this function gives access to the original data from the image.
115    original data are part of the processed data and should not be freed separately */
116 ExifData *exif_get_original(ExifData *processed);
117
118 gint exif_write(ExifData *exif);
119 void exif_free(ExifData *exif);
120
121 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key);
122 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value);
123 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign);
124
125 ExifItem *exif_get_item(ExifData *exif, const gchar *key);
126 ExifItem *exif_add_item(ExifData *exif, const gchar *key);
127 ExifItem *exif_get_first_item(ExifData *exif);
128 ExifItem *exif_get_next_item(ExifData *exif);
129
130
131 gchar *exif_item_get_tag_name(ExifItem *item);
132 guint exif_item_get_tag_id(ExifItem *item);
133 guint exif_item_get_elements(ExifItem *item);
134 gchar *exif_item_get_data(ExifItem *item, guint *data_len);
135 gchar *exif_item_get_description(ExifItem *item);
136 guint exif_item_get_format_id(ExifItem *item);
137 const gchar *exif_item_get_format_name(ExifItem *item, gint brief);
138 gchar *exif_item_get_data_as_text(ExifItem *item);
139 gint exif_item_get_integer(ExifItem *item, gint *value);
140 ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, guint n);
141
142 gchar *exif_item_get_string(ExifItem *item, gint idx);
143
144 gchar *exif_get_description_by_key(const gchar *key);
145 gchar *exif_get_tag_description_by_key(const gchar *key);
146
147 gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid);
148
149 gint exif_item_delete(ExifData *exif, ExifItem *item);
150 gint exif_item_set_string(ExifItem *item, const gchar *str);
151
152 guchar *exif_get_color_profile(ExifData *exif, guint *data_len);
153
154 /* jpeg embedded icc support */
155
156 void exif_add_jpeg_color_profile(ExifData *exif, guchar *cp_data, guint cp_length);
157
158
159 gint exif_jpeg_segment_find(guchar *data, guint size,
160                                    guchar app_marker, const gchar *magic, guint magic_len,
161                                    guint *seg_offset, guint *seg_length);
162 gint exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size);
163
164 /*raw support */
165 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height);
166 void exif_free_preview(guchar *buf);
167
168
169 #endif
170 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */