Outputting 1 channel 16-bit grayscale PNG

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
thwest
Posts: 2
Joined: 2011-10-09T15:31:49-07:00
Authentication code: 8675308

Outputting 1 channel 16-bit grayscale PNG

Post 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?
thwest
Posts: 2
Joined: 2011-10-09T15:31:49-07:00
Authentication code: 8675308

Re: Outputting 1 channel 16-bit grayscale PNG

Post 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");
Post Reply