5 Replies Latest reply on Feb 27, 2013 7:18 PM by sflisher

    Query Curves Layer for current settings

    sflisher

      Hi All,

       

      I am trying to work out how to query a curves layer for it's current settings. I have used the script listner to capture the code on how to apply settings but can't work out how to query the settings. The output from the script listner when applying new settings is as follows:

       

      // =======================================================

      var idsetd = charIDToTypeID( "setd" );

          var desc19 = new ActionDescriptor();

          var idnull = charIDToTypeID( "null" );

              var ref13 = new ActionReference();

              var idAdjL = charIDToTypeID( "AdjL" );

              var idOrdn = charIDToTypeID( "Ordn" );

              var idTrgt = charIDToTypeID( "Trgt" );

              ref13.putEnumerated( idAdjL, idOrdn, idTrgt );

          desc19.putReference( idnull, ref13 );

          var idT = charIDToTypeID( "T   " );

              var desc20 = new ActionDescriptor();

              var idAdjs = charIDToTypeID( "Adjs" );

                  var list3 = new ActionList();

                      var desc21 = new ActionDescriptor();

                      var idChnl = charIDToTypeID( "Chnl" );

                          var ref14 = new ActionReference();

                          var idChnl = charIDToTypeID( "Chnl" );

                          var idChnl = charIDToTypeID( "Chnl" );

                          var idCmps = charIDToTypeID( "Cmps" );

                          ref14.putEnumerated( idChnl, idChnl, idCmps );

                      desc21.putReference( idChnl, ref14 );

                      var idCrv = charIDToTypeID( "Crv " );

                          var list4 = new ActionList();

                              var desc22 = new ActionDescriptor();

                              var idHrzn = charIDToTypeID( "Hrzn" );

                              desc22.putDouble( idHrzn, 0.000000 );

                              var idVrtc = charIDToTypeID( "Vrtc" );

                              desc22.putDouble( idVrtc, 0.000000 );

                          var idPnt = charIDToTypeID( "Pnt " );

                          list4.putObject( idPnt, desc22 );

                              var desc23 = new ActionDescriptor();

                              var idHrzn = charIDToTypeID( "Hrzn" );

                              desc23.putDouble( idHrzn, 127.000000 );

                              var idVrtc = charIDToTypeID( "Vrtc" );

                              desc23.putDouble( idVrtc, 127.000000 );

                          var idPnt = charIDToTypeID( "Pnt " );

                          list4.putObject( idPnt, desc23 );

                              var desc24 = new ActionDescriptor();

                              var idHrzn = charIDToTypeID( "Hrzn" );

                              desc24.putDouble( idHrzn, 255.000000 );

                              var idVrtc = charIDToTypeID( "Vrtc" );

                              desc24.putDouble( idVrtc, 255.000000 );

                          var idPnt = charIDToTypeID( "Pnt " );

                          list4.putObject( idPnt, desc24 );

                      desc21.putList( idCrv, list4 );

                  var idCrvA = charIDToTypeID( "CrvA" );

                  list3.putObject( idCrvA, desc21 );

              desc20.putList( idAdjs, list3 );

          var idCrvs = charIDToTypeID( "Crvs" );

          desc19.putObject( idT, idCrvs, desc20 );

      executeAction( idsetd, desc19, DialogModes.NO );

       

       

      I want to query the Hrzn and Vrtc parameters for 0, 127 and 255 on an existing curves layer.

       

      Any help in working out how to do this would be greatly appreciated.

       

      Thx in advance.

        • 2. Re: Query Curves Layer for current settings
          Michael L Hale Level 5

          In newer vesions of Photoshop getting the current curve adjustment layer setting is much harder than is was. The settings are stored as a RAWTYPE in the stringIDToTypeID( "legacyContentData") key.

           

          Which version of Photoshop are you using?

          • 3. Re: Query Curves Layer for current settings
            sflisher Level 1

            Hi Michael. I am using CS5 extended. Thx

            • 4. Re: Query Curves Layer for current settings
              Michael L Hale Level 5

              This is a bit of a hack but it should give you a place to start.

               

              // Works with RGB or CMYK images. 
              // Does not work at all with greyscale, or indexColor
              // Does not work correctly with Lab
              function convertBCD( num ){
                  var res = new Array;
                  if(num > 16 ){
                      res.unshift(1);
                      num = num - 16;
                  }else{
                      res.unshift(0);
                  }
                  if(num > 8 ){
                      res.unshift(1);
                      num = num - 8;
                  }else{
                      res.unshift(0);
                  }
                  if(num > 4 ){
                      res.unshift(1);
                      num = num - 4;
                  }else{
                      res.unshift(0);
                  }
                  if(num > 2 ){
                      res.unshift(1);
                      num = num - 2;
                  }else{
                      res.unshift(0);
                  }
                  if(num == 1 ){
                      res.unshift(1);
                  }else{
                      res.unshift(0);
                  }
                  return res;
              };
              function getCurve( numberOfPoints ){
                  this.getPoints = function(){
                      this.tempArray = new Array;
                      this.tempArray.push( rawDesc.charCodeAt( pointer ) );
                      pointer = pointer + 2;// set pointer to next point
                      this.tempArray.push( rawDesc.charCodeAt( pointer ) );
                      return this.tempArray;
                  }
                  
                  this.pointsArray = new Array;
                  for( var i = 0; i < numberOfPoints; i++ ){
                      pointer = pointer + 2;// next point
                      this.pointsArray.push( this.getPoints() );
                  }
                  pointer = pointer + 2;// next curve
                  return this.pointsArray;
              };
              
              var ref = new ActionReference();
              ref.putEnumerated( charIDToTypeID( 'Lyr ' ), charIDToTypeID( 'Ordn' ), charIDToTypeID( 'Trgt' ) ); 
              var rawDesc = executeActionGet( ref ).getList( stringIDToTypeID( 'adjustment' ) ).getObjectValue( 0 ).getData( stringIDToTypeID( 'legacyContentData' ) );
              var pointer = 2;// used to read rawData similar to reading a file
              var flag = rawDesc.charCodeAt( pointer );// char at offset 2 always == 1 so use to validate data
              if( flag != 1 ) forceError;// unknown problem with rawData
                  pointer = 6;// update pointer to BCD byte
                  var bcd = rawDesc.charCodeAt( pointer );
                  if( bcd < 0 || bcd > 31 ) forceError;// check for valid value
                  if( bcd == 0 ) forceError;// an empty adjustment - no curves to process
                  var bcdArray = convertBCD( bcd );
                  var numberOfCurves = bcdArray.toString().match(/(1)/g).length;
                  var curvesArray = new Array;
                  pointer = 8;// set pointer to start of curve data
                  for(var i = 0; i < numberOfCurves; i++ ){
                      var numberOfPoints = rawDesc.charCodeAt( pointer );
                      curvesArray.push( getCurve( numberOfPoints ) );
                  }
              // now need to map rawData curves in curvesArray to known channel curves
              var acvArray = new Array;
              if( bcdArray[0] == 1 ) {
                  acvArray.push( curvesArray.shift() );
              } else {
                  acvArray.push( [ [0,0],[255,255] ] );
              }
              if( bcdArray[1] == 1 ) {
                  acvArray.push( curvesArray.shift() );
              } else {
                  acvArray.push( [ [0,0],[255,255] ] );
              }
              if( bcdArray[2] == 1 ) {
                  acvArray.push( curvesArray.shift() );
              } else {
                  acvArray.push( [ [0,0],[255,255] ] );
              }
              if( bcdArray[3] == 1 ) {
                  acvArray.push( curvesArray.shift() );
              } else {
                  acvArray.push( [ [0,0],[255,255] ] );
              }
              if( bcdArray[4] == 1 ) {
                  acvArray.push( curvesArray.shift() );
              } else {
                  acvArray.push( [ [0,0],[255,255] ] );
              }
              if(app.activeDocument.mode == DocumentMode.RGB){
                  var cNames = ['RGB','Red','Green','Blue'];
                  for(c=0;c<acvArray.length-1;c++){
                      alert(cNames[c]+': '+acvArray[c]);
                  }
              }
              if(app.activeDocument.mode ==  DocumentMode.CMYK){
                  var cNames = ['CMYK','Cyan','Magenta','Yellow','Black'];
                  for(c=0;c<acvArray.length;c++){
                      alert(cNames[c]+': '+acvArray[c]);
                  }
              }
              
              • 5. Re: Query Curves Layer for current settings
                sflisher Level 1

                Thanks works a treat!!