我有一个在<PIXEL>
上模板化的类,假定是boost::gil
的像素类型之一(目前,仅gray8_pixel_t
或gray16_pixel_t
,我只希望将来支持同类像素类型,例如rgb8_pixel_t
)。
该类需要获取适合于像素类型的unsigned char
或unsigned short
;我假设这被埋在像素类中,但是PIXEL::value_type
,PIXEL::channel_type
或PIXEL::channel_type::value type
似乎都不是我想要的。
诀窍是什么?
(我当然可以通过一些专门用于模板的帮助器结构使用类型间接获取此信息:
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;};
但可以肯定的是,如果我能找到的话,GIL必须已经提供了等效的东西...)
最佳答案
啊哈..这似乎可以解决问题:
typename boost::gil::channel_type<PIXEL>::type