From 45d0d4bef2bc6ab370656b84becfd7a648df642e Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Thu, 14 Nov 2024 19:29:49 +0000 Subject: [PATCH] app/core: Use babl for histogram luminance values This replaces the GIMP_RGB_LUMINANCE () macro with babl_process () to retrieve luminance from pixels in GimpHistogram. This allows us to consider the color space during the conversion, rather than assuming sRGB always. --- app/core/gimphistogram.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/core/gimphistogram.c b/app/core/gimphistogram.c index 2e654d3f31..2d67bf829d 100644 --- a/app/core/gimphistogram.c +++ b/app/core/gimphistogram.c @@ -984,6 +984,7 @@ gimp_histogram_calculate_area (const GeglRectangle *area, GimpAsync *async; CalculateContext *context; GeglBufferIterator *iter; + const Babl *fish; gdouble *values; gint n_components; gint n_bins; @@ -996,6 +997,8 @@ gimp_histogram_calculate_area (const GeglRectangle *area, n_bins = context->n_bins; n_components = context->n_components; + fish = babl_fish (data->format, babl_format ("Y float")); + values = g_new0 (gdouble, (n_components + N_DERIVED_CHANNELS) * n_bins); gimp_atomic_slist_push_head (&data->values_list, values); @@ -1093,7 +1096,7 @@ gimp_histogram_calculate_area (const GeglRectangle *area, max = MAX (data[2], max); VALUE (0, max) += masked; - luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]); + babl_process (fish, data, &luminance, 1); VALUE (4, luminance) += masked; data += n_components; @@ -1118,7 +1121,7 @@ gimp_histogram_calculate_area (const GeglRectangle *area, max = MAX (data[2], max); VALUE (0, max) += weight * masked; - luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]); + babl_process (fish, data, &luminance, 1); VALUE (5, luminance) += weight * masked; data += n_components; @@ -1169,7 +1172,7 @@ gimp_histogram_calculate_area (const GeglRectangle *area, max = MAX (data[2], max); VALUE (0, max) += 1.0; - luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]); + babl_process (fish, data, &luminance, 1); VALUE (4, luminance) += 1.0; data += n_components; @@ -1192,7 +1195,7 @@ gimp_histogram_calculate_area (const GeglRectangle *area, max = MAX (data[2], max); VALUE (0, max) += weight; - luminance = GIMP_RGB_LUMINANCE (data[0], data[1], data[2]); + babl_process (fish, data, &luminance, 1); VALUE (5, luminance) += weight; data += n_components;