|
Boost Users : |
Subject: [Boost-users] [fusion] Defining pixel formats
From: Christian Henning (chhenning_at_[hidden])
Date: 2013-03-16 14:16:44
Hi all,
ever since Jang Tongary suggested to use boost::fusion to define pixel
types I wondered what he meant by that. 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.
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 );
}
Thanks!
Christian
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