【问题标题】:Using boost::gil::color_converted_view with boost::gil::for_each_pixel使用 boost::gil::color_converted_view 和 boost::gil::for_each_pixel
【发布时间】: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&lt;gil::bgr8_view_t&gt;(view),观点一点都没变!我在调试器中检查了一下,似乎写入操作正在写入某种代理位置而不是原始像素。

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

【问题讨论】:

    标签: c++ boost-gil


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-13
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      相关资源
      最近更新 更多