Skip to content

Commit

Permalink
Merge pull request #17346 from zisoft/exposure-bias-filter
Browse files Browse the repository at this point in the history
Add collection and filter for exposure bias
  • Loading branch information
TurboGit authored Aug 24, 2024
2 parents c45adc7 + 3be0dc0 commit 0472092
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/common/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ const char *dt_collection_name_untranslated(const dt_collection_properties_t pro
return N_("aperture");
case DT_COLLECTION_PROP_EXPOSURE:
return N_("exposure");
case DT_COLLECTION_PROP_EXPOSURE_BIAS:
return N_("exposure bias");
case DT_COLLECTION_PROP_ASPECT_RATIO:
return N_("aspect ratio");
case DT_COLLECTION_PROP_FILENAME:
Expand Down Expand Up @@ -1980,6 +1982,33 @@ static gchar *get_query_string(const dt_collection_properties_t property, const
}
break;

case DT_COLLECTION_PROP_EXPOSURE_BIAS: // exposure bias
{
gchar *operator, * number1, *number2;
dt_collection_split_operator_number(escaped_text, &number1, &number2, &operator);

if(operator && strcmp(operator, "[]") == 0)
{
if(number1 && number2)
// clang-format off
query = g_strdup_printf
("((ROUND(exposure_bias,2) >= %s) AND (ROUND(exposure_bias,2) <= %s))",
number1, number2);
// clang-format on
}
else if(operator && number1)
query = g_strdup_printf("(ROUND(exposure_bias,2) %s %s)", operator, number1);
else if(number1)
query = g_strdup_printf("(ROUND(exposure_bias,2) = %s)", number1);
else
query = g_strdup_printf("(ROUND(exposure_bias,2) LIKE '%%%s%%')", escaped_text);

g_free(operator);
g_free(number1);
g_free(number2);
}
break;

case DT_COLLECTION_PROP_FILENAME: // filename
{
gchar *subquery = NULL;
Expand Down
4 changes: 3 additions & 1 deletion src/common/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ typedef enum dt_collection_properties_t
DT_COLLECTION_PROP_EXPOSURE_PROGRAM,
DT_COLLECTION_PROP_METERING_MODE,

DT_COLLECTION_PROP_GROUP_ID
DT_COLLECTION_PROP_GROUP_ID,

DT_COLLECTION_PROP_EXPOSURE_BIAS
} dt_collection_properties_t;

typedef enum dt_collection_change_t
Expand Down
15 changes: 15 additions & 0 deletions src/libs/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,19 @@ static void _list_view(dt_lib_collect_rule_t *dr)
// clang-format on
break;

case DT_COLLECTION_PROP_EXPOSURE_BIAS: // exposure bias
// clang-format off
g_snprintf(query, sizeof(query),
"SELECT ROUND(exposure_bias,2), 1, COUNT(*) AS count"
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY ROUND(exposure_bias,2)"
" ORDER BY ROUND(exposure_bias,2) %s",
where_ext,
sort_descending ? "DESC" : "ASC");
// clang-format on
break;

case DT_COLLECTION_PROP_FILENAME: // filename
// clang-format off
g_snprintf(query, sizeof(query),
Expand Down Expand Up @@ -3351,6 +3364,7 @@ static void _populate_collect_combo(GtkWidget *w)
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_LENS);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_APERTURE);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_EXPOSURE);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_EXPOSURE_BIAS);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_FOCAL_LENGTH);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_ISO);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_ASPECT_RATIO);
Expand Down Expand Up @@ -4083,6 +4097,7 @@ void init(struct dt_lib_module_t *self)
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_APERTURE);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_ASPECT_RATIO);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_EXPOSURE);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_EXPOSURE_BIAS);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_FILENAME);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_GEOTAGGING);
luaA_enum_value(L, dt_collection_properties_t, DT_COLLECTION_PROP_LOCAL_COPY);
Expand Down
5 changes: 5 additions & 0 deletions src/libs/filtering.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ typedef struct _filter_t
#include "libs/filters/colors.c"
#include "libs/filters/date.c"
#include "libs/filters/exposure.c"
#include "libs/filters/exposure_bias.c"
#include "libs/filters/filename.c"
#include "libs/filters/focal.c"
#include "libs/filters/history.c"
Expand Down Expand Up @@ -244,6 +245,7 @@ static _filter_t filters[]
{ DT_COLLECTION_PROP_FOCAL_LENGTH, _focal_widget_init, _focal_update },
{ DT_COLLECTION_PROP_ISO, _iso_widget_init, _iso_update },
{ DT_COLLECTION_PROP_EXPOSURE, _exposure_widget_init, _exposure_update },
{ DT_COLLECTION_PROP_EXPOSURE_BIAS, _exposure_bias_widget_init, _exposure_bias_update },
{ DT_COLLECTION_PROP_GROUP_ID, _misc_widget_init, _misc_update },
{ DT_COLLECTION_PROP_LOCAL_COPY, _local_copy_widget_init, _local_copy_update },
{ DT_COLLECTION_PROP_HISTORY, _history_widget_init, _history_update },
Expand Down Expand Up @@ -928,6 +930,7 @@ static gboolean _rule_show_popup(GtkWidget *widget, dt_lib_filtering_rule_t *rul
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_LENS);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_APERTURE);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_EXPOSURE);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_EXPOSURE_BIAS);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_FOCAL_LENGTH);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_ISO);
ADD_COLLECT_ENTRY(spop, DT_COLLECTION_PROP_ASPECT_RATIO);
Expand Down Expand Up @@ -999,6 +1002,7 @@ static void _populate_rules_combo(GtkWidget *w)
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_LENS);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_APERTURE);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_EXPOSURE);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_EXPOSURE_BIAS);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_FOCAL_LENGTH);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_ISO);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_ASPECT_RATIO);
Expand Down Expand Up @@ -1672,6 +1676,7 @@ static void _topbar_populate_rules_combo(GtkWidget *w, dt_lib_filtering_t *d)
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_LENS);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_APERTURE);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_EXPOSURE);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_EXPOSURE_BIAS);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_FOCAL_LENGTH);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_ISO);
ADD_COLLECT_ENTRY(DT_COLLECTION_PROP_ASPECT_RATIO);
Expand Down
123 changes: 123 additions & 0 deletions src/libs/filters/exposure_bias.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
This file is part of darktable,
Copyright (C) 2024 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
darktable 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 darktable. If not, see <http://www.gnu.org/licenses/>.
*/

