Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Blending colors in HSL (https://www.delphipraxis.net/169308-blending-colors-hsl.html)

WojTec 11. Jul 2012 11:13

Blending colors in HSL
 
Delphi-Quellcode:
function BlendColorsHueCW(const AColor1, AColor2: TColor; const AValue: Byte {0..100}): TColor;
var
  RGB: array [0..2] of Byte;
  HSL1, HSL2: array [0..2] of Integer;
  H, S, L: Integer;
begin
  GetRGB(AColor1, RGB[0], RGB[1], RGB[2]);
  RGBToHSL(RGB[0], RGB[1], RGB[2], HSL1[0], HSL1[1], HSL1[2]);

  GetRGB(AColor2, RGB[0], RGB[1], RGB[2]);
  RGBToHSL(RGB[0], RGB[1], RGB[2], HSL2[0], HSL2[1], HSL2[2]);

  H := Round((MaxHue / 100) * AValue) * (HSL2[0] - HSL1[0]) shr 8 + HSL1[0];
  S := Round((MaxSat / 100) * AValue) * (HSL2[1] - HSL1[1]) shr 8 + HSL1[1];
  L := Round((MaxLum / 100) * AValue) * (HSL2[2] - HSL1[2]) shr 8 + HSL1[2];

  HSLToRGB(H, S, L, RGB[0], RGB[1], RGB[2]);
  Result := SetRGB(RGB[0], RGB[1], RGB[2]);
end;
When ~100% then invalid result. Why?

lbccaleb 11. Jul 2012 12:47

AW: Blending colors in HSL
 
Maybe, you get it by yourself when you test the following code ;)

Delphi-Quellcode:
  showmessage(inttostr(Round(255{maxhue/maxsat/maxlum} / 100)));


All Numbers over 85 are to high!

WojTec 11. Jul 2012 15:52

Re: Blending colors in HSL
 
Delphi-Quellcode:
initialization
  MaxHue := 360;
  MaxSat := 100;
  MaxLum := 100;
You mean should be: MaxHue=MaxSat=MaxLum=255? I tried it and result is also not accurately: R is ok, but GB are not ok (G + 2 and B ok or G + 1 and B + 1) :?

Edited: for MaxHue=MaxSat=MaxLum=256 is ok. I did right?

And what about other range (default I have 360:100:100)?

freeway 11. Jul 2012 16:05

AW: Blending colors in HSL
 
hmm why hsl blend over, i donīt see the benefit to rgb blend methode
ok that donīt explain your question

you got
MaxHue := 360;
MaxSat := 100;
MaxLum := 100;


H := Round((MaxHue / 100) * AValue) * (HSL2[0] - HSL1[0]) shr 8 + HSL1[0];
S := Round((MaxSat / 100) * AValue) * (HSL2[1] - HSL1[1]) shr 8 + HSL1[1];
L := Round((MaxLum / 100) * AValue) * (HSL2[2] - HSL1[2]) shr 8 + HSL1[2];

you see the difference ?

WojTec 11. Jul 2012 17:12

Re: Blending colors in HSL
 
Oh, of course, will be 1 * percent = percent :-D

Because I want to get colors from HSL circle bethween these 2 colors, not just blend 2 paints :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:16 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz