Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ImageProcessing
Hello, Im creating program for adjusting HSL to image with 3 sliders (hue saturation lightness) like photoshop, gimp etc and something going wrong. I have taken converting algorithm from wiki - http://ru.wikipedia.org/wiki/HSL(strange thing that in english and russian wiki algorithms are different) and here is my code
 
CHslFilter::CHslFilter(float hue, float saturation, float lightness)
:m_r(0), m_g(0), m_b(0)
{
    if (saturation == 0)
    {
        m_r = m_g = m_b = lightness;
    }
    else
    {
        float temp2 = (lightness < 0.5f) ? lightness * (1.0f + saturation) : lightness + saturation - (lightness*saturation);
        float temp1 = 2.0f * lightness - temp2;
        float Hk = hue / 360;
 
        float temp3RGB[3] = {Hk + 1/3, Hk, Hk - 1/3};
        for (unsigned int i = 0; i != 3; ++i)
        {
            if (temp3RGB[i] < 0)
            {
                temp3RGB[i] += 1.0f;
            }
            else if (temp3RGB[i] > 1)
            {
                temp3RGB[i] -= 1.0f;
            }
        }
 
        for (unsigned int i = 0; i != 3; ++i)
        {
            float item = temp3RGB[i];
 
            if (item < 1/6)
            {
                item = temp1 + ((temp2 - temp1) * 6.0f * item);
            }
            else if (1/6 <= item && item < 1/2)
            {
                item = temp2;
            }
            else if (1/2 <= item && item < 2/3)
            {
                item = temp1 + ((temp2 - temp1) * (2/3 - item) * 6.0f);
            }
            else
            {
                item = temp1;
            }
 
            temp3RGB[i] = item;
        }
 
        m_r = temp3RGB[0];  m_r = temp3RGB[1];  m_b = temp3RGB[2];
    }
 
    m_r *= 255;
    m_g *= 255;
    m_b *= 255;
 
}
 
void CHslFilter::AdjustColor(float &r, float &g, float &b)const
{
    r += m_r;
    g += m_g;
    b += m_b;
 
    return;
}
function AdjustColor later just will receive every pixel of image and will modify it. Please can you answer me what im doing wrong? And sorry for my English
Posted 9-Oct-11 9:36am
flaese116
Edited 9-Oct-11 9:49am
v3
Comments
SAKryukov at 10-Oct-11 15:41pm
   
First, nothing wonderful about different algorithms. Russian is not just a language, it's a different way of thinking. :-)
Now, what's "going wrong"? For a software developer, there is no such thing. It needs precise problem report. What's the problem?
--SA
flaese at 10-Oct-11 16:11pm
   
Thanks for the response.
Well, "something is wrong" is the way my program differ from photoshop for example Actually, with lightness = 0 this algorithm dont count my rgb, and it will be good if with lightness = 0 my picture became totally black and lightness = 1 totally white but its not. This program can just increase lightness on my picture, not reduce.
I just anticipate that my sliders will work the same way as photoshop or gimp and I dont know whats wrong.
I assume that algorithm from wiki is perfect for converting HSL to RGB, and I just missed some important step in adjusting these values to my source image.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 10 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100