-
Notifications
You must be signed in to change notification settings - Fork 35
/
info.go
74 lines (64 loc) · 1.86 KB
/
info.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
package magick
// #include <string.h>
// #include <magick/api.h>
import "C"
import (
"runtime"
"unsafe"
)
// Info is used to specify the encoding parameters like
// format and quality when encoding and image.
type Info struct {
info *C.ImageInfo
}
// Format returns the format used for encoding the image.
func (in *Info) Format() string {
return C.GoString(&in.info.magick[0])
}
// SetFormat sets the image format for encoding this image.
// See http://www.graphicsmagick.org for a list of supported
// formats.
func (in *Info) SetFormat(format string) {
if format == "" {
in.info.magick[0] = 0
} else {
s := C.CString(format)
defer C.free(unsafe.Pointer(s))
C.strncpy(&in.info.magick[0], s, C.MaxTextExtent)
}
}
// Quality returns the quality used when compressing the image.
// This parameter does not affect all formats.
func (in *Info) Quality() uint {
return uint(in.info.quality)
}
// SetQuality sets the quality used when compressing the image.
// This parameter does not affect all formats.
func (in *Info) SetQuality(q uint) {
in.info.quality = magickSize(q)
}
// Colorspace returns the colorspace used when encoding the image.
func (in *Info) Colorspace() Colorspace {
return Colorspace(in.info.colorspace)
}
// SetColorspace set the colorspace used when encoding the image.
// Note that not all colorspaces are supported for encoding. See
// the documentation on Colorspace.
func (in *Info) SetColorspace(cs Colorspace) {
in.info.colorspace = C.ColorspaceType(cs)
}
// NewInfo returns a newly allocated *Info structure. Do not
// create Info objects directly, since they need to allocate
// some internal structures while being created.
func NewInfo() *Info {
cinfo := C.CloneImageInfo(nil)
info := new(Info)
info.info = cinfo
runtime.SetFinalizer(info, func(i *Info) {
if i.info != nil {
C.DestroyImageInfo(i.info)
i.info = nil
}
})
return info
}