-
-
Save p2or/1053fa9293d2498a0edaf924160b0dcf to your computer and use it in GitHub Desktop.
Unpremultiply the selected Photoshop layer #Nuke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set cut_paste_input [stack 0] | |
version 11.0 v1 | |
Read { | |
inputs 0 | |
file Untitled-1.psd | |
format "3881 1081 0 0 3881 1081 1 " | |
origset true | |
name Read6 | |
selected true | |
xpos 1335 | |
ypos -161 | |
} | |
Read { | |
inputs 0 | |
file Untitled-1.exr | |
format "3881 1081 0 0 3881 1081 1 " | |
origset true | |
name Read5 | |
selected true | |
xpos 1137 | |
ypos -169 | |
} | |
add_layer {Layer-01 Layer-01.red Layer-01.green Layer-01.blue Layer-01.alpha} | |
Shuffle { | |
in Layer-01 | |
name Shuffle3 | |
selected true | |
xpos 1137 | |
ypos -62 | |
} | |
Switch { | |
inputs 2 | |
which 1 | |
name Switch1 | |
selected true | |
xpos 1234 | |
ypos 30 | |
} | |
set Nb6252700 [stack 0] | |
Constant { | |
inputs 0 | |
channels rgb | |
color {1 0 0 0} | |
name Constant1 | |
selected true | |
xpos 988 | |
ypos 80 | |
} | |
set Nbe2ff880 [stack 0] | |
AddMix { | |
inputs 2 | |
name AddMix1 | |
selected true | |
xpos 1234 | |
ypos 103 | |
} | |
push $Nb6252700 | |
Dot { | |
name Dot2 | |
selected true | |
xpos 1490 | |
ypos 34 | |
} | |
Premult { | |
name Premult1 | |
selected true | |
xpos 1456 | |
ypos 240 | |
} | |
push $Nbe2ff880 | |
Dot { | |
name Dot1 | |
selected true | |
xpos 1022 | |
ypos 285 | |
} | |
Merge2 { | |
inputs 2 | |
name Merge1 | |
selected true | |
xpos 1456 | |
ypos 281 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Will unpremultiply the currently selected Photoshop layer | |
in order to export with: http://www.exr-io.com/ | |
*/ | |
var doc = app.activeDocument; | |
// Duplicate this layer | |
var premultLayer = app.activeDocument.activeLayer.duplicate(); | |
premultLayer.blendMode = BlendMode.NORMAL; | |
// Apply layer mask to the duplicate | |
// Create a black layer underneath the premult one | |
var beneathLayer = app.activeDocument.artLayers.add(); | |
doc.selection.selectAll(); | |
var blackColor = new SolidColor(); | |
blackColor.rgb.red = 0; | |
blackColor.rgb.green = 0; | |
blackColor.rgb.blue = 0; | |
doc.selection.fill(blackColor, ColorBlendMode.NORMAL, 100, false); | |
beneathLayer.move(premultLayer, ElementPlacement.PLACEAFTER); | |
// Create a black layer above the premult one | |
var aboveLayer = beneathLayer.duplicate(); | |
aboveLayer.move(premultLayer, ElementPlacement.PLACEBEFORE); | |
// Fill the premult opaque areas with white for the layer above | |
// Select transparency on the premult layer. Unfortunately we need the | |
// action ref abominations for that. | |
function SelectTransparency() | |
{ | |
var idChnl = charIDToTypeID( "Chnl" ); | |
var actionSelect = new ActionReference(); | |
actionSelect.putProperty( idChnl, charIDToTypeID( "fsel" ) ); | |
var actionTransparent = new ActionReference(); | |
actionTransparent.putEnumerated( idChnl, idChnl, charIDToTypeID( "Trsp" ) ); | |
var actionDesc = new ActionDescriptor(); | |
actionDesc.putReference( charIDToTypeID( "null" ), actionSelect ); | |
actionDesc.putReference( charIDToTypeID( "T " ), actionTransparent ); | |
executeAction( charIDToTypeID( "setd" ), actionDesc, DialogModes.NO ); | |
} | |
doc.activeLayer = premultLayer; | |
SelectTransparency(); | |
doc.activeLayer = aboveLayer; | |
var whiteColor = new SolidColor(); | |
whiteColor.rgb.red = 255; | |
whiteColor.rgb.green = 255; | |
whiteColor.rgb.blue = 255; | |
app.activeDocument.selection.fill(whiteColor, ColorBlendMode.NORMAL, 100, false); | |
// Set the layer above to "color dodge", preferably "divide" | |
aboveLayer.blendMode = BlendMode.COLORDODGE; | |
// Merge the cake of 3 layers together, using a layer set. | |
var unpremultSet = doc.layerSets.add(); | |
beneathLayer.move(unpremultSet, ElementPlacement.INSIDE); | |
premultLayer.move(unpremultSet, ElementPlacement.INSIDE); | |
aboveLayer.move(unpremultSet, ElementPlacement.INSIDE); | |
unpremultSet.merge(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment