Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba99f9c

Browse files
committed
some work on agg swig wrapper
svn path=/trunk/matplotlib/; revision=1496
1 parent 7d6a6d2 commit ba99f9c

9 files changed

Lines changed: 358 additions & 138 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
New entries should be added at the top
22

3+
2005-06-23 Updated examples/agg_test.py to demonstrate curved paths
4+
and fills - JDH
5+
36
2005-06-21 Moved some texmanager and backend_agg tex caching to class
47
level rather than instance level - JDH
58

examples/agg_test.py

Lines changed: 110 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,143 @@
22
# documentation -- you have to know how to use the agg c++ API to use
33
# it
44
import matplotlib.agg as agg
5+
from math import pi
56

7+
## Define some colors
8+
red = agg.rgba8(255,0,0,255)
9+
blue = agg.rgba8(0,0,255,255)
10+
green = agg.rgba8(0,255,0,255)
11+
black = agg.rgba8(0,0,0,255)
12+
white = agg.rgba8(255,255,255,255)
13+
yellow = agg.rgba8(192,192,255,255)
14+
15+
## Create the rendering buffer, rasterizer, etc
616
width, height = 600,400
717
stride = width*4
818
buffer = agg.buffer(width, height, stride)
919

1020
rbuf = agg.rendering_buffer()
1121
rbuf.attachb(buffer)
1222

13-
red = agg.rgba8(255,0,0,255)
14-
blue = agg.rgba8(0,0,255,255)
15-
green = agg.rgba8(0,255,0,255)
16-
black = agg.rgba8(0,0,0,255)
17-
white = agg.rgba8(255,255,255,255)
18-
yellow = agg.rgba8(192,192,255,255)
23+
pf = agg.pixel_format_rgba(rbuf)
24+
rbase = agg.renderer_base_rgba(pf)
25+
rbase.clear_rgba8(blue)
1926

27+
renderer = agg.renderer_scanline_aa_solid_rgba(rbase);
28+
renderer.color_rgba8( red )
29+
rasterizer = agg.rasterizer_scanline_aa()
30+
scanline = agg.scanline_p8()
2031

32+
## A polygon path
2133
path = agg.path_storage()
2234
path.move_to(10,10)
2335
path.line_to(100,100)
2436
path.line_to(200,200)
2537
path.line_to(100,200)
2638
path.close_polygon()
2739

40+
# stroke it
2841
stroke = agg.conv_stroke_path(path)
2942
stroke.width(3.0)
43+
rasterizer.add_path(stroke)
44+
agg.render_scanlines_rgba(rasterizer, scanline, renderer);
3045

31-
pf = agg.pixel_format_rgba(rbuf)
32-
rbase = agg.renderer_base_rgba(pf)
33-
rbase.clear_rgba8(blue)
46+
## A curved path
47+
path = agg.path_storage()
48+
path.move_to(200,10)
49+
path.line_to(350,50)
50+
path.curve3(150,200)
51+
path.curve3(100,70)
52+
path.close_polygon()
53+
curve = agg.conv_curve_path(path)
3454

35-
renderer = agg.renderer_scanline_aa_solid_rgba(rbase);
36-
renderer.color_rgba8( red )
55+
# fill it
56+
rasterizer.add_path(curve)
57+
renderer.color_rgba8( green )
58+
agg.render_scanlines_rgba(rasterizer, scanline, renderer);
3759

38-
rasterizer = agg.rasterizer_scanline_aa()
60+
# and stroke it
61+
stroke = agg.conv_stroke_curve(curve)
62+
stroke.width(5.0)
3963
rasterizer.add_path(stroke)
64+
renderer.color_rgba8( yellow )
65+
agg.render_scanlines_rgba(rasterizer, scanline, renderer);
4066

41-
scanline = agg.scanline_p8()
67+
## Transforming a path
68+
path = agg.path_storage()
69+
path.move_to(0,0)
70+
path.line_to(1,0)
71+
path.line_to(1,1)
72+
path.line_to(0,1)
73+
path.close_polygon()
74+
75+
rotation = agg.trans_affine_rotation(pi/4)
76+
scaling = agg.trans_affine_scaling(30,30)
77+
translation = agg.trans_affine_translation(300,300)
78+
trans = rotation*scaling*translation
79+
80+
transpath = agg.conv_transform_path(path, trans)
81+
stroke = agg.conv_stroke_transpath(transpath)
82+
stroke.width(2.0)
83+
rasterizer.add_path(stroke)
84+
renderer.color_rgba8( black )
85+
agg.render_scanlines_rgba(rasterizer, scanline, renderer);
86+
87+
## Converting a transformed path to a curve
88+
path = agg.path_storage()
89+
path.move_to(0,0)
90+
path.curve3(1,0)
91+
path.curve3(1,1)
92+
path.curve3(0,1)
93+
path.close_polygon()
4294

95+
rotation = agg.trans_affine_rotation(pi/4)
96+
scaling = agg.trans_affine_scaling(30,30)
97+
translation = agg.trans_affine_translation(300,250)
98+
trans = rotation*scaling*translation
99+
100+
transpath = agg.conv_transform_path(path, trans)
101+
curvetrans = agg.conv_curve_trans(transpath)
102+
stroke = agg.conv_stroke_curvetrans(curvetrans)
103+
stroke.width(2.0)
104+
rasterizer.add_path(stroke)
105+
renderer.color_rgba8( white )
43106
agg.render_scanlines_rgba(rasterizer, scanline, renderer);
44107

108+
## Copy a rectangle from the buffer the rectangle defined by
109+
## x0,y0->x1,y1 and paste it at xdest, ydest
110+
x0, y0 = 10, 50
111+
x1, y1 = 110, 190
112+
xdest, ydest = 350, 200
113+
114+
115+
widthr, heightr = x1-x0, y1-y0
116+
strider = widthr*4
117+
copybuffer = agg.buffer(widthr, heightr, strider)
118+
119+
rbufcopy = agg.rendering_buffer()
120+
rbufcopy.attachb(copybuffer)
121+
pfcopy = agg.pixel_format_rgba(rbufcopy)
122+
rbasecopy = agg.renderer_base_rgba(pfcopy)
123+
124+
rect = agg.rect(x0, y0, x1, y1)
125+
print rect.is_valid()
126+
rectp = agg.rectPtr(rect)
127+
#print dir(rbasecopy)
128+
129+
# agg is funny about the arguments to copy from; the last 2 args are
130+
# dx, dy. If the src and dest buffers are the same size and you omit
131+
# the dx and dy args, the position of the copy in the dest buffer is
132+
# the same as in the src. Since our dest buffer is smaller than our
133+
# src buffer, we have to offset the location by -x0, -y0
134+
rbasecopy.copy_from(rbuf, rect, -x0, -y0);
135+
136+
# paste the rectangle at a new location xdest, ydest
137+
rbase.copy_from(rbufcopy, None, xdest, ydest);
138+
139+
140+
141+
## Display it with PIL
45142
s = buffer.to_string()
46143
print len(s)
47144
import Image

0 commit comments

Comments
 (0)