|
Boost : |
From: Lubomir Bourdev (lbourdev_at_[hidden])
Date: 2006-12-10 13:53:02
Andreas Pokorny wrote:
> I just started using GIL, and I think I will need a mixture
> of packed thus interleaved pixels and a planar form: RGB565A8
> The alpha channel is stored in a separate buffer. How can I
> discribe this pixel layout?
Here is a general strategy that will work with any type of format.
If you look at the Mandelbrot function example, it takes a point
defining the coordinates of the pixel within the image and returns a
reference to the pixel. (The Mandelbrot view is immutable, so it returns
the value of the pixel, but one can return a reference (proxy) for
mutable views)
You can use the Mandelbrot example as a starting point. In your function
object you can keep a pointer to the source image (in your case, the two
images, packed RGB and alpha) and replace the body of operator() to
return the correct RGB565A8 reference.
The GIL virtual view support takes care of everything you need to create
an image view, and associated locators, x/y iterators, etc. The only
thing you need to provide is the mapping from coordiantes to pixel
reference. The disadvantage is that this could be suboptimal. It is
often faster to compute the reference given a pointer to the pixel
instead of given its coordinates.
________________
What I would do in your case is start from the interleaved_ptr example.
This is an example of how to write pixel pointers and references. It
creates the simplest possible models - that of an interleaved pixel
pointer and reference. interleaved_ptr contains a pointer to the first
channel of the current pixel and advances it accordingly. Upon
dereferencing it returns an interlaved_ref - a model of a pixel
reference, which also contains inside a pointer to the first channel of
the current pixel. Its channel(), semantic_channel() and operator[]
return references to the corresponding channels
STEP 1: Create a model of a RGB565A8 pixel reference
Start from interleaved_ref and extend it with a second pointer to the
current alpha channel in the second image.
But one complication in your case is that your pixel type is
heterogeneous (meaning that not all of your channels have the same
type). So you want to implement channel<0>() ... channel<3>() similar to
the way they are implemented in packed3_pixel (which is an example of a
model of a packed pixel reference). Your channel<4>() will simply
dereference the alpha pointer.
STEP 2: Create a model of a RGB565A8 pixel value
You can use rgba8_pixel_t for the value type. Any class that is large
enough to store the values of the channels will do.
STEP 3: Create a model of a RGB565A8 pixel iterator
Start from interleaved_ptr and extend it with a second pointer to the
current alpha channel in the second image. Upon dereference it should
construct your model of a pixel reference giving it the two pointers.
You can now construct related types, such as a locator and a view, from
your pixel iterator (see interleaved_ptr.cpp):
typedef type_from_x_iterator<rgb565a8_ptr_t>::view_t rgb565a8_view_t;
Lubomir
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk