Page 1 of 1

How to pass parameters in PixelSetHSL

Posted: 2017-05-10T02:30:52-07:00
by rpatelob
I have this CLI

Code: Select all

convert 'xc:hsl(120,50%,50%)' test.jpg
I want to achieve the same result using MagickWand. Please look at my code. I think, I made a mistake in passing the parameters of PixelSetHSL method. What is the correct way to pass it?

Code: Select all

  MagickWand * wand2;
  PixelWand * PW2; 
  PW2 = NewPixelWand();
  wand2 = NewMagickWand();

  PixelSetHSL(PW2, 120, 50, 50);
  //PixelSetHSL(PW2, 120, 50*QuantumRange/100, 50*QuantumRange/100);
  
  MagickNewImage(wand2, 10, 10, PW2);
  MagickWriteImage(wand2, "hslW.jpg");

Re: How to pass parameters in PixelSetHSL

Posted: 2017-05-10T10:10:46-07:00
by el_supremo
The arguments to PixelSetHSL are double floating point fractions of QuantumRange.

Code: Select all

	PixelSetHSL(PW2, (double)120/QuantumRange, 50/100.0, 50/100.);
Note that the first one has to be cast to double (or written as 120.0) so that the division isn't done as integers which would result in zero.

Pete

Re: How to pass parameters in PixelSetHSL

Posted: 2017-05-10T21:59:13-07:00
by rpatelob
el_supremo wrote: 2017-05-10T10:10:46-07:00 The arguments to PixelSetHSL are double floating point fractions of QuantumRange.

Code: Select all

	PixelSetHSL(PW2, (double)120/QuantumRange, 50/100.0, 50/100.);
Note that the first one has to be cast to double (or written as 120.0) so that the division isn't done as integers which would result in zero.

Pete
Hello @el_supremo, it's not working. It gives me a black image.
After some digging I found that I need to divide first argument(Hue) by 360. I've got an idea from second and third parameters as you have divided those parameters by 100, I thought the first one(Hue) would be divided by 360 and yes the solution works. Thank you @el_supremo.
So the method looks like this.

Code: Select all

PixelSetHSL(PW2, 120.0/360.0, 50/100.0, 50/100.);

Re: How to pass parameters in PixelSetHSL

Posted: 2017-05-11T07:12:21-07:00
by el_supremo
I, obviously, hadn't used HSL before. Hue is specified in degrees (thus the /360.0) and Saturation and Lightness are fractions from zero to one (often specified as a percentage).

Pete