Loading...

ColorHSLtoRGB method - issue with range of values

Support for GdPicture Light Imaging Toolkit and GdPicture Pro Imaging ActiveX/SDK.

ColorHSLtoRGB method - issue with range of values

Postby Kyer » Sun Jun 28, 2009 8:07 pm

Hi Loïc,

in the method

ColorHSLtoRGB (nHueValue, nSaturationValue, nLightnessValue, *nRedReturn, *nGreenReturn, *nBlueReturn)

the range of values for nHueValue is [0 - 5].

This way we are missing some colours. The range should be [0 - 2*pi].

Here is an example image created with gdpicturpro.
I used:
Code: Select all
 nHueValue = myAngle / (2*pi) * 5.0
to transform from full circle to [0, 5]

As you can see, all colours between magenta and red are missing:

Image


If you wanna do me a HUGE favour, you could correct the range in gdpicturepro version 3.9003, which I am still using.


Best regards,
Kyer
Kyer
 
Posts: 28
Joined: Wed Jul 18, 2007 8:23 pm

Re: ColorHSLtoRGB method - issue with range of values

Postby Kyer » Sun Jun 28, 2009 8:27 pm

Just in case, this is how the code looks in c++

Code: Select all
   const double pi = 3.14159265;

   int edgelength, x, y, xx, yy;
   long colour;
   double distance, radius;
   long r, g, b;
   double alpha;

   _cGdPicture mGdImg;
   mGdImg.CreateDispatch("GdpicturePro.cGdPicture");
   mGdImg.SetLicenceNumber("xxxxxxxxxxxxxxxxxxxxxx");

   radius = 400;

   edgelength = (int) (radius * 2.1);

   long id = mGdImg.CreateNewImage(edgelength, edgelength, 24, mGdImg.ARGB(0,255,255,255));

   for (x=0; x<edgelength; x++) for (y=0; y<edgelength; y++)
   {
      xx = x - edgelength / 2;
      yy = y - edgelength / 2;

      distance = sqrt ( xx * xx + yy * yy );

      if (distance < radius)
      {
         alpha = atan2(yy,xx);
         if (alpha<0.0) alpha = 2*pi + alpha;

         mGdImg.ColorHSLtoRGBl((float)(alpha / (2*pi) * 5.0), (float)(distance / radius), 0.5, &r, &g, &b);

         colour = mGdImg.ARGB(0, r, g, b);

         mGdImg.PixelSetColor((int) (xx+edgelength/2), (int)(yy+edgelength/2), colour);
      }
   }

   mGdImg.SaveAsJpeg("circle.jpg", 100);

   mGdImg.CloseImage(id);
Kyer
 
Posts: 28
Joined: Wed Jul 18, 2007 8:23 pm

Re: ColorHSLtoRGB method - issue with range of values

Postby Loïc » Sun Jun 28, 2009 9:06 pm

Hi Kyer,

I think you have a problem of space translation.

Could you give me the algorithm you are using to draw this circle ?

Kind regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4430
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: ColorHSLtoRGB method - issue with range of values

Postby Kyer » Mon Jun 29, 2009 3:01 am

Hi Loïc,

you find the code in my first reply, two posts above.

Kind regards,
Kyer
Kyer
 
Posts: 28
Joined: Wed Jul 18, 2007 8:23 pm

Re: ColorHSLtoRGB method - issue with range of values

Postby Kyer » Mon Jun 29, 2009 4:06 am

Hi again,

i just figured, that the function accepts values in [-1, 5] (instead of [0, 5] like the documentation says), so the interval is almost 2*pi, but shifted.

For an angle myAngle in [0, 2*pi], if i change
Code: Select all
nHueValue = myAngle / (2*pi) * 5.0

to
Code: Select all
nHueValue = myAngle / (2*pi) * 6.0 -1

i get a correct colour circle.

So you could shift the interval in the next release or just update the documentation...

Btw, the paramter nSaturationValue accepts values in [-1, 1]. The negative numbers result in an inversion of the colours.

Best regards,
Kyer
Kyer
 
Posts: 28
Joined: Wed Jul 18, 2007 8:23 pm

Re: ColorHSLtoRGB method - issue with range of values

Postby Loïc » Mon Jun 29, 2009 10:00 am

Hi Kyer,

You are absolutely right for intervals.


I will update the reference guides.

With best regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4430
Joined: Tue Oct 17, 2006 10:48 pm
Location: France


Return to GdPicture [Pro] ActiveX

Who is online

Users browsing this forum: No registered users and 2 guests

cron