4 Replies Latest reply on Mar 26, 2015 9:07 AM by Chuck Uebele

    merge all layers

    roychen Level 1

      if have layer1 and layer2 and layer3,backgroud is white,i want to Merge all layers to background.all layers is cmyk.

      because layer is cmyk(0<=c,m,y,k<=100), below in black(k), Compare the color data of  the different layer, in the same coordinate position,for example ,

      A.layer1---c1 m1 y1 k1,layer2---c2 m2 y2 k2,layer1 and layer2 Merge to layer1

      B.layer1---c1 m1 y1 k1,layer3---c3 m3 y3 k3,layer1 and layer3 Merge to layer1

      C.layer1 and background  multiply

      D.finish

      Merge arithmetic :

      if k1>=k2  k1=k1+k2-2*k1*k2/100+k1*k1*k2/10000

      else k1<k2 k1=k1+k2-2*k1*k2/100+k1*k2*k2/10000

       

       

      Can edit by JavaScript? pls help me....thx

        • 1. Re: merge all layers
          roychen Level 1

          ////////////////////////////////////////////////////////////////////////////////////////// /////

          //file format is cmyk                                                                      

          //run this javascript  must close all show layer!!!!!                  

          //file is have 3 layer,name is  layer1 and layer2 and background        

          //all Results display on layer1                                                        

          ////////////////////////////////////////////////////////////////////////////////////////// ////

           

          var units = app.preferences.rulerUnits;

          app.preferences.rulerUnits = Units.PIXELS; // set ruler units to PIXELS

          var myDocument = activeDocument;

          var theWidth = myDocument.width;

          var theHeight = myDocument.height;

           

          for(var i=0; i<theWidth; i++){

              for(var j=0; j<theHeight; j++){

          selectlayer2();//select layer2

          showlayer();//=======show layer

          // =============================================build selection

          var id84 = charIDToTypeID( "setd" );

              var desc13 = new ActionDescriptor();

              var id85 = charIDToTypeID( "null" );

                  var ref7 = new ActionReference();

                  var id86 = charIDToTypeID( "Chnl" );

                  var id87 = charIDToTypeID( "fsel" );

                  ref7.putProperty( id86, id87 );

              desc13.putReference( id85, ref7 );

              var id88 = charIDToTypeID( "T   " );

                  var desc14 = new ActionDescriptor();

                  var id89 = charIDToTypeID( "Top " );

                  var id90 = charIDToTypeID( "#Pxl" );

                  desc14.putUnitDouble( id89, id90, 0.000000+j );

                  var id91 = charIDToTypeID( "Left" );

                  var id92 = charIDToTypeID( "#Pxl" );

                  desc14.putUnitDouble( id91, id92, 0.000000+i );

                  var id93 = charIDToTypeID( "Btom" );

                  var id94 = charIDToTypeID( "#Pxl" );

                  desc14.putUnitDouble( id93, id94, 1.000000+j );

                  var id95 = charIDToTypeID( "Rght" );

                  var id96 = charIDToTypeID( "#Pxl" );

                  desc14.putUnitDouble( id95, id96, 1.000000+i );

              var id97 = charIDToTypeID( "Rctn" );

              desc13.putObject( id88, id97, desc14 );

          executeAction( id84, desc13, DialogModes.NO );

          // ===========================================choose  colorSamplerTool

          var idslct = charIDToTypeID( "slct" );

              var desc1249 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref1133 = new ActionReference();

                  var idcolorSamplerTool = stringIDToTypeID( "colorSamplerTool" );

                  ref1133.putClass( idcolorSamplerTool );

              desc1249.putReference( idnull, ref1133 );

              var iddontRecord = stringIDToTypeID( "dontRecord" );

              desc1249.putBoolean( iddontRecord, true );

              var idforceNotify = stringIDToTypeID( "forceNotify" );

              desc1249.putBoolean( idforceNotify, true );

          executeAction( idslct, desc1249, DialogModes.NO );

          //=========================================click colorSamplerTool

          var idMk = charIDToTypeID( "Mk  " );

              var desc1016 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref954 = new ActionReference();

                  var idClSm = charIDToTypeID( "ClSm" );

                  ref954.putClass( idClSm );

              desc1016.putReference( idnull, ref954 );

              var idPstn = charIDToTypeID( "Pstn" );

                  var desc1017 = new ActionDescriptor();

                  var idHrzn = charIDToTypeID( "Hrzn" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc1017.putUnitDouble( idHrzn, idPxl, 0.500000+i );

                  var idVrtc = charIDToTypeID( "Vrtc" );

                  var idPxl = charIDToTypeID( "#Pxl" );

                  desc1017.putUnitDouble( idVrtc, idPxl, 0.500000+j );

              var idPnt = charIDToTypeID( "Pnt " );

              desc1016.putObject( idPstn, idPnt, desc1017 );

          executeAction( idMk, desc1016, DialogModes.NO );

          //=================================get current layer2 samplecolor data(cmyk)

          var doc = app.activeDocument,   

          samps1 = doc.colorSamplers; 

          for ( var X = 0; X < samps1.length; X++ ) {  

               var C2= Math.round( samps1[X].color.cmyk.cyan ), 

               M2 = Math.round( samps1[X].color.cmyk.magenta ), 

               Y2 = Math.round( samps1[X].color.cmyk.yellow ), 

               B2= Math.round( samps1[X].color.cmyk.black );     

          //==========================close show layer2

          var idHd = charIDToTypeID( "Hd  " );

              var desc66 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var list15 = new ActionList();

                      var ref49 = new ActionReference();

                      var idLyr = charIDToTypeID( "Lyr " );

                      var idOrdn = charIDToTypeID( "Ordn" );

                      var idTrgt = charIDToTypeID( "Trgt" );

                      ref49.putEnumerated( idLyr, idOrdn, idTrgt );

                  list15.putReference( ref49 );

              desc66.putList( idnull, list15 );

          executeAction( idHd, desc66, DialogModes.NO );

          // =======================------------------------select layer1

          var idslct = charIDToTypeID( "slct" );

              var desc67 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref50 = new ActionReference();

                  var idLyr = charIDToTypeID( "Lyr " );

                  ref50.putName( idLyr, "layer1" );

              desc67.putReference( idnull, ref50 );

              var idMkVs = charIDToTypeID( "MkVs" );

              desc67.putBoolean( idMkVs, false );

          executeAction( idslct, desc67, DialogModes.NO );

          // ========================================Show layer1

          var idShw = charIDToTypeID( "Shw " );

              var desc68 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var list16 = new ActionList();

                      var ref51 = new ActionReference();

                      var idLyr = charIDToTypeID( "Lyr " );

                      var idOrdn = charIDToTypeID( "Ordn" );

                      var idTrgt = charIDToTypeID( "Trgt" );

                      ref51.putEnumerated( idLyr, idOrdn, idTrgt );

                  list16.putReference( ref51 );

              desc68.putList( idnull, list16 );

          executeAction( idShw, desc68, DialogModes.NO );

          //======================================get current layer1 samplecolor data(cmyk)

          var doc = app.activeDocument,   

          samps = doc.colorSamplers; 

          for ( var Q = 0; Q < samps.length; Q++ ) {  

               var C1 = Math.round( samps[Q].color.cmyk.cyan ), 

               M1 = Math.round( samps[Q].color.cmyk.magenta ), 

               Y1 = Math.round( samps[Q].color.cmyk.yellow ), 

               B1= Math.round( samps[Q].color.cmyk.black );     

          }

           

          // ======================================del samplecolor point

          var idDlt = charIDToTypeID( "Dlt " );

              var desc1284 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref1157 = new ActionReference();

                  var idClSm = charIDToTypeID( "ClSm" );

                  var idOrdn = charIDToTypeID( "Ordn" );

                  var idAl = charIDToTypeID( "Al  " );

                  ref1157.putEnumerated( idClSm, idOrdn, idAl );

              desc1284.putReference( idnull, ref1157 );

          executeAction( idDlt, desc1284, DialogModes.NO );

           

           

          //==============================Obtained  C3,M3,Y3,B3 color data by calculation

          var C3,M3,Y3,B3;

          if(C1>=C2)  {

              C3=C1+C2-2*C1*C2/100+C1*C1*C2/10000;

              }

          else  {

              C3=C1+C2-2*C1*C2/100+C1*C2*C2/10000;

              }

          if(M1>=M2)  {

              M3=M1+M2-2*M1*M2/100+M1*M1*M2/10000;

              }

          else  {

              M3=M1+M2-2*M1*M2/100+M1*M2*M2/10000;

              }

          if(Y1>=Y2)  {

              Y3=Y1+Y2-2*Y1*Y2/100+Y1*Y1*Y2/10000;

              }

          else  {

              Y3=Y1+Y2-2*Y1*Y2/100+Y1*Y2*Y2/10000;

              }

          if(B1>=B2)  {

              B3=B1+B2-2*B1*B2/100+B1*B1*B2/10000;

              }

          else  {

              B3=B1+B2-2*B1*B2/100+B1*B2*B2/10000;

              }

          fillcolor();

          }

          }

           

          //======================================select layer2

          function selectlayer2(){

          var idslct = charIDToTypeID( "slct" );

              var desc64 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref47 = new ActionReference();

                  var idLyr = charIDToTypeID( "Lyr " );

                  ref47.putName( idLyr, "layer2" );

              desc64.putReference( idnull, ref47 );

              var idMkVs = charIDToTypeID( "MkVs" );

              desc64.putBoolean( idMkVs, false );

          executeAction( idslct, desc64, DialogModes.NO );

          }

           

          //====================================display(show) layer

          function showlayer(){

          var idShw = charIDToTypeID( "Shw " );

              var desc65 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var list14 = new ActionList();

                      var ref48 = new ActionReference();

                      var idLyr = charIDToTypeID( "Lyr " );

                      var idOrdn = charIDToTypeID( "Ordn" );

                      var idTrgt = charIDToTypeID( "Trgt" );

                      ref48.putEnumerated( idLyr, idOrdn, idTrgt );

                  list14.putReference( ref48 );

              desc65.putList( idnull, list14 );

          executeAction( idShw, desc65, DialogModes.NO );

          }

           

           

           

          //======================================fill color to layer1

          function fillcolor(){

          var idFl = charIDToTypeID( "Fl  " );

              var desc197 = new ActionDescriptor();

              var idUsng = charIDToTypeID( "Usng" );

              var idFlCn = charIDToTypeID( "FlCn" );

              var idClr = charIDToTypeID( "Clr " );

              desc197.putEnumerated( idUsng, idFlCn, idClr );

              var idClr = charIDToTypeID( "Clr " );

                  var desc198 = new ActionDescriptor();

                  var idCyn = charIDToTypeID( "Cyn " );

                  desc198.putDouble( idCyn, C3 );            

                  var idMgnt = charIDToTypeID( "Mgnt" );

                  desc198.putDouble( idMgnt, M3 );

                  var idYlw = charIDToTypeID( "Ylw " );

                  desc198.putDouble( idYlw, Y3 );

                  var idBlck = charIDToTypeID( "Blck" );

                  desc198.putDouble( idBlck, B3 );

              var idCMYC = charIDToTypeID( "CMYC" );

              desc197.putObject( idClr, idCMYC, desc198 );

              var idOpct = charIDToTypeID( "Opct" );

              var idPrc = charIDToTypeID( "#Prc" );

              desc197.putUnitDouble( idOpct, idPrc, 100.000000 );

              var idMd = charIDToTypeID( "Md  " );

              var idBlnM = charIDToTypeID( "BlnM" );

              var idNrml = charIDToTypeID( "Nrml" );

              desc197.putEnumerated( idMd, idBlnM, idNrml );

          executeAction( idFl, desc197, DialogModes.NO );

          }

           

          run speed very very very very very very very very very very very very very  slow

          How to modify the increase speed?

          pls help me

          • 2. Re: merge all layers
            Chuck Uebele Adobe Community Professional & MVP

            Using the color sampler tool is VERY SLOW!!! And it looks like you're sampling every pixel. I can imagine this would take hours to run. I not sure, but I don't think there is a better option while using javascript, Some other programing language such as C++ would be needed.

            • 3. Re: merge all layers
              roychen Level 1

              C++--- I did not learn this programming language。

              pls help me

              thx

              • 4. Re: merge all layers
                Chuck Uebele Adobe Community Professional & MVP

                I don't know C++ either. I have done some scripts using the sampling tool, and it is very slow.