| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | CloseEvent, KeyEvent, LocationEvent, MouseEvent, ResizeEvent) | |
| 24 | 24 | from matplotlib._pylab_helpers import Gcf | |
| 25 | 25 | from . import _tkagg | |
| 26 | + from ._tkagg import TK_PHOTO_COMPOSITE_OVERLAY, TK_PHOTO_COMPOSITE_SET | ||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | 29 | _log = logging.getLogger(__name__) | |
@@ -51,9 +52,6 @@ def _restore_foreground_window_at_end(): | |||
| 51 | 52 | # Initialize to a non-empty string that is not a Tcl command | |
| 52 | 53 | _blit_tcl_name = "mpl_blit_" + uuid.uuid4().hex | |
| 53 | 54 | ||
| 54 | - TK_PHOTO_COMPOSITE_OVERLAY = 0 # apply transparency rules pixel-wise | ||
| 55 | - TK_PHOTO_COMPOSITE_SET = 1 # set image buffer directly | ||
| 56 | - | ||
| 57 | 55 | ||
| 58 | 56 | def _blit(argsid): | |
| 59 | 57 | """ | |
@@ -62,11 +60,11 @@ def _blit(argsid): | |||
| 62 | 60 | *argsid* is a unique string identifier to fetch the correct arguments from | |
| 63 | 61 | the ``_blit_args`` dict, since arguments cannot be passed directly. | |
| 64 | 62 | """ | |
| 65 | - photoimage, dataptr, offsets, bboxptr, comp_rule = _blit_args.pop(argsid) | ||
| 63 | + photoimage, data, offsets, bbox, comp_rule = _blit_args.pop(argsid) | ||
| 66 | 64 | if not photoimage.tk.call("info", "commands", photoimage): | |
| 67 | 65 | return | |
| 68 | - _tkagg.blit(photoimage.tk.interpaddr(), str(photoimage), dataptr, | ||
| 69 | - comp_rule, offsets, bboxptr) | ||
| 66 | + _tkagg.blit(photoimage.tk.interpaddr(), str(photoimage), data, comp_rule, offsets, | ||
| 67 | + bbox) | ||
| 70 | 68 | ||
| 71 | 69 | ||
| 72 | 70 | def blit(photoimage, aggimage, offsets, bbox=None): | |
@@ -87,7 +85,6 @@ def blit(photoimage, aggimage, offsets, bbox=None): | |||
| 87 | 85 | """ | |
| 88 | 86 | data = np.asarray(aggimage) | |
| 89 | 87 | height, width = data.shape[:2] | |
| 90 | - dataptr = (height, width, data.ctypes.data) | ||
| 91 | 88 | if bbox is not None: | |
| 92 | 89 | (x1, y1), (x2, y2) = bbox.__array__() | |
| 93 | 90 | x1 = max(math.floor(x1), 0) | |
@@ -109,7 +106,7 @@ def blit(photoimage, aggimage, offsets, bbox=None): | |||
| 109 | 106 | ||
| 110 | 107 | # tkapp.call coerces all arguments to strings, so to avoid string parsing | |
| 111 | 108 | # within _blit, pack up the arguments into a global data structure. | |
| 112 | - args = photoimage, dataptr, offsets, bboxptr, comp_rule | ||
| 109 | + args = photoimage, data, offsets, bboxptr, comp_rule | ||
| 113 | 110 | # Need a unique key to avoid thread races. | |
| 114 | 111 | # Again, make the key a string to avoid string parsing in _blit. | |
| 115 | 112 | argsid = str(id(args)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + import numpy as np | ||
| 2 | + from numpy.typing import NDArray | ||
| 3 | + | ||
| 4 | + TK_PHOTO_COMPOSITE_OVERLAY: int | ||
| 5 | + TK_PHOTO_COMPOSITE_SET: int | ||
| 6 | + | ||
| 7 | + def blit( | ||
| 8 | + interp: int, | ||
| 9 | + photo_name: str, | ||
| 10 | + data: NDArray[np.uint8], | ||
| 11 | + comp_rule: int, | ||
| 12 | + offset: tuple[int, int, int, int], | ||
| 13 | + bbox: tuple[int, int, int, int], | ||
| 14 | + ) -> None: ... | ||
| 15 | + def enable_dpi_awareness(frame_handle: int, interp: int) -> bool | None: ... | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,9 +81,7 @@ def test_blit(): | |||
| 81 | 81 | ||
| 82 | 82 | fig, ax = plt.subplots() | |
| 83 | 83 | photoimage = fig.canvas._tkphoto | |
| 84 | - data = np.ones((4, 4, 4)) | ||
| 85 | - height, width = data.shape[:2] | ||
| 86 | - dataptr = (height, width, data.ctypes.data) | ||
| 84 | + data = np.ones((4, 4, 4), dtype=np.uint8) | ||
| 87 | 85 | # Test out of bounds blitting. | |
| 88 | 86 | bad_boxes = ((-1, 2, 0, 2), | |
| 89 | 87 | (2, 0, 0, 2), | |
@@ -94,8 +92,8 @@ def test_blit(): | |||
| 94 | 92 | for bad_box in bad_boxes: | |
| 95 | 93 | try: | |
| 96 | 94 | _tkagg.blit( | |
| 97 | - photoimage.tk.interpaddr(), str(photoimage), dataptr, 0, | ||
| 98 | - (0, 1, 2, 3), bad_box) | ||
| 95 | + photoimage.tk.interpaddr(), str(photoimage), data, | ||
| 96 | + _tkagg.TK_PHOTO_COMPOSITE_OVERLAY, (0, 1, 2, 3), bad_box) | ||
| 99 | 97 | except ValueError: | |
| 100 | 98 | print("success") | |
| 101 | 99 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments