文章目錄
- 映像訪問器Image Accessor
- 映像過濾器(Image Filter)
映像訪問器Image Accessor
也許有不少同學看到開頭的線段產生器一節時,已經嘗試修改範例程式碼中的span_image_filter_rgb_bilinear_clip了(比如改成span_image_filter_rgb_bilinear)。不過編譯時間會出錯,這是因為大部分的線段產生器類接受的Source模板不是 PixelFormat Renderer,而是Image Accessor即映像存取器。
標頭檔
- #include <agg_image_accessors.h>
類型
- template<class PixFmt>
- class agg::image_accessor_clip // 映像以外的地方用指定顏色填充
- template<class PixFmt>
- class agg::image_accessor_clone // 映像以外的地方以映像邊緣填充
- template<class PixFmt>
- class agg::image_accessor_no_clip // 映像以外不可讀取,否則引發異常
- template<class PixFmt, class WrapX, class WrapY>
- class agg::image_accessor_wrap // 平鋪映像,平鋪方式由WrapX和WrapY指定
實驗代碼
把範例程式碼中的span_image_filter_rgb_bilinear_clip部分改成下面的代碼
- ...
- // 線段產生器
- //typedef agg::span_image_filter_rgb_bilinear_clip<agg::pixfmt_bgr24,
- //interpolator_type > span_gen_type; // 這個就是Span Generator
- //span_gen_type span_gen(pixf_img, agg::rgba(0,1,0), ip);
- // 映像訪問器
- typedef agg::image_accessor_clone<agg::pixfmt_bgr24> image_accessor_type;
- image_accessor_type accessor(pixf_img);
- // 使用span_image_filter_rgb_bilinear
- typedef agg::span_image_filter_rgb_bilinear<
- image_accessor_type,
- interpolator_type > span_gen_type;
- span_gen_type span_gen(accessor, ip);
- ...
建議把後面的ras.add_path(ell)改成ras.add_path(ccell)
顯示效果
image_accessor_wrap類要指定WrapX和WrapY,可選的有:
wrap_mode_reflect wrap_mode_reflect_auto_pow2 wrap_mode_pow2 wrap_mode_repeat wrap_mode_repeat_auto_pow2 wrap_mode_repeat_pow2
比如我們把本例中的image_accessor_type定義改成
- //typedef agg::image_accessor_clone<agg::pixfmt_bgr24> image_accessor_type;
- typedef agg::image_accessor_wrap<agg::pixfmt_bgr24,
- agg::wrap_mode_reflect,agg::wrap_mode_repeat> image_accessor_type;
顯示效果是
(為了突出效果,用矩陣img_mtx把源縮小了)
映像過濾器(Image Filter)
在一些線段產生器裡,比如span_image_filter_[gray|rgb|rgba],span_image_resample_[gray|rgb|rgba]等類,它們的建構函式還有一個“const image_filter_lut &filter”參數,這個參數用於變換映像的像素值。它們的名稱都以image_filter作為首碼,AGG中稱為Image Filter(映像過濾器)。
標頭檔
- #include <agg_image_filters.h>
類型
- image_filter_bilinear;
- image_filter_blackman;
- image_filter_blackman[36|64|100|144|196|256];
- image_filter_kaiser;
- image_filter_lanczos;
- image_filter_lanczos[36|64|100|144|196|256];
- image_filter_mitchell;
- ...還有很多呢...
實驗代碼
把上面的span_image_filter_rgb_bilinear改成span_image_resample_rgb_affine
- ...
- //typedef agg::image_accessor_clone<agg::pixfmt_bgr24> image_accessor_type;
- typedef agg::image_accessor_wrap<agg::pixfmt_bgr24,
- agg::wrap_mode_reflect,agg::wrap_mode_repeat> image_accessor_type;
- image_accessor_type accessor(pixf_img);
-
- //typedef agg::span_image_filter_rgb_bilinear<
- // image_accessor_type,
- // interpolator_type > span_gen_type;
- //span_gen_type span_gen(accessor, ip);
- typedef agg::span_image_resample_rgb_affine<image_accessor_type> span_gen_type;
- span_gen_type span_gen(accessor, ip, agg::image_filter_sinc36());
- ...
顯示效果
www.cppprog.com