예제 #1
0
파일: color.py 프로젝트: ppawlak/pystacia
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))
예제 #2
0
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))
예제 #3
0
파일: _impl.py 프로젝트: ppawlak/pystacia
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
예제 #4
0
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)
예제 #5
0
파일: pixel.py 프로젝트: ppawlak/pystacia
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)
예제 #6
0
파일: io.py 프로젝트: ppawlak/pystacia
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
예제 #7
0
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
예제 #8
0
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
예제 #9
0
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))
예제 #10
0
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))
예제 #11
0
파일: _impl.py 프로젝트: ppawlak/pystacia
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)]