43
43
44
44
// a helper class to pass agg::buffer objects around. agg::buffer is
45
45
// a class in the swig wrapper
46
+ template <class PixFmt >
46
47
class BufferRegion
47
48
{
48
49
public:
49
50
BufferRegion (const agg::rect_i &r) : rect(r)
50
51
{
51
52
width = r.x2 - r.x1 ;
52
53
height = r.y2 - r.y1 ;
53
- stride = width * 4 ;
54
+ stride = width * sizeof ( typename PixFmt::color_type) ;
54
55
data = new agg::int8u[stride * height];
55
56
}
56
57
@@ -84,7 +85,13 @@ class BufferRegion
84
85
return stride;
85
86
}
86
87
87
- void to_string_argb (uint8_t *buf);
88
+ void to_string_argb (uint8_t *buf)
89
+ {
90
+ agg::rendering_buffer src (data, width, height, width * sizeof (typename PixFmt::color_type));
91
+ agg::rendering_buffer dst (buf, width, height, width * sizeof (agg::rgba8));
92
+
93
+ agg::convert<agg::pixfmt_argb32, PixFmt>(&dst, &src);
94
+ }
88
95
89
96
private:
90
97
agg::int8u *data;
@@ -105,9 +112,8 @@ class BufferRegion
105
112
class RendererAgg
106
113
{
107
114
public:
108
-
109
- typedef fixed_blender_rgba_plain<agg::rgba8, agg::order_rgba> fixed_blender_rgba32_plain;
110
- typedef agg::pixfmt_alpha_blend_rgba<fixed_blender_rgba32_plain, agg::rendering_buffer> pixfmt;
115
+ typedef agg::pixfmt_rgba128_plain pixfmt;
116
+ typedef typename pixfmt::color_type color_type;
111
117
typedef agg::renderer_base<pixfmt> renderer_base;
112
118
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_aa;
113
119
typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_bin;
@@ -211,9 +217,54 @@ class RendererAgg
211
217
agg::rect_i get_content_extents ();
212
218
void clear ();
213
219
214
- BufferRegion *copy_from_bbox (agg::rect_d in_rect);
215
- void restore_region (BufferRegion ®);
216
- void restore_region (BufferRegion ®ion, int x, int y, int xx1, int yy1, int xx2, int yy2);
220
+ BufferRegion<pixfmt> *copy_from_bbox (agg::rect_d in_rect)
221
+ {
222
+ agg::rect_i rect (
223
+ (int )in_rect.x1 , height - (int )in_rect.y2 , (int )in_rect.x2 , height - (int )in_rect.y1 );
224
+
225
+ BufferRegion<pixfmt> *reg = NULL ;
226
+ reg = new BufferRegion<pixfmt>(rect);
227
+
228
+ agg::rendering_buffer rbuf;
229
+ rbuf.attach (reg->get_data (), reg->get_width (), reg->get_height (), reg->get_stride ());
230
+
231
+ pixfmt pf (rbuf);
232
+ renderer_base rb (pf);
233
+ rb.copy_from (renderingBuffer, &rect, -rect.x1 , -rect.y1 );
234
+
235
+ return reg;
236
+ }
237
+
238
+ void restore_region (BufferRegion<pixfmt> ®ion)
239
+ {
240
+ if (region.get_data () == NULL ) {
241
+ throw " Cannot restore_region from NULL data" ;
242
+ }
243
+
244
+ agg::rendering_buffer rbuf;
245
+ rbuf.attach (
246
+ region.get_data (), region.get_width (), region.get_height (), region.get_stride ());
247
+
248
+ rendererBase.copy_from (rbuf, 0 , region.get_rect ().x1 , region.get_rect ().y1 );
249
+ }
250
+
251
+ void
252
+ restore_region (BufferRegion<pixfmt> ®ion, int x, int y, int xx1, int yy1, int xx2, int yy2)
253
+ {
254
+ if (region.get_data () == NULL ) {
255
+ throw " Cannot restore_region from NULL data" ;
256
+ }
257
+
258
+ agg::rect_i &rrect = region.get_rect ();
259
+
260
+ agg::rect_i rect (xx1 - rrect.x1 , (yy1 - rrect.y1 ), xx2 - rrect.x1 , (yy2 - rrect.y1 ));
261
+
262
+ agg::rendering_buffer rbuf;
263
+ rbuf.attach (
264
+ region.get_data (), region.get_width (), region.get_height (), region.get_stride ());
265
+
266
+ rendererBase.copy_from (rbuf, &rect, x, y);
267
+ }
217
268
218
269
unsigned int width, height;
219
270
double dpi;
@@ -392,7 +443,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
392
443
agg::wrap_mode_repeat_auto_pow2,
393
444
agg::wrap_mode_repeat_auto_pow2> img_source_type;
394
445
typedef agg::span_pattern_rgba<img_source_type> span_gen_type;
395
- agg::span_allocator<agg::rgba8 > sa;
446
+ agg::span_allocator<pixfmt::color_type > sa;
396
447
img_source_type img_src (hatch_img_pixf);
397
448
span_gen_type sg (img_src, 0 , 0 );
398
449
theRasterizer.add_path (path);
@@ -551,10 +602,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
551
602
fillCache = new agg::int8u[fillSize];
552
603
}
553
604
scanlines.serialize (fillCache);
554
- marker_size = agg::rect_i (scanlines.min_x (),
555
- scanlines.min_y (),
556
- scanlines.max_x (),
557
- scanlines.max_y ());
605
+ marker_size = agg::rect_i (
606
+ scanlines.min_x (), scanlines.min_y (), scanlines.max_x (), scanlines.max_y ());
558
607
}
559
608
560
609
stroke_t stroke (marker_path_curve);
@@ -676,34 +725,34 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
676
725
* This is a custom span generator that converts spans in the
677
726
* 8-bit inverted greyscale font buffer to rgba that agg can use.
678
727
*/
679
- template <class ChildGenerator >
728
+ template <class ChildGenerator , class ColorType >
680
729
class font_to_rgba
681
730
{
682
731
public:
683
732
typedef ChildGenerator child_type;
684
- typedef agg::rgba8 color_type;
685
733
typedef typename child_type::color_type child_color_type;
686
734
typedef agg::span_allocator<child_color_type> span_alloc_type;
687
735
688
736
private:
689
737
child_type *_gen;
690
- color_type _color;
738
+ ColorType _color;
691
739
span_alloc_type _allocator;
692
740
693
741
public:
694
- font_to_rgba (child_type *gen, color_type color) : _gen(gen), _color(color)
742
+ font_to_rgba (child_type *gen, ColorType color) : _gen(gen), _color(color)
695
743
{
696
744
}
697
745
698
- inline void generate (color_type *output_span, int x, int y, unsigned len)
746
+ inline void generate (ColorType *output_span, int x, int y, unsigned len)
699
747
{
700
748
_allocator.allocate (len);
701
749
child_color_type *input_span = _allocator.span ();
702
750
_gen->generate (input_span, x, y, len);
703
751
704
752
do {
705
753
*output_span = _color;
706
- output_span->a = ((unsigned int )_color.a * (unsigned int )input_span->v ) >> 8 ;
754
+ output_span->opacity (_color.opacity () *
755
+ input_span->to_double (input_span->v ));
707
756
++output_span;
708
757
++input_span;
709
758
} while (--len);
@@ -718,11 +767,11 @@ class font_to_rgba
718
767
template <class ImageArray >
719
768
inline void RendererAgg::draw_text_image (GCAgg &gc, ImageArray &image, int x, int y, double angle)
720
769
{
721
- typedef agg::span_allocator<agg::rgba8 > color_span_alloc_type;
770
+ typedef agg::span_allocator<pixfmt::color_type > color_span_alloc_type;
722
771
typedef agg::span_interpolator_linear<> interpolator_type;
723
772
typedef agg::image_accessor_clip<agg::pixfmt_gray8> image_accessor_type;
724
773
typedef agg::span_image_filter_gray<image_accessor_type, interpolator_type> image_span_gen_type;
725
- typedef font_to_rgba<image_span_gen_type> span_gen_type;
774
+ typedef font_to_rgba<image_span_gen_type, color_type > span_gen_type;
726
775
typedef agg::renderer_scanline_aa<renderer_base, color_span_alloc_type, span_gen_type>
727
776
renderer_type;
728
777
@@ -763,11 +812,10 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
763
812
agg::render_scanlines (theRasterizer, slineP8, ri);
764
813
}
765
814
815
+ template <class color_type >
766
816
class span_conv_alpha
767
817
{
768
818
public:
769
- typedef agg::rgba8 color_type;
770
-
771
819
double m_alpha;
772
820
773
821
span_conv_alpha (double alpha) : m_alpha(alpha)
@@ -835,18 +883,19 @@ inline void RendererAgg::draw_image(GCAgg &gc,
835
883
agg::trans_affine inv_mtx (mtx);
836
884
inv_mtx.invert ();
837
885
838
- typedef agg::span_allocator<agg::rgba8 > color_span_alloc_type;
886
+ typedef agg::span_allocator<pixfmt::color_type > color_span_alloc_type;
839
887
typedef agg::image_accessor_clip<pixfmt> image_accessor_type;
840
888
typedef agg::span_interpolator_linear<> interpolator_type;
841
889
typedef agg::span_image_filter_rgba_nn<image_accessor_type, interpolator_type>
842
890
image_span_gen_type;
843
- typedef agg::span_converter<image_span_gen_type, span_conv_alpha> span_conv;
891
+ typedef agg::span_converter<image_span_gen_type, span_conv_alpha<pixfmt::color_type> >
892
+ span_conv;
844
893
845
894
color_span_alloc_type sa;
846
- image_accessor_type ia (pixf, agg::rgba8 (0 , 0 , 0 , 0 ));
895
+ image_accessor_type ia (pixf, pixfmt::color_type (0 , 0 , 0 , 0 ));
847
896
interpolator_type interpolator (inv_mtx);
848
897
image_span_gen_type image_span_generator (ia, interpolator);
849
- span_conv_alpha conv_alpha (alpha);
898
+ span_conv_alpha<pixfmt::color_type> conv_alpha (alpha);
850
899
span_conv spans (image_span_generator, conv_alpha);
851
900
852
901
if (has_clippath) {
@@ -1200,7 +1249,7 @@ inline void RendererAgg::_draw_gouraud_triangle(PointArray &points,
1200
1249
agg::trans_affine trans,
1201
1250
bool has_clippath)
1202
1251
{
1203
- typedef agg::rgba8 color_t ;
1252
+ typedef pixfmt::color_type color_t ;
1204
1253
typedef agg::span_gouraud_rgba<color_t > span_gen_t ;
1205
1254
typedef agg::span_allocator<color_t > span_alloc_t ;
1206
1255
@@ -1266,7 +1315,7 @@ inline void RendererAgg::draw_gouraud_triangle(GCAgg &gc,
1266
1315
throw " colors must be a 3x4 array" ;
1267
1316
}
1268
1317
1269
- _draw_gouraud_triangle (points, colors, trans, has_clippath);
1318
+ // _draw_gouraud_triangle(points, colors, trans, has_clippath);
1270
1319
}
1271
1320
1272
1321
template <class PointArray , class ColorArray >
@@ -1296,7 +1345,7 @@ inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc,
1296
1345
typename PointArray::sub_t point = points[i];
1297
1346
typename ColorArray::sub_t color = colors[i];
1298
1347
1299
- _draw_gouraud_triangle (point, color, trans, has_clippath);
1348
+ // _draw_gouraud_triangle(point, color, trans, has_clippath);
1300
1349
}
1301
1350
}
1302
1351
0 commit comments