|
Boost : |
From: Timothy M. Shead (tshead_at_[hidden])
Date: 2006-10-17 19:10:55
Lubomir:
I appreciate the fast response, your suggestion worked like a charm, so
I'll take the example a step further - suppose that I actually want to
convert floating-point RGBA data to 8bpp integer RGB (I'm going to
display the alpha separately, say). The current default policy for
conversion from RGBA to RGB is to multiply the RGB channels by the alpha
channel, which is inappropriate in this case - I just want to extract
RGB and ignore the alpha. I can override the default by creating my own
specialization:
namespace gil
{
template <typename T1, typename T2>
struct color_converter_default_impl<T1,rgba_t,T2,rgb_t>
{
template <typename P1, typename P2>
void operator()(const P1& src, P2& dst) const
{
dst.red = channel_convert<T2>(src.red);
dst.green = channel_convert<T2>(src.green);
dst.blue = channel_convert<T2>(src.blue);
}
};
} // namespace gil
... but this is a fairly intrusive, blanket replacement of the default.
How would you handle this on a case-by-case basis? I'd liken it to
providing custom functors for an STL algorithm.
Regards,
Tim Shead
On Mon, 2006-10-16 at 22:21 -0700, Lubomir Bourdev wrote:
> 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
> lossy.
> 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));
>
> Lubomir
>
> > -----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:
> > http://lists.boost.org/mailman/listinfo.cgi/boost
> >
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk