我意识到写入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),视图根本不会改变!我在调试器中检查了一下,似乎写操作正在写入某种代理位置,而不是原始像素。
有什么想法吗?提前感谢!
发布于 2010-12-11 00:30:46
这在Boost.GIL中是有效的行为,因为只有在访问像素时才会接触像素的颜色分量。您可以修改my_lambda::operator()以使用get_color触发颜色组件访问。
https://stackoverflow.com/questions/4355084
复制相似问题