Menu

gray8c_view_t from argb8c_view_t channel

2012-11-02
2013-04-29
  • Andreas Wurf

    Andreas Wurf - 2012-11-02

    Hi,

    I am looking for a no-pixel-copy way to get a gray8(C)_view_t from a single channel of a argb8(C)_view_t. Unfortunately I have to use an API that I cannot change and that expects a gray8_view_t as input, whereas my image data is ARGB8 and the data needed is always one of the source channels.

    I tried using nth_channel_view() which seems not to be usable as gray8_view_t. Since my code is targeted for mobile platforms, there are certain restrictions in terms of memory usage and processing speed, so a cheap view-only solution would be really great. Do you have any suggestion?

    Thank you in advance
    Andreas

     
  • Anonymous

    Anonymous - 2012-11-03

    Hi Andreas,

    am I understanding correctly that your API only takes the input parameter of type gray8(C)_view_t? No other view type is allowed?

    If that's the case you prob will have copy the data somewhere to create a gray8_view_t.

    Let me know,
    Christain

     
  • Andreas Wurf

    Andreas Wurf - 2012-11-03

    Hi Christian,

    thank you for answering!

    unfortunately the API I have to use is frozen. It takes argb8(C)_view_t for the pixel data and gray8(C)_view_t's for certain masks to further qualify image areas. My source data is always ARGB8, even for the masks (one or more channels are used as masks). My hope was to get a gray8(C)_view_t with a step iterator that operates directly on my ARGB8 source data.

    As mioskot suggested, I also thought of using a color_converted_view, but that would mean a performance slowdown, since the algorithm is quite complex and iterates multiple times over the pixel data. That said, it may indeed be better to copy pixels over to a gray8-based image.

    Best,
    Andreas

     
  • Anonymous

    Anonymous - 2012-11-03

    Andreas, why can you not use the view type generated by nth_channel_view? It seems you can use a color_converted_view type.

    This might help:

    argb8_image_t img( 640, 480 );
    fill_pixels(view(img), argb8_pixel_t(0, 255, 0, 0 ));
       
    auto v = nth_channel_view( view(img), 1 );
    auto c = color_converted_view<gray8_pixel_t>( v );

    auto p = v;

    Christian

     
  • Andreas Wurf

    Andreas Wurf - 2012-11-03

    Thank you Christian, I will give that a try.

    Best,
    Andreas

     
  • Andreas Wurf

    Andreas Wurf - 2012-11-06

    Hi Christian,

    this is my code:

    gray8_view_t Test::getMaskView( int channel )
    {
        auto channelView = nth_channel_view( _argb8View, channel );
        auto grayChannelView = color_converted_view< gray8_pixel_t >( channelView );
        return( grayChannelView );
    }
    

    Where _argb8View is declared as:

    argb8_view_t _argb8View;
    

    When I compile it, I get the following error:

    In file included from boost/gil/gil_all.hpp:27:
    In file included from boost/gil/algorithm.hpp:28:
    In file included from boost/gil/image_view_factory.hpp:32:
    In file included from boost/gil/color_convert.hpp:32:
    In file included from boost/gil/rgb.hpp:29:
    In file included from boost/gil/planar_pixel_iterator.hpp:30:
    boost/gil/step_iterator.hpp:165:11: error: no matching constructor for initialization of 'detail::step_iterator_adaptor<memory_based_step_iterator<pixel<unsigned char, layout<vector1<gray_color_t>, range_c<int, 0, 1> > > *>, pixel<unsigned char, layout<vector1<gray_color_t>, range_c<int, 0, 1> > > *, memunit_step_fn<pixel<unsigned char, layout<vector1<gray_color_t>, range_c<int, 0, 1> > > *> >'
            : parent_t(it.base(), memunit_step_fn<Iterator>(it.step())) {}
              ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    boost/gil/locator.hpp:271:91: note: in instantiation of function template specialization 'boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *>::memory_based_step_iterator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *> >' requested here
        template <typename X> memory_based_2d_locator(const memory_based_2d_locator<X>& pl) : _p(pl._p) {}
                                                                                              ^
    boost/gil/image_view.hpp:101:124: note: in instantiation of function template specialization 'boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *> >::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *> > >' requested here
        template <typename View> image_view(const View& iv)                                    : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
                                                                                                                               ^
    source/Test.cpp:168:8: note: in instantiation of function template specialization 'boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *> > >::image_view<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *> > > > >' requested here
            return( grayChannelView );
                  ^
    boost/gil/step_iterator.hpp:61:5: note: candidate constructor not viable: no known conversion from 'const x_iterator' (aka 'const boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *>') to 'boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > > *const' for 1st argument; 
        step_iterator_adaptor(const Iterator& it, SFn step_fn=SFn()) : parent_t(it), _step_fn(step_fn) {}
        ^
    boost/gil/step_iterator.hpp:60:5: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
        step_iterator_adaptor() {}
        ^
    boost/gil/step_iterator.hpp:53:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
    class step_iterator_adaptor : public iterator_adaptor<Derived, Iterator, use_default, use_default, use_default, typename SFn::difference_type> {
          ^
    boost/gil/step_iterator.hpp:53:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
    

    Do you have any idea?

    Thanks in advance,
    Andreas

     
  • Anonymous

    Anonymous - 2012-11-06

    Hi Andreas,

    just from the look of it I would argue that the resulting type of a color_converted_view is not the same as gray8_view_t. Even if the color_converted_view is a single channel view. Remember that the your view type has to jump differently through the memory than an ordinary gray8_view_t.

    Try to give your getMaskView a templated return type.

    template< typename View >
    View Test::getMaskView(…) { … }

    Hope that helps,
    Christian

     

Log in to post a comment.