26
26
#include " agg_scanline_storage_aa.h"
27
27
#include " agg_scanline_storage_bin.h"
28
28
#include " agg_span_allocator.h"
29
+ #include " agg_span_converter.h"
29
30
#include " agg_span_image_filter_gray.h"
30
31
#include " agg_span_image_filter_rgba.h"
31
32
#include " agg_span_interpolator_linear.h"
@@ -984,6 +985,30 @@ RendererAgg::draw_text_image(const Py::Tuple& args)
984
985
return Py::Object ();
985
986
}
986
987
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
+
987
1012
988
1013
Py::Object
989
1014
RendererAgg::draw_image (const Py::Tuple& args)
@@ -1068,11 +1093,14 @@ RendererAgg::draw_image(const Py::Tuple& args)
1068
1093
typedef agg::span_interpolator_linear<> interpolator_type;
1069
1094
typedef agg::span_image_filter_rgba_nn<image_accessor_type,
1070
1095
interpolator_type> image_span_gen_type;
1096
+ typedef agg::span_converter<image_span_gen_type, span_conv_alpha> span_conv;
1071
1097
1072
1098
color_span_alloc_type sa;
1073
1099
image_accessor_type ia (pixf, agg::rgba8 (0 , 0 , 0 , 0 ));
1074
1100
interpolator_type interpolator (inv_mtx);
1075
1101
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);
1076
1104
1077
1105
if (has_clippath)
1078
1106
{
@@ -1081,12 +1109,12 @@ RendererAgg::draw_image(const Py::Tuple& args)
1081
1109
typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
1082
1110
typedef agg::renderer_scanline_aa<amask_ren_type,
1083
1111
color_span_alloc_type,
1084
- image_span_gen_type >
1112
+ span_conv >
1085
1113
renderer_type_alpha;
1086
1114
1087
1115
pixfmt_amask_type pfa (pixFmt, alphaMask);
1088
1116
amask_ren_type r (pfa);
1089
- renderer_type_alpha ri (r, sa, image_span_generator );
1117
+ renderer_type_alpha ri (r, sa, spans );
1090
1118
1091
1119
theRasterizer.add_path (rect2);
1092
1120
agg::render_scanlines (theRasterizer, slineP8, ri);
@@ -1096,11 +1124,11 @@ RendererAgg::draw_image(const Py::Tuple& args)
1096
1124
typedef agg::renderer_base<pixfmt> ren_type;
1097
1125
typedef agg::renderer_scanline_aa<ren_type,
1098
1126
color_span_alloc_type,
1099
- image_span_gen_type >
1127
+ span_conv >
1100
1128
renderer_type;
1101
1129
1102
1130
ren_type r (pixFmt);
1103
- renderer_type ri (r, sa, image_span_generator );
1131
+ renderer_type ri (r, sa, spans );
1104
1132
1105
1133
theRasterizer.add_path (rect2);
1106
1134
agg::render_scanlines (theRasterizer, slineP8, ri);
@@ -1111,7 +1139,8 @@ RendererAgg::draw_image(const Py::Tuple& args)
1111
1139
{
1112
1140
set_clipbox (gc.cliprect , rendererBase);
1113
1141
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 ));
1115
1144
}
1116
1145
1117
1146
rendererBase.reset_clipping (true );
0 commit comments