Page 1 of 1

Outputting 1 channel 16-bit grayscale PNG

Posted: 2011-10-11T08:44:59-07:00
by thwest
I'm attempting to take uint16 data and output it as a 1024x768 1-channel 16-bit grayscale PNG. The output I get from the following is an RGB8 PNG. The image contents are correct besides the formatting.

Code: Select all

gray16_view_t u16view = ...;
uint16_t* data = interleaved_view_get_raw_data(u16view);
size_t length = sizeof(u16) * u16view.width() * u16view.height();
Magick::Blob u16Blob(data, length);
Magick::Geometry size(u16view.width(), u16view.height());
Magick::Image u16MagickImg(u16Blob, size, 16, "GRAY");
u16MagickImg.write("test-16bit.png");
Is there any way to specify more about the output format?

Some discussion of imagemagick's PNG handling is here: http://www.imagemagick.org/Usage/formats/#png_formats They list PNG8, PNG24, and PNG32 as available formats, but the following section implies that the following on the commandline would have the desired output.

Code: Select all

-define png:bit-depth 16 
-define png:color-type=0 
How do I issue these define commands with the Magick++ api? Or in a safe way, calling to the plain ol c magick API?

Re: Outputting 1 channel 16-bit grayscale PNG

Posted: 2011-10-11T10:08:25-07:00
by thwest
got it to work. Thanks for all the effort devs!

Code: Select all

        u16MagickImg.quality(00);
        u16MagickImg.defineSet("png:color-type", "0");
        u16MagickImg.defineSet("png:bit-depth", "16");