Fix #381: Feature-Request: Make JPEG comment available for overlays
[geeqie.git] / src / exif.h
index 5298dd3..06dec25 100644 (file)
@@ -1,31 +1,29 @@
 /*
- *  GQView
- *  (C) 2004 John Ellis
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
- *  Authors:
- *    Support for Exif file format, originally written by Eric Swalens.    
- *    Modified by Quy Tonthat
- *    Reimplemented with generic data storage by John Ellis
+ * Authors: Eric Swalens, Quy Tonthat, John Ellis
  *
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #ifndef __EXIF_H
 #define __EXIF_H
 
+#define EXIF_FORMATTED() "formatted."
+#define EXIF_FORMATTED_LEN (sizeof(EXIF_FORMATTED()) - 1)
 
 /*
  *-----------------------------------------------------------------------------
@@ -33,6 +31,8 @@
  *-----------------------------------------------------------------------------
  */
 
+#define EXIF_FORMAT_COUNT 13
+
 typedef enum {
        EXIF_FORMAT_UNKNOWN             = 0,
        EXIF_FORMAT_BYTE_UNSIGNED       = 1,
@@ -49,18 +49,6 @@ typedef enum {
        EXIF_FORMAT_DOUBLE              = 12
 } ExifFormatType;
 
-typedef struct _ExifFormatAttrib ExifFormatAttrib;
-struct _ExifFormatAttrib
-{
-       ExifFormatType type;
-       int size;
-       const char *short_name;
-       const char *description;
-};
-
-/* the list of known tag data formats */
-extern ExifFormatAttrib ExifFormatList[];
-
 
 /*
  *-----------------------------------------------------------------------------
@@ -68,65 +56,16 @@ extern ExifFormatAttrib ExifFormatList[];
  *-----------------------------------------------------------------------------
  */
 
-typedef struct _ExifData ExifData;
-struct _ExifData
-{
-       GList *items;   /* list of (ExifItem *) */
-};
+typedef struct _ExifItem ExifItem;
 
 typedef struct _ExifRational ExifRational;
 struct _ExifRational
 {
-       unsigned long int num;
-       unsigned long int den;
+       guint32 num;
+       guint32 den;
 };
 
 
-typedef struct _ExifItem ExifItem;
-typedef struct _ExifMarker ExifMarker;
-typedef struct _ExifTextList ExifTextList;
-
-struct _ExifItem
-{
-       ExifFormatType format;
-       int tag;
-       ExifMarker *marker;
-       int elements;
-       gpointer data;
-       int data_len;
-};
-
-struct _ExifMarker
-{
-       int             tag;
-       ExifFormatType  format;
-       int             components;
-       char            *key;
-       char            *description;
-       ExifTextList    *list;
-};
-
-struct _ExifTextList
-{
-       int value;
-       const char* description;
-};
-
-
-typedef struct _ExifFormattedText ExifFormattedText;
-struct _ExifFormattedText
-{
-       const char *key;
-       const char *description;
-};
-
-
-/*
- *-----------------------------------------------------------------------------
- * Data
- *-----------------------------------------------------------------------------
- */
-
 /* enums useful for image manipulation */
 
 typedef enum {
@@ -148,16 +87,13 @@ typedef enum {
        EXIF_UNIT_CENTIMETER    = 3
 } ExifUnitType;
 
-
-/* the known exif tags list */
-extern ExifMarker ExifKnownMarkersList[];
-
-/* the unknown tags utilize this generic list */
-extern ExifMarker ExifUnknownMarkersList[];
-
-/* the list of specially formatted keys, for human readable output */
-extern ExifFormattedText ExifFormattedList[];
-
+typedef struct _ExifFormattedText ExifFormattedText;
+struct _ExifFormattedText
+{
+       const gchar *key;
+       const gchar *description;
+       gchar *(*build_func)(ExifData *exif);
+};
 
 /*
  *-----------------------------------------------------------------------------
@@ -165,27 +101,72 @@ extern ExifFormattedText ExifFormattedList[];
  *-----------------------------------------------------------------------------
  */
 
-ExifData *exif_read(const gchar *path);
+void exif_init(void);
+
+ExifData *exif_read(gchar *path, gchar *sidecar_path, GHashTable *modified_xmp);
+
+ExifData *exif_read_fd(FileData *fd);
+void exif_free_fd(FileData *fd, ExifData *exif);
+
+/* exif_read returns processed data (merged from image and sidecar, etc.)
+   this function gives access to the original data from the image.
+   original data are part of the processed data and should not be freed separately */
+ExifData *exif_get_original(ExifData *processed);
+
+
+gboolean exif_write(ExifData *exif);
+gboolean exif_write_sidecar(ExifData *exif, gchar *path);
+
 void exif_free(ExifData *exif);
 
 gchar *exif_get_data_as_text(ExifData *exif, const gchar *key);
 gint exif_get_integer(ExifData *exif, const gchar *key, gint *value);
 ExifRational *exif_get_rational(ExifData *exif, const gchar *key, gint *sign);
-double exif_rational_to_double(ExifRational *r, gint sign);
 
 ExifItem *exif_get_item(ExifData *exif, const gchar *key);
+ExifItem *exif_get_first_item(ExifData *exif);
+ExifItem *exif_get_next_item(ExifData *exif);
+
 
-const char *exif_item_get_tag_name(ExifItem *item);
-const char *exif_item_get_description(ExifItem *item);
-const char *exif_item_get_format_name(ExifItem *item, gint brief);
+gchar *exif_item_get_tag_name(ExifItem *item);
+guint exif_item_get_tag_id(ExifItem *item);
+guint exif_item_get_elements(ExifItem *item);
+gchar *exif_item_get_data(ExifItem *item, guint *data_len);
+gchar *exif_item_get_description(ExifItem *item);
+guint exif_item_get_format_id(ExifItem *item);
+const gchar *exif_item_get_format_name(ExifItem *item, gboolean brief);
 gchar *exif_item_get_data_as_text(ExifItem *item);
 gint exif_item_get_integer(ExifItem *item, gint *value);
-ExifRational *exif_item_get_rational(ExifItem *item, gint *sign);
+ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, guint n);
+
+gchar *exif_item_get_string(ExifItem *item, gint idx);
+
+gchar *exif_get_description_by_key(const gchar *key);
+gchar *exif_get_tag_description_by_key(const gchar *key);
+
+gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gboolean *key_valid);
+
+gint exif_update_metadata(ExifData *exif, const gchar *key, const GList *values);
+GList *exif_get_metadata(ExifData *exif, const gchar *key, MetadataFormat format);
+
+guchar *exif_get_color_profile(ExifData *exif, guint *data_len);
+
+/* jpeg embedded icc support */
+
+void exif_add_jpeg_color_profile(ExifData *exif, guchar *cp_data, guint cp_length);
+
+
+gboolean exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size);
 
-const gchar *exif_get_description_by_key(const gchar *key);
+/* support for so called "jpeg comment" */
+gchar* exif_get_image_comment(FileData* fd);
+void exif_set_image_comment(FileData* fd, const gchar* comment);
 
-/* usually for debugging to stdout */
-void exif_write_data_list(ExifData *exif, FILE *f, gint human_readable_list);
+/*raw support */
+guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height);
+void exif_free_preview(guchar *buf);
 
+gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format);
 
 #endif
+/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */