MagickSetImageType and gm convert: inconsistent behaviour
Graham Leggett <[email protected]> Thu, 23 Sep 2010 01:28:20 +0200
| Newsgroups | gmane.comp.video.graphicsmagick.bugs |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I have encountered some inconsistent behaviour between the
MagickSetImageType call the the "convert" option inside the gm command
line tool.
What we need to do is set the type of a greyscale image back to the
truecolor space (we are aware our color isn't going to come back :)) ,
and normally as I understand you would use MagickSetImageType to do
this (is that correct?).
In the past we have used the gm command line tool to do this, and this
has always worked, however when we've changed it to use our own code
calling MagickSetImageType, the ImageType refuses to change away from
grayscale.
Digging in the source, we find the reason SetImageType isn't changing
the image type is because it believes the image is already in the RGB
colourspace:
2736 switch (image_type)
(gdb)
2735 logging=IsEventLogging();
(gdb) print image_type
$1 = TrueColorType
(gdb) next
2736 switch (image_type)
(gdb)
2888 if (!IsRGBColorspace(image->colorspace))
(gdb) print image->colorspace
$2 = RGBColorspace
Is a grayscale image supposed to be in the RGB colourspace, and am I
misunderstanding this?
It turns out the reason the gm tool's "convert" function "works" is
because the convert function cheats and hardcodes the ImageType direct
into a private structure within the image:
if (LocaleCompare("type",option+1) == 0)
{
resource_info.image_info->type=UndefinedType;
if (*option == '-')
{
i++;
if (i == argc)
MagickFatalError(OptionFatalError,MissingArgument,option);
option=argv[i];
resource_info.image_info-
>type=StringToImageType(option);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if (resource_info.image_info->type == UndefinedType)
MagickFatalError(OptionFatalError,UnrecognizedImageType,
option);
}
break;
}
MagickFatalError(OptionFatalError,UnrecognizedOption,option);
I am now confused - which behaviour is correct, the SetImageType()
function that does all the colourspace conversion, or the "convert"
function that hardcodes the ImageType value into the private structure
directly?
Why would the SetImageType() function think that a grayscale image is
already in the RGB colourspace (unless it I am misunderstanding it)?
Regards,
Graham
--
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev