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