|
31 | 31 | import warnings
|
32 | 32 |
|
33 | 33 | import numpy as np
|
| 34 | +from PIL import Image |
34 | 35 |
|
35 | 36 | import matplotlib as mpl
|
36 | 37 | from matplotlib._animation_data import (
|
@@ -263,6 +264,10 @@ class MovieWriter(AbstractMovieWriter):
|
263 | 264 | exec_key = cbook._deprecate_privatize_attribute("3.3")
|
264 | 265 | args_key = cbook._deprecate_privatize_attribute("3.3")
|
265 | 266 |
|
| 267 | + # Pipe-based writers only support RGBA, but file-based ones support more |
| 268 | + # formats. |
| 269 | + supported_formats = ["rgba"] |
| 270 | + |
266 | 271 | def __init__(self, fps=5, codec=None, bitrate=None, extra_args=None,
|
267 | 272 | metadata=None):
|
268 | 273 | """
|
@@ -296,8 +301,7 @@ def __init__(self, fps=5, codec=None, bitrate=None, extra_args=None,
|
296 | 301 |
|
297 | 302 | super().__init__(fps=fps, metadata=metadata, codec=codec,
|
298 | 303 | bitrate=bitrate)
|
299 |
| - |
300 |
| - self.frame_format = 'rgba' |
| 304 | + self.frame_format = self.supported_formats[0] |
301 | 305 | self.extra_args = extra_args
|
302 | 306 |
|
303 | 307 | def _adjust_frame_size(self):
|
@@ -467,6 +471,10 @@ def frame_format(self, frame_format):
|
467 | 471 | if frame_format in self.supported_formats:
|
468 | 472 | self._frame_format = frame_format
|
469 | 473 | else:
|
| 474 | + cbook._warn_external( |
| 475 | + f"Ignoring file format {frame_format!r} which is not " |
| 476 | + f"supported by {type(self).__name__}; using " |
| 477 | + f"{self.supported_formats[0]} instead.") |
470 | 478 | self._frame_format = self.supported_formats[0]
|
471 | 479 |
|
472 | 480 | def _base_temp_name(self):
|
@@ -529,7 +537,6 @@ def setup(self, fig, outfile, dpi=None):
|
529 | 537 | self._frames = []
|
530 | 538 |
|
531 | 539 | def grab_frame(self, **savefig_kwargs):
|
532 |
| - from PIL import Image |
533 | 540 | buf = BytesIO()
|
534 | 541 | self.fig.savefig(
|
535 | 542 | buf, **{**savefig_kwargs, "format": "rgba", "dpi": self.dpi})
|
@@ -744,15 +751,18 @@ class ImageMagickFileWriter(ImageMagickBase, FileMovieWriter):
|
744 | 751 |
|
745 | 752 | Frames are written to temporary files on disk and then stitched
|
746 | 753 | together at the end.
|
747 |
| -
|
748 | 754 | """
|
749 | 755 |
|
750 | 756 | supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp',
|
751 | 757 | 'pbm', 'raw', 'rgba']
|
752 | 758 |
|
753 | 759 | def _args(self):
|
754 |
| - return ([self.bin_path(), '-delay', str(self.delay), '-loop', '0', |
755 |
| - '%s*.%s' % (self.temp_prefix, self.frame_format)] |
| 760 | + # Force format: ImageMagick does not recognize 'raw'. |
| 761 | + fmt = 'rgba:' if self.frame_format == 'raw' else '' |
| 762 | + return ([self.bin_path(), |
| 763 | + '-size', '%ix%i' % self.frame_size, '-depth', '8', |
| 764 | + '-delay', str(self.delay), '-loop', '0', |
| 765 | + '%s%s*.%s' % (fmt, self.temp_prefix, self.frame_format)] |
756 | 766 | + self.output_args)
|
757 | 767 |
|
758 | 768 |
|
|
0 commit comments