Re: Dealing with MONO12 images in memory

Bob Friesenhahn <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
On Tue, 21 Nov 2017, Robert wrote:

> Not sure about the proper use of the 3rd argument in the image.read() function - I've tried both 16 and 2.

For what you are trying, the third argument should be 16.  There is a 
four argument variant:

Read single image frame of specified size, depth, and format from 
in-memory Blob:

void            read ( const Blob         &blob_,
                        const Geometry     &size_,
                        const unsigned int depth_,
                        const std::string  &magick_ )

which accepts the format specifier (which you need!).

For example

   image.read(blob,Geometry(arv_width, arv_height), 16, "GRAY");

Note that 16-bit values could be big-endian or little-endian.  The 
default is big-endian but little-endian is what Intel CPUs use.

Another way to read it would then be:

   image.depth(16);
   image.endian(LSBEndian);
   image.read(blob,Geometry(arv_width, arv_height));

Lastly, don't pass up this form of read:

Read single image frame from an array of raw pixels, with specified 
storage type (ConstituteImage), e.g. image.read( 640, 480, "RGB", 0, 
pixels ):

void            read ( const unsigned int width_,
                        const unsigned int height_,
                        const std::string &map_,
                        const StorageType  type_,
                        const void        *pixels_ )

This is a (sometimes) less CPU-efficient but more free-form way to 
read pixels from raw 16-bit data expressed in the host's native 
format:

image.read(arv_width, arv_height, "I", ShortPixel, pRaw16Image);

The underlying C function (with full documentation) is documented at 
"http://www.graphicsmagick.org/api/constitute.html#dispatchimage".  It 
seems that the C function offers a bit more power than the C++ 
equivalent.

Bob
-- 
Bob Friesenhahn
[email protected], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.