Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: Mike.Cornflake on June 26, 2014, 09:36:35 am

Title: [Solved] Darken TColor
Post by: Mike.Cornflake on June 26, 2014, 09:36:35 am
I'm ignorant in the world of image processing.   I'm highlighting rows in a grid by setting Color in OnPrepareCanvas (according to calculated criteria - bad = red, good = green, OKish = Yellow or Orange.  Unimportant = white.  The unimportant selected rows are highlighted in light gray automatically for me by the grid itself)

If the row is the selected row, I want to to highlight the row with a slighter darker version of the color.  Instead of hard-coding alternatives, is there a simple DarkenColor(AColor: TColor; APercent: Double): TColor anywhere?  (Or equivalent)

I've looked, and the ones I can find are in dedicated image processing libraries, which I *think* involves introducing levels of complexity beyond what I'm actually after...
Title: Re: Darken TColor
Post by: taazz on June 26, 2014, 10:04:45 am
use GraphUtil.ColorAdjustLuma or search for colorblend for alphablending two colors with a standart alpha value creating something like a chromasity ee a blue window on top of the back color.
Title: Re: Darken TColor
Post by: wp on June 26, 2014, 10:06:42 am
That's the way I did it in fpspreadsheetgrid. It darkens a bright color and brightens a dark color:

Code: [Select]
function CalcSelectionColor(c: TColor; ADelta: Byte) : TColor;
type
  TRGBA = record R,G,B,A: Byte end;
begin
  c := ColorToRGB(c);
  TRGBA(Result).A := 0;
  if TRGBA(c).R < 128
    then TRGBA(Result).R := TRGBA(c).R + ADelta
    else TRGBA(Result).R := TRGBA(c).R - ADelta;
  if TRGBA(c).G < 128
    then TRGBA(Result).G := TRGBA(c).G + ADelta
    else TRGBA(Result).G := TRGBA(c).G - ADelta;
  if TRGBA(c).B < 128
    then TRGBA(Result).B := TRGBA(c).B + ADelta
    else TRGBA(Result).B := TRGBA(c).B - ADelta;
end;
Title: Re: Darken TColor
Post by: Mike.Cornflake on June 26, 2014, 10:34:46 am
Many thanks @taazz and @wp, I'll play with both solutions :-)
Title: Re: Darken TColor
Post by: Blaazen on June 26, 2014, 11:12:57 am
Quote
use GraphUtil.....
I didn't know this unit at all! I reinvented some methods in EC-Controls (NormalizeRect, GetMonochromaticColor, maybe more). I'll refactore the code.
Also unit GraphMath is interesting.
Anyway, thanks.
Title: Re: Darken TColor
Post by: Mike.Cornflake on June 26, 2014, 11:21:41 am
Quote
use GraphUtil.....
I didn't know this unit at all!

There's a bucketload of undiscovered goodies all around :-)

And I've just noticed your tagline
Quote
POKE 54296,15
Wow, that takes me back :-)
Title: Re: Darken TColor
Post by: Mike.Cornflake on June 26, 2014, 06:28:04 pm
Again, many thanks all.  I ended up going with
Code: [Select]
oColor := GetHighLightColor(oColor, 32);GetHighlightColor is defined in GraphUtil.
Title: Re: [Solved] Darken TColor
Post by: Mike.Cornflake on August 29, 2018, 07:41:00 pm
That's the way I did it in fpspreadsheetgrid. It darkens a bright color and brightens a dark color:

Apologies for re-opening an old topic, but thanks are due:   I just had to fix an issue where I was darkening a row all the way to blackness.  I resolved by popping back here and using @wp's solution instead.  So many thanks @wp :-)
TinyPortal © 2005-2018