1
我意識到寫入gil::color_converted_view
不會影響底層視圖的數據。我想知道這是否正確?使用boost :: gil :: color_converted_view with boost :: gil :: for_each_pixel
例如,假設我想編寫一個程序,該程序將採用紅色通道的值並將藍色通道的值設置爲其中的一半。這裏是我的失敗嘗試:
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)
,視圖完全沒有改變!我在調試器中檢查了一下,看來寫操作正在寫入某種代理位置,而不是原始像素。
任何想法?提前致謝!