2626#include " agg_scanline_storage_aa.h"
2727#include " agg_scanline_storage_bin.h"
2828#include " agg_span_allocator.h"
29+ #include " agg_span_converter.h"
2930#include " agg_span_image_filter_gray.h"
3031#include " agg_span_image_filter_rgba.h"
3132#include " agg_span_interpolator_linear.h"
@@ -984,6 +985,30 @@ RendererAgg::draw_text_image(const Py::Tuple& args)
984985 return Py::Object ();
985986}
986987
988+ class span_conv_alpha
989+ {
990+ public:
991+ typedef agg::rgba8 color_type;
992+
993+ double m_alpha;
994+
995+ span_conv_alpha (double alpha) :
996+ m_alpha (alpha)
997+ {
998+ }
999+
1000+ void prepare () {}
1001+ void generate (color_type* span, int x, int y, unsigned len) const
1002+ {
1003+ do
1004+ {
1005+ span->a = (agg::int8u)((double )span->a * m_alpha);
1006+ ++span;
1007+ }
1008+ while (--len);
1009+ }
1010+ };
1011+
9871012
9881013Py::Object
9891014RendererAgg::draw_image (const Py::Tuple& args)
@@ -1068,11 +1093,14 @@ RendererAgg::draw_image(const Py::Tuple& args)
10681093 typedef agg::span_interpolator_linear<> interpolator_type;
10691094 typedef agg::span_image_filter_rgba_nn<image_accessor_type,
10701095 interpolator_type> image_span_gen_type;
1096+ typedef agg::span_converter<image_span_gen_type, span_conv_alpha> span_conv;
10711097
10721098 color_span_alloc_type sa;
10731099 image_accessor_type ia (pixf, agg::rgba8 (0 , 0 , 0 , 0 ));
10741100 interpolator_type interpolator (inv_mtx);
10751101 image_span_gen_type image_span_generator (ia, interpolator);
1102+ span_conv_alpha conv_alpha (alpha);
1103+ span_conv spans (image_span_generator, conv_alpha);
10761104
10771105 if (has_clippath)
10781106 {
@@ -1081,12 +1109,12 @@ RendererAgg::draw_image(const Py::Tuple& args)
10811109 typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
10821110 typedef agg::renderer_scanline_aa<amask_ren_type,
10831111 color_span_alloc_type,
1084- image_span_gen_type >
1112+ span_conv >
10851113 renderer_type_alpha;
10861114
10871115 pixfmt_amask_type pfa (pixFmt, alphaMask);
10881116 amask_ren_type r (pfa);
1089- renderer_type_alpha ri (r, sa, image_span_generator );
1117+ renderer_type_alpha ri (r, sa, spans );
10901118
10911119 theRasterizer.add_path (rect2);
10921120 agg::render_scanlines (theRasterizer, slineP8, ri);
@@ -1096,11 +1124,11 @@ RendererAgg::draw_image(const Py::Tuple& args)
10961124 typedef agg::renderer_base<pixfmt> ren_type;
10971125 typedef agg::renderer_scanline_aa<ren_type,
10981126 color_span_alloc_type,
1099- image_span_gen_type >
1127+ span_conv >
11001128 renderer_type;
11011129
11021130 ren_type r (pixFmt);
1103- renderer_type ri (r, sa, image_span_generator );
1131+ renderer_type ri (r, sa, spans );
11041132
11051133 theRasterizer.add_path (rect2);
11061134 agg::render_scanlines (theRasterizer, slineP8, ri);
@@ -1111,7 +1139,8 @@ RendererAgg::draw_image(const Py::Tuple& args)
11111139 {
11121140 set_clipbox (gc.cliprect , rendererBase);
11131141 rendererBase.blend_from (
1114- pixf, 0 , (int )x, (int )(height - (y + image->rowsOut )), alpha * 255 );
1142+ pixf, 0 , (int )x, (int )(height - (y + image->rowsOut )),
1143+ (agg::int8u)(alpha * 255 ));
11151144 }
11161145
11171146 rendererBase.reset_clipping (true );
0 commit comments