Boost logo

Boost :

Subject: Re: [boost] [GIL] default_color_converter from float to integer should clamp
From: Christian Henning (chhenning_at_[hidden])
Date: 2012-10-15 09:06:20


Hi Fabian,

thanks for your patch. I think the default converter was created with
floating point values between 0 and 1 in mind. I suggest you don't use
the default converter but just create a new one. It fairly easy to do
so.

I could imagine to create a clamping default converter for the toolbox.

Thanks,
Christian

On Sun, Oct 14, 2012 at 7:33 AM, Fabien Castan <fabcastan_at_[hidden]> wrote:
> Hi,
>
> The conversion from floating point image to 8 bits or 16 bits image should
> clamp instead of writing arbitrary values...
>
> // a floating point image, with some pixel values < 0.0 and > 1.0
> boost::gil::rgba32f_view_t HDR;
>
> // use default_color_converter to convert this HDR image to 8 bits
> boost::gil::png_write_view(
> "LDR.png", boost::gil::color_converted_view<boost::gil::rgba8_pixel_t>( HDR
> ) );
>
> The 8 bits LDR image contains arbitrary cast conversion values, that are
> not very nice. The conversion from floating point to integer values has no
> other valid solution than clamping.
> So I suggest this patch, for the file "boost/gil/channel_algorithm.hpp":
>
> @@ -272,7 +272,13 @@
> template <typename DstChannelV> struct
> channel_converter_unsigned<bits32f,DstChannelV> : public
> std::unary_function<bits32f,DstChannelV> {
> DstChannelV operator()(bits32f x) const
> {
> typedef typename detail::unsigned_integral_max_value< DstChannelV
>>::value_type dst_integer_t;
> - return DstChannelV( static_cast< dst_integer_t
>>(x*channel_traits<DstChannelV>::max_value()+0.5f ));
> +
> + const bits32f convertedValue = x *
> channel_traits<DstChannelV>::max_value() + 0.5f;
> + const bits32f clampedValue = std::min(
> + (bits32f)channel_traits<DstChannelV>::max_value(),
> + std::max(
> (bits32f)channel_traits<DstChannelV>::min_value(), convertedValue ) );
> +
> + return DstChannelV( static_cast< dst_integer_t >(clampedValue) );
> }
> };
>
>
> Regards,
> Fabien Castan
>
> _______________________________________________
> 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