Skip to content

Remove JPEG-specific parameters and rcParams. #19810

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
Apr 1, 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
10 changes: 10 additions & 0 deletions doc/api/next_api_changes/removals/19810-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
jpeg-related keywords and rcParams
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Support has been removed for the *quality*, *optimize*, and *progressive*
parameters of `.Figure.savefig` (which only affected jpeg output), as well as
:rc:`savefig.jpeg_quality`. This support has also been removed from the
corresponding ``print_jpg`` methods.

JPEG output options can be set by directly passing the relevant parameters in
*pil_kwargs*.
1 change: 0 additions & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ def gen_candidates():
'animation.avconv_path': ('3.3',),
'animation.avconv_args': ('3.3',),
'animation.html_args': ('3.3',),
'savefig.jpeg_quality': ('3.3',),
}


Expand Down
38 changes: 2 additions & 36 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,7 @@ def print_to_buffer(self):
# print_figure(), and the latter ensures that `self.figure.dpi` already
# matches the dpi kwarg (if any).

@_check_savefig_extra_args(
extra_kwargs=["quality", "optimize", "progressive"])
@_api.delete_parameter("3.3", "quality",
alternative="pil_kwargs={'quality': ...}")
@_api.delete_parameter("3.3", "optimize",
alternative="pil_kwargs={'optimize': ...}")
@_api.delete_parameter("3.3", "progressive",
alternative="pil_kwargs={'progressive': ...}")
@_check_savefig_extra_args()
@_api.delete_parameter("3.5", "args")
def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs):
"""
Expand All @@ -542,23 +535,9 @@ def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs):

Other Parameters
----------------
quality : int, default: :rc:`savefig.jpeg_quality`
The image quality, on a scale from 1 (worst) to 95 (best).
Values above 95 should be avoided; 100 disables portions of
the JPEG compression algorithm, and results in large files
with hardly any gain in image quality. This parameter is
deprecated.
optimize : bool, default: False
Whether the encoder should make an extra pass over the image
in order to select optimal encoder settings. This parameter is
deprecated.
progressive : bool, default: False
Whether the image should be stored as a progressive JPEG file.
This parameter is deprecated.
pil_kwargs : dict, optional
Additional keyword arguments that are passed to
`PIL.Image.Image.save` when saving the figure. These take
precedence over *quality*, *optimize* and *progressive*.
`PIL.Image.Image.save` when saving the figure.
"""
# Remove transparency by alpha-blending on an assumed white background.
r, g, b, a = mcolors.to_rgba(self.figure.get_facecolor())
Expand All @@ -569,19 +548,6 @@ def print_jpg(self, filename_or_obj, *args, pil_kwargs=None, **kwargs):
self.figure.set_facecolor((r, g, b, a))
if pil_kwargs is None:
pil_kwargs = {}
for k in ["quality", "optimize", "progressive"]:
if k in kwargs:
pil_kwargs.setdefault(k, kwargs.pop(k))
if "quality" not in pil_kwargs:
quality = pil_kwargs["quality"] = \
dict.__getitem__(mpl.rcParams, "savefig.jpeg_quality")
if quality not in [0, 75, 95]: # default qualities.
_api.warn_deprecated(
"3.3", name="savefig.jpeg_quality", obj_type="rcParam",
addendum="Set the quality using "
"`pil_kwargs={'quality': ...}`; the future default "
"quality will be 75, matching the default of Pillow and "
"libjpeg.")
pil_kwargs.setdefault("dpi", (self.figure.dpi, self.figure.dpi))
# Drop alpha channel now.
return (Image.fromarray(np.asarray(self.buffer_rgba())[..., :3])
Expand Down
12 changes: 1 addition & 11 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def draw(self, drawDC=None):
self.gui_repaint(drawDC=drawDC)

@_check_savefig_extra_args
def _print_image(self, filetype, filename, *, quality=None):
def _print_image(self, filetype, filename):
origBitmap = self.bitmap

self.bitmap = wx.Bitmap(math.ceil(self.figure.bbox.width),
Expand All @@ -843,16 +843,6 @@ def _print_image(self, filetype, filename, *, quality=None):

# image is the object that we call SaveFile on.
image = self.bitmap
# set the JPEG quality appropriately. Unfortunately, it is only
# possible to set the quality on a wx.Image object. So if we
# are saving a JPEG, convert the wx.Bitmap to a wx.Image,
# and set the quality.
if filetype == wx.BITMAP_TYPE_JPEG:
if quality is None:
quality = dict.__getitem__(mpl.rcParams,
'savefig.jpeg_quality')
image = self.bitmap.ConvertToImage()
image.SetOption(wx.IMAGE_OPTION_QUALITY, str(quality))

# Now that we have rendered into the bitmap, save it to the appropriate
# file type and clean up.
Expand Down
25 changes: 0 additions & 25 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2840,31 +2840,6 @@ def savefig(self, fname, *, transparent=None, **kwargs):
The resolution in dots per inch. If 'figure', use the figure's
dpi value.

quality : int, default: :rc:`savefig.jpeg_quality`
Applicable only if *format* is 'jpg' or 'jpeg', ignored otherwise.

The image quality, on a scale from 1 (worst) to 95 (best).
Values above 95 should be avoided; 100 disables portions of
the JPEG compression algorithm, and results in large files
with hardly any gain in image quality.

This parameter is deprecated.

optimize : bool, default: False
Applicable only if *format* is 'jpg' or 'jpeg', ignored otherwise.

Whether the encoder should make an extra pass over the image
in order to select optimal encoder settings.

This parameter is deprecated.

progressive : bool, default: False
Applicable only if *format* is 'jpg' or 'jpeg', ignored otherwise.

Whether the image should be stored as a progressive JPEG file.

This parameter is deprecated.

facecolor : color or 'auto', default: :rc:`savefig.facecolor`
The facecolor of the figure. If 'auto', use the current figure
facecolor.
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,6 @@ def _convert_validator_spec(key, conv):
'savefig.facecolor': validate_color_or_auto,
'savefig.edgecolor': validate_color_or_auto,
'savefig.orientation': ['landscape', 'portrait'],
'savefig.jpeg_quality': validate_int,
"savefig.format": validate_string,
"savefig.bbox": validate_bbox, # "tight", or "standard" (= None)
"savefig.pad_inches": validate_float,
Expand Down Expand Up @@ -1420,7 +1419,6 @@ def _convert_validator_spec(key, conv):
"animation.avconv_path": "avconv",
"animation.avconv_args": [],
"animation.html_args": [],
"savefig.jpeg_quality": 95,
}
_validators = {k: _convert_validator_spec(k, conv)
for k, conv in _validators.items()}
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_jpeg_alpha():
# If this fails, there will be only one color (all black). If this
# is working, we should have all 256 shades of grey represented.
num_colors = len(image.getcolors(256))
assert 175 <= num_colors <= 185
assert 175 <= num_colors <= 210
# The fully transparent part should be red.
corner_pixel = image.getpixel((0, 0))
assert corner_pixel == (254, 0, 0)
Expand Down