Skip to content

Commit

Permalink
Merge ffa249a into 681c9ca
Browse files Browse the repository at this point in the history
  • Loading branch information
emcconville committed Nov 27, 2020
2 parents 681c9ca + ffa249a commit bdf70fc
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 168 deletions.
2 changes: 1 addition & 1 deletion tests/drawing_test.py
Expand Up @@ -72,7 +72,7 @@ def test_set_get_font(fx_wand, fx_asset):


def test_set_get_font_family(fx_wand):
assert fx_wand.font_family is None
assert fx_wand.font_family == None
fx_wand.font_family = 'sans-serif'
assert fx_wand.font_family == 'sans-serif'
with raises(TypeError):
Expand Down
4 changes: 2 additions & 2 deletions wand/cdefs/core.py
Expand Up @@ -4,7 +4,7 @@
.. versionadded:: 0.5.0
"""
from ctypes import POINTER, c_void_p, c_char_p, c_int, c_size_t
from wand.cdefs.wandtypes import c_magick_char_p, c_ssize_t
from wand.cdefs.wandtypes import c_ssize_t

__all__ = ('load', 'load_with_version')

Expand Down Expand Up @@ -81,7 +81,7 @@ def load(libmagick):
libmagick.GetNextImageInList.argtypes = [c_void_p]
libmagick.GetNextImageInList.restype = c_void_p
libmagick.MagickToMime.argtypes = [c_char_p]
libmagick.MagickToMime.restype = c_magick_char_p
libmagick.MagickToMime.restype = c_void_p
try:
libmagick.ParseAbsoluteGeometry.argtypes = [c_char_p, c_void_p]
libmagick.ParseAbsoluteGeometry.restype = c_int
Expand Down
14 changes: 7 additions & 7 deletions wand/cdefs/drawing_wand.py
Expand Up @@ -5,7 +5,7 @@
"""
from ctypes import (POINTER, c_void_p, c_char_p, c_double, c_int, c_uint,
c_size_t, c_ubyte, c_ulong)
from wand.cdefs.wandtypes import c_magick_char_p, c_ssize_t
from wand.cdefs.wandtypes import c_ssize_t
from wand.cdefs.structures import PointInfo

