Page 1 of 1

HSL to RGB conversion slightly different in 6.4.6

Posted: 2008-11-23T09:29:20-07:00
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);
}

Re: HSL to RGB conversion slightly different in 6.4.6

Posted: 2008-11-23T16:21:37-07:00
by magick
The problem you reported is fixed in ImageMagick 6.4.6-1, the current release.

Re: HSL to RGB conversion slightly different in 6.4.6

Posted: 2008-11-23T16:51:01-07:00
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.

Re: HSL to RGB conversion slightly different in 6.4.6

Posted: 2008-11-24T15:44:53-07:00
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.

Re: HSL to RGB conversion slightly different in 6.4.6

Posted: 2008-11-24T17:53:17-07:00
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.