Skip to content

Commit

Permalink
Fixes #644 - Image.quantize(colorspace="undefined")
Browse files Browse the repository at this point in the history
  • Loading branch information
emcconville committed Dec 13, 2023
1 parent 9bc790a commit d3cb95a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Version 0.7.0
Unreleased.

- Added :meth:`Image.evaluate_images() <wand.image.BaseImage.evaluate_images>` method.
- Fixed :meth:`Image.quantize() <wand.image.BaseImage.quantize>` behavior by switching
default value of ``colorspace_type`` from :const:`None` to ``"undefined"``. [:issue:`644`]


.. _changelog-0.6:
Expand Down
2 changes: 2 additions & 0 deletions wand/cdefs/magick_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 12 additions & 10 deletions wand/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -7180,17 +7180,17 @@ 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
with ``Log4(number_colors)``. Default value is ``0``.
: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.
Expand All @@ -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:
Expand All @@ -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
)

Expand Down

0 comments on commit d3cb95a

Please sign in to comment.