Skip to content

Commit 8f4ed5d

Browse files
Substitute TkPhotoPutBlock
Also release GIL Currently, drawing an equivalence between blank and TK_PHOTO_COMPOSITE_SET which may not be entirely accurate
1 parent 1fbe7fe commit 8f4ed5d

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,10 @@ def _blit(argsid):
6060
6161
*argsid* is a unique string identifier to fetch the correct arguments from
6262
the ``_blit_args`` dict, since arguments cannot be passed directly.
63-
64-
photoimage blanking must occur in the same event and thread as blitting
65-
to avoid flickering.
6663
"""
6764
photoimage, dataptr, offsets, bboxptr, blank = _blit_args.pop(argsid)
68-
if blank:
69-
photoimage.blank()
7065
_tkagg.blit(
71-
photoimage.tk.interpaddr(), str(photoimage), dataptr, offsets, bboxptr)
66+
photoimage.tk.interpaddr(), str(photoimage), dataptr, blank, offsets, bboxptr)
7267

7368

7469
def blit(photoimage, aggimage, offsets, bbox=None):

src/_tkagg.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args)
6464
char const *photo_name;
6565
int height, width;
6666
unsigned char *data_ptr;
67+
int blank;
6768
int o0, o1, o2, o3;
6869
int x1, x2, y1, y2;
6970
Tk_PhotoHandle photo;
7071
Tk_PhotoImageBlock block;
71-
if (!PyArg_ParseTuple(args, "O&s(iiO&)(iiii)(iiii):blit",
72+
if (!PyArg_ParseTuple(args, "O&s(iiO&)i(iiii)(iiii):blit",
7273
convert_voidptr, &interp, &photo_name,
7374
&height, &width, convert_voidptr, &data_ptr,
75+
&blank,
7476
&o0, &o1, &o2, &o3,
7577
&x1, &x2, &y1, &y2)) {
7678
goto exit;
@@ -83,7 +85,12 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args)
8385
PyErr_SetString(PyExc_ValueError, "Attempting to draw out of bounds");
8486
goto exit;
8587
}
88+
if (blank != TK_PHOTO_COMPOSITE_OVERLAY && blank != TK_PHOTO_COMPOSITE_SET){
89+
PyErr_SetString(PyExc_ValueError, "Invalid blank argument");
90+
goto exit;
91+
}
8692

93+
Py_BEGIN_ALLOW_THREADS
8794
block.pixelPtr = data_ptr + 4 * ((height - y2) * width + x1);
8895
block.width = x2 - x1;
8996
block.height = y2 - y1;
@@ -93,8 +100,10 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args)
93100
block.offset[1] = o1;
94101
block.offset[2] = o2;
95102
block.offset[3] = o3;
96-
TK_PHOTO_PUT_BLOCK_NO_COMPOSITE(
97-
photo, &block, x1, height - y2, x2 - x1, y2 - y1);
103+
TK_PHOTO_PUT_BLOCK(
104+
interp, photo, &block, x1, height - y2, x2 - x1, y2 - y1, blank);
105+
Py_END_ALLOW_THREADS
106+
98107
exit:
99108
if (PyErr_Occurred()) {
100109
return NULL;

src/_tkmini.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ typedef struct Tk_PhotoImageBlock
8686
int offset[4];
8787
} Tk_PhotoImageBlock;
8888

89-
#define TK_PHOTO_COMPOSITE_OVERLAY 0
90-
#define TK_PHOTO_COMPOSITE_SET 1
89+
#define TK_PHOTO_COMPOSITE_OVERLAY 0 // don't blank
90+
#define TK_PHOTO_COMPOSITE_SET 1 // blank
9191

9292
/* Typedefs derived from function signatures in Tk header */
9393
/* Tk_FindPhoto typedef */
@@ -96,7 +96,7 @@ typedef Tk_PhotoHandle (*Tk_FindPhoto_t) (Tcl_Interp *interp, const char
9696
/* Tk_PhotoPutBLock typedef */
9797
typedef int (*Tk_PhotoPutBlock_t) (Tcl_Interp *interp, Tk_PhotoHandle handle,
9898
Tk_PhotoImageBlock *blockPtr, int x, int y,
99-
int width, int height);
99+
int width, int height, int compRule);
100100
/* Tk_PhotoPutBLock_NoComposite typedef */
101101
typedef void (*Tk_PhotoPutBlock_NoComposite_t) (Tk_PhotoHandle handle,
102102
Tk_PhotoImageBlock *blockPtr, int x, int y,

0 commit comments

Comments
 (0)