8000 Fold _rgbacache into _imcache. by anntzer · Pull Request #21910 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fold _rgbacache into _imcache. #21910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,8 @@ def __init__(self, ax,
self.update(kwargs)

def __getstate__(self):
state = super().__getstate__()
# We can't pickle the C Image cached object.
state['_imcache'] = None
return state
# Save some space on the pickle by not saving the cache.
return {**super().__getstate__(), "_imcache": None}

def get_size(self):
"""Return the size of the image as tuple (numrows, numcols)."""
Expand Down Expand Up @@ -304,7 +302,6 @@ def changed(self):
Call this whenever the mappable is changed so observers can update.
"""
self._imcache = None
self._rgbacache = None
cm.ScalarMappable.changed(self)

def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
Expand Down Expand Up @@ -710,7 +707,6 @@ def set_data(self, A):
self._A = self._A.astype(np.uint8)

self._imcache = None
self._rgbacache = None
self.stale = True

def set_array(self, A):
Expand Down Expand Up @@ -1214,10 +1210,10 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
if unsampled:
raise ValueError('unsampled not supported on PColorImage')

if self._rgbacache is None:
if self._imcache is None:
A = self.to_rgba(self._A, bytes=True)
self._rgbacache = np.pad(A, [(1, 1), (1, 1), (0, 0)], "constant")
padded_A = self._rgbacache
self._imcache = np.pad(A, [(1, 1), (1, 1), (0, 0)], "constant")
padded_A = self._imcache
bg = mcolors.to_rgba(self.axes.patch.get_facecolor(), 0)
bg = (np.array(bg) * 255).astype(np.uint8)
if (padded_A[0, 0] != bg).all():
Expand Down Expand Up @@ -1294,7 +1290,7 @@ def set_data(self, x, y, A):
self._A = A
self._Ax = x
self._Ay = y
self._rgbacache = None
self._imcache = None
self.stale = True

def set_array(self, *args):
Expand Down
0