gpt4 book ai didi

c++ - 使用 boost::gil::color_converted_view 和 boost::gil::for_each_pixel

转载 作者:太空宇宙 更新时间:2023-11-04 14:25:25 24 4
gpt4 key购买 nike

我意识到写信给 gil::color_converted_view不影响底层 View 的数据。我想知道这是否正确?

例如,假设我想编写一个程序,获取红色 channel 的值并将蓝色 channel 的值设置为该值的一半。这是我失败的尝试:

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) , View 完全没有改变!我在调试器中进行了一些检查,似乎写入操作正在写入某种代理位置而不是原始像素。

有什么想法吗?提前致谢!

最佳答案

这是 Boost.GIL 中的有效行为,因为只有在访问像素时才会触及像素的颜色分量。您可以修改 my_lambda::operator() 以使用 get_color 来触发颜色组件访问。

关于c++ - 使用 boost::gil::color_converted_view 和 boost::gil::for_each_pixel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4355084/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com