// create curves layer with white, gray and black determined by three color samplers;
// 2025, use it at your own risk;
// call the function to run the script;
createCurveAdjustmetFromColorSamplers();
// create a function fo hold most of the code;
function createCurveAdjustmetFromColorSamplers(){
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDocument = activeDocument;
// needs an open document in a color mode that supports layers;
if(app.documents.length == 0 || ( app.activeDocument.mode != DocumentMode.RGB ) ){
alert('This script requires a document in RGB');
return;
}
// color sample;
var outputArray = new Array();
var theSamples = [[1000,40], [1000, 500], [1000, 960]];
// collect the samples;
for(var sampleIndex = 0; sampleIndex < theSamples.length; sampleIndex++ ){
var theSampler = myDocument.colorSamplers.add(theSamples[sampleIndex]);
outputArray.push(theSampler.color);
theSampler.remove()
}
// create arrays of the color values:
var theArray = [[], [], []];
for (var m = 0; m < outputArray.length; m++) {
theArray[0].push(Math.round(outputArray[m].rgb.red));
theArray[1].push(Math.round(outputArray[m].rgb.green));
theArray[2].push(Math.round(outputArray[m].rgb.blue));
};
// create the curves layer;
rgbCurvesLayer ([theArray[0], [0, 128, 255], theArray[1], [0, 128, 255], theArray[2], [0, 128, 255]]);
app.preferences.rulerUnits = originalRulerUnits;
};
////// make rgb curves layer //////
function rgbCurvesLayer (theArray) {
var idpresetKind = stringIDToTypeID( "presetKind" );
var idpresetKindType = stringIDToTypeID( "presetKindType" );
var idChnl = charIDToTypeID( "Chnl" );
var idCrv = charIDToTypeID( "Crv " );
var idCrvA = charIDToTypeID( "CrvA" );
var idAdjL = charIDToTypeID( "AdjL" );
// =======================================================
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
ref2.putClass( idAdjL );
desc5.putReference( idnull, ref2 );
var idUsng = charIDToTypeID( "Usng" );
var desc6 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc7 = new ActionDescriptor();
desc7.putEnumerated( idpresetKind, idpresetKindType, stringIDToTypeID( "presetKindDefault" ) );
desc6.putObject( idType, charIDToTypeID( "Crvs" ), desc7 );
var idAdjL = charIDToTypeID( "AdjL" );
desc5.putObject( idUsng, idAdjL, desc6 );
executeAction( charIDToTypeID( "Mk " ), desc5, DialogModes.NO );
// =======================================================
var desc8 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
ref3.putEnumerated( idAdjL, charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc8.putReference( idnull, ref3 );
var idT = charIDToTypeID( "T " );
var desc9 = new ActionDescriptor();
desc9.putEnumerated( idpresetKind, idpresetKindType, stringIDToTypeID( "presetKindCustom" ) );
var idAdjs = charIDToTypeID( "Adjs" );
var list1 = new ActionList();
var desc10 = new ActionDescriptor();
var ref4 = new ActionReference();
ref4.putEnumerated( idChnl, idChnl, charIDToTypeID( "Rd " ) );
desc10.putReference( idChnl, ref4 );
var list2 = new ActionList();
// add r points;
for (var m = 0; m < theArray[0].length; m++) {
addCurvePoint (list2, theArray[0][m], theArray[1][m])
};
desc10.putList( idCrv, list2 );
list1.putObject( idCrvA, desc10 );
var desc15 = new ActionDescriptor();
var ref5 = new ActionReference();
ref5.putEnumerated( idChnl, idChnl, charIDToTypeID( "Grn " ) );
desc15.putReference( idChnl, ref5 );
var list3 = new ActionList();
// add g points;
for (var m = 0; m < theArray[2].length; m++) {
addCurvePoint (list3, theArray[2][m], theArray[3][m])
};
desc15.putList( idCrv, list3 );
list1.putObject( idCrvA, desc15 );
var desc20 = new ActionDescriptor();
var ref6 = new ActionReference();
ref6.putEnumerated( idChnl, idChnl, charIDToTypeID( "Bl " ) );
desc20.putReference( idChnl, ref6 );
var list4 = new ActionList();
// add b points;
for (var m = 0; m < theArray[4].length; m++) {
addCurvePoint (list4, theArray[4][m], theArray[5][m])
};
desc20.putList( idCrv, list4 );
list1.putObject( idCrvA, desc20 );
desc9.putList( idAdjs, list1 );
desc8.putObject( idT, charIDToTypeID( "Crvs" ), desc9 );
executeAction( charIDToTypeID( "setd" ), desc8, DialogModes.NO );
//
return app.activeDocument.activeLayer;
////// add curve point //////
function addCurvePoint (theList, valueHor, valueVer) {
var desc11 = new ActionDescriptor();
desc11.putDouble( charIDToTypeID( "Hrzn" ), valueHor );
desc11.putDouble( charIDToTypeID( "Vrtc" ), valueVer );
theList.putObject( charIDToTypeID( "Pnt " ), desc11 );
};
};
... View more