How to use the pyvips.ffi.cast function in pyvips

To help you get started, we’ve selected a few pyvips examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libvips / pyvips / pyvips / vobject.py View on Github external
def set(self, name, value):
        """Set a GObject property.

        The value is converted to the property type, if possible.

        """

        logger.debug('VipsObject.set: name = %s, value = %s', name, value)

        gtype = self.get_typeof(name)

        gv = pyvips.GValue()
        gv.set_type(gtype)
        gv.set(value)
        go = ffi.cast('GObject *', self.pointer)
        gobject_lib.g_object_set_property(go, _to_bytes(name), gv.pointer)
github libvips / pyvips / pyvips / vobject.py View on Github external
def __init__(self, pointer):
        # logger.debug('VipsObject.__init__: pointer = %s', pointer)
        super(VipsObject, self).__init__(pointer)
        self.vobject = ffi.cast('VipsObject*', pointer)
github libvips / pyvips / pyvips / gobject.py View on Github external
return callback(offset, whence)
        _marshal_seek_cb = \
            ffi.cast('GCallback',
                     ffi.callback('gint64(VipsStreamiu*, gint64, int, void*)',
                                  _marshal_seek))
    _marshalers['seek'] = _marshal_seek_cb

    if pyvips.API_mode:
        @ffi.def_extern()
        def _marshal_write(streamiu, pointer, length, handle):
            buf = ffi.buffer(pointer, length)
            callback = ffi.from_handle(handle)
            result = callback(buf)
            return result
        _marshal_write_cb = \
            ffi.cast('GCallback', gobject_lib._marshal_write)
    else:
        def _marshal_write(streamiu, pointer, length, handle):
            buf = ffi.buffer(pointer, length)
            callback = ffi.from_handle(handle)
            return callback(buf)
        _marshal_write_cb = \
            ffi.cast('GCallback',
                     ffi.callback('gint64(VipsStreamou*, void*, gint64, void*)',
                                  _marshal_write))
    _marshalers['write'] = _marshal_write_cb

    if pyvips.API_mode:
        @ffi.def_extern()
        def _marshal_finish(streamiu, handle):
            callback = ffi.from_handle(handle)
            callback()
github libvips / pyvips / pyvips / vstream.py View on Github external
def filename(self):
        """Get the filename assoiciated with a stream. Return None if there is
        no associated file.

        """

        so = ffi.cast('VipsStream *', self.pointer)
        pointer = vips_lib.vips_stream_filename(so)
        if pointer == ffi.NULL:
            return None
        else:
            return _to_string(pointer)
github libvips / pyvips / pyvips / vstream.py View on Github external
def nick(self):
        """Make a human-readable name for a stream suitable for error
        messages.

        """

        so = ffi.cast('VipsStream *', self.pointer)
        pointer = vips_lib.vips_stream_nick(so)
        if pointer == ffi.NULL:
            return None
        else:
            return _to_string(pointer)
github libvips / pyvips / pyvips / gobject.py View on Github external
image = pyvips.Image(vi)
        callback = ffi.from_handle(handle)
        progress = ffi.cast('VipsProgress*', pointer)
        callback(image, progress)
    _marshal_image_progress_cb = \
        ffi.cast('GCallback', gobject_lib._marshal_image_progress)
else:
    def _marshal_image_progress(vi, pointer, handle):
        # the image we're passed is not reffed for us, so make a ref for us
        gobject_lib.g_object_ref(vi)
        image = pyvips.Image(vi)
        callback = ffi.from_handle(handle)
        progress = ffi.cast('VipsProgress*', pointer)
        callback(image, progress)
    _marshal_image_progress_cb = \
        ffi.cast('GCallback',
                 ffi.callback('void(VipsImage*, void*, void*)',
                              _marshal_image_progress))

_marshalers = {
    'preeval': _marshal_image_progress_cb,
    'eval': _marshal_image_progress_cb,
    'posteval': _marshal_image_progress_cb,
}

if at_least_libvips(8, 9):
    if pyvips.API_mode:
        @ffi.def_extern()
        def _marshal_read(streamiu, pointer, length, handle):
            buf = ffi.buffer(pointer, length)
            callback = ffi.from_handle(handle)
            return callback(buf)
github libvips / pyvips / pyvips / gobject.py View on Github external
# the python marshalers for gobject signal handling
# - we keep a ref to each callback to stop them being GCd
# - I tried to make this less copy-paste, but failed -- check again

if pyvips.API_mode:
    @ffi.def_extern()
    def _marshal_image_progress(vi, pointer, handle):
        # the image we're passed is not reffed for us, so make a ref for us
        gobject_lib.g_object_ref(vi)
        image = pyvips.Image(vi)
        callback = ffi.from_handle(handle)
        progress = ffi.cast('VipsProgress*', pointer)
        callback(image, progress)
    _marshal_image_progress_cb = \
        ffi.cast('GCallback', gobject_lib._marshal_image_progress)
else:
    def _marshal_image_progress(vi, pointer, handle):
        # the image we're passed is not reffed for us, so make a ref for us
        gobject_lib.g_object_ref(vi)
        image = pyvips.Image(vi)
        callback = ffi.from_handle(handle)
        progress = ffi.cast('VipsProgress*', pointer)
        callback(image, progress)
    _marshal_image_progress_cb = \
        ffi.cast('GCallback',
                 ffi.callback('void(VipsImage*, void*, void*)',
                              _marshal_image_progress))

_marshalers = {
    'preeval': _marshal_image_progress_cb,
    'eval': _marshal_image_progress_cb,
github libvips / pyvips / pyvips / gobject.py View on Github external
buf = ffi.buffer(pointer, length)
            callback = ffi.from_handle(handle)
            return callback(buf)
        _marshal_read_cb = \
            ffi.cast('GCallback',
                     ffi.callback('gint64(VipsStreamiu*, void*, gint64, void*)',
                                  _marshal_read))
    _marshalers['read'] = _marshal_read_cb

    if pyvips.API_mode:
        @ffi.def_extern()
        def _marshal_seek(streamiu, offset, whence, handle):
            callback = ffi.from_handle(handle)
            return callback(offset, whence)
        _marshal_seek_cb = \
            ffi.cast('GCallback', gobject_lib._marshal_seek)
    else:
        def _marshal_seek(streamiu, offset, whence, handle):
            callback = ffi.from_handle(handle)
            return callback(offset, whence)
        _marshal_seek_cb = \
            ffi.cast('GCallback',
                     ffi.callback('gint64(VipsStreamiu*, gint64, int, void*)',
                                  _marshal_seek))
    _marshalers['seek'] = _marshal_seek_cb

    if pyvips.API_mode:
        @ffi.def_extern()
        def _marshal_write(streamiu, pointer, length, handle):
            buf = ffi.buffer(pointer, length)
            callback = ffi.from_handle(handle)
            result = callback(buf)
github libvips / pyvips / pyvips / vobject.py View on Github external
def set(self, name, value):
        """Set a GObject property.

        The value is converted to the property type, if possible.

        """

        logger.debug('VipsObject.set: name = %s, value = %s', name, value)

        gtype = self.get_typeof(name)

        gv = pyvips.GValue()
        gv.set_type(gtype)
        gv.set(value)
        go = ffi.cast('GObject *', self.pointer)
        gobject_lib.g_object_set_property(go, _to_bytes(name), gv.pointer)