diff --git a/doc/api/next_api_changes/removals/19810-AL.rst b/doc/api/next_api_changes/removals/19810-AL.rst new file mode 100644 index 000000000000..2b641a2e622f --- /dev/null +++ b/doc/api/next_api_changes/removals/19810-AL.rst @@ -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*. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 968875c58731..856686e4f1de 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -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',), } diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index 1e48fd0d7725..d3f25afc7bbf 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -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): """ @@ -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()) @@ -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]) diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index ed06ed5c141d..af7165f98db4 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -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), @@ -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. diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 40ba35c76a11..00f45e7be232 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -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. diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 1874d0a9fee2..edb8683d1f26 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -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, @@ -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()} diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 9657968de7eb..de4ed54e71c6 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -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)