__all__ = ('load',)
Expand Down Expand Up @@ -45,7 +45,7 @@ def load(lib, IM_VERSION):
lib.IsDrawingWand.argtypes = [c_void_p]
lib.IsDrawingWand.restype = c_int
lib.DrawGetException.argtypes = [c_void_p, POINTER(c_int)]
lib.DrawGetException.restype = c_magick_char_p
lib.DrawGetException.restype = c_void_p
lib.DrawClearException.argtypes = [c_void_p]
lib.DrawClearException.restype = c_int
lib.DrawAffine.argtypes = [c_void_p, c_void_p]
Expand Down Expand Up @@ -112,7 +112,7 @@ def load(lib, IM_VERSION):
]
lib.DrawGetBorderColor.argtypes = [c_void_p, c_void_p]
lib.DrawGetClipPath.argtypes = [c_void_p]
lib.DrawGetClipPath.restype = c_magick_char_p
lib.DrawGetClipPath.restype = c_void_p
lib.DrawGetClipRule.argtypes = [c_void_p]
lib.DrawGetClipRule.restype = c_uint
lib.DrawGetClipUnits.argtypes = [c_void_p]
Expand Down Expand Up @@ -142,9 +142,9 @@ def load(lib, IM_VERSION):
lib.DrawGetStrokeWidth.argtypes = [c_void_p]
lib.DrawGetStrokeWidth.restype = c_double
lib.DrawGetFont.argtypes = [c_void_p]
lib.DrawGetFont.restype = c_magick_char_p
lib.DrawGetFont.restype = c_void_p
lib.DrawGetFontFamily.argtypes = [c_void_p]
lib.DrawGetFontFamily.restype = c_magick_char_p
lib.DrawGetFontFamily.restype = c_void_p
lib.DrawGetFontResolution.argtypes = [
c_void_p, POINTER(c_double), POINTER(c_double)
]
Expand All @@ -169,7 +169,7 @@ def load(lib, IM_VERSION):
except AttributeError:
lib.DrawGetTextDirection = None
lib.DrawGetTextEncoding.argtypes = [c_void_p]
lib.DrawGetTextEncoding.restype = c_magick_char_p
lib.DrawGetTextEncoding.restype = c_void_p
try:
lib.DrawGetTextInterlineSpacing.argtypes = [c_void_p]
lib.DrawGetTextInterlineSpacing.restype = c_double
Expand All @@ -181,7 +181,7 @@ def load(lib, IM_VERSION):
lib.DrawGetTextKerning.restype = c_double
lib.DrawGetTextUnderColor.argtypes = [c_void_p, c_void_p]
lib.DrawGetVectorGraphics.argtypes = [c_void_p]
lib.DrawGetVectorGraphics.restype = c_magick_char_p
lib.DrawGetVectorGraphics.restype = c_void_p
lib.DrawSetGravity.argtypes = [c_void_p, c_int]
lib.DrawGetGravity.argtypes = [c_void_p]
lib.DrawGetGravity.restype = c_int
Expand Down
10 changes: 5 additions & 5 deletions wand/cdefs/magick_image.py
Expand Up @@ -5,7 +5,7 @@
"""
from ctypes import (CFUNCTYPE, POINTER, c_void_p, c_int, c_size_t, c_double,
c_char_p, c_ubyte, c_bool)
from wand.cdefs.wandtypes import c_ssize_t, c_magick_char_p
from wand.cdefs.wandtypes import c_ssize_t

__all__ = ('MagickProgressMonitor', 'load')

Expand Down Expand Up @@ -485,9 +485,9 @@ def load(lib, IM_VERSION):
lib.MagickGetImageFeatures.argtypes = [c_void_p, c_size_t]
lib.MagickGetImageFeatures.restype = c_void_p
lib.MagickGetImageFilename.argtypes = [c_void_p]
lib.MagickGetImageFilename.restype = c_magick_char_p
lib.MagickGetImageFilename.restype = c_void_p
lib.MagickGetImageFormat.argtypes = [c_void_p]
lib.MagickGetImageFormat.restype = c_magick_char_p
lib.MagickGetImageFormat.restype = c_void_p
lib.MagickGetImageFuzz.argtypes = [c_void_p]
lib.MagickGetImageFuzz.restype = c_double
lib.MagickGetImageGamma.argtypes = [c_void_p]
Expand Down Expand Up @@ -574,7 +574,7 @@ def load(lib, IM_VERSION):
lib.MagickGetImageScene.argtypes = [c_void_p]
lib.MagickGetImageScene.restype = c_size_t
lib.MagickGetImageSignature.argtypes = [c_void_p]
lib.MagickGetImageSignature.restype = c_magick_char_p
lib.MagickGetImageSignature.restype = c_void_p
lib.MagickGetImageTicksPerSecond.argtypes = [c_void_p]
lib.MagickGetImageTicksPerSecond.restype = c_size_t
lib.MagickGetImageTotalInkDensity.argtypes = [c_void_p]
Expand Down Expand Up @@ -617,7 +617,7 @@ def load(lib, IM_VERSION):
else:
lib.MagickHoughLineImage = None
lib.MagickIdentifyImage.argtypes = [c_void_p]
lib.MagickIdentifyImage.restype = c_magick_char_p
lib.MagickIdentifyImage.restype = c_void_p
if is_im_6:
lib.MagickImplodeImage.argtypes = [c_void_p, c_double]
else:
Expand Down
24 changes: 12 additions & 12 deletions wand/cdefs/magick_property.py
Expand Up @@ -5,7 +5,7 @@
"""
from ctypes import (POINTER, c_void_p, c_char_p, c_size_t, c_ubyte, c_uint,
c_int, c_ulong, c_double, c_bool)
from wand.cdefs.wandtypes import c_magick_char_p, c_ssize_t
from wand.cdefs.wandtypes import c_ssize_t

__all__ = ('load',)

