Boost logo

Boost Users :

Subject: [Boost-users] [gil] Using gil::color_converted_view with gil::for_each_pixel
From: Chris Yuen (kizzx2+boost_at_[hidden])
Date: 2010-12-04 13:00:16


Hey guys,

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
    type 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 not 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!

Best regards,
Chris Yuen



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net