Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
xmp_sidecar.cc File Reference

The XMP-sidecar half of what used to be common/exif.cc. More...

#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <time.h>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <exiv2/exiv2.hpp>
#include <pugixml.hpp>
#include "common/xmp_sidecar.h"
#include "metadata/exif.h"
#include "metadata/exif_internal.h"
#include "caches/image_cache.h"
#include "common/conf.h"
#include "common/datetime.h"
#include "common/deprecations.h"
#include "history/history.h"
#include "common/utility.h"
#include "common/variables.h"
#include "database/colorlabel_repository.h"
#include "database/database.h"
#include "database/history_repository.h"
#include "database/image_repository.h"
#include "database/metadata_repository.h"
#include "develop/blend.h"
#include "develop/iop_order.h"
#include "develop/masks.h"
#include "imageio/imageio_core.h"
#include "metadata/metadata.h"
#include "metadata/notify.h"
#include "metadata/tags.h"
#include "system/macros.h"
#include "system/mem_alloc.h"
+ Include dependency graph for xmp_sidecar.cc:

Go to the source code of this file.

Data Structures

struct  history_entry_t
 
struct  mask_entry_t
 
struct  _xmp_mask_ctx_t
 
struct  _xmp_history_ctx_t
 
struct  _xmp_metadata_ctx_t
 

Macros

#define __STDC_FORMAT_MACROS
 
#define WIDEN(s)   (s)
 
#define DT_XMP_EXIF_VERSION   5
 
#define ERROR_CODE(a)   (a)
 

Typedefs

typedef struct history_entry_t history_entry_t
 
typedef struct mask_entry_t mask_entry_t
 
typedef struct _xmp_mask_ctx_t _xmp_mask_ctx_t
 
typedef struct _xmp_history_ctx_t _xmp_history_ctx_t
 
typedef struct _xmp_metadata_ctx_t _xmp_metadata_ctx_t
 

Functions

static const char * _exif_get_exiv2_tag_type (const char *tagname)
 
static void read_xmp_timestamps (Exiv2::XmpData &xmpData, dt_image_t *img, const int xmp_version)
 
static void dt_remove_known_keys (Exiv2::XmpData &xmp)
 
static void dt_remove_xmp_keys (Exiv2::XmpData &xmp, const char *keys[], unsigned int n_keys)
 
static void dt_remove_exif_geotag (Exiv2::ExifData &exifData)
 
int dt_exif_read_blob (uint8_t **buf, const char *path, const int32_t imgid, const int sRGB, const int out_width, const int out_height, const int dng_mode)
 
static void print_history_entry (history_entry_t *entry) __attribute__((unused))
 
static void free_history_entry (gpointer data)
 
static GListread_history_v1 (const std::string &xmpPacket, const char *filename, const int superold)
 
static GListread_history_v2 (Exiv2::XmpData &xmpData, const char *filename)
 
void free_mask_entry (gpointer data)
 
static GHashTableread_masks (Exiv2::XmpData &xmpData, const char *filename, const int version)
 
static GListread_masks_v3 (Exiv2::XmpData &xmpData, const char *filename, const int version)
 
static void add_mask_entry_to_db (int32_t imgid, mask_entry_t *entry)
 
static void add_non_clone_mask_entries_to_db (gpointer key, gpointer value, gpointer user_data)
 
static void add_mask_entries_to_db (int32_t imgid, GHashTable *mask_entries, int mask_id)
 
int _get_max_multi_priority (GList *history, const char *operation)
 
int dt_exif_xmp_read (dt_image_t *img, const char *filename, const int history_only)
 
static void _xmp_append_mask (void *user_data, const int mask_num, const int mask_id, const int mask_type, const char *mask_name, const int mask_version, const void *points, const int points_len, const int mask_nb, const void *source, const int source_len)
 
static void _xmp_append_history (void *user_data, const int32_t row_imgid, const int hist_num, const int modversion, const char *operation, const void *op_params, const int params_len, const gboolean enabled, const void *blendop_params_blob, const int blendop_params_len, const int blendop_version, const int multi_priority, const char *multi_name, const char *preset_name)
 
static void dt_set_xmp_dt_history (Exiv2::XmpData &xmpData, const int32_t imgid, int history_end)
 
static void set_xmp_timestamps (Exiv2::XmpData &xmpData, const int32_t imgid)
 
