Boost logo

Boost :

From: Lubomir Bourdev (lbourdev_at_[hidden])
Date: 2006-10-17 01:21:43

Hi Tim,

We don't recommend that you treat half as compatible with bits8.

In general, GIL does not allow standard copying using copy_pixels,
operator=, etc. between pixels that are incompatible. For pixels to be
compatible they must have the same base color space and channel types.
(See PixelsCompatibleConcept)
In other words, you must be able to convert back and forth between them
with no loss of precision.

In your case you want to perform a lossy conversion between half and
bits8. You have to do it via color conversion, which is allowed to be
To do that you must make half model ChannelConvertibleConcept. Here is
how to do what you want:

namespace gil {
template <>
inline bits8 _channel_convert<bits8>(half h) { return bits8(h*255); }

boost::function_requires<ChannelConvertibleConcept<half,bits32f> >();
rgb16f_image_t a(100, 100);
rgb8_image_t b(100, 100);
copy_and_convert_pixels(const_view(a), view(b));


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Timothy M. Shead
> Sent: Monday, October 16, 2006 8:14 PM
> To: boost_at_[hidden]
> Subject: [boost] Generic Image Library (GIL) and floating-point types
> I am trying to use GIL with the OpenEXR library, which uses
> half-precision floating-point channels:
> typedef image_type<half, rgb_t>::type rgb16f_image_t; typedef
> pixel<half, rgb_t> rgb16f_pixel_t;
> ... which works fine. However, I also need to convert to
> 8bpp integer images for use with a UI toolkit:
> rgb16f_image_t a(100, 100);
> rgb8_image_t b(100, 100);
> copy_pixels(const_view(a), view(b));
> After providing a specialization for PixelsCompatibleConcept
> the code compiles fine, but I would like to provide my own
> code for converting channels of type "half" to type "bits8"
> (e.g: to convert values in the range [0, 1] to [0, 255]).
> Any thoughts?
> Tim Shead
> _______________________________________________
> Unsubscribe & other changes:

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