Welcome to TalkGraphics.com
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 27
  1. #11
    Join Date
    Aug 2000
    Location
    Austria
    Posts
    1,081

    Default

    Soquili,

    I believe HSB is the same as HSL. But I am using PHP as a programming language and I have no knowledge of VB nor do I have the program.
    I did not find a respective function in PHP.

    Gary,
    about.com works again for me and I found the article by Judy Litt. I just asked her for permission to use her schemes and I am awaiting her response.
    My problem with the conversion is, that I need to program a fuction that does the conversion. Just like if you wanted the squareroot of something. You type in your number and the function gives the squareroot back. But I can't use any graphics package to just 'switch' - I need a way to program it myself.

    Quaker,
    I must admit, I have no clue how to use your sheet, but it seems that I would need something just like that for HSL/HSB <-> RGB to 'peel out' the formula.

    By the way, in Xara there is a HSV-mode, but it seems to be different from HSB/HSL. Yet another color model ???

    Joroho: You once asket Judy for a permission, did she ever answer ??

    Wolfgang

  2. #12
    Join Date
    Nov 2000
    Location
    Red Boiling Springs TN USA
    Posts
    19,208

    Default

    Hi Wolfgang,

    I'm not familiar with PHP, but if it has if-then-else types of statements and can compare Single Precision numeric values then I'll make a plain english description of the steps to take to make the HSL conversion.

    It will be later today (after I get home from work) before I can do that.

    Soquili
    Soquili
    a.k.a. Bill Taylor
    Bill is no longer with us. He died on 10 Dec 2012. We remember him always.
    My TG Album
    Last XaReg update

  3. #13
    Join Date
    Aug 2000
    Location
    Austria
    Posts
    1,081

    Default

    Thanks Soquili,

    that sounds like just what I need.

    Am I right, that the Triads are easily calculated in HSL/HSB if I just add 120 and 240 to the current Hue ??

    Wolfgang

  4. #14
    Join Date
    Nov 2000
    Location
    Red Boiling Springs TN USA
    Posts
    19,208

    Default

    Wolfgang,

    I'll verify the adding 120 and 240 for the triads when I start the translation. If my memory serves me correctly (not usual for me as I get older) then yes that is how triads are calculated. If the result is greater than 360 you would simple subtract 360 to get the correct value.

    Soquili
    Soquili
    a.k.a. Bill Taylor
    Bill is no longer with us. He died on 10 Dec 2012. We remember him always.
    My TG Album
    Last XaReg update

  5. #15
    Join Date
    Feb 2001
    Location
    Northampton, Northants, UK
    Posts
    156

    Default

    Wolfgang,

    When you add a palette file to the XaraX palette directory it shows up in the Colour Gallery after you re-open XaraX.

    The algorithm I used when developing XPal is below, if this helps...

    Brian

    RGB to HSV & HSV to RGB

    The Hue/Saturation/Value model was created by A. R. Smith in 1978. It is based on such intuitive color characteristics as tint, shade and tone (or family, purety and intensity). The coordinate system is cylindrical, and the colors are defined inside a hexcone. The hue value H runs from 0 to 360ΒΊ. The saturation S is the degree of strength or purity and is from 0 to 1. Purity is how much white is added to the color, so S=1 makes the purest color (no white). Brightness V also ranges from 0 to 1, where 0 is the black.

    There is no transformation matrix for RGB/HSV conversion, but the algorithm follows:

    // r,g,b values are from 0 to 1
    // h = [0,360], s = [0,1], v = [0,1]
    //if s == 0, then h = -1 (undefined)

    void RGBtoHSV( float r, float g, float b, float *h, float *s, float *v )
    {
    float min, max, delta;

    min = MIN( r, g, b );
    max = MAX( r, g, b );
    *v = max;// v

    delta = max - min;

    if( max != 0 )
    *s = delta / max;// s
    else {
    // r = g = b = 0// s = 0, v is undefined
    *s = 0;
    *h = -1;
    return;
    }

    if( r == max )
    *h = ( g - b ) / delta;// between yellow & magenta
    else if( g == max )
    *h = 2 + ( b - r ) / delta;// between cyan & yellow
    else
    *h = 4 + ( r - g ) / delta;// between magenta & cyan

    *h *= 60;// degrees
    if( *h < 0 )
    *h += 360;

    }

    void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v )
    {
    int i;
    float f, p, q, t;

    if( s == 0 ) {
    // achromatic (grey)
    *r = *g = *b = v;
    return;
    }

    h /= 60;// sector 0 to 5
    i = floor( h );
    f = h - i;// factorial part of h
    p = v * ( 1 - s );
    q = v * ( 1 - s * f );
    t = v * ( 1 - s * ( 1 - f ) );

    switch( i ) {
    case 0:
    *r = v;
    *g = t;
    *b = p;
    break;
    case 1:
    *r = q;
    *g = v;
    *b = p;
    break;
    case 2
    *r = p;
    *g = v;
    *b = t;
    break;
    case 3:
    *r = p;
    *g = q;
    *b = v;
    break;
    case 4:
    *r = t;
    *g = p;
    *b = v;
    break;
    default:// case 5:
    *r = v;
    *g = p;
    *b = q;
    break;
    }

    }

  6. #16
    Join Date
    Aug 2000
    Location
    Austria
    Posts
    1,081

    Default

    Hi Brian,

    that's exactly what I meant, BUT:

    I managed to convert the syntax of your example (C ??) to PHP, where it looks like this:

    function RGBtoHSV($r,$g,$b)
    {
    $min = MIN( $r, $g, $b );
    $max = MAX( $r, $g, $b );
    $v = $max;// v
    $delta = $max - $min;

    if( $max != 0 )
    {
    $s = floor(($delta / $max) * 255);// s
    }
    else
    {
    $s = 0;
    $h = -1;
    }

    if( $r == $max )
    {
    @$h = ( $g - $b ) / $delta;// between yellow & magenta
    }
    else if( $g == $max )
    {
    @$h = 2 + ( $b - $r ) / $delta;// between cyan & yellow
    }
    else
    {
    @$h = 4 + ( $r - $g ) / $delta;// between magenta & cyan
    }

    $h *= 60;// degrees
    if( $h < 0 )
    {
    $h += 360;
    }
    $h = round($h,1);

    // output for testing
    print "H: " . $h . "
    ";
    print "S: " . $s . "
    ";
    print "V: " . $v . "
    ";
    }


    Maybe your example has an error or I misunderstand something. But your original

    *s = delta / max;// s

    gives fractions of 1 as result, while (according to Xara X's color editor) it should be between 0 and 255.
    I changed the line like this

    $s = floor(($delta / $max) * 255);// s

    and now it gives the same result as in X's color editor.

    Still I have a slight problem with the "H"-value.
    The darker the color is, the more is the difference between Xara's value and mine.

    For instance:
    <font size='1'>
    <table border=1><tr><td>
    RGB-color</td><td>
    My values (HSV)</td><td>
    Xara's values (HSV)</td><tr><tr>
    <td>204, 204, 153</td><td>60, 63, 204</td><td>60, 63, 204</td></tr><tr><td>153, 153, 204</td><td>240, 64, 204</td><td>240, 64, 104</td></tr><tr><td>84, 118, 98</td><td>144.7, 74, 118</td><td>144.4, 74, 118</td></tr><tr><td>30, 19, 46</td><td>264.4, 149, 46</td><td>265.7, 149, 46</td></tr></table>
    </font>
    As you can see, the result differs, the darker the color gets. Do you think, this is a rounding error or something ???

    Apart from that, I am quite happy with the solution. I don't need the other way around, RGB->HSV alone is fine.

    Still missing: RGB -> HSB/HSL, which is different from HSV ...

    Thanks

    Wolfgang

    P.S.: Don't know why the font inside the table is so big ??

    [This message was edited by Wolfgang on February 06, 2002 at 12:09.]

  7. #17

    Default

    If you thought of a colour-harmony utility, just in case, check out these two websites:

    Easy RGB: http://www.easyrgb.com
    Color Schemer: http://www.colorschemer.com

    Perhaps it isn't necessary to reinvent the wheel ;-)

    -------------------------
    Joan M. Mas
    TypePhases: Dingbats and Fonts for yer computor!
    http://inicia.es/de/jmas
    -------------------------
    -------------------------
    Joan M. Mas
    TypePhases: Dingbats and Fonts for yer computor!
    http://inicia.es/de/jmas
    -------------------------

  8. #18
    Join Date
    Aug 2000
    Location
    Placitas, New Mexico, USA
    Posts
    41,532

    Default

    These are pretty much the same near as I can tell. HSB is Hue Saturation and Brightness, while HSL is Hue Saturation and Lightness. And there is also HSV Hue Saturation and Value.

    Brightness and Lightness both refer to the value of the color, or the amount of black to white in the color.

    Gary

    Gary Priester

    Moderator Person

    <a href="http://www.gwpriester.com">
    www.gwpriester.com </a>


    XaraXone




  9. #19
    Join Date
    Nov 2000
    Location
    Red Boiling Springs TN USA
    Posts
    19,208

    Default

    Hi Wolfgang,

    In Brian's code the red, green, and blue need to be converted to percentages before being used in the code. Simply divide the red, green, and blue values by 255 to get their percentages.

    HSV and HSL are different colour definitions. As promised, here's the "plain english" algorithm for HSL:

    RGB TO HSL

    Convert Red, Green, and Blue to percentages

    PercentRed = Red divided by 255
    PercentGreen = Green divided by 255
    PercentBlue = Blue divided by 255

    Determine maximum and minimum percentages

    SingleMax = Maximum of (PercentRed, PercentGreen, PercentBlue)
    SingleMin = Minimum of (PercentRed, PercentGreen, PercentBlue)

    Determine the Delta

    SingleDelta = SingleMax - SingleMin

    Luminosity = (SingleMax + SingleMin) divided by 2

    If SingleMax = SingleMin then
    Saturation = 0
    else
    Saturation = 1
    end if

    If Luminosity <= 0.5 then
    If Saturation > 0 then
    Saturation = SingleDelta / (SingleMax + SingleMin)
    end if
    else
    If Saturation > 0 then
    Saturation = SingleDelta / (2 - SingleMax - SingleMin)
    end if
    end if

    If Saturation != 0 then
    If PercentRed = SingleMax then
    Hue = (PercentGreen - PercentBlue) / SingleDelta
    end if
    If PercentGreen = SingleMax then
    Hue = 2 + (PercentBlue - PercentRed) / SingleDelta
    end if
    if PercentBlue = SingleMax then
    Hue = 4 + (PercentRed - PercentGreen) / SingleDelta
    end if
    Hue = Hue * 60
    end if

    If Hue < 0 then
    Hue = Hue + 360
    end if


    Soquili

    P.S. unfortunately the forum removed all the formatting of the text. Hope it's still readable as code.
    Soquili
    a.k.a. Bill Taylor
    Bill is no longer with us. He died on 10 Dec 2012. We remember him always.
    My TG Album
    Last XaReg update

  10. #20
    Join Date
    Aug 2000
    Location
    Leigh, Lancashire, UK
    Posts
    436

    Default

    Programming and Xara in the same place.

    I could be in heaven!



    Michael Ward
    http://www.metalandplastics.co.uk
    http://www.leighcenturions.net

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •