Einzelnen Beitrag anzeigen

static_cast

Registriert seit: 19. Okt 2003
Ort: Peine
300 Beiträge
 
#6

Re: TColor - Helligkeit und Sättigung (Get/Set)

  Alt 15. Okt 2004, 12:03
@alcaeus

nee ich mag kein vorgekauten code der so wirr ist (deswegen konnt ich mit dem post nix anfangen), dann bau ich es mir selber

Hehe jetzt hab ich meine get functions auch fertig die funzen auch, ist zwar eine abweichung von +/- 1..2 aber damit kann ich leben *g*

jetzt muss ich noch die set proceduren baun, mal schaun, hat da wer noch gute infos?

Delphi-Quellcode:
function GetLightness(AColor:TColor):Byte;
var
  R,G,B:Byte;
  MaxValue,MinValue:Double;
  Lightness:Double;
begin
  R:=GetRValue(ColorToRGB(AColor));
  G:=GetGValue(ColorToRGB(AColor));
  B:=GetBValue(ColorToRGB(AColor));

  MaxValue:=Max(Max(R,G),B);
  MinValue:=Min(Min(R,G),B);

  Lightness:=(((MaxValue + MinValue) * 240) + 255 ) / 510;

  Result:=Round(Lightness);
end;

function GetSaturation(AColor:TColor):Byte;
var
  R,G,B:Byte;
  MaxValue,MinValue:Double;
  Lightness,Saturation:Double;
begin
  R:=GetRValue(ColorToRGB(AColor));
  G:=GetGValue(ColorToRGB(AColor));
  B:=GetBValue(ColorToRGB(AColor));

  MaxValue:=Max(Max(R,G),B);
  MinValue:=Min(Min(R,G),B);

  Lightness:=(((MaxValue + MinValue) * 240) + 255 ) / 510;

  if Lightness <= 120 then
  begin
    Saturation:=(((MaxValue - MinValue) * 240) +
                 ((MaxValue + MinValue) / 2)) /
                  (MaxValue + MinValue);
  end else
  begin
    Saturation:=(((MaxValue - MinValue) * 240) +
                 ((510 - MaxValue - MinValue) / 2)) /
                  (510 - MaxValue - MinValue);
  end;

  Result:=Round(Saturation);
end;
PS: Ihr könntet die funktionen ja auch mal testen.
Daniel M.
"The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore."
  Mit Zitat antworten Zitat