Boost logo

Boost Users :

Subject: [Boost-users] [gil] bad_cast exception
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2009-01-27 14:44:22


Hi all,

I am trying to use GIL and face a problem. Here is the code :

namespace boost
{
    namespace gil
    {
        /// Extension a GIL pour gerer les pixels "double" ...
        typedef pixel< double, boost::gil::gray_layout_t > gray64_pixel_t;
        typedef image< gray64_pixel_t, false > gray64_image_t;
        typedef image< gray64_pixel_t, true > gray64_planar_image_t;

        //typedef image_view< gray64_pixel_t > gray64_view_t;
    }
}

int main ( int argc , char **argv)
{
    typedef boost::mpl::vector<
        boost::gil::gray8_image_t,
        boost::gil::gray16_image_t,
        boost::gil::gray32_image_t,
        //boost::gil::gray64_image_t,
        boost::gil::rgb8_image_t,
        boost::gil::rgb16_image_t,
        boost::gil::rgb32_image_t > my_img_types;

    typedef boost::mpl::vector<
        boost::gil::gray8_view_t,
        boost::gil::gray16_view_t,
        boost::gil::gray32_view_t,
        //boost::gil::gray64_view_t,
        boost::gil::rgb8_view_t,
        boost::gil::rgb16_view_t,
        boost::gil::rgb32_view_t > my_view_types;

    if ( argc < 4 )
    {
        usage();
        return 1;
    }

    std::string input_filename( argv[1] );
    std::string output_filename( argv[3] );
    int channel_index;
    try
    {
        channel_index = boost::lexical_cast<int>( argv[2] );
    }
    catch( boost::bad_lexical_cast &e)
    {
        std::cout << "bad_lexical_cast exception : " << e.what() <<
std::endl;
        return 1;
    }

    boost::gil::any_image<my_img_types> runtime_image;
    boost::gil::any_image_view<my_view_types> runtime_view;

    try
    {
        boost::gil::jpeg_read_image( input_filename , runtime_image );
        runtime_view = boost::gil::nth_channel_view(
const_view(runtime_image) , channel_index );
        boost::gil::jpeg_write_view( output_filename , runtime_view );
    }
    catch( std::exception &e )
    {
        std::cout << e.what() << std::endl;
        return 1;
    }

    return 0;
}

I get an exception on this line : runtime_view =
boost::gil::nth_channel_view( const_view(runtime_image) , channel_index );
However, when I write : boost::gil::jpeg_write_view( output_filename ,
boost::gil::nth_channel_view( const_view(runtime_image) , channel_index ) );
everything goes well. Where is my mistake ?

Best regards,

Olivier

-- 
Olivier Tournaire
MATIS - Institut Géographique National
73, Ave de Paris
94165 St Mandé cedex, France
tel: (+33) 1 43 98 80 00 - 71 25
fax: (+33) 1 43 98 85 81


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