-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcontentawarebatch.jsx
197 lines (196 loc) · 7.57 KB
/
contentawarebatch.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
// Content Aware Batch Script
// 1. Run the script
// 2. Select source footage sequence folder (TIFFs are nice)
// 3. Select mask sequence folder (Alpha matte PNGs are fine)
// 4. Wait
// Hold ESC if you want to stop the process
// This script saves TIFF-files, bit-depth is source depended
// open file function
function openImageFile(file) {
var idOpn = charIDToTypeID( "Opn " );
var desc78 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc78.putPath( idnull, file );
executeAction( idOpn, desc78, DialogModes.NO );
}
// close file function
function closeFile() {
var idCls = charIDToTypeID( "Cls " );
var desc874 = new ActionDescriptor();
var idDocI = charIDToTypeID( "DocI" );
desc874.putInteger( idDocI, 242 );
var idforceNotify = stringIDToTypeID( "forceNotify" );
desc874.putBoolean( idforceNotify, true );
executeAction( idCls, desc874, DialogModes.NO );
}
// merge documents function
function mergeDocuments(destName) {
var idDplc = charIDToTypeID( "Dplc" );
var desc872 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref45 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref45.putEnumerated( idLyr, idOrdn, idTrgt );
desc872.putReference( idnull, ref45 );
var idT = charIDToTypeID( "T " );
var ref46 = new ActionReference();
var idDcmn = charIDToTypeID( "Dcmn" );
ref46.putName( idDcmn, destName );
desc872.putReference( idT, ref46 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc872.putInteger( idVrsn, 5 );
var idIdnt = charIDToTypeID( "Idnt" );
var list12 = new ActionList();
list12.putInteger( 2 );
desc872.putList( idIdnt, list12 );
executeAction( idDplc, desc872, DialogModes.NO );
}
// create a mask selection
function selectMask() {
var idsetd = charIDToTypeID( "setd" );
var desc432 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref14 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref14.putProperty( idChnl, idfsel );
desc432.putReference( idnull, ref14 );
var idT = charIDToTypeID( "T " );
var ref15 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idTrsp = charIDToTypeID( "Trsp" );
ref15.putEnumerated( idChnl, idChnl, idTrsp );
desc432.putReference( idT, ref15 );
executeAction( idsetd, desc432, DialogModes.NO );
}
// content aware tool
function contentAware() {
var idFl = charIDToTypeID( "Fl " );
var desc12 = new ActionDescriptor();
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idcontentAware = stringIDToTypeID( "contentAware" );
desc12.putEnumerated( idUsng, idFlCn, idcontentAware );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc12.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc12.putEnumerated( idMd, idBlnM, idNrml );
executeAction( idFl, desc12, DialogModes.NO );
}
// select layer function
function selectLayer(layerName) {
var idslct = charIDToTypeID( "slct" );
var desc433 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref16 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref16.putName( idLyr, layerName );
desc433.putReference( idnull, ref16 );
var idMkVs = charIDToTypeID( "MkVs" );
desc433.putBoolean( idMkVs, false );
var idLyrI = charIDToTypeID( "LyrI" );
var list6 = new ActionList();
list6.putInteger( 1 );
desc433.putList( idLyrI, list6 );
executeAction( idslct, desc433, DialogModes.NO );
}
// deselect selection function
function deSelect() {
var idsetd = charIDToTypeID( "setd" );
var desc889 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref51 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref51.putProperty( idChnl, idfsel );
desc889.putReference( idnull, ref51 );
var idT = charIDToTypeID( "T " );
var idOrdn = charIDToTypeID( "Ordn" );
var idNone = charIDToTypeID( "None" );
desc889.putEnumerated( idT, idOrdn, idNone );
executeAction( idsetd, desc889, DialogModes.NO );
}
// delete layer
function deleteLayer() {
var idDlt = charIDToTypeID( "Dlt " );
var desc895 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref56 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref56.putEnumerated( idLyr, idOrdn, idTrgt );
desc895.putReference( idnull, ref56 );
var idLyrI = charIDToTypeID( "LyrI" );
var list17 = new ActionList();
list17.putInteger( 2 );
desc895.putList( idLyrI, list17 );
executeAction( idDlt, desc895, DialogModes.NO );
}
// save file function
function saveImageFile(file) {
var idsave = charIDToTypeID( "save" );
var desc20 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc21 = new ActionDescriptor();
var idBytO = charIDToTypeID( "BytO" );
var idPltf = charIDToTypeID( "Pltf" );
var idIBMP = charIDToTypeID( "IBMP" );
desc21.putEnumerated( idBytO, idPltf, idIBMP );
var idLZWC = charIDToTypeID( "LZWC" );
desc21.putBoolean( idLZWC, true );
var idTIFF = charIDToTypeID( "TIFF" );
desc20.putObject( idAs, idTIFF, desc21 );
var idIn = charIDToTypeID( "In " );
desc20.putPath( idIn, file );
var idDocI = charIDToTypeID( "DocI" );
desc20.putInteger( idDocI, 195 );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc20.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc20, DialogModes.NO );
}
// run function
function run(){
for (var i = 0; i < footageFiles.length; i++) {
if (footageFiles[i] instanceof File){
openImageFile(footageFiles[i]);
var footageDocument = app.activeDocument;
var bgLayer = footageDocument.activeLayer.name;
openImageFile(maskFiles[i]);
var maskDocument = app.activeDocument;
mergeDocuments(footageDocument.name);
closeFile();
var maskLayer = footageDocument.activeLayer.name;
selectMask();
selectLayer(bgLayer);
contentAware();
selectLayer(maskLayer);
deSelect();
deleteLayer();
var processedFolder = Folder(saveFolderPath);
if (!processedFolder.exists) {
processedFolder.create();
}
saveImageFile(new File(saveFolderPath + "/ca_" +footageDocument.name));
closeFile();
}
}
alert("Processing done!");
}
//var currentFolder = Folder.current;
var footageFolder = Folder.selectDialog("Select source footage folder:");
var footageFolderPath = footageFolder.fsName.replace(/\\/g,'/') + "/";
var saveFolderPath = footageFolder.parent.fsName.replace(/\\/g,'/') + "/result";
var maskFolder = Folder.selectDialog("Select mask folder:");
var maskFolderPath = maskFolder.fsName.replace(/\\/g,'/') + "/";
var footageFiles = Folder(footageFolderPath).getFiles();
var maskFiles = Folder(maskFolderPath).getFiles();
run();