Expand Down Expand Up @@ -51,33 +51,33 @@ def load(lib, IM_VERSION):
lib.MagickGetCompressionQuality.argtypes = [c_void_p]
lib.MagickGetCompressionQuality.restype = c_size_t
lib.MagickGetFont.argtypes = [c_void_p]
lib.MagickGetFont.restype = c_char_p
lib.MagickGetFont.restype = c_void_p
lib.MagickGetGravity.argtypes = [c_void_p]
lib.MagickGetGravity.restype = c_int
lib.MagickGetImageArtifact.argtypes = [c_void_p, c_char_p]
lib.MagickGetImageArtifact.restype = c_magick_char_p
lib.MagickGetImageArtifact.restype = c_void_p
lib.MagickGetImageArtifacts.argtypes = [
c_void_p, c_char_p, POINTER(c_size_t)
]
lib.MagickGetImageArtifacts.restype = POINTER(c_char_p)
lib.MagickGetImageArtifacts.restype = POINTER(c_void_p)
lib.MagickGetImageProfile.argtypes = [
c_void_p, c_char_p, POINTER(c_size_t)
]
lib.MagickGetImageProfile.restype = POINTER(c_ubyte)
lib.MagickGetImageProfiles.argtypes = [
c_void_p, c_char_p, POINTER(c_size_t)
]
lib.MagickGetImageProfiles.restype = POINTER(c_char_p)
lib.MagickGetImageProfiles.restype = POINTER(c_void_p)
lib.MagickGetImageProperty.argtypes = [c_void_p, c_char_p]
lib.MagickGetImageProperty.restype = c_magick_char_p
lib.MagickGetImageProperty.restype = c_void_p
lib.MagickGetImageProperties.argtypes = [
c_void_p, c_char_p, POINTER(c_size_t)
]
lib.MagickGetImageProperties.restype = POINTER(c_char_p)
lib.MagickGetImageProperties.restype = POINTER(c_void_p)
lib.MagickGetInterlaceScheme.argtypes = [c_void_p]
lib.MagickGetInterlaceScheme.restype = c_int
lib.MagickGetOption.argtypes = [c_void_p, c_char_p]
lib.MagickGetOption.restype = c_char_p
lib.MagickGetOption.restype = c_void_p
lib.MagickGetPointsize.argtypes = [c_void_p]
lib.MagickGetPointsize.restype = c_double
lib.MagickGetQuantumRange.argtypes = [POINTER(c_size_t)]
Expand All @@ -90,15 +90,15 @@ def load(lib, IM_VERSION):
lib.MagickGetSize.argtypes = [c_void_p, POINTER(c_uint), POINTER(c_uint)]
lib.MagickGetSize.restype = c_int
lib.MagickQueryConfigureOption.argtypes = [c_char_p]
lib.MagickQueryConfigureOption.restype = c_magick_char_p
lib.MagickQueryConfigureOption.restype = c_void_p
lib.MagickQueryConfigureOptions.argtypes = [c_char_p, POINTER(c_size_t)]
lib.MagickQueryConfigureOptions.restype = POINTER(c_magick_char_p)
lib.MagickQueryConfigureOptions.restype = POINTER(c_void_p)
lib.MagickQueryFontMetrics.argtypes = [c_void_p, c_void_p, c_char_p]
lib.MagickQueryFontMetrics.restype = POINTER(c_double)
lib.MagickQueryFonts.argtypes = [c_char_p, POINTER(c_size_t)]
lib.MagickQueryFonts.restype = POINTER(c_magick_char_p)
lib.MagickQueryFonts.restype = POINTER(c_void_p)
lib.MagickQueryFormats.argtypes = [c_char_p, POINTER(c_size_t)]
lib.MagickQueryFormats.restype = POINTER(c_magick_char_p)
lib.MagickQueryFormats.restype = POINTER(c_void_p)
lib.MagickQueryMultilineFontMetrics.argtypes = [
c_void_p, c_void_p, c_char_p
]
Expand Down
4 changes: 2 additions & 2 deletions wand/cdefs/magick_wand.py
Expand Up @@ -4,7 +4,7 @@
.. versionadded:: 0.5.0
"""
from ctypes import POINTER, c_void_p, c_bool, c_int
from wand.cdefs.wandtypes import c_ssize_t, c_magick_char_p
from wand.cdefs.wandtypes import c_ssize_t

__all__ = ('load',)

Expand Down Expand Up @@ -47,7 +47,7 @@ def load(lib, IM_VERSION):
pass
lib.MagickClearException.argtypes = [c_void_p]
lib.MagickGetException.argtypes = [c_void_p, POINTER(c_int)]
lib.MagickGetException.restype = c_magick_char_p
lib.MagickGetException.restype = c_void_p
lib.MagickGetExceptionType.argtypes = [c_void_p]
lib.MagickGetExceptionType.restype = c_int
lib.MagickGetIteratorIndex.argtypes = [c_void_p]
Expand Down
4 changes: 2 additions & 2 deletions wand/cdefs/pixel_iterator.py
Expand Up @@ -4,7 +4,7 @@
.. versionadded:: 0.5.0
"""
from ctypes import POINTER, c_void_p, c_int, c_size_t
from wand.cdefs.wandtypes import c_ssize_t, c_magick_char_p
from wand.cdefs.wandtypes import c_ssize_t

__all__ = ('load',)

