-1

This may be a very stupid question but just wanted to clarify my issue. Having seen a few different algorithms for conversion between RGB & HSL, I have seen var_1 and var_2. I was just wondering what these variables actually are? I knew they'd show up as errors just wanted to fully understand why and where I need to make changes for the conversion.

void HSLToRGB( int H, int S, int L, int& R, int& G, int& B )
{
H = 240;
S = 47;
L = 58; 


if (S == 0)
{

    R = L * 255
        G = L * 255
        B = L * 255
}
else
{
    if (L < 0.5) { var_2 = L * (1 + S); }
    else
    {
        var_2 = (L + S) - (S * L);
        var_1 = 2 * L - var_2;
    }
    var_1 = 2 * L- var_2;
    R = 255 * Hue_2_RGB(var_1, var_2, H + (1 / 3));
    G = 255 * Hue_2_RGB(var_1, var_2, H);
    B = 255 * Hue_2_RGB(var_1, var_2, H - (1 / 3));
}
static float Hue_2_RGB(float v1, float v2, float vH)
{
if (vH < 0) { vH += 1; }
if (vH > 1) { vH -= 1; }
if ((6 * vH) < 1) { return (v1 + (v2 - v1) * 6 * vH); }
if ((2 * vH) < 1) {return (v2); }
if ((3 * vH) < 2)
{
    return (v1 + (v2 - v1) * ((2 / 3) - vH) * 6);
    return (v1);
}
}

Sorry if this is a dumb question just wanted to 100% understand in laymans term.

Thank you. I also have not included the code for RGB to HSL conversion.

IFKCode
  • 43
  • 1
  • 5
  • 1
    There is no way to know since they are not defined in the code you show. We can guess, based on what the other values are that are defined, but that is no guarantee either. I presume this is C which would mean they are possibly int. – Rob Dec 21 '17 at 21:23
  • As of yet I have not assigned them to anything but I was looking at algorithms for conversions with RGB and the issue I had was what Var_1 and 2 should be declared as. Not sure if that helps. – IFKCode Dec 21 '17 at 21:26
  • I would make them int if you just want to try it and see if it compiles. – Rob Dec 21 '17 at 21:26
  • Ok cheers Rob. I'll give that a go. – IFKCode Dec 21 '17 at 21:28
  • Compiles fine just doesnt return what I'm expecting to see. – IFKCode Dec 21 '17 at 21:47
  • Well, that's a different question you need to post. As far as this one goes, can I copy them into an answer you'll accept? – Rob Dec 21 '17 at 22:02
  • Yeah thats fine, I will continue to look. Thanks for the help. – IFKCode Dec 21 '17 at 22:03
  • It looks like you're confused about the types required for H, S, and L. Those probably should be floating-point in the range 0.0 to 1.0, but you've made them `int`. – Mark Ransom Dec 21 '17 at 22:04

1 Answers1

0

There is no way to know since they are not defined in the code you show. We can guess, based on what the other values are that are defined, but that is no guarantee either. I presume this is C which would mean they are possibly int.

I would make them int if you just want to try it and see if it compiles. If it compiles, then you can dig more into the algorithm to see what works and how far it goes.

Rob
  • 14,746
  • 28
  • 47
  • 65