回答我自己的问题:可以返回“平衡”颜色的值。这不是一个优雅的解决方案:
colourBalanceLayer("C0FFEE", 100,0,0);
function colourBalanceLayer(hexcol, cya, mag, yel)
{
var pixH = 10;
var pixV = 10;
// create a document to work with
var docRef = app.documents.add(pixH *2, pixV *2, 72, "colours")
var newDoc = app.activeDocument;
// =======================================================
var id70 = charIDToTypeID( "Fl " );
var desc18 = new ActionDescriptor();
var id71 = charIDToTypeID( "From" );
var desc19 = new ActionDescriptor();
var id72 = charIDToTypeID( "Hrzn" );
var id73 = charIDToTypeID( "#Pxl" );
desc19.putUnitDouble( id72, id73, 10.000000 );
var id74 = charIDToTypeID( "Vrtc" );
var id75 = charIDToTypeID( "#Pxl" );
desc19.putUnitDouble( id74, id75, 9.000000 );
var id76 = charIDToTypeID( "Pnt " );
desc18.putObject( id71, id76, desc19 );
var id77 = charIDToTypeID( "Tlrn" );
desc18.putInteger( id77, 32 );
var id78 = charIDToTypeID( "AntA" );
desc18.putBoolean( id78, true );
var id79 = charIDToTypeID( "Usng" );
var id80 = charIDToTypeID( "FlCn" );
var id81 = charIDToTypeID( "FrgC" );
desc18.putEnumerated( id79, id80, id81 );
executeAction( id70, desc18, DialogModes.NO );
// cyan, magenta, yellow values are between -100 & +100
var id713 = charIDToTypeID( "ClrB" );
var desc162 = new ActionDescriptor();
var id714 = charIDToTypeID( "ShdL" );
var list37 = new ActionList();
list37.putInteger( 0 );
list37.putInteger( 0 );
list37.putInteger( 0 );
desc162.putList( id714, list37 );
var id715 = charIDToTypeID( "MdtL" );
var list38 = new ActionList();
list38.putInteger( cya );
list38.putInteger( mag );
list38.putInteger( yel );
desc162.putList( id715, list38 );
var id716 = charIDToTypeID( "HghL" );
var list39 = new ActionList();
list39.putInteger( 0 );
list39.putInteger( 0 );
list39.putInteger( 0 );
desc162.putList( id716, list39 );
var id717 = charIDToTypeID( "PrsL" );
desc162.putBoolean( id717, true );
executeAction( id713, desc162, DialogModes.NO );
// =======================================================
var id40 = charIDToTypeID( "setd" );
var desc11 = new ActionDescriptor();
var id41 = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var id42 = charIDToTypeID( "Clr " );
var id43 = charIDToTypeID( "FrgC" );
ref5.putProperty( id42, id43 );
desc11.putReference( id41, ref5 );
var id44 = charIDToTypeID( "T " );
var desc12 = new ActionDescriptor();
var id45 = charIDToTypeID( "Rd " );
desc12.putDouble( id45, 255.000000 );
var id46 = charIDToTypeID( "Grn " );
desc12.putDouble( id46, 255.000000 );
var id47 = charIDToTypeID( "Bl " );
desc12.putDouble( id47, 255.000000 );
var id48 = charIDToTypeID( "RGBC" );
desc11.putObject( id44, id48, desc12 );
executeAction( id40, desc11, DialogModes.NO );
var selRegion = null;
selRegion = Array(Array(pixH, pixV),
Array(pixH + 1, pixV),
Array(pixH + 1, pixV + 1),
Array(pixH, pixV + 1),
Array(pixH, pixV));
newDoc.selection.select(selRegion);
var histR = newDoc.channels.getByName("Red").histogram;
var histG = newDoc.channels.getByName("Green").histogram;
var histB = newDoc.channels.getByName("Blue").histogram;
var returnColor = new RGBColor();
for (iHistR in histR)
{
if (histR[iHistR]!=0)
{
returnColor.red = iHistR;
}
}
for (iHistG in histG)
{
if(histG[iHistG]!=0)
{
returnColor.green = iHistG;
}
}
for (iHistB in histB)
{
if(histB[iHistB]!=0)
{
returnColor.blue = iHistB;
}
}
alert(returnColor.red+","+returnColor.green+","+returnColor.blue);
return returnColor;
}