Boost logo

Boost Users :

Subject: Re: [Boost-users] [GIL] Black filled or not ?
From: Christian Henning (chhenning_at_[hidden])
Date: 2010-01-13 17:04:22


Eloi, this would be my solution. Wording might be a little off but I'm
sure you'll get the idea:

#include <boost\gil\gil_all.hpp>

using namespace std;
using namespace boost;
using namespace gil;

template< typename Data, int N > struct black_pixel_factory {
BOOST_STATIC_ASSERT(( false )); };
template< typename Data > struct black_pixel_factory< Data, 1 >
{
    typedef pixel< Data, devicen_layout_t< 1 > > pixel_t;
    static const pixel_t black() { return pixel_t( 0 ); }
};

template< typename Data > struct black_pixel_factory< Data, 2 >
{
    typedef pixel< Data, devicen_layout_t< 2 > > pixel_t;
    static const pixel_t black() { return pixel_t( 0, 0 ); }
};

template< typename Data > struct black_pixel_factory< Data, 3 >
{
    typedef pixel< Data, devicen_layout_t< 3 > > pixel_t;
    static const pixel_t black() { return pixel_t( 0, 0, 0 ); }
};

template< typename Data > struct black_pixel_factory< Data, 4 >
{
    typedef pixel< Data, devicen_layout_t< 4 > > pixel_t;
    static const pixel_t black() { return pixel_t( 0, 0, 0, 0 ); }
};

template< typename Data > struct black_pixel_factory< Data, 5 >
{
    typedef pixel< Data, devicen_layout_t< 5 > > pixel_t;
    static const pixel_t black() { return pixel_t( 0, 0, 0, 0, 0 ); }
};

template< typename View >
void foo( const View& dst )
{
    typedef pixel<bits32f, devicen_layout_t< num_channels<View>::value
> > comp_pixel_t;
    typedef image<comp_pixel_t, false, std::allocator<unsigned char> >
comp_image_t;
    typedef typename view_type_from_pixel<comp_pixel_t>::type comp_view_t;
    typedef typename comp_view_t::x_iterator tmp_iterator;

    typedef black_pixel_factory< bits32f, num_channels<View>::value >
black_pixel_factory_t;
    typename black_pixel_factory_t::pixel_t black =
black_pixel_factory_t::black();

    comp_image_t itmp( dst.dimensions( ) );
    comp_view_t tmpv( view( itmp ) );
    fill_pixels( tmpv, black);

    return;
}

int main()
{
    rgb32f_image_t img;
    foo( view( img ));

    return 0;
}

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