GTimeSpan _convert_unix_to_gtimespan (const time_t unix)
 
static void dt_remove_xmp_exif_geotag (Exiv2::XmpData &xmpData)
 
static void dt_set_xmp_exif_geotag (Exiv2::XmpData &xmpData, double longitude, double latitude, double altitude)
 
static void _xmp_append_metadata (void *user_data, const int keyid, const char *value)
 
static void _xmp_append_colorlabel (void *user_data, const int color)
 
static void dt_set_xmp_dt_metadata (Exiv2::XmpData &xmpData, const int32_t imgid, const gboolean export_flag)
 
static void _exif_xmp_append_history_hash (Exiv2::XmpData &xmpData, const int32_t imgid, const dt_image_t *image)
 
static void _exif_xmp_read_data (Exiv2::XmpData &xmpData, const int32_t imgid, const dt_image_t *image)
 
static void _exif_xmp_read_data_export (Exiv2::XmpData &xmpData, const int32_t imgid, dt_export_metadata_t *metadata)
 
char * dt_exif_xmp_read_string (const int32_t imgid)
 
static void dt_remove_xmp_key (Exiv2::XmpData &xmp, const char *key)
 
static void _remove_xmp_keys (Exiv2::XmpData &xmpData, const char *key)
 
static void dt_remove_exif_key (Exiv2::ExifData &exif, const char *key)
 
static void dt_remove_iptc_key (Exiv2::IptcData &iptc, const char *key)
 
int dt_exif_xmp_attach_export (const int32_t imgid, const char *filename, void *metadata)
 
int dt_exif_xmp_write_with_imgpath (const dt_image_t *image, const char *filename, const char *imgpath)
 

Variables

const char * dt_xmp_keys []
 
static const guint dt_xmp_keys_n = G_N_ELEMENTS(dt_xmp_keys)
 

Detailed Description

The XMP-sidecar half of what used to be common/exif.cc.

Cut out of a 4775-line translation unit that was doing two unrelated jobs. This one serialises the development – history stack, mask shapes, module order – into and out of the XMP document; the other, the photograph's own tags, is metadata/exif.cc. See common/xmp_sidecar.h, including why this is not in src/metadata.

Definition in file xmp_sidecar.cc.

Macro Definition Documentation

◆ __STDC_FORMAT_MACROS

#define __STDC_FORMAT_MACROS

Definition at line 73 of file xmp_sidecar.cc.

◆ DT_XMP_EXIF_VERSION

#define DT_XMP_EXIF_VERSION   5

Definition at line 140 of file xmp_sidecar.cc.

◆ ERROR_CODE

#define ERROR_CODE (   a)    (a)

Definition at line 2189 of file xmp_sidecar.cc.

◆ WIDEN

#define WIDEN (   s)    (s)

Definition at line 107 of file xmp_sidecar.cc.

Typedef Documentation

◆ _xmp_history_ctx_t

◆ _xmp_mask_ctx_t

◆ _xmp_metadata_ctx_t

◆ history_entry_t

◆ mask_entry_t

Function Documentation

◆ _convert_unix_to_gtimespan()

GTimeSpan _convert_unix_to_gtimespan ( const time_t  unix)

Definition at line 1760 of file xmp_sidecar.cc.

References dt_datetime_gdatetime_to_gtimespan(), and L.

Referenced by read_xmp_timestamps().

◆ _exif_get_exiv2_tag_type()

static const char * _exif_get_exiv2_tag_type ( const char *  tagname)
static

Definition at line 147 of file xmp_sidecar.cc.

References dt_exif_get_exiv2_taglist(), IS_NULL_PTR, L, and t.

Referenced by dt_exif_xmp_attach_export().

◆ _exif_xmp_append_history_hash()

static void _exif_xmp_append_history_hash ( Exiv2::XmpData xmpData,
const int32_t  imgid,
const dt_image_t image 
)
static

◆ _exif_xmp_read_data()

◆ _exif_xmp_read_data_export()

◆ _get_max_multi_priority()

int _get_max_multi_priority ( GList history,
const char *  operation 
)

Definition at line 1196 of file xmp_sidecar.cc.

References L, MAX, history_entry_t::multi_priority, and history_entry_t::operation.

◆ _remove_xmp_keys()

static void _remove_xmp_keys ( Exiv2::XmpData xmpData,
const char *  key 
)
static

