On Wed, 2007-02-07 at 08:57 +0100, Sven Neumann wrote:
> As far as I understand the dialog doesn't show absolute values for
> Saturation and Lightness but relative ones. Perhaps the Saturation
> slider should also go from -100 to +100 then.
Saturation appears to be absolute. Lightness is relative. See below.
> First of all someone should take a look at the code and find out what it
> really does. I very much doubt that anyone here can tell you this
> without looking at the code. So why don't you just have a look and tell
> us what you found?
Okay, here's how it looked to me. I had to trace through to figure out
where the meat was being cooked, so this includes my tracing (in case I
Call sequence for changing the Lightness slider in the Colorize dialog:
colorize_lightness_adj_update() is the callback in the Colorize
dialog that handles Lightness slider changes.
colorize_lightness_adj_update() calls colorize_update() after
retrieving the L value from the dialog and saving it in a Colorize
structure. The Colorize structure holds current HSL values as
and two sets of 3 256-entry tables, one set of 3 for Luminance
one set of 3 for RGB lookups. Colorize is initialized (by
colorize_init()) so that the Lum lookup table is non-zero.
colorize_update() calls colorize_calculate() before updating
Doesn't use the L component of Colorize structure. It simply
256 RGB lookup values (0-255) and sets L to i/255.0 for each
using the S and H components passed in the Colorize structure.
and S components are used as you would expect in HSV space: the
value for H is divided by 360 and the value for S is divided by
For the Colorize dialog, which has a preview, this function
colorize_lightness_adj_update() then calls
This call sequence eventually calls the gimp_colorize_tool_map()
function to do the preview update.
gimp_colorize_tool_map() calls gimp_image_map_apply(), which is
the colorize() function and a Colorize structure, along with the
a structure containing a pointer to the drawable (re: preview) to
At each pixel across the width and height of the preview:
Note: L = slider setting in the dialog, ie colorize->lightness
"lum" inits to the combined luminance of the current pixel based
on the luminance lookup table in the Colorize structure.
If L > 0,
lum = (gdouble) lum * (100.0 - colorize->lightness) / 100.0;
lum = += 255 - (100.0 - colorize->lightness) * 255.0 /
else if L < 0
lum = (gdouble) lum * (colorize->lightness + 100.0) / 100.0;
New pixel value is RGB = Colorize.RGBlookup[lum] (Alpha
If L = 0 then the pixel is always the luminance of the selected H/S
If L < 0 then the pixel is the (absolute value of the lightness
of the current pixels luminance for the selected H/S
If L > 0
Add the (lightness slider)% of 0-255 to (lightness slider)% of
pixels current luminance and use that to compute the new color
the RGB table based on the H/S combination.
It's unclear to me why the percent of 0-255 is added to a percent of the
current luminance value instead of directly to the current luminance
value though I can see why you might want to have -100 to 100 for the L
slider: negative slider values reduce luminance of the current pixel
while positive values increase it. You need to do this because your
working relative to the current pixel and not on an absolute scale. In
other words, the L slider is a percent increase or percent decrease in
any given pixels luminance. Sort of.
Michael J. Hammel Senior Software Engineer
[EMAIL PROTECTED] http://graphics-muse.org
Failure is not an option. It comes bundled with your Microsoft product.
-- Ferenc Mantfeld
Gimp-developer mailing list