Boost logo

Boost Users :

Subject: Re: [Boost-users] [GIL] Array to image
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2011-11-29 11:36:58


Hi,

> Can anyone point me in the right directions for copying or assigning an
> array in memory to an image? I’m reading an frame out of an AVI file using
> Microsoft’s vfw32.lib/vfw.h and the function that grabs the frame returns a
> pointer to a bitmap in memory, like this:
>
>
>
> BYTE* pDIB = (BYTE*) AVIStreamGetFrame(pFrame, index);
>
>
>
> And I need to transfer that information into an image. I have extracted the
> bitmap header and have a pointer to the first pixel, so I suppose I could
> iterate over each pixel and channel and populate the image by hand, but I
> imagine there is a better way.
>
>

Don't quite understand what do you want to achieve with GIL but to make a
raw memory usable by GIL algorithms you need a proper view. Views are
abstractions over underlying pixel representation so that algorithms may
operate on the data regardless of storage / layout. As long as views are
compatible (same dimmensions, channel count etc) all will work fine.

For example in my code (source data is decoded theora video frame):

gil::interleaved_view(frame->getWidth(), frame->getHeight(),
      (gil::rgb8_pixel_t*) frame->getBuffer(), frame->getStride() * 3);

frame->getBuffer() is pointer to first byte of RGB data, last param
is scanline length in bytes.

You could use it like this:

rgb8_image_t img(frame->getWidth(), frame->getHeight());

copy_pixels(gil::interleaved_view(frame->getWidth(), frame->getHeight(),
      (gil::rgb8_pixel_t*) frame->getBuffer(), frame->getStride() * 3), img);

I guess in your case pixel ptr is pDIB and the rest of params has to be taken
from the image header.

Hope this helps.

Cheers,
Simon

-- 
Szymon Gatner
The Lordz Games Studio
www.thelordzgamesstudio.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net