Hm, I seem to have finally figured out the missing magic sauce.
Using SetImageAlphaChannel( imgMagickPngImage, AlphaChannelType::
ActivateAlphaChannel);
produces a fully semi-transparent image - that turns on the alpha channel with some value used across the board (56285 in my case).
Using SetImageAlphaChannel( imgMagickPngImage, AlphaChannelType::
SetAlphaChannel);
produces an opaque image - the alpha channel is set to opacity of 0 (which is the counter-intuitive FULLY OPAQUE - ImageMagick really should call that parameter
transparency)
Using SetImageAlphaChannel( imgMagickImage, AlphaChannelType::
OpaqueAlphaChannel);
produces the same effect I think.
But that wasn't the primary problem I was having ... the magic sauce that was as non-obvious as the fact that opaque is opacity of 0 is that ...
one needs to
initilaize the MagickPixelPacket from the image, and not just rely on the default initialization and fill in the color info into the R G and B attributes.
( and
TransparentOpacity is a synonym for the fully transparent value (opacity QuantumRange) )
So what works is:
Code: Select all
SetImageAlphaChannel( imgMagickImage, AlphaChannelType::OpaqueAlphaChannel); // set an opaque alpha channel
MagickPixelPacket imgFilter; // determines which pixels are set to transparent
GetMagickPixelPacket(imgMagickPngImage,&imgFilter); // initialize the pixel packet from our image
// scale our 16Bit SDI transparent RGB color (0->FFFF) into the RGB 0->QuantumRange of ImageMagick
imgFilter.red = bitonalTileIn->image_atts->transparent_cell_color.red *(QuantumRange/65535.0);
imgFilter.green = bitonalTileIn->image_atts->transparent_cell_color.green *(QuantumRange/65535.0);
imgFilter.blue = bitonalTileIn->image_atts->transparent_cell_color.blue *(QuantumRange/65535.0);
imgFilter.fuzz = 0; // anything near white is also transparent
Quantum opacity = TransparentOpacity; // quantum range is 0 to QuantumRange (eg 65535); QuantumRange is 'transparent', 0 is opaque
MagickBooleanType invertBool = MagickFalse; //
TransparentPaintImage( imgMagickPngImage, &imgFilter, opacity, invertBool);
So for the benefit of others, the key appears to be
MagickPixelPacket imgFilter; // determines which pixels are set to transparent
GetMagickPixelPacket(imgMagickPngImage,&imgFilter); // initialize the pixel packet from our image
// scale our 16Bit SDI transparent RGB color (0->FFFF) into the RGB 0->QuantumRange of ImageMagick
imgFilter.red = bitonalTileIn->image_atts->transparent_cell_color.red *(QuantumRange/65535.0);
imgFilter.green = bitonalTileIn->image_atts->transparent_cell_color.green *(QuantumRange/65535.0);
imgFilter.blue = bitonalTileIn->image_atts->transparent_cell_color.blue *(QuantumRange/65535.0);
And then we finally get: