|
Boost : |
From: Lubomir Bourdev (lbourdev_at_[hidden])
Date: 2006-11-10 12:25:03
Christian,
I see two problems with this code.
The obvious one is that you are not using indexed_view - this is why its
operator() is not called :-)
Use:
copy_pixels( indexed_view, view( rgb_img ));
The other problem is that your dereference adaptor returns pixels by
value, so you must not define its reference type to be a pixel
reference. The correct typedefs are:
struct indexed_pixel_deref_fn
{
typedef indexed_pixel_deref_fn const_t;
typedef rgb8_pixel_t value_type;
typedef value_type reference; // returns by value!
typedef value_type const_reference;
typedef reference result_type;
...
};
"const_t" is the type of the immutable equivalent of this type. Since
your adaptor is immutable, it returns its own type.
Lubomir
> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Christian Henning
> Sent: Friday, November 10, 2006 7:05 AM
> To: boost_at_[hidden]; Christian Henning
> Subject: [boost] [gil] Indexed Images
>
> Hi there, I'm playing around with indexed images in GIL. My starting
> point was an email from Lubomir during the review.
>
> Here is what I have:
>
> struct indexed_pixel_deref_fn
> {
> typedef pixel_traits<rgb8_pixel_t>::reference reference;
> typedef pixel_traits<rgb8_pixel_t>::const_reference
> const_reference;
>
> typedef const_reference const_t;
> typedef reference result_type;
>
> typedef rgb8_pixel_t value_type;
> static const bool is_mutable = false;
>
> indexed_pixel_deref_fn( rgb8_pixel_t* table ) : _table( table ) {}
>
> rgb8_pixel_t operator()( const gray8_pixel_t& index ) const
> {
> return _table[index[0]];
> }
>
> rgb8_pixel_t* _table;
> };
>
> typedef gray8_view_t::add_deref<indexed_pixel_deref_fn>
> indexed_factory_t;
> typedef indexed_factory_t::type rgb8_indexed_view_t;
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> // create color lookup table
> rgb8_pixel_t rgb_black( 0, 0, 0 );
> rgb8_pixel_t rgb_red( 255, 0, 0 );
>
> rgb8_pixel_t my_index_table[2];
> my_index_table[0] = rgb_red;
> my_index_table[1] = rgb_black;
>
> // create indexed image
> gray8_image_t indexed_img( 10,10 );
> fill_pixels( view( indexed_img ), unsigned char( 0 ) );
>
> rgb8_indexed_view_t indexed_view= indexed_factory_t::make( view(
> indexed_img )
> ,
> indexed_pixel_deref_fn( &my_index_table[0] ));
>
>
> // color convert the indexed image into an rgb8 image
> rgb8_image_t rgb_img( indexed_img.dimensions() );
> copy_pixels( color_converted_view<rgb8_pixel_t>( view(
> indexed_img ))
> , view( rgb_img )
> );
>
> // save image - it should be all red
> jpeg_write_view( "test.jpg", const_view( rgb_img ));
>
> return 0;
> }
>
> I'm not sure if all these typedefs in the deref functor class are
> correct. Esspecially, I don't know what the const_t is for.
>
> So, my problem is the operator() in my deref isn't called at all. That
> shows me there is something wrong.
>
> Anyone, any idea why?
>
> Thanks,
> Christian
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk