Boost logo

Boost :

From: Lubomir Bourdev (lbourdev_at_[hidden])
Date: 2006-10-13 13:13:08

A few reviewers have remarked on whether GIL can handle more complex
formats, such as packed RGB565 format, (i.e. 5 bits red, 6 bits green, 5
bits blue). Since we can handle even images representing syntethic
functions, we can certainly handle packed pixels.

We took a stab at providing a model for packed pixel formats and posted
it here:
This just serves as an example. The code could be improved and made more

Here is how you can define a packed pixel of three channels:

typedef packed3_pixel<rgb_t,boost::uint16_t,boost::uint8_t,5,11>

This defines an RGB pixel over 16-bit data. The first channel always
starts at bit 0. The second channel starts at bit 5, and the third at
bit 11.

Of course, you can define a whole range of packed pixels. Here is an LAB
pixel that fits in a byte:
typedef packed3_pixel<lab_t,boost::uint8_t,boost::uint8_t,2,2>

Here is example code of using packed pixels:

::reference> >();

typedef type_from_x_iterator<rgb565_pixel_t*>::view_t rgb565_view_t;
typedef image<rgb565_view_t> rgb565_image_t;

// Read a test image
rgb8_image_t unpacked_image;

// copy it into packed 565 form
rgb565_image_t packed565_image(get_dimensions(unpacked_image));

// save it back unpacked. You will see dithering artifacts, especially
for channels of low bit depth

// Invoke gradient on the packed data directly. Note: You need the most
// generic version of x_gradient that supports heterogeneous pixels
rgb8_image_t gradient(get_dimensions(unpacked_image));
x_gradient(view(packed565_image), view(gradient));

Note that everything you can do with GIL already automatically extends
to packed pixels. You can run GIL heterogeneous algorithms on them. You
can color convert them. You can include them in runtime types...

Most importantly, GIL core does not need to change.


Boost list run by bdawes at, gregod at, cpdaniel at, john at