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

Skip to content

Commit 9f7f71a

Browse files
committed
Save a copy in tkcairo.
1 parent dc93a74 commit 9f7f71a

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ def raise_msg_to_str(msg):
4646
msg = '\n'.join(map(str, msg))
4747
return msg
4848

49+
4950
def error_msg_tkpaint(msg, parent=None):
5051
from six.moves import tkinter_messagebox as tkMessageBox
5152
tkMessageBox.showerror("matplotlib", msg)
5253

5354

54-
def blit(photoimage, aggimage, bbox=None):
55+
def blit(photoimage, aggimage, offsets, bbox=None):
5556
"""
5657
Blit *aggimage* to *photoimage*.
5758
59+
*offsets* is a tuple describing how to fill the ``offset`` field of the
60+
``Tk_PhotoImageBlock`` struct: it should be (0, 1, 2, 3) for RGBA8888 data,
61+
(2, 1, 0, 3) for little-endian ARBG32 (i.e. GBRA8888) data and (1, 2, 3, 0)
62+
for big-endian ARGB32 (i.e. ARGB8888) data.
63+
5864
If *bbox* is passed, it defines the region that gets blitted.
5965
"""
6066
data = np.asarray(aggimage)
@@ -67,7 +73,7 @@ def blit(photoimage, aggimage, bbox=None):
6773
else:
6874
photoimage.blank()
6975
bboxptr = (0, width, 0, height)
70-
_tkagg.blit(photoimage, dataptr, bboxptr)
76+
_tkagg.blit(photoimage, dataptr, offsets, bboxptr)
7177

7278

7379
class TimerTk(TimerBase):

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
class FigureCanvasTkAgg(FigureCanvasAgg, FigureCanvasTk):
88
def draw(self):
99
super(FigureCanvasTkAgg, self).draw()
10-
_backend_tk.blit(self._tkphoto, self.renderer._renderer)
10+
_backend_tk.blit(self._tkphoto, self.renderer._renderer, (0, 1, 2, 3))
1111
self._master.update_idletasks()
1212

1313
def blit(self, bbox=None):
1414
_backend_tk.blit(
15-
self._tkphoto, self.renderer._renderer, bbox=bbox)
15+
self._tkphoto, self.renderer._renderer, (0, 1, 2, 3), bbox=bbox)
1616
self._master.update_idletasks()
1717

1818

lib/matplotlib/backends/backend_tkcairo.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@ def draw(self):
2020
self._renderer.set_width_height(width, height)
2121
self.figure.draw(self._renderer)
2222
buf = np.reshape(surface.get_data(), (height, width, 4))
23-
# Convert from ARGB32 to RGBA8888. Using .take() instead of directly
24-
# indexing ensures C-contiguity of the result, which is needed by
25-
# _backend_tk.
26-
buf = buf.take(
27-
[2, 1, 0, 3] if sys.byteorder == "little" else [1, 2, 3, 0],
28-
axis=2)
29-
_backend_tk.blit(self._tkphoto, buf)
23+
_backend_tk.blit(
24+
self._tkphoto, buf,
25+
(2, 1, 0, 3) if sys.byteorder == "little" else (1, 2, 3, 0))
3026
self._master.update_idletasks()
3127

3228

src/_tkagg.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,15 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args) {
211211
int height, width;
212212
unsigned char *data_ptr;
213213
int x1, x2, y1, y2;
214+
int o0, o1, o2, o3;
214215
Tcl_Interp *interp;
215216
char const *photo_name;
216217
Tk_PhotoHandle photo;
217218
Tk_PhotoImageBlock block;
218-
if (!PyArg_ParseTuple(args, "O(iin)(iiii):blit",
219+
if (!PyArg_ParseTuple(args, "O(iin)(iiii)(iiii):blit",
219220
&py_photo,
220221
&height, &width, &data_ptr,
222+
&o0, &o1, &o2, &o3,
221223
&x1, &x2, &y1, &y2)) {
222224
goto exit;
223225
}
@@ -238,10 +240,10 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args) {
238240
block.height = y2 - y1;
239241
block.pitch = 4 * width;
240242
block.pixelSize = 4;
241-
block.offset[0] = 0;
242-
block.offset[1] = 1;
243-
block.offset[2] = 2;
244-
block.offset[3] = 3;
243+
block.offset[0] = o0;
244+
block.offset[1] = o1;
245+
block.offset[2] = o2;
246+
block.offset[3] = o3;
245247
TK_PHOTO_PUT_BLOCK_NO_COMPOSITE(
246248
photo, &block, x1, height - y2, x2 - x1, y2 - y1);
247249
exit:

0 commit comments

Comments
 (0)