Recent

Author Topic: difference in HSL values from ColorDialog & GraphUtil class  (Read 6691 times)

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
difference in HSL values from ColorDialog & GraphUtil class
« on: August 25, 2010, 10:50:23 am »
Hello, i have a RGB color,

i calculate the HSL values from the GraphUtil class, method ColorToHLS
here is the code i use:

Code: [Select]
var:
  H, S, L: Byte;
begin
  ColorToHLS(PanelColor.Color, H, L, S);
  SpinH.Value     := integer(H);
  SpinS.Value     := integer(S);
  SpinL.Value     := integer(L);

but when i open the ColorDialog, the HSL values are different.

Why? which ones are the good ones?

PS:
SVN Version: 22279
Win32 version on Windows XP
« Last Edit: August 25, 2010, 10:56:20 am by Dr4x »
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

PAEz

  • New Member
  • *
  • Posts: 29
Re: difference in HSL values from ColorDialog & GraphUtil class
« Reply #1 on: October 10, 2010, 05:14:14 pm »
Sorry for the late reply, but I only just got here.
Im not the best at Lazarus/Pascal stuff but this isnt one of those questions,so...
The first colour picker is the windows one and in that one Saturation and Luminance only go up to 240 and Id say that the pascal one goes up to 255, so the slight differences.  The hsl routine I was interested in recently did it as 0 to 1 values.  Plus how you convert rgb to hsl can be done different ways.  I recently looked at this and noticed it done a few ways, some consider saturation to affect lightness and some even considered some colours to have a lighter value than others.
For a colour picker you might want to offer 0-255, percentage and 0-1 and offer some way of copying the values, in the files Im using them for (Chrome Themes) their listed as h, s, l so maybe offer a comma seperator as an option
Plus the colours are listed that way in the themes as comma seperated rgb values.  This way is also used sometimes in css files as something like rgba(0,0,0,0) so could be usefull for that aswell
Lazarus 0.9.29  Windows XP sp3
E6400 2gig ram 7900GTX 512meg

I have a shocking memory and am a crap coder, so take everything I say with a grain of doubt

PAEz

  • New Member
  • *
  • Posts: 29
Re: difference in HSL values from ColorDialog & GraphUtil class
« Reply #2 on: November 01, 2010, 11:45:18 am »
I was looking around for something else and found a page with some code you might like.
Its got some HSL > RGB conversion stuff that seems to be using the same value system as the windows picker so you may get the results you wanted.
Its also got some nice code for css color values that you may like to add to your picker.
http://www.mythcode.org/
Lazarus 0.9.29  Windows XP sp3
E6400 2gig ram 7900GTX 512meg

I have a shocking memory and am a crap coder, so take everything I say with a grain of doubt

 

TinyPortal © 2005-2018