Skip to content

Commit 9fbfaf1

Browse files
committed
finished tkagg blitting
svn path=/trunk/matplotlib/; revision=1592
1 parent 84df267 commit 9fbfaf1

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

CHANGELOG

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

3+
2005-08-08 Added blitting/animation for TkAgg
4+
35
2005-08-05 Fixed duplicate tickline bug - JDH
46

57
2005-08-05 Fixed a GTK animation bug that cropped up when doing

setupext.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,12 @@ def build_gtkagg(ext_modules, packages, numerix):
379379
def build_tkagg(ext_modules, packages, numerix):
380380
global BUILT_TKAGG
381381
if BUILT_TKAGG: return # only build it if you you haven't already
382+
deps = ['src/_tkagg.cpp']
383+
deps.extend(glob.glob('CXX/*.cxx'))
384+
deps.extend(glob.glob('CXX/*.c'))
385+
382386
module = Extension('matplotlib.backends._tkagg',
383-
['src/_tkagg.cpp'],
387+
deps,
384388
)
385389

386390
# add agg flags before pygtk because agg only supports freetype1

src/_tkagg.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <Python.h>
1313
#include <stdlib.h>
1414

15+
#include "agg_basics.h"
1516
#include "_backend_agg.h"
1617
#include "_transforms.h"
1718

@@ -46,7 +47,9 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
4647
// vars for blitting
4748
PyObject* bboxo;
4849
Bbox* bbox;
50+
agg::int8u *destbuffer;
4951
double l,b,r,t;
52+
int destx, desty, destwidth, destheight, deststride;
5053

5154
long mode;
5255
long nval;
@@ -83,11 +86,26 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
8386
b = bbox->ll_api()->y_api()->val();
8487
r = bbox->ur_api()->x_api()->val();
8588
t = bbox->ur_api()->y_api()->val();
86-
// int casts messes up precision, so must round
87-
l = round(l);
88-
b = round(b);
89-
r = round(r);
90-
t = round(t);
89+
90+
destx = (int)l;
91+
desty = (int)b;
92+
destwidth = (int)(r-l);
93+
destheight = (int)(t-b);
94+
deststride = 4*destwidth;
95+
96+
destbuffer = new agg::int8u[deststride*destheight];
97+
if (destbuffer == NULL) {
98+
throw Py::MemoryError("_tkagg could not allocate memory for destbuffer");
99+
}
100+
101+
agg::rendering_buffer destrbuf;
102+
destrbuf.attach(destbuffer, destwidth, destheight, deststride);
103+
pixfmt destpf(destrbuf);
104+
renderer_base destrb(destpf);
105+
106+
agg::rect_base<int> region(destx, desty, (int)r, (int)t);
107+
destrb.copy_from(*aggRenderer->renderingBuffer, &region,
108+
-destx, -desty);
91109
} else {
92110
bbox = NULL;
93111
}
@@ -112,15 +130,22 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
112130
}
113131
}
114132

115-
block.width = aggRenderer->get_width();
116-
block.height = aggRenderer->get_height();
117-
//std::cout << "w,h: " << block.width << " " << block.height << std::endl;
118-
block.pitch = block.width * nval;
119-
block.pixelPtr = aggRenderer->pixBuffer;
120-
121133
if (bbox) {
122-
Tk_PhotoPutBlock(photo, &block, (int)l, (int)b, (int)(r-l), (int)(t-b));
134+
135+
block.width = destwidth;
136+
block.height = destheight;
137+
block.pitch = deststride;
138+
block.pixelPtr = destbuffer;
139+
140+
Tk_PhotoPutBlock(photo, &block, destx, desty, destwidth, destheight);
141+
delete [] destbuffer;
142+
123143
} else {
144+
block.width = aggRenderer->get_width();
145+
block.height = aggRenderer->get_height();
146+
block.pitch = block.width * nval;
147+
block.pixelPtr = aggRenderer->pixBuffer;
148+
124149
/* Clear current contents */
125150
Tk_PhotoBlank(photo);
126151
/* Copy opaque block to photo image, and leave the rest to TK */

0 commit comments

Comments
 (0)