【发布时间】:2010-12-04 18:28:35
【问题描述】:
我意识到写信给gil::color_converted_view 不会影响底层视图的数据。我想知道这是否正确?
例如,假设我想编写一个程序,它将获取红色通道的值并将蓝色通道的值设置为该值的一半。这是我失败的尝试:
template <typename SrcView>
void half_red_to_blue(SrcView & view)
{
// Since SrcView might be RGB or BGR or some other types,
// I decided to use a color_converted_view to ensure that I'm
// accessing the correct channels
typedef gil::color_converted_view_type<SrcView, gil::rgb8_pixel_t>::type MyView;
MyView my_view = gil::color_converted_view<gil::rgb8_pixel_t>(view):
struct my_lambda
{
void operator()(gil::rgb8_pixel_t & p)
{
p[2] = p[0] / 2;
}
};
gil::for_each_pixel(my_view, my_lambda());
}
但是,它仅在 SrcView 实际上是 gil::rgb8_view_t 时才有效。如果我打电话,例如half_red_to_blue<gil::bgr8_view_t>(view),观点一点都没变!我在调试器中检查了一下,似乎写入操作正在写入某种代理位置而不是原始像素。
有什么想法吗?提前致谢!
【问题讨论】: