@@ -53,22 +53,20 @@ def _restore_foreground_window_at_end():
5353# Initialize to a non-empty string that is not a Tcl command
5454_blit_tcl_name = "mpl_blit_" + uuid .uuid4 ().hex
5555
56+ TK_PHOTO_COMPOSITE_OVERLAY = 0 # apply transparency rules pixel-wise
57+ TK_PHOTO_COMPOSITE_SET = 1 # set image buffer directly
58+
5659
5760def _blit (argsid ):
5861 """
5962 Thin wrapper to blit called via tkapp.call.
6063
6164 *argsid* is a unique string identifier to fetch the correct arguments from
6265 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.
6666 """
67- photoimage , dataptr , offsets , bboxptr , blank = _blit_args .pop (argsid )
68- if blank :
69- photoimage .blank ()
70- _tkagg .blit (
71- photoimage .tk .interpaddr (), str (photoimage ), dataptr , offsets , bboxptr )
67+ photoimage , dataptr , offsets , bboxptr , comp_rule = _blit_args .pop (argsid )
68+ _tkagg .blit (photoimage .tk .interpaddr (), str (photoimage ), dataptr ,
69+ comp_rule , offsets , bboxptr )
7270
7371
7472def blit (photoimage , aggimage , offsets , bbox = None ):
@@ -81,7 +79,7 @@ def blit(photoimage, aggimage, offsets, bbox=None):
8179 for big-endian ARGB32 (i.e. ARGB8888) data.
8280
8381 If *bbox* is passed, it defines the region that gets blitted. That region
84- will NOT be blanked before blitting .
82+ will be composed with the previous data according to the alpha channel .
8583
8684 Tcl events must be dispatched to trigger a blit from a non-Tcl thread.
8785 """
@@ -95,10 +93,10 @@ def blit(photoimage, aggimage, offsets, bbox=None):
9593 y1 = max (math .floor (y1 ), 0 )
9694 y2 = min (math .ceil (y2 ), height )
9795 bboxptr = (x1 , x2 , y1 , y2 )
98- blank = False
96+ comp_rule = TK_PHOTO_COMPOSITE_OVERLAY
9997 else :
10098 bboxptr = (0 , width , 0 , height )
101- blank = True
99+ comp_rule = TK_PHOTO_COMPOSITE_SET
102100
103101 # NOTE: _tkagg.blit is thread unsafe and will crash the process if called
104102 # from a thread (GH#13293). Instead of blanking and blitting here,
@@ -107,7 +105,7 @@ def blit(photoimage, aggimage, offsets, bbox=None):
107105
108106 # tkapp.call coerces all arguments to strings, so to avoid string parsing
109107 # within _blit, pack up the arguments into a global data structure.
110- args = photoimage , dataptr , offsets , bboxptr , blank
108+ args = photoimage , dataptr , offsets , bboxptr , comp_rule
111109 # Need a unique key to avoid thread races.
112110 # Again, make the key a string to avoid string parsing in _blit.
113111 argsid = str (id (args ))
0 commit comments