Skip to content

Commit 84df267

Browse files
committed
almost have tkagg blitting working
svn path=/trunk/matplotlib/; revision=1591
1 parent d951344 commit 84df267

3 files changed

Lines changed: 40 additions & 11 deletions

File tree

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ def resize(self, event):
149149

150150
def draw(self):
151151
FigureCanvasAgg.draw(self)
152-
tkagg.blit(self._tkphoto, self.renderer._renderer, 2)
152+
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
153153
self._master.update_idletasks()
154154

155155
def blit(self, bbox=None):
156-
tkagg.blit(self._tkphoto, self.renderer._renderer, 2)
156+
tkagg.blit(self._tkphoto, self.renderer._renderer, bbox=bbox, colormode=2)
157157
self._master.update_idletasks()
158158

159159
show = draw

lib/matplotlib/backends/tkagg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import _tkagg
22
import Tkinter as Tk
33

4-
def blit(photoimage, aggimage, colormode=1):
4+
def blit(photoimage, aggimage, bbox=None, colormode=1):
55
tk = photoimage.tk
66
try:
7-
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode)
7+
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox))
88
except Tk.TclError, v:
99
try:
1010
try:
1111
_tkagg.tkinit(tk.interpaddr(), 1)
1212
except AttributeError:
1313
_tkagg.tkinit(id(tk), 0)
14-
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode)
14+
tk.call("PyAggImagePhoto", photoimage, id(aggimage), colormode, id(bbox))
1515
except (ImportError, AttributeError, Tk.TclError):
1616
raise
1717

src/_tkagg.cpp

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

1515
#include "_backend_agg.h"
16+
#include "_transforms.h"
1617

1718
extern "C" {
1819
#ifdef __APPLE__
@@ -41,10 +42,15 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
4142
Tk_PhotoHandle photo;
4243
Tk_PhotoImageBlock block;
4344
PyObject* aggo;
45+
46+
// vars for blitting
47+
PyObject* bboxo;
48+
Bbox* bbox;
49+
double l,b,r,t;
4450

4551
long mode;
4652
long nval;
47-
if (argc != 4) {
53+
if (argc != 5) {
4854
Tcl_AppendResult(interp, "usage: ", argv[0],
4955
" destPhoto srcImage", (char *) NULL);
5056
return TCL_ERROR;
@@ -69,6 +75,23 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
6975
return TCL_ERROR;
7076
}
7177

78+
/* check for bbox/blitting */
79+
bboxo = (PyObject*)atol(argv[4]);
80+
if (bboxo != Py_None) {
81+
bbox = (Bbox*)bboxo;
82+
l = bbox->ll_api()->x_api()->val();
83+
b = bbox->ll_api()->y_api()->val();
84+
r = bbox->ur_api()->x_api()->val();
85+
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);
91+
} else {
92+
bbox = NULL;
93+
}
94+
7295
/* setup tkblock */
7396
block.pixelSize = 1;
7497
if (mode == 0) {
@@ -87,16 +110,22 @@ PyAggImagePhoto(ClientData clientdata, Tcl_Interp* interp,
87110
block.pixelSize = 4;
88111
nval = 4;
89112
}
90-
}
113+
}
114+
91115
block.width = aggRenderer->get_width();
92116
block.height = aggRenderer->get_height();
93117
//std::cout << "w,h: " << block.width << " " << block.height << std::endl;
94118
block.pitch = block.width * nval;
95119
block.pixelPtr = aggRenderer->pixBuffer;
96-
/* Clear current contents */
97-
Tk_PhotoBlank(photo);
98-
/* Copy opaque block to photo image, and leave the rest to TK */
99-
Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height);
120+
121+
if (bbox) {
122+
Tk_PhotoPutBlock(photo, &block, (int)l, (int)b, (int)(r-l), (int)(t-b));
123+
} else {
124+
/* Clear current contents */
125+
Tk_PhotoBlank(photo);
126+
/* Copy opaque block to photo image, and leave the rest to TK */
127+
Tk_PhotoPutBlock(photo, &block, 0, 0, block.width, block.height);
128+
}
100129

101130
return TCL_OK;
102131
}

0 commit comments

Comments
 (0)