-
Notifications
You must be signed in to change notification settings - Fork 1
/
transform.go
176 lines (149 loc) · 4.94 KB
/
transform.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package ocio
/*
#include "stdlib.h"
#include "ocio.h"
*/
import "C"
import (
"runtime"
"unsafe"
)
type TransformDirection int
const (
TRANSFORM_DIR_UNKNOWN TransformDirection = C.TRANSFORM_DIR_UNKNOWN
TRANSFORM_DIR_FORWARD TransformDirection = C.TRANSFORM_DIR_FORWARD
TRANSFORM_DIR_INVERSE TransformDirection = C.TRANSFORM_DIR_INVERSE
)
// Transform interface represents the different types of
// concrete transform types that can be passed into API calls
type Transform interface {
transformHandle() C.HandleId
}
type DisplayTransform struct {
ptr C.DisplayTransformId
}
func newDisplayTransform(p C.DisplayTransformId) *DisplayTransform {
tx := &DisplayTransform{p}
runtime.SetFinalizer(tx, deleteDisplayTransform)
return tx
}
func deleteDisplayTransform(tx *DisplayTransform) {
if tx == nil {
return
}
if tx.ptr != 0 {
runtime.SetFinalizer(tx, nil)
C.deleteDisplayTransform(tx.ptr)
tx.ptr = 0
}
runtime.KeepAlive(tx)
}
// Create a new empty DisplayTransform
func NewDisplayTransform() *DisplayTransform {
return newDisplayTransform(C.DisplayTransform_Create())
}
// Destroy immediately frees resources for this
// instance instead of waiting for garbage collection
// finalizer to run at some point later
func (tx *DisplayTransform) Destroy() {
deleteDisplayTransform(tx)
}
func (tx *DisplayTransform) transformHandle() C.HandleId {
return tx.ptr
}
// Create a new editable copy of this DisplayTransform
func (tx *DisplayTransform) EditableCopy() *DisplayTransform {
cpy := newDisplayTransform(C.DisplayTransform_createEditableCopy(tx.ptr))
runtime.KeepAlive(tx)
return cpy
}
func (tx *DisplayTransform) Direction() TransformDirection {
dir := TransformDirection(C.DisplayTransform_getDirection(tx.ptr))
runtime.KeepAlive(tx)
return dir
}
func (tx *DisplayTransform) SetDirection(dir TransformDirection) {
C.DisplayTransform_setDirection(tx.ptr, C.TransformDirection(dir))
runtime.KeepAlive(tx)
}
// InputColorSpace returns the incoming color space
func (tx *DisplayTransform) InputColorSpace() string {
cs := C.GoString(C.DisplayTransform_getInputColorSpaceName(tx.ptr))
runtime.KeepAlive(tx)
return cs
}
// SetInputColorSpace sets the incoming color space
func (tx *DisplayTransform) SetInputColorSpace(cs string) {
c_str := C.CString(cs)
defer C.free(unsafe.Pointer(c_str))
C.DisplayTransform_setInputColorSpaceName(tx.ptr, c_str)
runtime.KeepAlive(tx)
runtime.KeepAlive(c_str)
}
// Display returns the output display transform.
func (tx *DisplayTransform) Display() string {
name := C.GoString(C.DisplayTransform_getDisplay(tx.ptr))
runtime.KeepAlive(tx)
return name
}
// SetDisplay sets the output display transform.
// This is controlled by the specification of (display, view).
func (tx *DisplayTransform) SetDisplay(name string) {
c_str := C.CString(name)
defer C.free(unsafe.Pointer(c_str))
C.DisplayTransform_setDisplay(tx.ptr, c_str)
runtime.KeepAlive(tx)
runtime.KeepAlive(c_str)
}
// View returns the view transform to use
func (tx *DisplayTransform) View() string {
name := C.GoString(C.DisplayTransform_getView(tx.ptr))
runtime.KeepAlive(tx)
return name
}
// SetView: Specify which view transform to use
func (tx *DisplayTransform) SetView(name string) {
c_str := C.CString(name)
defer C.free(unsafe.Pointer(c_str))
C.DisplayTransform_setView(tx.ptr, c_str)
runtime.KeepAlive(tx)
runtime.KeepAlive(c_str)
}
func (tx *DisplayTransform) LooksOverride() string {
looks := C.GoString(C.DisplayTransform_getLooksOverride(tx.ptr))
runtime.KeepAlive(tx)
return looks
}
/*
A user can optionally override the looks that are, by default,
used with the expected display / view combination. A common
use case for this functionality is in an image viewing app,
where per-shot looks are supported. If for some reason a per-shot
look is not defined for the current Context, the Config.Processor()
function will not succeed by default. Thus, with this mechanism the
viewing app could override to looks = "", and this will allow image
display to continue (though hopefully) the interface would reflect
this fallback option).
Looks is a potentially comma (or colon) delimited list of lookNames,
where +/- prefixes are optionally allowed to denote forward/inverse
look specification (And forward is assumed in the absence of either).
*/
func (tx *DisplayTransform) SetLooksOverride(looks string) {
c_str := C.CString(looks)
defer C.free(unsafe.Pointer(c_str))
C.DisplayTransform_setLooksOverride(tx.ptr, c_str)
runtime.KeepAlive(tx)
runtime.KeepAlive(c_str)
}
func (tx *DisplayTransform) LooksOverrideEnabled() bool {
enabled := C.DisplayTransform_getLooksOverrideEnabled(tx.ptr)
runtime.KeepAlive(tx)
return bool(enabled)
}
// SetLooksOverrideEnabled specifies whether the lookOverride should
// be used or not. This is a separate flag, as it's often useful to
// override "looks" to an empty string
func (tx *DisplayTransform) SetLooksOverrideEnabled(enabled bool) {
C.DisplayTransform_setLooksOverrideEnabled(tx.ptr, C.bool(enabled))
runtime.KeepAlive(tx)
}