Expand Down Expand Up @@ -42,7 +42,7 @@ def load(lib, IM_VERSION):
lib.NewPixelIterator.restype = c_void_p
lib.PixelClearIteratorException.argtypes = [c_void_p]
lib.PixelGetIteratorException.argtypes = [c_void_p, POINTER(c_int)]
lib.PixelGetIteratorException.restype = c_magick_char_p
lib.PixelGetIteratorException.restype = c_void_p
lib.PixelGetNextIteratorRow.argtypes = [c_void_p, POINTER(c_size_t)]
lib.PixelGetNextIteratorRow.restype = POINTER(c_void_p)
lib.PixelSetFirstIteratorRow.argtypes = [c_void_p]
Expand Down
7 changes: 3 additions & 4 deletions wand/cdefs/pixel_wand.py
Expand Up @@ -6,7 +6,6 @@
from ctypes import (CDLL, POINTER, c_char_p, c_double,
c_float, c_int, c_longdouble, c_size_t,
c_ubyte, c_uint, c_ushort, c_void_p)
from wand.cdefs.wandtypes import c_magick_char_p
import numbers
import platform

Expand Down Expand Up @@ -100,17 +99,17 @@ def load(lib, IM_VERSION, IM_QUANTUM_DEPTH, IM_HDRI):
lib.PixelGetBlueQuantum.argtypes = [c_void_p]
lib.PixelGetBlueQuantum.restype = QuantumType
lib.PixelGetColorAsNormalizedString.argtypes = [c_void_p]
lib.PixelGetColorAsNormalizedString.restype = c_magick_char_p
lib.PixelGetColorAsNormalizedString.restype = c_void_p
lib.PixelGetColorAsString.argtypes = [c_void_p]
lib.PixelGetColorAsString.restype = c_magick_char_p
lib.PixelGetColorAsString.restype = c_void_p
lib.PixelGetColorCount.argtypes = [c_void_p]
lib.PixelGetColorCount.restype = c_size_t
lib.PixelGetCyan.argtypes = [c_void_p]
lib.PixelGetCyan.restype = c_double
lib.PixelGetCyanQuantum.argtypes = [c_void_p]
lib.PixelGetCyanQuantum.restype = QuantumType
lib.PixelGetException.argtypes = [c_void_p, POINTER(c_int)]
lib.PixelGetException.restype = c_magick_char_p
lib.PixelGetException.restype = c_void_p
lib.PixelGetExceptionType.argtypes = [c_void_p]
lib.PixelGetExceptionType.restype = c_int
lib.PixelGetFuzz.argtypes = [c_void_p]
Expand Down
29 changes: 1 addition & 28 deletions wand/cdefs/wandtypes.py
Expand Up @@ -8,34 +8,7 @@
import platform
import sys

__all__ = ('c_magick_char_p', 'c_magick_real_t', 'c_magick_size_t',
'c_ssize_t')


class c_magick_char_p(ctypes.c_char_p):
"""This subclass prevents the automatic conversion behavior of
:class:`ctypes.c_char_p`, allowing memory to be properly freed in the
destructor. It must only be used for non-const character pointers
returned by ImageMagick functions.
"""

def __del__(self):
"""Relinquishes memory allocated by ImageMagick.
We don't need to worry about checking for ``NULL`` because
:c:func:`MagickRelinquishMemory` does that for us.
Note alslo that :class:`ctypes.c_char_p` has no
:meth:`~object.__del__` method, so we don't need to
(and indeed can't) call the superclass destructor.
"""
try:
from wand.api import library # Lazy load global library
library.MagickRelinquishMemory(self)
except ImportError:
# Python my be shutting down; and such, ``sys.meta_path``
# may not be available.
pass
__all__ = ('c_magick_real_t', 'c_magick_size_t', 'c_ssize_t')


if not hasattr(ctypes, 'c_ssize_t'):
Expand Down
16 changes: 12 additions & 4 deletions wand/color.py
Expand Up @@ -613,8 +613,12 @@ def normalized_string(self):
"""
with self:
string = library.PixelGetColorAsNormalizedString(self.resource)
return text(string.value)
string = None
ptr = library.PixelGetColorAsNormalizedString(self.resource)
if ptr:
string = text(ctypes.string_at(ptr))
ptr = library.MagickRelinquishMemory(ptr)
return string

@property
def red(self):
Expand Down Expand Up @@ -666,8 +670,12 @@ def red_quantum(self, value):
def string(self):
"""(:class:`basestring`) The string representation of the color."""
with self:
color_string = library.PixelGetColorAsString(self.resource)
return text(color_string.value)
color_string = None
ptr = library.PixelGetColorAsString(self.resource)
if ptr:
color_string = text(ctypes.string_at(ptr))
ptr = library.MagickRelinquishMemory(ptr)
return color_string

@property
def yellow(self):
Expand Down

0 comments on commit bdf70fc

Please sign in to comment.