Definition at line 2277 of file xmp_sidecar.cc.

References i, key, and L.

Referenced by dt_exif_xmp_attach_export().

◆ _xmp_append_colorlabel()

static void _xmp_append_colorlabel ( void user_data,
const int  color 
)
static

Definition at line 1881 of file xmp_sidecar.cc.

References color, L, and v.

Referenced by dt_set_xmp_dt_metadata().

◆ _xmp_append_history()

static void _xmp_append_history ( void user_data,
const int32_t  row_imgid,
const int  hist_num,
const int  modversion,
const char *  operation,
const void op_params,
const int  params_len,
const gboolean  enabled,
const void blendop_params_blob,
const int  blendop_params_len,
const int  blendop_version,
const int  multi_priority,
const char *  multi_name,
const char *  preset_name 
)
static

Definition at line 1660 of file xmp_sidecar.cc.

References dt_exif_xmp_encode(), dt_free, IS_NULL_PTR, key, L, and _xmp_history_ctx_t::xmpData.

Referenced by dt_set_xmp_dt_history().

◆ _xmp_append_mask()

static void _xmp_append_mask ( void user_data,
const int  mask_num,
const int  mask_id,
const int  mask_type,
const char *  mask_name,
const int  mask_version,
const void points,
const int  points_len,
const int  mask_nb,
const void source,
const int  source_len 
)
static

Definition at line 1618 of file xmp_sidecar.cc.

References dt_exif_xmp_encode(), dt_free, key, L, mask_id, mask_name, and _xmp_mask_ctx_t::xmpData.

Referenced by dt_set_xmp_dt_history().

◆ _xmp_append_metadata()

◆ add_mask_entries_to_db()

static void add_mask_entries_to_db ( int32_t  imgid,
GHashTable mask_entries,
int  mask_id 
)
static

◆ add_mask_entry_to_db()

◆ add_non_clone_mask_entries_to_db()

static void add_non_clone_mask_entries_to_db ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
static

◆ dt_exif_read_blob()

int dt_exif_read_blob ( uint8_t **  blob,
const char *  path,
const int32_t  imgid,
const int  sRGB,
const int  out_width,
const int  out_height,
const int  dng_mode 
)

write exif to blob, return length in bytes. blob will be allocated by the function. sRGB should be true if sRGB colorspace is used as output.

Todo:
: find a nice place for the missing metadata (tags, publisher, colorlabels?). Additionally find out

Definition at line 249 of file xmp_sidecar.cc.

References darktable_package_string, dt_conf_get_int(), DT_DATETIME_EXIF_LENGTH, dt_datetime_img_to_exif(), DT_DATETIME_LENGTH, dt_datetime_now_to_exif(), dt_free, dt_free_gpointer(), dt_image_cache_get(), dt_image_cache_read_release(), dt_metadata_get(), dt_remove_exif_geotag(), dt_remove_exif_keys(), i, IS_NULL_PTR, L, read_metadata_threadsafe, sRGB, and WIDEN.

Referenced by dt_control_merge_hdr_job_run(), and dt_imageio_export_with_flags().

◆ dt_exif_xmp_attach_export()

◆ dt_exif_xmp_read()

int dt_exif_xmp_read ( dt_image_t img,
const char *  filename,
const int  history_only 
)

read xmp sidecar file.

Todo:
: make this configurable? or remove it altogether?

Definition at line 1212 of file xmp_sidecar.cc.

