8000 Refactor common parts of ImageMagick{,File}Writer. by anntzer · Pull Request #21955 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Refactor common parts of ImageMagick{,File}Writer. #21955

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 15, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions doc/api/next_api_changes/deprecations/21995-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``ImageMagickBase.delay`` and ``ImageMagickBase.output_args``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
are deprecated with no replacement.
47 changes: 27 additions & 20 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ class FFMpegBase:
"""
Mixin class for FFMpeg output.

To be useful this must be multiply-inherited from with a
`MovieWriterBase` sub-class.
This is a base class for the concrete `FFMpegWriter` and `FFMpegFileWriter`
classes.
"""

_exec_key = 'animation.ffmpeg_path'
Expand Down Expand Up @@ -620,23 +620,42 @@ class ImageMagickBase:
"""
Mixin class for ImageMagick output.

To be useful this must be multiply-inherited from with a
`MovieWriterBase` sub-class.
This is a base class for the concrete `ImageMagickWriter` and
`ImageMagickFileWriter` classes, which define an ``input_names`` attribute
(or property) specifying the input names passed to ImageMagick.
"""

_exec_key = 'animation.convert_path'
_args_key = 'animation.convert_args'

@_api.deprecated("3.6")
@property
def delay(self):
return 100. / self.fps

@_api.deprecated("3.6")
@property
def output_args(self):
extra_args = (self.extra_args if self.extra_args is not None
else mpl.rcParams[self._args_key])
return [*extra_args, self.outfile]

def _args(self):
# ImageMagick does not recognize "raw".
fmt = "rgba" if self.frame_format == "raw" else self.frame_format
extra_args = (self.extra_args if self.extra_args is not None
else mpl.rcParams[self._args_key])
return [
self.bin_path(),
"-size", "%ix%i" % self.frame_size,
"-depth", "8",
"-delay", str(100 / self.fps),
"-loop", "0",
f"{fmt}:{self.input_names}",
*extra_args,
self.outfile,
]

@classmethod
def bin_path(cls):
binpath = super().bin_path()
Expand All @@ -662,14 +681,9 @@ class ImageMagickWriter(ImageMagickBase, MovieWriter):

Frames are streamed directly to ImageMagick via a pipe and written
in a single pass.

"""
def _args(self):
return ([self.bin_path(),
'-size', '%ix%i' % self.frame_size, '-depth', '8',
'-delay', str(self.delay), '-loop', '0',
'%s:-' % self.frame_format]
+ self.output_args)

input_names = "-" # stdin


# Combine ImageMagick options with temp file-based writing
Expand All @@ -683,15 +697,8 @@ class ImageMagickFileWriter(ImageMagickBase, FileMovieWriter):
"""

supported_formats = ['png', 'jpeg', 'tiff', 'raw', 'rgba']

def _args(self):
# Force format: ImageMagick does not recognize 'raw'.
fmt = 'rgba:' if self.frame_format == 'raw' else ''
return ([self.bin_path(),
'-size', '%ix%i' % self.frame_size, '-depth', '8',
'-delay', str(self.delay), '-loop', '0',
'%s%s*.%s' % (fmt, self.temp_prefix, self.frame_format)]
+ self.output_args)
input_names = property(
lambda self: f'{self.temp_prefix}*.{self.frame_format}')


# Taken directly from jakevdp's JSAnimation package at
Expand Down
0