Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] Defining pixel formats
From: TONGARI (tongari95_at_[hidden])
Date: 2013-03-16 14:52:23


2013/3/17 Christian Henning <chhenning_at_[hidden]>

> Hi all,
>
> ever since Jang Tongary suggested to use boost::fusion to define pixel
> types I wondered what he meant by that.

I believe you're mentioning me here. ;-)

> I never had the opportunity to
> get myself familiar with fusion so I started learning it and I'm
> really amazed how easy the library is to use. I think I'm at a point
> where I would like to reach to the community for some advice.
>

The very idea is to use Fusion to manipulate the pixel, not defining the
pixel, though you could do it.

I have one file "adapted_pixel.hpp" that adapts GIL pixel (concept) to
Fusion Associative Sequence. Though I want to share here but there's
another dependency on my other header.

> Let's say I wanna create a homogeneous three channel pixel type, like
> RGB. For that I would use a fusion map since I want to access channel
> by name. I also would like to be able to swap channels around to
> create BGR. How would I do that?
>
> namespace boost { namespace gil_3 {
>
> struct red_t;
> struct green_t;
> struct blue_t;
>
> } } // namespace boost::gil_3
>
> void foo()
> {
> typedef fusion::map< fusion::pair< gil_3::red_t , boost::uint8_t >
> , fusion::pair< gil_3::green_t, boost::uint8_t >
> , fusion::pair< gil_3::blue_t , boost::uint8_t >
> > rgb8_pixel_t;
>
> // not working
> typedef fusion::reverse_view< rgb8_pixel_t >::type bgr8_pixel_t;
>
>
> rgb8_pixel_t a( 10, 20, 30 );
> bgr8_pixel_t b( 30, 20, 10 );
>
> boost::uint8_t red_a = fusion::at_key< gil_3::red_t >( a );
> boost::uint8_t red_b = fusion::at_key< gil_3::red_t >( b );
> }
>

reverse_view is a view after all, so you can't instantiate it with ( 30,
20, 10 ).
If you wanna define the reverse one, then fusion::map<..in reverse
order...>.

I'm happy with the way that GIL defines the pixel, what Fusion really
shines here is the generalized way to manipulate the data.

HTH



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