forked from gotk3/gotk3
/
gdk_pixbuf_format.go
89 lines (74 loc) · 2.09 KB
/
gdk_pixbuf_format.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gdk
// #include <gdk/gdk.h>
// #include "gdk.go.h"
import "C"
import (
"unsafe"
"github.com/gotk3/gotk3/glib"
)
type PixbufFormat struct {
format *C.GdkPixbufFormat
}
// native returns a pointer to the underlying GdkPixbuf.
func (v *PixbufFormat) native() *C.GdkPixbufFormat {
if v == nil {
return nil
}
return v.format
}
// Native returns a pointer to the underlying GdkPixbuf.
func (v *PixbufFormat) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
func (f *PixbufFormat) GetName() (string, error) {
c := C.gdk_pixbuf_format_get_name(f.native())
return C.GoString((*C.char)(c)), nil
}
func (f *PixbufFormat) GetDescription() (string, error) {
c := C.gdk_pixbuf_format_get_description(f.native())
return C.GoString((*C.char)(c)), nil
}
func (f *PixbufFormat) GetLicense() (string, error) {
c := C.gdk_pixbuf_format_get_license(f.native())
return C.GoString((*C.char)(c)), nil
}
// GetMimeTypes is a wrapper around gdk_pixbuf_format_get_mime_types().
func (f *PixbufFormat) GetMimeTypes() []string {
var types []string
c := C.gdk_pixbuf_format_get_mime_types(f.native())
if c == nil {
return nil
}
for *c != nil {
types = append(types, C.GoString((*C.char)(*c)))
c = C.next_gcharptr(c)
}
return types
}
// GetExtensions is a wrapper around gdk_pixbuf_format_get_extensions().
func (f *PixbufFormat) GetExtensions() []string {
var extensions []string
c := C.gdk_pixbuf_format_get_extensions(f.native())
if c == nil {
return nil
}
for *c != nil {
extensions = append(extensions, C.GoString((*C.char)(*c)))
c = C.next_gcharptr(c)
}
return extensions
}
func PixbufGetFormats() []*PixbufFormat {
l := (*C.struct__GSList)(C.gdk_pixbuf_get_formats())
formats := glib.WrapSList(uintptr(unsafe.Pointer(l)))
if formats == nil {
return nil // no error. A nil list is considered to be empty.
}
// "The structures themselves are owned by GdkPixbuf". Free the list only.
defer formats.Free()
ret := make([]*PixbufFormat, 0, formats.Length())
formats.Foreach(func(ptr unsafe.Pointer) {
ret = append(ret, &PixbufFormat{(*C.GdkPixbufFormat)(ptr)})
})
return ret
}