HSL to RGB conversion slightly different in 6.4.6

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
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

HSL to RGB conversion slightly different in 6.4.6

Post by rmagick »

I'm not asserting this is a bug, just that the result is different. This may also indicate that I don't understand how to properly use MagickCore to convert HSL to RGB. The test program converts "hsla(0,48,39,0)" to a MagickPixelPacket, then back to HSL with ConvertRGBToHSL.

In 6.4.5-8, the program prints

Code: Select all

ImageMagick 6.4.5 2008-11-18 Q16 http://www.imagemagick.org
R=37827.000000 G=13290.000000 B=13290.000000
H=0.000000 S=0.480016 L=0.389998
In 6.4.6-0, it prints

Code: Select all

ImageMagick 6.4.6 2008-11-22 Q16 http://www.imagemagick.org
R=37827.000000 G=13290.000000 B=13291.000000
H=0.999993 S=0.480016 L=0.389998

Code: Select all

/*
gcc `Magick-config --cflags --cppflags` to_hsla.c `Magick-config --ldflags --libs` -o to_hsla
*/


#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include "magick/MagickCore.h"


int main(int argc,char **argv)
{
    const char *version;
    MagickPixelPacket pp;
    double hue, sat, lum;
    ExceptionInfo exception;

    MagickCoreGenesis(argv[0], MagickFalse);

    version = GetMagickVersion(NULL);
    fputs(version, stderr); fputc('\n', stderr);

    GetExceptionInfo(&exception);
    GetMagickPixelPacket(NULL, &pp);
    (void) QueryMagickColor("hsla(0,48,39,0)", &pp, &exception);
    printf("R=%f G=%f B=%f\n", pp.red, pp.green, pp.blue);
    ConvertRGBToHSL(pp.red, pp.green, pp.blue, &hue, &sat, &lum);
    printf("H=%f S=%f L=%f\n", hue, sat, lum);

    DestroyExceptionInfo(&exception);
    MagickCoreTerminus();

    exit(0);
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: HSL to RGB conversion slightly different in 6.4.6

Post by magick »

The problem you reported is fixed in ImageMagick 6.4.6-1, the current release.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: HSL to RGB conversion slightly different in 6.4.6

Post by magick »

Consider contributing your regression tests to the ImageMagick project and we can run them before an ImageMagick release. We can accept the tests privately where only the developers run them before a release or we can include them in the public distribution of ImageMagick. Or you can continue to run them yourself and post any problem here.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: HSL to RGB conversion slightly different in 6.4.6

Post by rmagick »

Thanks for your offer! However, I don't think you'd get much use from my tests. I've really tried to focus the RMagick tests on validating RMagick, so they only incidentally turn up bugs in ImageMagick.

For example, I found this particular problem because I have a test that round-trips the conversion to ensure that RMagick uses the MagickCore API properly. The test has no idea how to convert between HSL and RGB, it just tests that the result of converting HSL->RGB->HSL matches the starting value.

BTW, I'm still seeing the difference with 6.4.6-1.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: HSL to RGB conversion slightly different in 6.4.6

Post by magick »

Try against ImageMagick 6.4.6-2 available in just a few hours. You code works properly for us with 6.4.6-2.
Post Reply