From d3cb95af3557ad0badcbaca702ea47983f8fad9f Mon Sep 17 00:00:00 2001 From: "E. McConville" Date: Wed, 13 Dec 2023 08:55:07 -0600 Subject: [PATCH] Fixes #644 - Image.quantize(colorspace="undefined") --- docs/changes.rst | 2 ++ wand/cdefs/magick_image.py | 2 ++ wand/image.py | 22 ++++++++++++---------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index 8af387ad..5fefb45e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -15,6 +15,8 @@ Version 0.7.0 Unreleased. - Added :meth:`Image.evaluate_images() ` method. + - Fixed :meth:`Image.quantize() ` behavior by switching + default value of ``colorspace_type`` from :const:`None` to ``"undefined"``. [:issue:`644`] .. _changelog-0.6: diff --git a/wand/cdefs/magick_image.py b/wand/cdefs/magick_image.py index 3c1a6471..2a3c1ce1 100644 --- a/wand/cdefs/magick_image.py +++ b/wand/cdefs/magick_image.py @@ -628,6 +628,8 @@ def load(lib, IM_VERSION): lib.MagickHoughLineImage = None lib.MagickIdentifyImage.argtypes = [c_void_p] lib.MagickIdentifyImage.restype = c_void_p + lib.MagickIdentifyImageType.argtypes = [c_void_p] + lib.MagickIdentifyImageType.restype = c_int if is_im_6: lib.MagickImplodeImage.argtypes = [c_void_p, c_double] else: diff --git a/wand/image.py b/wand/image.py index c5819b54..5fe132be 100644 --- a/wand/image.py +++ b/wand/image.py @@ -7169,7 +7169,7 @@ def posterize(self, levels=None, dither='no'): @manipulative @trap_exception - def quantize(self, number_colors, colorspace_type=None, + def quantize(self, number_colors, colorspace_type='undefined', treedepth=0, dither=False, measure_error=False): """`quantize` analyzes the colors within a sequence of images and chooses a fixed number of colors to represent the image. The goal of @@ -7180,7 +7180,7 @@ def quantize(self, number_colors, colorspace_type=None, :type number_colors: :class:`numbers.Integral` :param colorspace_type: Available value can be found in the :const:`COLORSPACE_TYPES`. Defaults - :attr:`colorspace`. + value ``"undefined"``. :type colorspace_type: :class:`basestring` :param treedepth: A value between ``0`` & ``8`` where ``0`` will allow ImageMagick to calculate the optimal depth @@ -7188,9 +7188,9 @@ def quantize(self, number_colors, colorspace_type=None, :type treedepth: :class:`numbers.Integral` :param dither: Perform dither operation between neighboring pixel values. If using ImageMagick-6, this can be a value - of ``True``, or ``False``. With ImageMagick-7, use - a string from :const:`DITHER_METHODS`. Default - ``False``. + of :const:`True`, or :const:`False`. With ImageMagick-7, + use a string from :const:`DITHER_METHODS`. Default + :const:`False`. :type dither: :class:`bool`, or :class:`basestring` :param measure_error: Include total quantization error of all pixels in an image & quantized value. @@ -7200,17 +7200,20 @@ def quantize(self, number_colors, colorspace_type=None, .. versionchanged:: 0.5.9 Fixed ImageMagick-7 ``dither`` argument, and added keyword defaults. + + .. versionchanged:: 0.7.0 + The default value for ``colorspace_type`` argument + is now set to ``"undefeined"`` to match CLI behavior. """ assertions.assert_integer(number_colors=number_colors) - if colorspace_type is None: - colorspace_type = self.colorspace assertions.string_in_list(COLORSPACE_TYPES, 'wand.image.COLORSPACE_TYPES', colorspace_type=colorspace_type) + colorspace_type = COLORSPACE_TYPES.index(colorspace_type) assertions.assert_integer(treedepth=treedepth) if MAGICK_VERSION_NUMBER < 0x700: assertions.assert_bool(dither=dither) - else: # pragma: no cover + else: if dither is False: dither = 'no' elif dither is True: @@ -7221,8 +7224,7 @@ def quantize(self, number_colors, colorspace_type=None, dither = DITHER_METHODS.index(dither) assertions.assert_bool(measure_error=measure_error) return library.MagickQuantizeImage( - self.wand, number_colors, - COLORSPACE_TYPES.index(colorspace_type), + self.wand, number_colors, colorspace_type, treedepth, dither, measure_error )