How to pass parameters in PixelSetHSL

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

How to pass parameters in PixelSetHSL

Post by rpatelob » 2017-05-10T02:30:52-07:00

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");

el_supremo
Posts: 1017
Joined: 2005-03-21T21:16:57-07:00

Re: How to pass parameters in PixelSetHSL

Post by el_supremo » 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Re: How to pass parameters in PixelSetHSL

Post by rpatelob » 2017-05-10T21:59:13-07:00

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.);

el_supremo
Posts: 1017
Joined: 2005-03-21T21:16:57-07:00

Re: How to pass parameters in PixelSetHSL

Post by el_supremo » 2017-05-11T07:12:21-07:00

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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

Post Reply