I realized that writing to gil::color_converted_view
doesn't affect the underlying view's data. I wonder if that's correct?
For example, let's say that I want to write a program that will take the value of the red channel and set the blue channel's value to half of that. Here's my failed attempt:
template <typename SrcView>
void half_red_to_blue(SrcView & view)
{
// Since SrcView might be RGB or BGR or some other types,
// I decided to use a color_converted_view to ensure that I'm
// accessing the correct channels
typedef gil::color_converted_view_type<SrcView, gil::rgb8_pixel_t>::type MyView;
MyView my_view = gil::color_converted_view<gil::rgb8_pixel_t>(view):
struct my_lambda
{
void operator()(gil::rgb8_pixel_t & p)
{
p[2] = p[0] / 2;
}
};
gil::for_each_pixel(my_view, my_lambda());
}
However, it only works when SrcView
is actually gil::rgb8_view_t
. If I call, e.g. half_red_to_blue<gil::bgr8_view_t>(view)
, the view is not changed at all! I inspected a little in the debugger and it seems the write operation is writing to some kind of proxy location instead of the original pixels.
Any ideas? Thanks in advance!