[gil]: Generic operation on channels

Hello there, I try to write a generic floyd steinberg implementation using boost.gil. Within that I have to compute the error the color conversion. So I thought that I simply have to take a signed version of the pixel type, and compute the difference between the original and converted pixel. This operation is supposed to compute the error: template<typename CT> struct calc_error { template <typename Out, typename T> CT operator()(const Out& in1, const T& orig) const { return orig - in1; } }; Inside the algorithm I do the following: typedef typename channel_type<OriginalView>::type channel_t; typedef typename channel_convert_to_signed<channel_t>::type signed_channel_t; typedef boost::gil::pixel< signed_channel_t, typename OriginalView::value_type::layout_t > error_pixel_t; But somehow singed_channel_t is still unsigned char if an rgb8 image is passed to the method. Which causes problems in the second stage of the algorithm where these always positive values are added to the channels. error_pixel_t error; static_transform(*conv_it, *orig_it, error, calc_error<signed_channel_t>()); //.... Regards Andreas Pokorny

Andreas Pokorny wrote:
I try to write a generic floyd steinberg implementation using boost.gil. ...
Andreas, The bug is not in the implementation but in the name of the function. It really should be called "convert_from_unsigned" instead of "convert_to_signed" because it takes the _destination_ type as its parameter. I will also move it in gil::detail because its behavior is much attuned to what GIL needs there (it operates on integral channels only and assumes the two channels are of the same bit size). It really shouldn't be used as a general purpose metafunction. In your case you should write your own metafunctions. Metafunctions like is_integral_scalar, is_signed, add_sign and remove_sign should be added to Boost.TypeTraits in my opinion. Lubomir

Hello, Lubomir Bourdev <lbourdev@adobe.com> wrote:
The bug is not in the implementation but in the name of the function. It really should be called "convert_from_unsigned" instead of "convert_to_signed" because it takes the _destination_ type as its parameter. [...]
In your case you should write your own metafunctions. Metafunctions like is_integral_scalar, is_signed, add_sign and remove_sign should be added to Boost.TypeTraits in my opinion.
Agreed. I also noticed that, just getting the signed type is not enough. E.g. when converting with a conversion function that does not yield the nearest color, I might get an error bigger than the signed type can hold. Thank you for clearing that up. Regards Andreas Pokorny
participants (2)
-
Andreas Pokorny
-
Lubomir Bourdev