开发者

How to extract channel POD-type from a boost::gil homogeneous pixel type?

开发者 https://www.devze.com 2022-12-25 16:17 出处:网络
I have a class templated on <PIXEL>, assumed to be one of boost::gil\'s pixel types (for now, only either gray8_pixel_t or gray16_pixel_t, and I only expect to support homogeneous pixel types e.

I have a class templated on <PIXEL>, assumed to be one of boost::gil's pixel types (for now, only either gray8_pixel_t or gray16_pixel_t, and I only expect to support homogeneous pixel types e.g rgb8_pixel_t in future).

The class needs to开发者_开发知识库 get hold of unsigned char or unsigned short as appropriate to the pixel type; I assume this is buried somehwere in the pixel class, but none of PIXEL::value_type, PIXEL::channel_type or PIXEL::channel_type::value type seems to be what I want.

What's the trick ?

(I could of course use type-indirection via some template-specialized helper structs to get this info:

template <typename PIXEL> struct types_for
  {};
template <> struct types_for<boost::gil::gray8_pixel_t>
  {typedef unsigned char channel_type;};
template <> struct types_for<boost::gil::gray16_pixel_t>
  {typedef unsigned short channel_type;};

but surely GIL must provide something equivalent already, if I could just find it...)


Aha.. this seems to do the trick:

typename boost::gil::channel_type<PIXEL>::type
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号