From c8b0da57748f54c674a1e544ddb541a1c7da4231 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sat, 18 May 2019 15:54:25 +0200 Subject: [PATCH] Avoid a buffer copy in PillowWriter. --- lib/matplotlib/animation.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 936ef8e626a6..5a2ba104d63a 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -563,12 +563,10 @@ def grab_frame(self, **savefig_kwargs): buf = BytesIO() self._fig.savefig(buf, **dict(savefig_kwargs, format="rgba")) renderer = self._fig.canvas.get_renderer() - # Using frombuffer / getbuffer may be slightly more efficient, but - # Py3-only. - self._frames.append(Image.frombytes( + self._frames.append(Image.frombuffer( "RGBA", - (int(renderer.width), int(renderer.height)), - buf.getvalue())) + (int(renderer.width), int(renderer.height)), buf.getbuffer(), + "raw", "RGBA", 0, 1)) def finish(self): self._frames[0].save(