欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【photoshop Action Manager】动作管理器- 获取调整图层信息

程序员文章站 2022-05-19 15:56:03
...

1.获取调整图层亮度对比度



var ref = new ActionReference();  
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );   
var layerDesc = executeActionGet(ref);  
var adjList = layerDesc.getList(stringIDToTypeID('adjustment'));  
 var theColors = adjList.getObjectValue(0);
 var rawData=theColors.getData(theColors.getKey(0)); 
 
 var val="",valtemp="";
 for(var _i=0;_i<rawData.length;_i++)
 {
     valtemp=rawData.charCodeAt(_i);
  //  if(valtemp>127) valtemp = 0xFFFFFF00^valtemp;
     val=val+"\t"+valtemp;
  }
alert(rawData.toSource()+"\n"+val,"data analysis ")
 
var brightness = rawData.charCodeAt(1); 
alert(rawData.length)
if(brightness>127) brightness = 0xFFFFFF00^brightness;// check sign  
var contrast = rawData.charCodeAt(3);  
alert(contrast)
if(contrast>127) contrast = 0xFFFFFF00^contrast;  
alert('The brightness is '+brightness+'\rContrast is '+contrast+"\n"+rawData.toSource());
 

必须勾选使用旧版才能获取成功

【photoshop Action Manager】动作管理器- 获取调整图层信息

2.获取调整图层色相饱和度

function getHueSatAdjustment(){     
      var ref = new ActionReference();
     ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
     var desc = executeActionGet(ref).getList(stringIDToTypeID('adjustment')).getObjectValue(0);
     var rawData = desc.getData(stringIDToTypeID('legacyContentData'));
      var hueSatAdjustment = {};
      hueSatAdjustment.isColorized = Boolean(readInteger(rawData, 2));
         hueSatAdjustment.colorized = {};
       hueSatAdjustment.colorized.hue = readAngle(rawData, 4);
       hueSatAdjustment.colorized.sat = readInteger(rawData, 6);
       hueSatAdjustment.colorized.brightness = readInteger(rawData, 8);
       hueSatAdjustment.master = {};
       hueSatAdjustment.master.hue = readInteger(rawData, 10);
       hueSatAdjustment.master.sat = readInteger(rawData, 12);
       hueSatAdjustment.master.brightness = readInteger(rawData, 14);
       hueSatAdjustment.reds = {};
       hueSatAdjustment.reds.beginRamp = readInteger(rawData, 16);
       hueSatAdjustment.reds.beginSustain = readInteger(rawData, 18);
       hueSatAdjustment.reds.endSustain = readInteger(rawData, 20);
       hueSatAdjustment.reds.endRamp = readInteger(rawData, 22);
       hueSatAdjustment.reds.hue = readInteger(rawData, 24);
       hueSatAdjustment.reds.sat = readInteger(rawData, 26);
       hueSatAdjustment.reds.brightness = readInteger(rawData, 28);
       hueSatAdjustment.yellows = {};
       hueSatAdjustment.yellows.beginRamp = readInteger(rawData, 30);
       hueSatAdjustment.yellows.beginSustain = readInteger(rawData, 32);
       hueSatAdjustment.yellows.endSustain = readInteger(rawData, 34);
       hueSatAdjustment.yellows.endRamp = readInteger(rawData, 36);
       hueSatAdjustment.yellows.hue = readInteger(rawData, 38);
       hueSatAdjustment.yellows.sat = readInteger(rawData, 40);
       hueSatAdjustment.yellows.brightness = readInteger(rawData, 42);
       hueSatAdjustment.greens = {};
       hueSatAdjustment.greens.beginRamp = readInteger(rawData, 44);
       hueSatAdjustment.greens.beginSustain = readInteger(rawData, 46);
       hueSatAdjustment.greens.endSustain = readInteger(rawData, 48);
       hueSatAdjustment.greens.endRamp = readInteger(rawData, 50);
       hueSatAdjustment.greens.hue = readInteger(rawData, 52);
       hueSatAdjustment.greens.sat = readInteger(rawData, 54);
       hueSatAdjustment.greens.brightness = readInteger(rawData, 56);
       hueSatAdjustment.cyans = {};
       hueSatAdjustment.cyans.beginRamp = readInteger(rawData, 58);
       hueSatAdjustment.cyans.beginSustain = readInteger(rawData, 60);
       hueSatAdjustment.cyans.endSustain = readInteger(rawData, 62);
       hueSatAdjustment.cyans.endRamp = readInteger(rawData, 64);
       hueSatAdjustment.cyans.hue = readInteger(rawData, 66);
       hueSatAdjustment.cyans.sat = readInteger(rawData, 68);
       hueSatAdjustment.cyans.brightness = readInteger(rawData, 70);
          hueSatAdjustment.blues = {};
          hueSatAdjustment.blues.beginRamp = readInteger(rawData, 72);
       hueSatAdjustment.blues.beginSustain = readInteger(rawData, 74);
       hueSatAdjustment.blues.endSustain = readInteger(rawData, 76);
       hueSatAdjustment.blues.endRamp = readInteger(rawData, 78);
       hueSatAdjustment.blues.hue = readInteger(rawData, 80);
       hueSatAdjustment.blues.sat = readInteger(rawData, 82);
       hueSatAdjustment.blues.brightness = readInteger(rawData, 84);
       hueSatAdjustment.magentas = {};
       hueSatAdjustment.magentas.beginRamp = readInteger(rawData, 86);
       hueSatAdjustment.magentas.beginSustain = readInteger(rawData, 88);
       hueSatAdjustment.magentas.endSustain = readInteger(rawData, 90);
       hueSatAdjustment.magentas.endRamp = readInteger(rawData, 92);       
       hueSatAdjustment.magentas.hue = readInteger(rawData, 94);
       hueSatAdjustment.magentas.sat = readInteger(rawData, 96);
       hueSatAdjustment.magentas.brightness = readInteger(rawData, 98);
       return hueSatAdjustment;
};
function readInteger(str, pointer) { 
    var byte1 = str.charCodeAt(pointer);
    var byte2 = str.charCodeAt(pointer + 1);
    var singedsShort = (byte1 <<8) + byte2;
    if (singedsShort > 0x7FFF) {
        singedsShort = 0xFFFF0000 ^ singedsShort;
    }
    return singedsShort;
}
function readAngle(str, pointer) { 
   var b1 = str.charCodeAt(pointer);
   var b2 = str.charCodeAt(pointer+1);
   if(b1==0){
      var ss = b2;
   }else{
      var ss = b2+104;//???
   }
  return ss;
};
 
function writeObj(obj){ 
 var description = ""; 
 for(var i in obj){ 
 var property=obj[i]; 
 description+=i+" = "+property+"\n"; 
 } 
 alert(description); 
} 


   var getInfo= getHueSatAdjustment()
   var property = "";
    for (var item in getInfo) {

        //如果该对象中还有对象就遍历一遍
        if (getInfo[item] instanceof Object) {
            for (var itemobject in getInfo[item]) {
                property += "对象属性:" + itemobject + "  :" + getInfo[item][itemobject] + "\n";
            }
        }
        property += "属性:" + item + "数值:" + getInfo[item] + "\n";
    }
alert(property)
 

【photoshop Action Manager】动作管理器- 获取调整图层信息