Ejemplo n.º 1
0
// Close() is a wrapper around gdk_pixbuf_loader_close().
func (v *PixbufLoader) Close() error {
	var cerr *C.GError

	if ok := gobool(C.gdk_pixbuf_loader_close(v.Native(), &cerr)); !ok {
		defer C.g_error_free(cerr)
		return errors.New(C.GoString((*C.char)(C.error_get_message(cerr))))
	}
	return nil
}
Ejemplo n.º 2
0
// PixbufNewFromFileAtScale() is a wrapper around gdk_pixbuf_new_from_file_at_scale().
func PixbufNewFromFileAtScale(fileName string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
	var cerr *C.GError
	cstr := C.CString(fileName)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gdk_pixbuf_new_from_file_at_scale(cstr, C.int(width), C.int(height), gbool(preserveAspectRatio), &cerr)
	if c == nil {
		defer C.g_error_free(cerr)
		return nil, errors.New(C.GoString((*C.char)(C.error_get_message(cerr))))
	}
	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
	p := wrapPixbuf(obj)
	runtime.SetFinalizer(obj, (*glib.Object).Unref)
	return p, nil
}
Ejemplo n.º 3
0
// PixbufNewFromFile() is a wrapper around gdk_pixbuf_new_from_file().
func PixbufNewFromFile(fileName string) (*Pixbuf, error) {
	var cerr *C.GError
	cstr := C.CString(fileName)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gdk_pixbuf_new_from_file(cstr, &cerr)
	if c == nil {
		defer C.g_error_free(cerr)
		return nil, errors.New(C.GoString((*C.char)(C.error_get_message(cerr))))
	}
	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
	p := wrapPixbuf(obj)
	runtime.SetFinalizer(obj, (*glib.Object).Unref)
	return p, nil
}
Ejemplo n.º 4
0
// Write() is a wrapper around gdk_pixbuf_loader_write().
func (v *PixbufLoader) Write(data []byte) (n int, err error) {
	// n is set to 0 on error, and set to len(data) otherwise.
	// This is a tiny hacky to satisfy io.Writer and io.WriteCloser,
	// which would allow access to all io and ioutil goodies,
	// and play along nice with go environment.

	if len(data) == 0 {
		return 0, nil
	}

	var cerr *C.GError
	ok := gobool(C.gdk_pixbuf_loader_write(v.Native(), (*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)), &cerr))
	if !ok {
		defer C.g_error_free(cerr)
		return 0, errors.New(C.GoString((*C.char)(C.error_get_message(cerr))))
	}

	return len(data), nil
}