Boost logo

Boost :

From: Lubomir Bourdev (lbourdev_at_[hidden])
Date: 2006-10-18 18:14:23


 
Tim Shead wrote:
> Another question / observation on the GIL API. When
> interfacing with external code, particularly "C" libraries,
> it's often necessary to pass a pointer to the memory managed
> by an image
> (gdk_pixbuf_create_from_raw_data() in my case). So far, I've
> been using
>
> &image[0]
>
> to get a pointer to memory, but that's pretty ugly, and I'm
> thinking it might not work for all cases. Is there a better
> way to do it? If not, I'd suggest adding an "image::data()"
> method that would provide canonical access to memory. The
> choice of name is for consistency with std::basic_string::data().
>
> Cheers,
> Tim
>

The problem of course is that the image view may not at all be
memory-based, like the Mandelbrot set.
Even for memory-based image views, and for images, they may be planar,
so in this case you really need to get pointers to each color plane.

If the image is interleaved you can just do what you would do with
std::vector:

rgba8_image_t img(100, 100);
void* data=&img[0];

If the image is planar, you can get the pointers to each plane like
this:

rgb8_planar_image_t planar_img(100, 100);
void* plane0=&planar_img[0]->channel<0>();
void* plane1=&planar_img[0]->channel<1>();
...

Useful MPL predicates:

// plain memory-based views/images with no dereference adaptors
view_is_basic<View>
image_is_basic<Image>

view_is_planar<View>
image_is_planar<Image>

I am open to adding an interface like data() but I am not sure how best
to do this to accommodate these variations.

Lubomir


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk