I inspected the images with tiffinfo; the original image is palette and the mogrified image is grayscale.
I tracked down the problem to
MagickReadImage;
MagickGetType for this image returns Grayscale.
Workaround:
Code: Select all
MagickSetType (a_wand, PaletteType);
This is important because a 4-colour Palette image grows 4 times when converted to Grayscale.
This problem does not occur when the palette contains colours, as in
Code: Select all
convert -size 32x32 canvas:red canvas:blue +append canvas:green +append canvas:yellow +append \
-type Palette in.tiff
Non-Workaround:
Code: Select all
MagickSetImageChannelDepth (a_wand, GrayChannels, 02);
This workaround does not work with subtle intensity differences, as lighter shades turn white:
Code: Select all
convert -size 32x32 canvas:black canvas:#e0e0e0 +append canvas:#f0f0f0 +append canvas:white +append \
-type Palette in.tiff
The converted image ends up as 2-bit Grayscale DirectClass while the original is 2-bit PseudoClass (which is what is needed)