possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by fmw42 »

I am not getting consistent color creation when using hsl as percent vs raw values. From the page http://www.imagemagick.org/script/color.php it says for raw values:

"The format of an HSL color value in the functional notation is hsl(h,s,l). The hue value h ranges from 0 to 360. Saturation and lightness (s and l) range from 0 to 255"

So I created a color swatch as follows:

convert -size 100x100 xc:"rgb(238,208,200)" colorswatch.png
Image

Now I measure its hsl colors:

convert colorswatch.png -scale 1x1! -colorspace HSL txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: ( 2299,34588,56283) #08FB871CDBDB hsl(3.50877%,52.7778%,85.8824%)


Now I create a swatch with these HSL percent values:
convert -size 100x100 xc:"hsl(3.50877%,52.7778%,85.8824%)" colorswatch_hsl.png
Image

(This is close but not exactly the same)

Also it is puzzling that http://www.imagemagick.org/script/color.php says to specify an HSL color one should use hue in range of 0-360 NOT percent, but saturation and lightness as percent. So why is hue as specified by txt: above being shown as percent. Is this correct?

If I convert 3.50877% to range 0-360 (eg 3.5*360/100=13) and use that as
convert -size 100x100 xc:"hsl(13,52.7778%,85.8824%)" colorswatch_hsl.png
Image

it actually comes out better than using the percent value as above and listed by txt:

So one potential error is the way that txt: presents the hue value in hsl.



Now I convert the percents to raw values (hue in range 0-360 and saturation and lightness in range 0-255)
convert -size 100x100 xc:"hsl(13,135,219)" colorswatch_hsl2.png
Image

The latter is not even close. What am I missing?

No matter what value I use for hue (I tried 360-13=347), e.g. hsl(347,135,219), I get the same cyan-like color as above.

Am I misreading the documentation above such that one can only specify hsl colors as hue (0-360) and saturation and lightness as percent?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by magick »

Grab ImageMagick 6.5.6-5 Beta from magick.imagemagick.org in about an hour. Let us know if the patch works properly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by fmw42 »

This now works as I believe it should with hue in range 0-360 and saturation and lightness as percent.

convert colorswatch.png -scale 1x1! -colorspace HSL txt:-# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: ( 2299,34588,56283) #08FB871CDBDB hsl(12.6316,52.7778%,85.8824%)



But converting
hue=12.6316 (range 0-360)
sat=52.7778*255/100=134.58339 (range 0-255)
light=85.8824*255/100=219.00012 (range 0-255)

and doing
convert -size 100x100 xc:"hsl(12.6316,134.58339,219.00012)" colorswatch_hsl5.png
Image

still does not give anything like the original

Image

So I ask again, can one specify hsl colors as raw values hue (0-360) sat (0-255) light (0-255) per my interpretation of what is say on the http://www.imagemagick.org/script/color.php


"The format of an HSL color value in the functional notation is hsl(h,s,l). The hue value h ranges from 0 to 360. Saturation and lightness (s and l) range from 0 to 255"

Or must the values be hue in range 0-360 and sat and light as percent as the only way to specify them in hsl(...) notation.

Am I misreading that sentence (the key perhaps is the word "functional").
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by magick »

We can reproduce the problem you posted and have a fix in ImageMagick 6.5.6-4 beta available in about an hour.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by fmw42 »

presume you mean 6.5.6-5. downloading and installing now. back with results shortly

Still some install errors:

Running Mkbootstrap for Image::Magick ()
chmod 644 Magick.bs
rm -f blib/arch/auto/Image/Magick/Magick.bundle
LD_RUN_PATH="/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../magick/.libs:/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../wand/.libs" gcc -std=gnu99 -L../magick/.libs -lMagickCore -L../wand/.libs -lMagickWand -bundle -undefined dynamic_lookup -L/usr/local/lib -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/magick -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/wand -L/usr/X11R6/lib -L/usr/local/lib -lfreetype -lz Magick.o -o blib/arch/auto/Image/Magick/Magick.bundle -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../magick/.libs -lMagickCore -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../wand/.libs -lMagickWand -lm
/usr/bin/ld: flag: -undefined dynamic_lookup can't be used with MACOSX_DEPLOYMENT_TARGET environment variable set to: 10.1
collect2: ld returned 1 exit status
make[3]: *** [blib/arch/auto/Image/Magick/Magick.bundle] Error 1
make[2]: *** [install-exec-perl] Error 2
make[1]: *** [install-am] Error 2
make: *** [install] Error 2


But moving on if I can. Retesting (trying to use raw values for hue 0-360, sat 0-255, and light 0-255 rather than percent values)

convert -size 100x100 xc:"hsl(12.6316,134.58339,219.00012)" colorswatch_hsl5.png
Image

So still get the wrong color (if using raw values rather than percent is permitted?). Please correct me if this is not allowed.


Also I note that HSB, is behaving the same way. The color output from txt: shows hue as percent rather than in range 0-360.

HSL is now fixed:
convert colorswatch.png -scale 1x1! -colorspace HSL txt:-# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: ( 2299,34588,56283) #08FB871CDBDB hsl(12.6316,52.7778%,85.8824%)

But HSB is wrong:

convert colorswatch.png -scale 1x1! -colorspace HSB txt:-# ImageMagick pixel enumeration: 1,1,65535,hsb
0,0: ( 2299,10464,61166) #08FB28E0EEEE hsb(3.50877%,15.9664%,93.3333%)

Once all this is corrected to the degree it can be, I will update the documentation on the page http://www.imagemagick.org/script/color.php

(I note your example #ffff000000000ffff has one too many zeros)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by magick »

We can reproduce the problem you posted and have a fix in ImageMagick 6.5.6-4 beta available in about an hour.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by fmw42 »

still seeing this install error

Running Mkbootstrap for Image::Magick ()
chmod 644 Magick.bs
rm -f blib/arch/auto/Image/Magick/Magick.bundle
LD_RUN_PATH="/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../magick/.libs:/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../wand/.libs" gcc -std=gnu99 -L../magick/.libs -lMagickCore -L../wand/.libs -lMagickWand -bundle -undefined dynamic_lookup -L/usr/local/lib -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/magick -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/wand -L/usr/X11R6/lib -L/usr/local/lib -lfreetype -lz Magick.o -o blib/arch/auto/Image/Magick/Magick.bundle -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../magick/.libs -lMagickCore -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../wand/.libs -lMagickWand -lm
/usr/bin/ld: flag: -undefined dynamic_lookup can't be used with MACOSX_DEPLOYMENT_TARGET environment variable set to: 10.1
collect2: ld returned 1 exit status
make[3]: *** [blib/arch/auto/Image/Magick/Magick.bundle] Error 1
make[2]: *** [install-exec-perl] Error 2
make[1]: *** [install-am] Error 2
make: *** [install] Error 2


Still getting the same error in reporting percent for HSB hue in txt:

convert colorswatch.png -scale 1x1! -colorspace HSB txt:-# ImageMagick pixel enumeration: 1,1,65535,hsb
0,0: ( 2299,10464,61166) #08FB28E0EEEE hsb(3.50877%,15.9664%,93.3333%)

However, the other bug regarding creating a color image using raw hsb with hue (0-360), sat and light (0-255), now does seem to be fixed:


convert -size 100x100 xc:"hsl(12.6316,134.58339,219.00012)" colorswatch_hsl5b.png
Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by magick »

We can reproduce the problem you posted and have a fix in ImageMagick 6.5.6-5 beta available in about an hour.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by fmw42 »

still getting the install error!

Running Mkbootstrap for Image::Magick ()
chmod 644 Magick.bs
rm -f blib/arch/auto/Image/Magick/Magick.bundle
LD_RUN_PATH="/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../magick/.libs:/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../wand/.libs" gcc -std=gnu99 -L../magick/.libs -lMagickCore -L../wand/.libs -lMagickWand -bundle -undefined dynamic_lookup -L/usr/local/lib -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/magick -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/wand -L/usr/X11R6/lib -L/usr/local/lib -lfreetype -lz Magick.o -o blib/arch/auto/Image/Magick/Magick.bundle -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../magick/.libs -lMagickCore -L/Users/fred/Applications/ImageMagick-6.5.6-5betasource/PerlMagick/../wand/.libs -lMagickWand -lm
/usr/bin/ld: flag: -undefined dynamic_lookup can't be used with MACOSX_DEPLOYMENT_TARGET environment variable set to: 10.1
collect2: ld returned 1 exit status
make[3]: *** [blib/arch/auto/Image/Magick/Magick.bundle] Error 1
make[2]: *** [install-exec-perl] Error 2
make[1]: *** [install-am] Error 2
make: *** [install] Error 2


OK, the HSB reporting in txt: seems to be fixed now.

convert colorswatch.png -scale 1x1! -colorspace HSB txt:-# ImageMagick pixel enumeration: 1,1,65535,hsb
0,0: ( 2299,10464,61166) #08FB28E0EEEE hsb(12.6316,15.9664%,93.3333%)

Also, creating a color swatch image with that color after converting percent to raw values (0-255) also works now.

convert -size 100x100 xc:"hsb(12.6316,40.71432,237.999915)" colorswatch_hsb1.png
Image


So I will now work on updating the page at http://www.imagemagick.org/script/color.php to clarify these color specifications.

Thanks. Much appreciated.

Fred
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by fmw42 »

Sorry still a problem creating color swatches using non percent values with both HSL and HSB.


For example, both of these HSL colors should make a full green image, but the second is dark blue:

convert -size 100x100 xc:"hsl(120, 100%, 50%)" show:
convert -size 100x100 xc:"hsl(120, 255, 127)" show:


Similarly for HSB:

convert -size 100x100 xc:"hsb(120, 100%, 100%)" show:
convert -size 100x100 xc:"hsb(120, 255, 127)" show:
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by magick »

We can reproduce the problem you posted and have a fix in ImageMagick 6.5.6-5 beta available in about an hour.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug in hsl color creation IM 6.5.6-4 Q16 (HDRI)

Post by fmw42 »

The problem described above still persists where the non-percent forms of hsl and hsb colors are creating blue swatches in stead of green, if I have not prematurely downloaded and installed the beta prior to your fix. The timestamp on the file I downloaded is: ImageMagick-6.5.6-5.tar.bz2 Sept 27, 2009 1:55 PM.

Fred
Post Reply