From ffdd5ee0261d60b1e4711cda7cb7d11859b3814b Mon Sep 17 00:00:00 2001 From: Dave Neary Date: Fri, 26 Dec 2003 21:28:30 +0000 Subject: [PATCH] Modify behaviour of levels tool to conserve lightness when using the 2003-12-26 Dave Neary * app/base/levels.c: Modify behaviour of levels tool to conserve lightness when using the grey-point color-picker. --- ChangeLog | 5 +++++ app/base/levels.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1df03e225d..b1fccc4897 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-12-26 Dave Neary + + * app/base/levels.c: Modify behaviour of levels tool to + conserve lightness when using the grey-point color-picker. + 2003-12-26 Sven Neumann * plug-ins/common/edge.c: forgot to change diff --git a/app/base/levels.c b/app/base/levels.c index 1d5cdfdad4..691a4e9706 100644 --- a/app/base/levels.c +++ b/app/base/levels.c @@ -22,6 +22,9 @@ #include "libgimpmath/gimpmath.h" +#include "libgimpcolor/gimpcolortypes.h" +#include "libgimpcolor/gimprgb.h" + #include "base-types.h" #include "gimphistogram.h" @@ -185,6 +188,11 @@ levels_adjust_by_colors (Levels *levels, gint input; gint range; gdouble inten; + gdouble out_light; + guchar lightness; + + /* Calculate lightness value */ + lightness = GIMP_RGB_INTENSITY (gray[0], gray[1], gray[2]); input = levels_input_from_color (channel, gray); @@ -196,9 +204,15 @@ levels_adjust_by_colors (Levels *levels, if (input < 0) return; + /* Normalize input and lightness */ inten = (gdouble) input / (gdouble) range; + out_light = (gdouble) lightness/ (gdouble) range; - levels->gamma[channel] = log (inten) / log (0.5); + if (out_light <= 0) + return; + + /* Map selected color to corresponding lightness */ + levels->gamma[channel] = log (inten) / log (out_light); } }