3

I cant find the correct way to extract the pixel or channel type from an image view. I'm looking to define pod_t below to be 'unsigned char' in the case of gray8_view_t. There is no simple ViewType::pixel_t. What is the proper definition of this type in function PixelFoo?

    template<class ViewType> 
    void PixelFoo(ViewType v)
    {
        typedef typename ViewType::x_iterator::value_type::channel_t pod_t;
        pod_t maxVal = channel_traits<pod_t>::max_value();
        pod_t podVal = v(0, 0); //expect error with emptyView
    }
    void PixelBar()
    {
        gray8_view_t emptyView;
        PixelFoo(emptyView);
    }
totowtwo
  • 2,101
  • 1
  • 14
  • 21

2 Answers2

1

ViewType::value_type should be similar to what you expected to be ViewType::pixel_t.

Then, for homogeneous pixel types, the channel_type<T>::type from HomogeneousPixelBasedConcept should lead to the type you are looking for:

template<class ViewType> 
void PixelFoo(ViewType v)
{
    typedef typename boost::gil::channel_type<typename ViewType::value_type>::type pod_t;
    pod_t maxVal = channel_traits<pod_t>::max_value();
    pod_t podVal = v(0, 0); //expect error with emptyView
}
OK.
  • 2,374
  • 2
  • 17
  • 20
0

This is my current work around, but I'm sure there is a provided method to get to the type i need.

template<class DestView>
struct view_traits;
template<>
struct view_traits<gray8_view_t> {
    typedef bits8 channel_t;
};
template<>
struct view_traits<gray16_view_t> {
    typedef bits16 channel_t;
};
template<>
struct view_traits<gray64f_view_t> {
    typedef double channel_t;
};
totowtwo
  • 2,101
  • 1
  • 14
  • 21