def get_range(image): minimum, maximum = c_double(), c_double() c_call(image, ('get', 'range'), byref(minimum), byref(maximum)) return tuple(x.value / (2**magick.get_depth() - 1) for x in (minimum, maximum))
def get_range(image): minimum, maximum = c_double(), c_double() c_call(image, ('get', 'range'), byref(minimum), byref(maximum)) return tuple(x.value / (2 ** magick.get_depth() - 1) for x in (minimum, maximum))
def get_options(): options = {} size = c_size_t() keys = c_call('magick_', 'query_configure_options', '*', byref(size)) for key in [native_str(keys[i]) for i in range(size.value)]: options[key] = c_call('magick_', 'query_configure_option', key) return options
def compare(image, other, metric, factory): if image.size != other.size: return False if not metric: metric = metrics.absolute_error metric = enum_lookup(metric, metrics) if not factory: factory = Image distortion = c_double() diff = c_call(image, ('compare', None, 'images'), other, metric, byref(distortion)) return (factory(diff), distortion.value)
def compare(image, other, metric, factory): if image.size != other.size: return False if not metric: metric = metrics.absolute_error metric = enum_lookup(metric, metrics) if not factory: factory = Image distortion = c_double() diff = c_call(image, ('compare', None, 'images'), other, metric, byref(distortion)) return(factory(diff), distortion.value)
def get_blob(image, format, compression, # @ReservedAssignment quality): with state(image, compression=compression, compression_quality=quality): format = format.upper() # @ReservedAssignment old_format = c_call('magick', 'get_format', image) c_call('magick', 'set_format', image, format) size = c_size_t() result = c_call(image, ('get', 'blob'), byref(size)) #from nose.tools import set_trace; set_trace() blob = string_at(result, size.value) c_call('magick_', 'relinquish_memory', result) c_call('magick', 'set_format', image, old_format) return blob
def handle_result(result, restype, args, argtypes): if restype == c_char_p: result = native_str(result) if restype in (c_uint, c_ssize_t, c_size_t): result = int(result) elif restype == enum and not jython: result = result.value elif restype == MagickBoolean and not result: exc_type = ExceptionType() if argtypes[0] == MagickWand_p: klass = 'magick' elif argtypes[0] == PixelWand_p: klass = 'pixel' description = c_call(klass, 'get_exception', args[0], byref(exc_type)) try: raise PystaciaException(native_str(string_at(description))) finally: c_call('magick_', 'relinquish_memory', description) return result
def get_blob( image, format, compression, # @ReservedAssignment quality): with state(image, compression=compression, compression_quality=quality): format = format.upper() # @ReservedAssignment old_format = c_call('magick', 'get_format', image) c_call('magick', 'set_format', image, format) size = c_size_t() result = c_call(image, ('get', 'blob'), byref(size)) #from nose.tools import set_trace; set_trace() blob = string_at(result, size.value) c_call('magick_', 'relinquish_memory', result) c_call('magick', 'set_format', image, old_format) return blob
def get_hsl(color): h, s, l = tuple(x() for x in (c_double, ) * 3) c_call(color, 'get_hsl', byref(h), byref(s), byref(l)) return tuple(saturate(x.value) for x in (h, s, l))
def get_hsl(color): h, s, l = tuple(x() for x in (c_double,) * 3) c_call(color, 'get_hsl', byref(h), byref(s), byref(l)) return tuple(saturate(x.value) for x in (h, s, l))
def get_formats(): size = c_size_t() formats = c_call('magick_', 'query_formats', '*', byref(size)) return [native_str(formats[i]).lower() for i in range(size.value)]