Skip to content

Commit

Permalink
Merge pull request darktable-org#18437 from victoryforce/exif-flash-t…
Browse files Browse the repository at this point in the history
…ag-value

[imageio] [DAM] Support Exif flash tag value in addition to its exiv2 textual explanation
  • Loading branch information
TurboGit authored Feb 23, 2025
2 parents 910064b + 4fe8d3c commit e6ad946
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
12 changes: 11 additions & 1 deletion src/common/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
// is created by running the upgrade steps.
#define LAST_FULL_DATABASE_VERSION_LIBRARY 55
#define LAST_FULL_DATABASE_VERSION_DATA 10

// You HAVE TO bump THESE versions whenever you add an update branches to _upgrade_*_schema_step()!
#define CURRENT_DATABASE_VERSION_LIBRARY 56
#define CURRENT_DATABASE_VERSION_LIBRARY 57
#define CURRENT_DATABASE_VERSION_DATA 13

#define USE_NESTED_TRANSACTIONS
Expand Down Expand Up @@ -2944,6 +2945,15 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version)
sqlite3_exec(db->handle, "PRAGMA foreign_keys = ON", NULL, NULL, NULL);
new_version = 56;
}
else if(version == 56)
{
// The default value of -1 means that we have no information
// (the corresponding Exif tag has been removed or Exif has been
// removed altogether or the image format does not support Exif)
TRY_EXEC("ALTER TABLE main.images ADD COLUMN flash_tagvalue INTEGER DEFAULT -1",
"[init] can't add `flash_tagvalue' column to images table in database\n");
new_version = 57;
}
else
new_version = version; // should be the fallback so that calling code sees that we are in an infinite loop

Expand Down
3 changes: 2 additions & 1 deletion src/common/exif.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2009-2024 darktable developers.
Copyright (C) 2009-2025 darktable developers.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1740,6 +1740,7 @@ static bool _exif_decode_exif_data(dt_image_t *img, Exiv2::ExifData &exifData)
if(FIND_EXIF_TAG("Exif.Photo.Flash"))
{
const int value = pos->toLong();
img->exif_flash_tagvalue = value;
if(value != 0)
{
_strlcpy_to_utf8(img->exif_flash, sizeof(img->exif_flash), pos, exifData);
Expand Down
11 changes: 6 additions & 5 deletions src/common/image.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2009-2024 darktable developers.
Copyright (C) 2009-2025 darktable developers.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1276,15 +1276,15 @@ static dt_imgid_t _image_duplicate_with_version_ext(const dt_imgid_t imgid,
" orientation, longitude, latitude, altitude, color_matrix,"
" colorspace, version, max_version,"
" history_end, position, aspect_ratio, exposure_bias, import_timestamp,"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id)"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id, flash_tagvalue)"
" SELECT NULL, group_id, film_id, width, height, filename,"
" maker_id, model_id, camera_id, lens_id,"
" exposure, aperture, iso, focal_length, focus_distance, datetime_taken,"
" flags, output_width, output_height, crop, raw_parameters,"
" raw_black, raw_maximum, orientation,"
" longitude, latitude, altitude, color_matrix, colorspace, NULL, NULL, 0, ?1,"
" aspect_ratio, exposure_bias, import_timestamp,"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id, flash_tagvalue"
" FROM main.images WHERE id = ?2",
-1, &stmt, NULL);
// clang-format on
Expand Down Expand Up @@ -2106,6 +2106,7 @@ void dt_image_init(dt_image_t *img)
memset(img->camera_makermodel, 0, sizeof(img->camera_makermodel));
memset(img->filename, 0, sizeof(img->filename));
g_strlcpy(img->filename, "(unknown)", sizeof(img->filename));
img->exif_flash_tagvalue = -1; // -1 means we have no data (this is not the same as "flash not fired")
img->exif_crop = 1.0;
img->exif_exposure = 0;
img->exif_exposure_bias = DT_EXIF_TAG_UNINITIALIZED;
Expand Down Expand Up @@ -2458,15 +2459,15 @@ dt_imgid_t dt_image_copy_rename(const dt_imgid_t imgid,
" raw_black, raw_maximum, orientation,"
" longitude, latitude, altitude, color_matrix, colorspace, version, max_version,"
" position, aspect_ratio, exposure_bias,"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id)"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id, flash_tagvalue)"
" SELECT NULL, group_id, ?1 as film_id, width, height, ?2 as filename,"
" maker_id, model_id, lens_id,"
" exposure, aperture, iso, focal_length, focus_distance, datetime_taken,"
" flags, width, height, crop, raw_parameters, raw_black, raw_maximum,"
" orientation, longitude, latitude, altitude,"
" color_matrix, colorspace, -1, -1,"
" ?3, aspect_ratio, exposure_bias,"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id"
" whitebalance_id, flash_id, exposure_program_id, metering_mode_id, flash_tagvalue"
" FROM main.images"
" WHERE id = ?4",
-1, &stmt, NULL);
Expand Down
1 change: 1 addition & 0 deletions src/common/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ typedef struct dt_image_t
float exif_focal_length;
float exif_focus_distance;
float exif_crop;
int32_t exif_flash_tagvalue;
char exif_maker[64];
char exif_model[64];
char exif_lens[128];
Expand Down
9 changes: 6 additions & 3 deletions src/common/image_cache.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2009-2024 darktable developers.
Copyright (C) 2009-2025 darktable developers.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -49,7 +49,7 @@ static void _image_cache_allocate(void *data,
" raw_black, raw_maximum, aspect_ratio, exposure_bias,"
" import_timestamp, change_timestamp, export_timestamp, print_timestamp,"
" output_width, output_height, cm.maker, cm.model, cm.alias,"
" wb.name, fl.name, ep.name, mm.name"
" wb.name, fl.name, ep.name, mm.name, flash_tagvalue"
" FROM main.images AS mi"
" LEFT JOIN main.cameras AS cm ON cm.id = mi.camera_id"
" LEFT JOIN main.makers AS mk ON mk.id = mi.maker_id"
Expand Down Expand Up @@ -154,6 +154,8 @@ static void _image_cache_allocate(void *data,
str = (char *)sqlite3_column_text(stmt, 41);
if(str) g_strlcpy(img->exif_metering_mode, str, sizeof(img->exif_metering_mode));

img->exif_flash_tagvalue = sqlite3_column_int(stmt, 42);

dt_color_harmony_get(entry->key, &img->color_harmony_guide);

// buffer size? colorspace?
Expand Down Expand Up @@ -343,7 +345,7 @@ void dt_image_cache_write_release_info(dt_image_t *img,
" import_timestamp = ?28, change_timestamp = ?29, export_timestamp = ?30,"
" print_timestamp = ?31, output_width = ?32, output_height = ?33,"
" whitebalance_id = ?36, flash_id = ?37,"
" exposure_program_id = ?38, metering_mode_id = ?39"
" exposure_program_id = ?38, metering_mode_id = ?39, flash_tagvalue = ?41"
" WHERE id = ?40",
-1, &stmt, NULL);

Expand Down Expand Up @@ -409,6 +411,7 @@ void dt_image_cache_write_release_info(dt_image_t *img,
DT_DEBUG_SQLITE3_BIND_INT(stmt, 38, exposure_program_id);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 39, metering_mode_id);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 40, img->id);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 41, img->exif_flash_tagvalue);

