-
Notifications
You must be signed in to change notification settings - Fork 35
/
magick_gm.go
66 lines (53 loc) · 1.23 KB
/
magick_gm.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
// +build gm
package magick
// #cgo pkg-config: GraphicsMagick
// #cgo CFLAGS: -D_MAGICK_USES_GM
// #cgo LDFLAGS: -lm
// #include <magick/api.h>
import "C"
import (
"fmt"
"reflect"
"unsafe"
)
var (
backend = "GraphicsMagick"
)
func magickBool(flag bool) C.int {
if flag {
return 1
}
return 0
}
func magickLong(v int) C.long {
return C.long(v)
}
func magickSize(v uint) C.ulong {
return C.ulong(v)
}
func magickUint(v uint) C.uint {
return C.uint(v)
}
func imageToBlob(info *Info, im *Image, s *C.size_t, ex *C.ExceptionInfo) unsafe.Pointer {
return C.ImageToBlob(info.info, im.image, s, ex)
}
func freeMagickMemory(p unsafe.Pointer) {
C.MagickFree(p)
}
func supportedFormats(ex *C.ExceptionInfo) ([]*C.MagickInfo, unsafe.Pointer) {
info := C.GetMagickInfoArray(ex)
if info == nil {
return nil, nil
}
var infos []*C.MagickInfo
header := (*reflect.SliceHeader)(unsafe.Pointer(&infos))
header.Len = 10000
header.Cap = header.Len
p := unsafe.Pointer(info)
header.Data = uintptr(p)
return infos, p
}
type notImplementedError string
func (e notImplementedError) Error() string {
return fmt.Sprintf("magick does not implement %s when built against GraphicsMagick. Build magick against ImageMagick to use it.", string(e))
}