Boost logo

Boost Users :

Subject: Re: [Boost-users] [gil] Using gil::color_converted_view with gil::for_each_pixel
From: Christian Henning (chhenning_at_[hidden])
Date: 2010-12-04 16:45:58


Hi Chris, please see below:

On Sat, Dec 4, 2010 at 1:00 PM, Chris Yuen <kizzx2+boost_at_[hidden]> wrote:
> 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?

Yes, you're correct about your findings. The color of a pixel is only
converted when you access that pixel. That's the mantra of all
mutating views. Which can save a lot operations if you don't need the
whole image to be converted.

>
> 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

Are you aware of "get_color()"? Here is small example:

rgb8_image_t img( 10, 10 );
rgb8_pixel_t p = *view( img ).xy_at( 0, 0 );

unsigned char c = get_color( p, red_t() );

This works for rgb, bgr, etc.

>     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());
> }
>

Does that answer you question? Please mail back if you have more
questions. A complete source code example would be very helpful to
address your needs.

Regards,
Christian

PS: There is a review of my io extension for gil going on right now.
If you have some time please write a review. Thanks!


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