References add_mask_entries_to_db(), add_mask_entry_to_db(), add_non_clone_mask_entries_to_db(), history_entry_t::blendop_params, history_entry_t::blendop_params_len, history_entry_t::blendop_version, dt_database_get_last_error(), dt_database_release_transaction, dt_database_rollback_transaction(), dt_database_start_transaction, dt_deprecated(), dt_exif_decode_xmp_data(), dt_exif_xmp_decode(), dt_free, dt_free_gpointer(), dt_history_repository_count_mask_items(), dt_history_repository_delete_history(), dt_history_repository_delete_masks_history(), dt_history_repository_get_next_num(), dt_history_repository_set_end(), dt_history_repository_shift_nums(), dt_history_repository_write_item(), DT_IMAGE_AUTO_PRESETS_APPLIED, DT_IMAGE_NO_LEGACY_PRESETS, DT_IOP_ORDER_ANSEL_RAW, DT_IOP_ORDER_LEGACY, dt_ioppr_deserialize_text_iop_order_list(), dt_ioppr_get_iop_order_link(), dt_ioppr_get_iop_order_list_version(), dt_ioppr_insert_missing_modules(), dt_ioppr_write_iop_order_list(), dt_sort_iop_list_by_order_f(), history_entry_t::enabled, FALSE, dt_image_t::flags, free_history_entry(), free_mask_entry(), dt_image_t::history_hash, dt_image_t::id, dt_iop_order_entry_t::instance, history_entry_t::iop_order, dt_iop_order_entry_t::iop_order_f, IS_NULL_PTR, L, dt_image_raw_parameters_t::legacy, dt_image_t::legacy_flip, MIN, history_entry_t::modversion, history_entry_t::multi_name, history_entry_t::multi_priority, history_entry_t::num, dt_iop_order_entry_t::o, history_entry_t::operation, dt_iop_order_entry_t::operation, out, history_entry_t::params, history_entry_t::params_len, read_history_v1(), read_history_v2(), read_masks(), read_masks_v3(), read_metadata_threadsafe, read_xmp_timestamps(), TRUE, dt_image_raw_parameters_t::user_flip, and WIDEN.

Referenced by _history_load_and_apply_apply(), _image_import_internal(), dt_image_read_duplicates(), and main().

◆ dt_exif_xmp_read_string()

char * dt_exif_xmp_read_string ( const int32_t  imgid)

get the xmp blob for imgid.

Definition at line 2192 of file xmp_sidecar.cc.

References _exif_xmp_read_data(), dt_image_full_path(), dt_image_path_append_version(), dt_remove_known_keys(), ERROR_CODE, FALSE, L, lock, PATH_MAX, and WIDEN.

Referenced by write_image(), and write_image().

◆ dt_exif_xmp_write_with_imgpath()

int dt_exif_xmp_write_with_imgpath ( const dt_image_t image,
const char *  filename,
const char *  imgpath 
)

◆ dt_remove_exif_geotag()

static void dt_remove_exif_geotag ( Exiv2::ExifData exifData)
static

Definition at line 233 of file xmp_sidecar.cc.

References dt_remove_exif_keys(), and L.

Referenced by dt_exif_read_blob(), and dt_exif_xmp_attach_export().

◆ dt_remove_exif_key()

static void dt_remove_exif_key ( Exiv2::ExifData exif,
const char *  key 
)
static

Definition at line 2295 of file xmp_sidecar.cc.

References key.

Referenced by dt_exif_xmp_attach_export().

◆ dt_remove_iptc_key()

static void dt_remove_iptc_key ( Exiv2::IptcData iptc,
const char *  key 
)
static

Definition at line 2308 of file xmp_sidecar.cc.

References key, and L.

Referenced by dt_exif_xmp_attach_export().

◆ dt_remove_known_keys()

static void dt_remove_known_keys ( Exiv2::XmpData xmp)
static

◆ dt_remove_xmp_exif_geotag()

static void dt_remove_xmp_exif_geotag ( Exiv2::XmpData xmpData)
static

Definition at line 1801 of file xmp_sidecar.cc.

References dt_remove_xmp_keys(), and L.

Referenced by _exif_xmp_read_data_export(), and dt_set_xmp_exif_geotag().

◆ dt_remove_xmp_key()

static void dt_remove_xmp_key ( Exiv2::XmpData xmp,
const char *  key 
)
static

Definition at line 2264 of file xmp_sidecar.cc.

References key, and L.

Referenced by dt_exif_xmp_attach_export().

◆ dt_remove_xmp_keys()

static void dt_remove_xmp_keys ( Exiv2::XmpData xmp,
const char *  keys[],
unsigned int  n_keys 
)
static

Definition at line 213 of file xmp_sidecar.cc.

References i, and L.

Referenced by dt_exif_xmp_attach_export(), dt_remove_xmp_exif_geotag(), and set_xmp_timestamps().

◆ dt_set_xmp_dt_history()

static void dt_set_xmp_dt_history ( Exiv2::XmpData xmpData,
const int32_t  imgid,
int  history_end 
)
static

◆ dt_set_xmp_dt_metadata()