/*
This file contains the necessary routines to implement a filter for the filtering module
*/

#include "common/utility.h"

static gboolean _exposure_bias_update(dt_lib_filtering_rule_t *rule)
{
if(!rule->w_specific) return FALSE;

dt_lib_filtering_t *d = rule->lib;
_widgets_range_t *special = (_widgets_range_t *)rule->w_specific;
_widgets_range_t *specialtop = (_widgets_range_t *)rule->w_specific_top;
GtkDarktableRangeSelect *range = DTGTK_RANGE_SELECT(special->range_select);
GtkDarktableRangeSelect *rangetop = (specialtop) ? DTGTK_RANGE_SELECT(specialtop->range_select) : NULL;

rule->manual_widget_set++;
// first, we update the graph
char query[1024] = { 0 };
// clang-format off
g_snprintf(query, sizeof(query),
"SELECT ROUND(exposure_bias,2), COUNT(*) AS count"
" FROM main.images AS mi"
" WHERE %s"
" GROUP BY ROUND(exposure_bias,2)",
d->last_where_ext);
// clang-format on
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
dtgtk_range_select_reset_blocks(range);
if(rangetop) dtgtk_range_select_reset_blocks(rangetop);
while(sqlite3_step(stmt) == SQLITE_ROW)
{
const double val = sqlite3_column_double(stmt, 0);
const int count = sqlite3_column_int(stmt, 1);
dtgtk_range_select_add_block(range, val, count);
if(rangetop) dtgtk_range_select_add_block(rangetop, val, count);
}
sqlite3_finalize(stmt);

// and setup the selection
dtgtk_range_select_set_selection_from_raw_text(range, rule->raw_text, FALSE);
if(rangetop) dtgtk_range_select_set_selection_from_raw_text(rangetop, rule->raw_text, FALSE);
rule->manual_widget_set--;

dtgtk_range_select_redraw(range);
if(rangetop) dtgtk_range_select_redraw(rangetop);
return TRUE;
}

static gchar *_exposure_bias_print_func(const double value, const gboolean detailled)
{
if(detailled)
{
return g_strdup_printf("%+.2f EV", value);
}
else
{
return dt_util_float_to_str("%+.2f", value);
}
}

static void _exposure_bias_widget_init(dt_lib_filtering_rule_t *rule,
const dt_collection_properties_t prop,
const gchar *text,
dt_lib_module_t *self,
const gboolean top)
{
_widgets_range_t *special = (_widgets_range_t *)g_malloc0(sizeof(_widgets_range_t));

special->range_select
= dtgtk_range_select_new(dt_collection_name_untranslated(prop), !top, DT_RANGE_TYPE_NUMERIC);
if(top) gtk_widget_set_size_request(special->range_select, 160, -1);
GtkDarktableRangeSelect *range = DTGTK_RANGE_SELECT(special->range_select);
range->step_bd = 1.0/3.0;
dtgtk_range_select_set_selection_from_raw_text(range, text, FALSE);
range->print = _exposure_bias_print_func;

char query[1024] = { 0 };
// clang-format off
g_snprintf(query, sizeof(query),
"SELECT MIN(exposure_bias), MAX(exposure_bias)"
" FROM main.images");
// clang-format on
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL);
double min = -5.0;
double max = 5.0;
if(sqlite3_step(stmt) == SQLITE_ROW)
{
min = sqlite3_column_double(stmt, 0);
max = sqlite3_column_double(stmt, 1);
}
sqlite3_finalize(stmt);
range->min_r = floor(min * 100.0) / 100.0;
range->max_r = (floor(max * 100.0) + 1.0) / 100.0;

_range_widget_add_to_rule(rule, special, top);
}

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

0 comments on commit 0472092

Please sign in to comment.