Magick++, image.read() greyscale image from buffer?

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
aseering

Magick++, image.read() greyscale image from buffer?

Post by aseering »

Hi,
I have an array of integers in memory, that I want to convert into a greyscale image. I'm trying to do this with image.read(), pointing it at the array as a buffer and giving it the appropriate width and height. The docs state that the "map_" argument to read() should be something like "RGB" or "CMYK" (or some re-ordering of these letters); but what should it be for greyscale images?

(I'm ultimately hoping to do 8-, 16- and 32-bit greyscale images this way. Fancy scientific imagery; long story. Not sure if the number of bits is relevant to this argument, though? I already specify it with "image.depth()".)

Adam
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick++, image.read() greyscale image from buffer?

Post by fmw42 »

(I'm ultimately hoping to do 8-, 16- and 32-bit greyscale images this way. Fancy scientific imagery; long story. Not sure if the number of bits is relevant to this argument, though? I already specify it with "image.depth()".)
To do that for grayscale images, you will have to recompile IM into Q8, Q16 and Q32 mode to get each of those bits per channel as the channel depth is a compile time issue. Or be at Q32 and then you can use -depth to decrease the depth to 16 and 8.

Note at Q32, those are 32 bit non-negative integers. If you want floats, (pos and/or neg) then you need to compile in HDRI mode.
aseering

Re: Magick++, image.read() greyscale image from buffer?

Post by aseering »

Yep, thanks. I've already recompiled IM into Q32, and am using -depth (well, depth(); I'm using the C++ API, not the command line tools) as I mentioned. I don't have floats or negative integers right now; I might gain negative integers at some point, in which case I'll look into HDRI mode.

Do you have any idea what to put into the map_ field, though? I've tried just "K", but get errors saying that "K" doesn't work.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick++, image.read() greyscale image from buffer?

Post by fmw42 »

Sorry, I only know command line and have not used the APIs
aseering

Re: Magick++, image.read() greyscale image from buffer?

Post by aseering »

Ah, there we go: The string I want is "I" (for Intensity).

It seems that ImageMagick is downsampling to 16-bit for most image formats, though... Is there a list somewhere of image formats that support Q32?
Post Reply