static void dt_set_xmp_dt_metadata ( Exiv2::XmpData xmpData,
const int32_t  imgid,
const gboolean  export_flag 
)
static

◆ dt_set_xmp_exif_geotag()

static void dt_set_xmp_exif_geotag ( Exiv2::XmpData xmpData,
double  longitude,
double  latitude,
double  altitude 
)
static

Definition at line 1815 of file xmp_sidecar.cc.

References double(), dt_free, dt_remove_xmp_exif_geotag(), and L.

Referenced by _exif_xmp_read_data(), and _exif_xmp_read_data_export().

◆ free_history_entry()

static void free_history_entry ( gpointer  data)
static

◆ free_mask_entry()

void free_mask_entry ( gpointer  data)

◆ print_history_entry()

◆ read_history_v1()

static GList * read_history_v1 ( const std::string &  xmpPacket,
const char *  filename,
const int  superold 
)
static

Definition at line 675 of file xmp_sidecar.cc.

References history_entry_t::blendop_version, dt_exif_xmp_decode(), and L.

Referenced by dt_exif_xmp_read().

◆ read_history_v2()

static GList * read_history_v2 ( Exiv2::XmpData xmpData,
const char *  filename 
)
static
Todo:
: support human readable params via introspection with something like this:

Definition at line 810 of file xmp_sidecar.cc.

References dt_exif_xmp_decode(), dt_free, free_history_entry(), history_entry_t::have_modversion, history_entry_t::have_operation, history_entry_t::have_params, key, L, n, and TRUE.

Referenced by dt_exif_xmp_read().

◆ read_masks()

◆ read_masks_v3()

static GList * read_masks_v3 ( Exiv2::XmpData xmpData,
const char *  filename,
const int  version 
)
static
Todo:
: support human readable params via introspection with something like this:

Definition at line 1029 of file xmp_sidecar.cc.

References dt_exif_xmp_decode(), dt_free, free_mask_entry(), key, L, and n.

Referenced by dt_exif_xmp_read().

◆ read_xmp_timestamps()

void read_xmp_timestamps ( Exiv2::XmpData xmpData,
dt_image_t img,
const int  xmp_version 
)
static

◆ set_xmp_timestamps()

Variable Documentation

◆ dt_xmp_keys

const char* dt_xmp_keys[]
Initial value:
= { "Xmp.dc.subject", "Xmp.lr.hierarchicalSubject", "Xmp.darktable.colorlabels", "Xmp.darktable.history",
"Xmp.darktable.history_modversion", "Xmp.darktable.history_enabled", "Xmp.darktable.history_end",
"Xmp.darktable.iop_order_version", "Xmp.darktable.iop_order_list",
"Xmp.darktable.history_operation", "Xmp.darktable.history_params", "Xmp.darktable.blendop_params",
"Xmp.darktable.blendop_version", "Xmp.darktable.multi_priority", "Xmp.darktable.multi_name",
"Xmp.darktable.iop_order",
"Xmp.darktable.xmp_version", "Xmp.darktable.raw_params", "Xmp.darktable.auto_presets_applied",
"Xmp.darktable.mask_id", "Xmp.darktable.mask_type", "Xmp.darktable.mask_name",
"Xmp.darktable.masks_history", "Xmp.darktable.mask_num", "Xmp.darktable.mask_points",
"Xmp.darktable.mask_version", "Xmp.darktable.mask", "Xmp.darktable.mask_nb", "Xmp.darktable.mask_src",
"Xmp.darktable.history_basic_hash", "Xmp.darktable.history_auto_hash", "Xmp.darktable.history_current_hash",
"Xmp.darktable.import_timestamp", "Xmp.darktable.change_timestamp",
"Xmp.darktable.export_timestamp", "Xmp.darktable.print_timestamp",
"Xmp.acdsee.notes", "Xmp.darktable.version_name",
"Xmp.dc.creator", "Xmp.dc.publisher", "Xmp.dc.title", "Xmp.dc.description", "Xmp.dc.rights",
"Xmp.xmpMM.DerivedFrom" }

Definition at line 171 of file xmp_sidecar.cc.

Referenced by dt_remove_known_keys().

◆ dt_xmp_keys_n

const guint dt_xmp_keys_n = G_N_ELEMENTS(dt_xmp_keys)
static

Definition at line 189 of file xmp_sidecar.cc.

Referenced by dt_remove_known_keys().