From e71918e42acd525365521c558265c079cc0297b6 Mon Sep 17 00:00:00 2001 From: Kofa Date: Mon, 17 Nov 2025 19:41:28 +0100 Subject: [PATCH 1/3] agx: Remove migration of test (pre-7) versions, simply move them to the latest defaults. --- src/iop/agx.c | 396 ++------------------------------------------------ 1 file changed, 14 insertions(+), 382 deletions(-) diff --git a/src/iop/agx.c b/src/iop/agx.c index 4e493d3375ca..1383d1806fdd 100644 --- a/src/iop/agx.c +++ b/src/iop/agx.c @@ -38,7 +38,9 @@ #include #include -DT_MODULE_INTROSPECTION(7, dt_iop_agx_params_t) +#define AGX_VERSION 7 + +DT_MODULE_INTROSPECTION(AGX_VERSION, dt_iop_agx_params_t) const char *name() { @@ -271,6 +273,8 @@ typedef struct dt_iop_agx_data_t primaries_params_t primaries_params; } dt_iop_agx_data_t; +static void _set_scene_referred_default_params(dt_iop_agx_params_t *p); + int legacy_params(dt_iop_module_t *self, const void *const old_params, const int old_version, @@ -278,390 +282,18 @@ int legacy_params(dt_iop_module_t *self, int32_t *new_params_size, int *new_version) { - typedef struct dt_iop_agx_params_v2_3_4_t - { - float look_offset; - float look_slope; - float look_power; - float look_saturation; - float look_original_hue_mix_ratio; - - float range_black_relative_exposure; - float range_white_relative_exposure; - float security_factor; - - float curve_pivot_x_shift_ratio; - float curve_pivot_y_linear_output; - float curve_contrast_around_pivot; - float curve_linear_ratio_below_pivot; - float curve_linear_ratio_above_pivot; - float curve_toe_power; - float curve_shoulder_power; - float curve_gamma; - gboolean auto_gamma; - float curve_target_display_black_ratio; - float curve_target_display_white_ratio; - - dt_iop_agx_base_primaries_t base_primaries; - gboolean disable_primaries_adjustments; - float red_inset; - float red_rotation; - float green_inset; - float green_rotation; - float blue_inset; - float blue_rotation; - - float master_outset_ratio; - float master_unrotation_ratio; - float red_outset; - float red_unrotation; - float green_outset; - float green_unrotation; - float blue_outset; - float blue_unrotation; - } dt_iop_agx_params_v2_3_4_t; - - typedef struct dt_iop_agx_params_v5_t - { - float look_offset; // renamed to look_lift in v6, but no conversion is needed - float look_slope; - float look_power; // is replaced by look_brightness in v6 - float look_saturation; - float look_original_hue_mix_ratio; - - float range_black_relative_exposure; - float range_white_relative_exposure; - float dynamic_range_scaling; - - float curve_pivot_x_shift_ratio; - float curve_pivot_y_linear_output; - float curve_contrast_around_pivot; - float curve_linear_ratio_below_pivot; - float curve_linear_ratio_above_pivot; - float curve_toe_power; - float curve_shoulder_power; - float curve_gamma; - gboolean auto_gamma; - float curve_target_display_black_ratio; - float curve_target_display_white_ratio; - - dt_iop_agx_base_primaries_t base_primaries; - gboolean disable_primaries_adjustments; - float red_inset; - float red_rotation; - float green_inset; - float green_rotation; - float blue_inset; - float blue_rotation; - - float master_outset_ratio; - float master_unrotation_ratio; - float red_outset; - float red_unrotation; - float green_outset; - float green_unrotation; - float blue_outset; - float blue_unrotation; - - gboolean completely_reverse_primaries; // added in v5 - } dt_iop_agx_params_v5_t; - - typedef struct dt_iop_agx_params_v6_t - { - float look_lift; // replaces look_offset in v5->v6 - float look_slope; - float look_brightness; // replaces look_power in v5->v6 - float look_saturation; - float look_original_hue_mix_ratio; - - float range_black_relative_exposure; - float range_white_relative_exposure; - float dynamic_range_scaling; - - float curve_pivot_x_shift_ratio; - float curve_pivot_y_linear_output; - float curve_contrast_around_pivot; - float curve_linear_ratio_below_pivot; - float curve_linear_ratio_above_pivot; - float curve_toe_power; - float curve_shoulder_power; - float curve_gamma; - gboolean auto_gamma; - float curve_target_display_black_ratio; - float curve_target_display_white_ratio; - - dt_iop_agx_base_primaries_t base_primaries; - gboolean disable_primaries_adjustments; - float red_inset; - float red_rotation; - float green_inset; - float green_rotation; - float blue_inset; - float blue_rotation; - - float master_outset_ratio; - float master_unrotation_ratio; - float red_outset; - float red_unrotation; - float green_outset; - float green_unrotation; - float blue_outset; - float blue_unrotation; - - gboolean completely_reverse_primaries; // added in v5 - } dt_iop_agx_params_v6_t; - - typedef struct dt_iop_agx_params_v7_t - { - float look_lift; - float look_slope; - float look_brightness; - float look_saturation; - float look_original_hue_mix_ratio; - - float range_black_relative_ev; - float range_white_relative_ev; - float dynamic_range_scaling; - - float curve_pivot_x; // replaces curve_pivot_x_shift_ratio in v6 -> v7 - float curve_pivot_y_linear_output; - float curve_contrast_around_pivot; - float curve_linear_ratio_below_pivot; - float curve_linear_ratio_above_pivot; - float curve_toe_power; - float curve_shoulder_power; - float curve_gamma; - gboolean auto_gamma; - float curve_target_display_black_ratio; - float curve_target_display_white_ratio; - - dt_iop_agx_base_primaries_t base_primaries; - gboolean disable_primaries_adjustments; - float red_inset; - float red_rotation; - float green_inset; - float green_rotation; - float blue_inset; - float blue_rotation; - - float master_outset_ratio; - float master_unrotation_ratio; - float red_outset; - float red_unrotation; - float green_outset; - float green_unrotation; - float blue_outset; - float blue_unrotation; - - gboolean completely_reverse_primaries; - } dt_iop_agx_params_v7_t; - - if(old_version == 1) - { - typedef struct dt_iop_agx_params_v1_t - { - float look_offset; - float look_slope; - float look_power; - float look_saturation; - float look_original_hue_mix_ratio; - - // log mapping - float range_black_relative_exposure; - float range_white_relative_exposure; - float security_factor; - - // curve params - float curve_pivot_x_shift; - float curve_pivot_y_linear; - float curve_contrast_around_pivot; - float curve_linear_percent_below_pivot; - float curve_linear_percent_above_pivot; - float curve_toe_power; - float curve_shoulder_power; - float curve_gamma; - gboolean auto_gamma; - float curve_target_display_black_percent; - float curve_target_display_white_percent; - - // custom primaries - dt_iop_agx_base_primaries_t base_primaries; - // 'disable_primaries_adjustments' is missing here in v1 - float red_inset; - float red_rotation; - float green_inset; - float green_rotation; - float blue_inset; - float blue_rotation; - - float master_outset_ratio; - float master_unrotation_ratio; - float red_outset; - float red_unrotation; - float green_outset; - float green_unrotation; - float blue_outset; - float blue_unrotation; - } dt_iop_agx_params_v1_t; - - dt_iop_agx_params_v2_3_4_t *np = calloc(1, sizeof(dt_iop_agx_params_v2_3_4_t)); - const dt_iop_agx_params_v1_t *op = old_params; - - // Because the new 'disable_primaries_adjustments' field was added - // in the middle of the struct, we must copy the data in two - // parts, around the new field. - - // fields before 'disable_primaries_adjustments'. - const size_t part1_size = offsetof(dt_iop_agx_params_v2_3_4_t, disable_primaries_adjustments); - memcpy(np, op, part1_size); - - // the new param - np->disable_primaries_adjustments = FALSE; - - // fields after 'disable_primaries_adjustments'. - const void *old_part2_start = &op->red_inset; - void *new_part2_start = &np->red_inset; - const size_t part2_size = - sizeof(dt_iop_agx_params_v1_t) - offsetof(dt_iop_agx_params_v1_t, red_inset); - memcpy(new_part2_start, old_part2_start, part2_size); - - *new_params = np; - *new_params_size = sizeof(dt_iop_agx_params_v2_3_4_t); - *new_version = 2; - - return 0; // success - } - - if(old_version == 2) - { - // v2 and v3 have the same layout, but some v2 parameters are converted to percentages. - // (Later, this turned out to be a mistake, see v4.) Rather than defining the same - // struct again, with different names, we convert in place. - // Fields names reflect the v4 names, so this is somewhat confusing, but I did not want - // to repeat the whole struct, when the layout is identical. - - const dt_iop_agx_params_v2_3_4_t *op = old_params; - dt_iop_agx_params_v2_3_4_t *np = calloc(1, sizeof(dt_iop_agx_params_v2_3_4_t)); - - memcpy(np, op, sizeof(dt_iop_agx_params_v2_3_4_t)); - np->look_offset *= 100.f; - np->look_saturation *= 100.f; - np->look_original_hue_mix_ratio *= 100.f; - np->curve_pivot_x_shift_ratio *= 100.f; - np->curve_pivot_y_linear_output *= 100.f; - - *new_params = np; - *new_params_size = sizeof(dt_iop_agx_params_v2_3_4_t); - *new_version = 3; - - return 0; // success - } - - if(old_version == 3) - { - // v3 and v4 have the same layout, so we convert in place, but now the GUI will take - // care of all percentage conversions, and it will provide simple ratios - // (1 instead of 100%) via dt_bauhaus_slider_set_factor. - // This undoes some conversions done in the v2 -> v3 step, and makes all such sliders - // consistent. - - const dt_iop_agx_params_v2_3_4_t *op = old_params; - dt_iop_agx_params_v2_3_4_t *np = calloc(1, sizeof(dt_iop_agx_params_v2_3_4_t)); - - memcpy(np, op, sizeof(dt_iop_agx_params_v2_3_4_t)); - - np->look_offset /= 100.f; - np->look_saturation /= 100.f; - np->look_original_hue_mix_ratio /= 100.f; - np->security_factor /= 100.f; - np->curve_pivot_x_shift_ratio /= 100.f; - np->curve_pivot_y_linear_output /= 100.f; - np->curve_linear_ratio_below_pivot /= 100.f; - np->curve_linear_ratio_above_pivot /= 100.f; - np->curve_target_display_black_ratio /= 100.f; - np->curve_target_display_white_ratio /= 100.f; - - *new_params = np; - *new_params_size = sizeof(dt_iop_agx_params_v2_3_4_t); - *new_version = 4; - - return 0; // success - } - - if(old_version == 4) - { - // v5 adds 'completely_reverse_primaries' at the end of the struct - const dt_iop_agx_params_v2_3_4_t *op = old_params; - dt_iop_agx_params_v5_t *np = calloc(1, sizeof(dt_iop_agx_params_v5_t)); - - memcpy(np, op, sizeof(dt_iop_agx_params_v2_3_4_t)); - - np->completely_reverse_primaries = FALSE; - - *new_params = np; - *new_params_size = sizeof(dt_iop_agx_params_v5_t); - *new_version = 5; - - return 0; // success - } - - if(old_version == 5) - { - // v6 replaces look -> power with look -> brightness - const dt_iop_agx_params_v5_t *op = old_params; - dt_iop_agx_params_v6_t *np = calloc(1, sizeof(dt_iop_agx_params_v6_t)); - - // v5 and v6 are compatible at the binary level - memcpy(np, op, sizeof(dt_iop_agx_params_v5_t)); - - const float look_power_v5 = op->look_power; - np->look_brightness = look_power_v5 > 1 ? - 1.f / (look_power_v5 * look_power_v5) - : 1.f / fmaxf(look_power_v5, 0.01f); // max allowed brightness is 100 - *new_params = np; - *new_params_size = sizeof(dt_iop_agx_params_v6_t); - *new_version = 6; - - return 0; // success - } - - if(old_version == 6) + if(old_version < 7) { - // v6 replaces look -> power with look -> brightness - const dt_iop_agx_params_v6_t *op = old_params; - dt_iop_agx_params_v7_t *np = calloc(1, sizeof(dt_iop_agx_params_v7_t)); - - // v6 and v7 are compatible at the binary level - memcpy(np, op, sizeof(dt_iop_agx_params_v6_t)); - - const float pivot_relative_ev = op->curve_pivot_x_shift_ratio > 0 ? - op->range_white_relative_exposure * op->curve_pivot_x_shift_ratio : - - (op->range_black_relative_exposure * op->curve_pivot_x_shift_ratio); - const float pivot_distance_in_ev_from_black = pivot_relative_ev - op->range_black_relative_exposure; - - if(pivot_distance_in_ev_from_black < _epsilon) - { - np->curve_pivot_x = _epsilon; - } - else - { - const float exposure_range_in_ev = op->range_white_relative_exposure - op->range_black_relative_exposure; - if(exposure_range_in_ev < _epsilon) - { - // should never happen, because of hard limits on the sliders - np->curve_pivot_x = 0.5f; - } - else - { - np->curve_pivot_x = CLIP(pivot_distance_in_ev_from_black / exposure_range_in_ev); - } - } - + // SPECIAL CASE: all versions before 7 were unreleased test versions, + // and migration is not relevant anymore; they will always be migrated + // to the CURRENT LATEST version, without further gradual migration steps + dt_iop_agx_params_t *np = calloc(1, sizeof(dt_iop_agx_params_t)); + _set_scene_referred_default_params(np); *new_params = np; - *new_params_size = sizeof(dt_iop_agx_params_v7_t); - *new_version = 7; + *new_params_size = sizeof(dt_iop_agx_params_t); + *new_version = AGX_VERSION; // SPECIAL CASE: test versions jump directly to latest - return 0; // success + return 1; // SPECIAL CASE for test versions: we're done } return 1; // no other conversion possible From 9721e05408179368040ba76efa73e6ef18e33264 Mon Sep 17 00:00:00 2001 From: Kofa Date: Mon, 17 Nov 2025 20:53:10 +0100 Subject: [PATCH 2/3] agx: Fix return value of 'migrating' test versions --- src/iop/agx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iop/agx.c b/src/iop/agx.c index 1383d1806fdd..8cd9c4fbfc6d 100644 --- a/src/iop/agx.c +++ b/src/iop/agx.c @@ -293,7 +293,7 @@ int legacy_params(dt_iop_module_t *self, *new_params_size = sizeof(dt_iop_agx_params_t); *new_version = AGX_VERSION; // SPECIAL CASE: test versions jump directly to latest - return 1; // SPECIAL CASE for test versions: we're done + return 0; } return 1; // no other conversion possible From b144aa0443a932b2e25321311fbbcc63c926e1fa Mon Sep 17 00:00:00 2001 From: Kofa Date: Tue, 18 Nov 2025 19:39:02 +0100 Subject: [PATCH 3/3] agx: Fixed startup crash: version cannot be set via #define --- src/iop/agx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/iop/agx.c b/src/iop/agx.c index 8cd9c4fbfc6d..cacfc75fa91c 100644 --- a/src/iop/agx.c +++ b/src/iop/agx.c @@ -38,9 +38,7 @@ #include #include -#define AGX_VERSION 7 - -DT_MODULE_INTROSPECTION(AGX_VERSION, dt_iop_agx_params_t) +DT_MODULE_INTROSPECTION(7, dt_iop_agx_params_t) const char *name() { @@ -291,12 +289,12 @@ int legacy_params(dt_iop_module_t *self, _set_scene_referred_default_params(np); *new_params = np; *new_params_size = sizeof(dt_iop_agx_params_t); - *new_version = AGX_VERSION; // SPECIAL CASE: test versions jump directly to latest + *new_version = self->so->version(); // SPECIAL CASE: jump directly to latest version return 0; } - return 1; // no other conversion possible + return 1; } static inline dt_colorspaces_color_profile_type_t