const int rc = sqlite3_step(stmt);
if(rc != SQLITE_DONE)
Expand Down
31 changes: 17 additions & 14 deletions src/common/variables.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2010-2024 darktable developers.
Copyright (C) 2010-2025 darktable developers.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -106,17 +106,6 @@ typedef struct dt_variables_data_t

static char *_expand_source(dt_variables_params_t *params, char **source, char extra_stop);

static gboolean _is_flash_fired(const dt_image_t *img)
{
if(img->exif_flash[0] == '\0') // string is empty
return FALSE; // so we can't claim that flash fired
if(g_strrstr(img->exif_flash, "did not fire"))
return FALSE;
if(img->exif_flash[0] == 'N') // "No", that is no flash function present
return FALSE;
else
return TRUE; // all other strings mean that the flash fired
}

// gather some data that might be used for variable expansion
static void _init_expansion(dt_variables_params_t *params, gboolean iterate)
Expand Down Expand Up @@ -192,8 +181,22 @@ static void _init_expansion(dt_variables_params_t *params, gboolean iterate)
params->data->longitude = img->geoloc.longitude;
params->data->latitude = img->geoloc.latitude;
params->data->elevation = img->geoloc.elevation;
params->data->exif_flash_icon = _is_flash_fired(img) ? "⚡" : "";
params->data->exif_flash = _is_flash_fired(img) ? _("yes") : _("no");


// We don't want to claim that the flash did not fire when the photo is
// clearly taken with a flash, but information about this is not available
if(img->exif_flash_tagvalue == -1)
{
params->data->exif_flash_icon = "";
params->data->exif_flash = _("no info");
}
else
{
// Bit 0 set means that flash was fired
params->data->exif_flash_icon = (img->exif_flash_tagvalue & 1) ? "⚡" : "";
params->data->exif_flash = (img->exif_flash_tagvalue & 1) ? _("yes") : _("no");
}

params->data->exif_exposure_program = img->exif_exposure_program;
params->data->exif_metering_mode = img->exif_metering_mode;
params->data->exif_whitebalance = img->exif_whitebalance;
Expand Down

0 comments on commit e6ad946

Please sign in to comment.