-
Notifications
You must be signed in to change notification settings - Fork 22
/
Apply Colour File To Colorista Free.jsx
231 lines (196 loc) · 6.13 KB
/
Apply Colour File To Colorista Free.jsx
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
* Applies a colour file to colorista free
*
* Prompts user to select a .cdl or .ccc file.
*
* IF LAYER SELECTED:
* - Tries to find Colorista Free on the layer
* - If it finds it, updates the values from the CDL/CCC
* - If it doesn't find it, acts like NO LAYER SELECTED
* IF NO LAYER SELECTED:
* - Creates an adjustment layer in the active comp,
* - Applies Red Giant Colorista Free (http://redgiant.com/downloads/legacy-versions)
* - Applies the CDL/CCC as values to it.
*
* @author Zack Lovatt <[email protected]>
* @version 1.2.1
*/
(function applyColourFileToColoristaFree() {
app.beginUndoGroup("Apply Colour File to Colorista Free");
try {
var colourFile = getColourFile();
var colourContents = readFile(colourFile);
var colourObj = buildColourObject(colourContents);
var comp = app.project.activeItem;
if (!(comp && comp instanceof CompItem)) {
throw "Open a comp!";
}
var layer = comp.selectedLayers[0];
var foundEffect = false;
var coloristaEffect;
if (!layer) {
coloristaEffect = findEffect(layer, "RG MBCC CDL");
if (coloristaEffect.length > 0) {
setColoristaValues(coloristaEffect[0], colourObj);
foundEffect = true;
}
}
if (!layer || !foundEffect) {
layer = comp.layers.addSolid(
[0, 0, 0],
colourObj.name,
comp.width,
comp.height,
comp.pixelAspect,
comp.duration
);
layer.adjustmentLayer = true;
coloristaEffect = addEffect(layer, "RG MBCC CDL");
setColoristaValues(coloristaEffect, colourObj);
}
} catch (e) {
alert(e);
} finally {
app.endUndoGroup();
}
/**
* Sets Colorista effect values to those from colourObj
*
* @param {Effect} coloristaEffect - Colorista Object
* @param {any} colourObj - Colour data object from file
*/
function setColoristaValues(coloristaEffect, colourObj) {
coloristaEffect
.property("RG MBCC CDL-0002")
.setValue(parseFloat(colourObj.saturation));
// Slope
coloristaEffect
.property("RG MBCC CDL-0004")
.setValue(parseFloat(colourObj.slope[0]));
coloristaEffect
.property("RG MBCC CDL-0005")
.setValue(parseFloat(colourObj.slope[1]));
coloristaEffect
.property("RG MBCC CDL-0006")
.setValue(parseFloat(colourObj.slope[2]));
// Offset
coloristaEffect
.property("RG MBCC CDL-0007")
.setValue(parseFloat(colourObj.offset[0]));
coloristaEffect
.property("RG MBCC CDL-0008")
.setValue(parseFloat(colourObj.offset[1]));
coloristaEffect
.property("RG MBCC CDL-0009")
.setValue(parseFloat(colourObj.offset[2]));
// Power
coloristaEffect
.property("RG MBCC CDL-0010")
.setValue(parseFloat(colourObj.power[0]));
coloristaEffect
.property("RG MBCC CDL-0011")
.setValue(parseFloat(colourObj.power[1]));
coloristaEffect
.property("RG MBCC CDL-0012")
.setValue(parseFloat(colourObj.power[2]));
}
/**
* Reads a file, returns contents
*
* @param {File} file File to read
* @returns {String} File contents
*/
function readFile(file) {
if (!file.exists) {
throw "File " + file.fullName + " does not exist!";
}
file.open("r");
var content = file.read();
file.close();
if (!content) {
throw "Can't read file " + file.fullName;
}
return content;
}
/**
* Prompts user to select a cdl or ccc file
*
* @returns {File} CDL/CCC file
*/
function getColourFile() {
var colourFile = File.openDialog("Select CDL/CCC", "*.cdl;*.ccc");
var extension = colourFile.fullName.split(".")[
colourFile.fullName.split(".").length - 1
];
if (extension !== "cdl" && extension !== "ccc") {
throw "File " + colourFile.fullName + " doesn't seem to be a cdl or ccc!";
}
return colourFile;
}
/**
* Builds a colour data object from file contents
*
* @param {String} colourContents - Colour file XML contents
* @returns {any} - Colour data object from file
*/
function buildColourObject(colourContents) {
var root = new XML(colourContents);
var isCCC = colourContents.indexOf("ColorCorrectionCollection") > -1;
if (isCCC) {
colourContents = colourContents.replace(/ xmlns='.+'/, "");
root = new XML(colourContents).ColorCorrection;
}
if (root.SOPNode === "" || root.SatNode === "") {
throw "Colour File seems to be corrupted!";
}
var colourObj = {
name: String(isCCC ? root.attributes() : root.SOPNode.Description),
slope: root.SOPNode.Slope.split(" "),
offset: root.SOPNode.Offset.split(" "),
power: root.SOPNode.Power.split(" "),
saturation: String(root.SatNode.Saturation),
};
return colourObj;
}
/**
* Adds an effect to a layer
*
* @param {Layer} layer - Layer to add effect to
* @param {String} effectName - Effect matchname to add
* @returns {Effect} - Newly-created effect
*/
function addEffect(layer, effectName) {
if (!(layer instanceof AVLayer)) {
throw String(layer) + " is not a valid layer!";
}
var effectGroup = layer.property("ADBE Effect Parade");
if (effectGroup.canAddProperty(effectName)) {
return effectGroup.addProperty(effectName);
}
throw [
"Can't add " + effectName + " to " + layer.name + ".",
"Ensure you have effect " + effectName + " installed.",
].join("\n");
}
/**
* Finds an effect on a layer
*
* @param {Layer} layer - Layer to add effect to
* @param {String} effectName - Effect matchname to add
* @returns {Effect} - Newly-created effect
*/
function findEffect(layer, effectName) {
if (!(layer instanceof AVLayer)) {
throw String(layer) + " is not a valid layer!";
}
var effectGroup = layer.property("ADBE Effect Parade");
var foundEffects = [];
for (var ii = 1, il = effectGroup.numProperties; ii <= il; ii++) {
var effect = effectGroup(ii);
if (effect.matchName === effectName || effect.name === effectName) {
foundEffects.push(effect);
}
}
return foundEffects;
}
})();