boost库中的gil模块提供了各种图像处理和生成的工具。其中,packed_channel_value结构体可以用于表示像素通道的位宽不是8或16的情况,如1位、2位、4位或12位的通道。本文将着重介绍packed_channel_value的用法,并提供一个测试程序的源代码。
packed_channel_value结构体定义如下:
template <typename BitField, int Offset, int Size>
class packed_channel_value {
public:
typedef BitField value_type;
typedef BitField* pointer;
typedef BitField& reference;
typedef const BitField& const_reference;
static const int bit_size = Size;
static const int bit_offset = Offset;
BOOST_STATIC_ASSERT(sizeof(BitField)*CHAR_BIT >= bit_size + bit_offset);
packed_channel_value() : _value(0) {}
explicit packed_channel_value(value_type v) : _value(v) {}
operator value_type () const { return