daily pastebin goal
57%
SHARE
TWEET

FacePalmer 3.0 Script

a guest Jul 16th, 2012 1,639 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // FacePalmer v3.0
  2. // http://forums.qhimm.com/index.php?topic=11933.0
  3.  
  4. // A Final Fantasy VII Texture Resizing Batch Script for Photoshop CS5.1
  5. // by Omzy
  6. // Credits to yarLson for resize() function
  7.  
  8. // Requires Aali's Palmer 0.7 for input and conversion
  9. // Requires Adobe Photoshop CS5.1 (untested on other versions)
  10. // Recommended ExtendScript Toolkit for script editing
  11. // Requires Perfect Resize 7.0 Professional Edition (PS Plug-in)
  12. // Requires Perfectum Filter v1.4 (PS Plug-in)
  13. // Requires Aali's OpenGL Driver to play in-game
  14. // Tested under Windows 7 32-bit
  15.  
  16. //========Adjustment Parameters=========
  17. //General
  18. var resizeFactor = 4    //Only put 2 or 4
  19.  
  20. //Perfect Resize
  21. var textureControlAmount = 1
  22. var textureControlThreshold = 10
  23. var textureControlSmoothness = 0
  24. var sharpen = true
  25. var sharpenMethod = 0
  26. var sharpenRadius = 2
  27. var sharpenAmount = 25
  28. var sharpenHighlights = 20
  29. var sharpenShadows = 20
  30.  
  31. //Reduce noise filter
  32. var rdfStrength = 2
  33. var rdfPresDetail = 100
  34. var rdfRemColNoise = 50
  35. var rdfSharpDetail = 25
  36.  
  37. //Film Grain
  38. var fgIntensity = 15
  39. var fgContrast = 50
  40.  
  41. //Perfectum Smoothing
  42. var perfSmoothPercent = 20 //Doesn't work, always 20 unless recorded again
  43. //========Adjustment Parameters=========
  44.  
  45. //Resizes activeDocument
  46. //May be modified to support other resizing methods / programs
  47. function resize ()
  48. {
  49.     perfectResize(sharpen, sharpenMethod, sharpenRadius, sharpenAmount, sharpenHighlights, sharpenShadows, textureControlAmount, textureControlThreshold, textureControlSmoothness)
  50.     reduceNoise(rdfRemColNoise, rdfSharpDetail, rdfStrength, rdfPresDetail)
  51.     //applyFilmGrain(fgIntensity, fgContrast)
  52.     perfectum(/*perfSmoothPercent*/)
  53. }
  54.  
  55. //GLOBALS
  56.  
  57. var textureFolder = null
  58. var fileList = null
  59. var layerGroup = null
  60. //layerGroup Structure
  61.     //LayerType 0   (Standard)
  62.         //Group 0 = BG (0, 0-128)
  63.             //child = 0
  64.                 //child = file id << 8 + file index
  65.         //Group 1 = FG (0, 128-147)
  66.             //child = 0
  67.                 //child = file id << 8 + file index
  68.         //Group 2 = Anims (0, 148-65535)
  69.             //child = anim group
  70.                 //child = file id << 8 + file index
  71.         //Group 3 = Alpha Anims (0, 65536>)
  72.             //child = anim group
  73.                 //child = file id << 8 + file index
  74.         //Group 4 = missingBlock
  75.             //child = 0
  76.                 //child = file id << 8 + file index
  77.         //Group 5 = RequiredAnims
  78.             //child = file id << 8 + file index
  79.     //LayerType 1   (Parallax 1)
  80.         //Same (no Group 5)
  81.     //LayerType 2   (Parallax 2)
  82.         //Same  (no Group 5)
  83.  
  84. //MAIN SECTION
  85.  
  86. //Save original preferences
  87. var originalUnit = preferences.rulerUnits
  88. var originalType = preferences.typeUnits
  89. preferences.rulerUnits = Units.PIXELS
  90. preferences.typeUnits = TypeUnits.PIXELS
  91.  
  92. //Get all folders and resize their contents
  93. var inputFolder = new Folder(app.path + "\\ff7TexturesIN") //Texture input folder
  94. var outputFolder = new Folder(app.path + "\\ff7TexturesOUT") //Texture output folder
  95. outputFolder.create()
  96. var folderList = inputFolder.getFiles() //List of all folders (one folder per texture)
  97. var i = 0
  98. for (i = 0; i < folderList.length; i++) //For every texture
  99. {
  100.     textureFolder = new Folder(outputFolder.path + "\\" + outputFolder.name+ "\\" + folderList[i].name) //Texture output folder
  101.     textureFolder.create()
  102.     fileList = folderList[i].getFiles("*.png") //List of all layers in texture
  103.     analyzeFiles()
  104.     //printTree()
  105.     //printRequiredAnims()
  106.     //printParallaxAnims()
  107.     //printLightingTextures()
  108.     if (layerGroup != null) {
  109.     var j = 0
  110.     for (j = 0; j < layerGroup.length; j++) {   //For all types
  111.         if (layerGroup[j] != null) {
  112.         var k = 0
  113.         for (k = 0; k < layerGroup[j].length; k++) {    //For all groups
  114.             if (layerGroup[j][k] != null) {
  115.             var l = 0
  116.             for (l = 0; l < layerGroup[j][k].length; l++) { //For all subgroups
  117.                 if (layerGroup[j][k][l] != null) {
  118.                 var m = 0
  119.                 for (m = 0; m < layerGroup[j][k][l].length; m++) {  //For all images
  120.                     if (k != 1 && k != 4 && !(k == 2 && m > 0)) buildComposite (j, k, l, m) //Condition ensures only required composites are generated (efficiency)
  121.                     facepalm (j, k, l, m)
  122.                 }m = null}
  123.             }l = null}
  124.         }k = null}
  125.     }j = null}
  126.  
  127.     //Delete all composite files
  128.     var compList = textureFolder.getFiles("*_c.png") //List of all composites
  129.     var p = 0
  130.     for (p = 0; p < compList.length; p++)
  131.     {
  132.             compList[p].remove()
  133.     }
  134.  
  135.     //Release references
  136.     p = null
  137.     compList = null
  138. }
  139. //Restore original preferences
  140. preferences.rulerUnits = originalUnit
  141. preferences.typeUnits = originalType
  142.  
  143. //Release references
  144. i = null
  145. originalUnit = null
  146. originalType = null
  147. inputFolder = null
  148. outputFolder = null
  149. folderList = null
  150. resizeFactor = null
  151. textureControlAmount = null
  152. textureControlThreshold = null
  153. textureControlSmoothness = null
  154. sharpen = null
  155. sharpenMethod = null
  156. sharpenRadius = null
  157. sharpenAmount = null
  158. sharpenHighlights = null
  159. sharpenShadows = null
  160. rdfStrength = null
  161. rdfPresDetail = null
  162. rdfRemColNoise = null
  163. rdfSharpDetail = null
  164. fgIntensity = null
  165. fgContrast = null
  166. perfSmoothPercent = null
  167. textureFolder = null
  168. fileList = null
  169. layerGroup = null
  170.  
  171. //ESSENTIAL FUNCTIONS
  172. function analyzeFiles ()
  173. {    
  174.      layerGroup = new Array(3);
  175.      layerGroup[0] = new Array(6);
  176.      layerGroup[1] = new Array(5);
  177.      layerGroup[2] = new Array(5);
  178.      
  179.      //Required Anims cases
  180.      var name = fileList[0].name.substring(0, fileList[0].name.length - 15)
  181.      if (name == "anfrst_4") {
  182.         layerGroup[0][5] = new Array(4) //Length of this array specifies number of requiredAnims
  183.         layerGroup[0][5][0] = (644 << 8) + 4
  184.         layerGroup[0][5][1] = (648 << 8) + 4
  185.         layerGroup[0][5][2] = (652 << 8) + 4
  186.         layerGroup[0][5][3] = (656 << 8) + 4
  187.      } else if (name == "blin66_1") {
  188.         layerGroup[0][5] = new Array(1)
  189.         layerGroup[0][5][0] = (644 << 8) + 1    
  190.      } else if (name == "blin66_2") {
  191.         layerGroup[0][5] = new Array(2)
  192.         layerGroup[0][5][0] = (644 << 8) + 1
  193.         layerGroup[0][5][1] = (648 << 8) + 1          
  194.      } else if (name == "blin66_6") {
  195.         layerGroup[0][5] = new Array(2)
  196.         layerGroup[0][5][0] = (644 << 8) + 1
  197.         layerGroup[0][5][1] = (648 << 8) + 1    
  198.      } else if (name == "bonevil2") {
  199.         layerGroup[0][5] = new Array(1)
  200.         layerGroup[0][5][0] = (644 << 8) + 1  
  201.      } else if (name == "bonevil") {
  202.         layerGroup[0][5] = new Array(1)
  203.         layerGroup[0][5][0] = (644 << 8) + 1  
  204.      } else if (name == "bugin1a") {
  205.         layerGroup[0][5] = new Array(1)
  206.         layerGroup[0][5][0] = (644 << 8) + 0  
  207.      } else if (name == "bugin2") {
  208.         layerGroup[0][5] = new Array(1)
  209.         layerGroup[0][5][0] = (648 << 8) + 1  
  210.      } else if (name == "colne_1") {
  211.         layerGroup[0][5] = new Array(2)
  212.         layerGroup[0][5][0] = (908 << 8) + 2
  213.         layerGroup[0][5][1] = (912 << 8) + 1
  214.      } else if (name == "colne_3") {
  215.         layerGroup[0][5] = new Array(1)
  216.         layerGroup[0][5][0] = (900 << 8) + 3
  217.      } else if (name == "colne_5") {
  218.         layerGroup[0][5] = new Array(1)
  219.         layerGroup[0][5][0] = (1412 << 8) + 0  
  220.      } else if (name == "condor2") {
  221.         layerGroup[0][5] = new Array(1)
  222.         layerGroup[0][5][0] = (644 << 8) + 1  
  223.      } else if (name== "ealin_2") {
  224.         layerGroup[0][5] = new Array(1)
  225.         layerGroup[0][5][0] = (644 << 8) + 1  
  226.      } else if (name == "gidun_1") {
  227.         layerGroup[0][5] = new Array(4)
  228.         layerGroup[0][5][0] = (644 << 8) + 1
  229.         layerGroup[0][5][1] = (648 << 8) + 1
  230.         layerGroup[0][5][2] = (652 << 8) + 1
  231.         layerGroup[0][5][3] = (656 << 8) + 1
  232.      } else if (name == "hyou4") {
  233.         layerGroup[0][5] = new Array(1)
  234.         layerGroup[0][5][0] = (644 << 8) + 5      
  235.      } else if (name == "itown12") {
  236.         layerGroup[0][5] = new Array(2)
  237.         layerGroup[0][5][0] = (644 << 8) + 7
  238.      } else if (name == "itown1a") {
  239.         layerGroup[0][5] = new Array(2)
  240.         layerGroup[0][5][0] = (644 << 8) + 7
  241.      } else if (name == "itown2") {
  242.         layerGroup[0][5] = new Array(4)
  243.         layerGroup[0][5][0] = (644 << 8) + 7
  244.         layerGroup[0][5][2] = (652 << 8) + 7
  245.      } else if (name == "junbin4") {
  246.         layerGroup[0][5] = new Array(1)
  247.         layerGroup[0][5][0] = (648 << 8) + 1  
  248.      } else if (name == "junonr3") {
  249.         layerGroup[0][5] = new Array(1)
  250.         layerGroup[0][5][0] = (644 << 8) + 1  
  251.      } else if (name == "md8_52") {
  252.         layerGroup[0][5] = new Array(1)
  253.         layerGroup[0][5][0] = (644 << 8) + 4  
  254.      } else if (name == "mkt_s3") {
  255.         layerGroup[0][5] = new Array(1)
  256.         layerGroup[0][5][0] = (900<< 8) + 1  
  257.      } else if (name == "move_f") {
  258.         layerGroup[0][5] = new Array(2)
  259.         layerGroup[0][5][0] = (644 << 8) + 1
  260.         layerGroup[0][5][1] = (648 << 8) + 1  
  261.      } else if (name == "mrkt1") {
  262.         layerGroup[0][5] = new Array(1)
  263.         layerGroup[0][5][0] = (644 << 8) + 5  
  264.      } else if (name == "nivinn_1") {
  265.         layerGroup[0][5] = new Array(2)
  266.         layerGroup[0][5][0] = (900 << 8) + 1
  267.         layerGroup[0][5][1] = (904 << 8) + 1    
  268.      } else if (name == "nivinn_2") {
  269.         layerGroup[0][5] = new Array(1)
  270.         layerGroup[0][5][0] = (904 << 8) + 1  
  271.      } else if (name == "nivl_2") {
  272.         layerGroup[0][5] = new Array(1)
  273.         layerGroup[0][5][0] = (648 << 8) + 4  
  274.      } else if (name == "nivl_4") {
  275.         layerGroup[0][5] = new Array(1)
  276.         layerGroup[0][5][0] = (648 << 8) + 4  
  277.      } else if (name == "nivl") {
  278.         layerGroup[0][5] = new Array(1)
  279.         layerGroup[0][5][0] = (648 << 8) + 4  
  280.      } else if (name == "nvmkin1") {
  281.         layerGroup[0][5] = new Array(1)
  282.         layerGroup[0][5][0] = (644 << 8) + 3  
  283.      } else if (name == "sbwy4_1") {
  284.         layerGroup[0][5] = new Array(1)
  285.         layerGroup[0][5][0] = (644 << 8) + 1  
  286.      } else if (name == "ship_1") {
  287.         layerGroup[0][5] = new Array(1)
  288.         layerGroup[0][5][0] = (644 << 8) + 7  
  289.      } else if (name == "sininb41") {
  290.         layerGroup[0][5] = new Array(4)
  291.         layerGroup[0][5][0] = (900 << 8) + 0
  292.         layerGroup[0][5][1] = (904 << 8) + 0  
  293.         layerGroup[0][5][2] = (908 << 8) + 0
  294.         layerGroup[0][5][3] = (912 << 8) + 0          
  295.      } else if (name == "southmk2") {
  296.         layerGroup[0][5] = new Array(1)
  297.         layerGroup[0][5][0] = (644 << 8) + 1  
  298.      } else if (name == "subin_2a") {
  299.         layerGroup[0][5] = new Array(1)
  300.         layerGroup[0][5][0] = (644 << 8) + 1  
  301.      } else if (name == "subin_2b") {
  302.         layerGroup[0][5] = new Array(1)
  303.         layerGroup[0][5][0] = (644 << 8) + 1  
  304.      } else if (name == "tin_1") {
  305.         layerGroup[0][5] = new Array(1)
  306.         layerGroup[0][5][0] = (920 << 8) + 3  
  307.      } else if (name == "tin_2") {
  308.         layerGroup[0][5] = new Array(1)
  309.         layerGroup[0][5][0] = (920 << 8) + 3  
  310.      } else if (name == "tin_3") {
  311.         layerGroup[0][5] = new Array(1)
  312.         layerGroup[0][5][0] = (920 << 8) + 3  
  313.      } else if (name == "tin_4") {
  314.         layerGroup[0][5] = new Array(1)
  315.         layerGroup[0][5][0] = (920 << 8) + 3  
  316.      } else if (name == "tower5") {
  317.         layerGroup[0][5] = new Array(2)
  318.         layerGroup[0][5][0] = (644 << 8) + 4
  319.         layerGroup[0][5][1] = (656 << 8) + 1        
  320.      } else if (name == "uttmpin4") {
  321.         layerGroup[0][5] = new Array(1)
  322.         layerGroup[0][5][0] = (648 << 8) + 1  
  323.      } else if (name == "uutai2") {
  324.         layerGroup[0][5] = new Array(1)
  325.         layerGroup[0][5][0] = (652 << 8) + 1  
  326.      } else if (name == "zcoal_1") {
  327.         layerGroup[0][5] = new Array(1)
  328.         layerGroup[0][5][0] = (764 << 8) + 0  
  329.      } else if (name == "zcoal_2") {
  330.         layerGroup[0][5] = new Array(1)
  331.         layerGroup[0][5][0] = (644 << 8) + 1  
  332.      } else if (name == "zcoal_3") {
  333.         layerGroup[0][5] = new Array(1)
  334.         layerGroup[0][5][0] = (648 << 8) + 1
  335.      }
  336.    
  337.      var type = 0
  338.      var gid = 0
  339.      var sgid = 0
  340.      var i = 0
  341.          for (i = 0; i < fileList.length; i++) {
  342.         var tempType = parseInt(fileList[i].name.charAt(fileList[i].name.indexOf("000") - 2), 10)
  343.         var newType = false
  344.         if (type != tempType)
  345.         {
  346.                 newType = true
  347.         }
  348.         type = tempType
  349.         var idIndex = fileList[i].name.indexOf("000")
  350.         var id = parseInt(fileList[i].name.substring(idIndex, fileList[i].name.length - 4), 10)
  351.         if ( (type == 0) && (name != "hyou5_2") && (   //Missing block exceptions
  352.                 (id == 260) ||
  353.                 (id == 304) ||
  354.                 (id == 516) ||
  355.                 (id == 520) ||
  356.                 (id == 772) ||
  357.                 (id == 776) ||
  358.                 (id == 1020) ||
  359.                 (id == 1284) ||
  360.                 (id == 1296) ||
  361.                 (id == 1816) ||
  362.                 (id == 2308) ||
  363.                 (id == 5712) ||
  364.                 (id == 6504) ||
  365.                 (id == 8456) ||
  366.                 (id == 12816) ||
  367.                 (id == 16660) ||
  368.                 (id == 65632) ||
  369.                 (id == 65732)  ))
  370.         {
  371.             gid = 4
  372.             sgid = 0
  373.         }
  374.         else if (id < 128)
  375.         {
  376.             gid = 0
  377.             sgid = 0
  378.         }
  379.         else if (id >= 128 && id < 148)
  380.         {
  381.             gid = 1
  382.             sgid = 0
  383.         }
  384.         else if (id >= 148 && id < 65536)
  385.         {
  386.             if ((layerGroup[0][4] != null) && (layerGroup[0][2] != null))   //Bugfix
  387.             {
  388.                 if ((layerGroup[0][4][0][0] & 255) == (i - 1))
  389.                 {
  390.                     gid = 2
  391.                     sgid = layerGroup[0][2].length - 1
  392.                 }
  393.             }
  394.             if (gid != 2 || newType) {sgid = -1}
  395.             gid = 2
  396.             if (id % 4 == 0) //New SubGroup
  397.             {
  398.                 sgid++
  399.             }
  400.         }
  401.         else if (id >= 65536)
  402.         {
  403.             if (gid != 3 || newType) {sgid = -1}
  404.             gid = 3
  405.             if (id % 4 == 0) //New SubGroup
  406.             {
  407.                 sgid++
  408.             }  
  409.         }
  410.      
  411.          if (layerGroup[type][gid] == null)    //Open Group
  412.          {
  413.                 layerGroup[type][gid] = new Array();
  414.          }
  415.          if (layerGroup[type][gid][sgid] == null)    //Open SubGroup
  416.          {
  417.                 layerGroup[type][gid][sgid] = new Array();
  418.                 layerGroup[type][gid][sgid][0] = (id << 8) + i;
  419.          } else {    
  420.             layerGroup[type][gid][sgid][layerGroup[type][gid][sgid].length] = (id << 8) + i;   //Add layer
  421.          }    
  422.      
  423.         //Release references
  424.         idIndex = null
  425.         id = null
  426.         tempType = null
  427.         newType = null
  428.         }
  429.    
  430.     //Release references
  431.     i = null
  432.     type = null
  433.     gid = null
  434.     sgid = null
  435.     name = null
  436. }
  437.  
  438. function buildComposite (type, gid, sgid, id)
  439. {
  440.     //Open layer
  441.     var file = fileList[layerGroup[type][gid][sgid][id] & 255]
  442.     app.open(file)
  443.     //If has consecutive animation layers, place all on bottom
  444.     if (gid == 2 || gid == 3)
  445.     {
  446.         moveGroup(type, gid, sgid, id, gid, false)
  447.     }
  448.     //If no required anims, use background composite
  449.     if (gid == 2 && layerGroup[0][5] == null)
  450.     {
  451.         var c_file = new File(textureFolder.path + "\\" + textureFolder.name+ "\\" + fileList[0].name.substring(0, fileList[0].name.length - 15) + "_" + type + "_" + "00000000" + "_c.png")
  452.         var master = activeDocument
  453.         try {
  454.             app.open(c_file)
  455.             var foreLayer = activeDocument.activeLayer.duplicate(master)
  456.             activeDocument.close(SaveOptions.DONOTSAVECHANGES)
  457.             foreLayer.move(master.artLayers[master.artLayers.length - 1], ElementPlacement.PLACEAFTER)
  458.            
  459.             //Release references
  460.             foreLayer = null
  461.         } catch (err) {}
  462.        
  463.         //Release references
  464.         c_file = null
  465.         master = null
  466.     }
  467.     //If has required anims, place all on bottom
  468.     if (type == 0 && ((gid == 0 || gid == 2) && layerGroup[0][5] != null)) //RequiredAnims Flag = true
  469.     {
  470.         //Move req anims
  471.         moveGroup(type, gid, sgid, id, 2, true)
  472.     }
  473.     //If has foreground layers, place all on bottom
  474.     if (gid == 0 || (type == 0 && gid == 2 && layerGroup[0][5] != null))
  475.     {
  476.         moveGroup(type, gid, sgid, id, 1, false)
  477.     }
  478.     //If has bg layer, place it on bottom
  479.     if (gid == 0 || (type == 0 && gid == 2 && layerGroup[0][5] != null))
  480.     {
  481.         moveGroup(type, gid, sgid, id, 0, false)
  482.     }
  483.     //If missingBlock, place it on bottom
  484.     if (type == 0 && (gid == 0 || (gid == 2 && layerGroup[0][5] != null)))
  485.     {
  486.         if (type == 0) moveGroup(type, gid, sgid, id, 4, false)
  487.     }
  488.     //If needed, place black layer on bottom
  489.     if ((type == 0 && (gid == 0 || (gid == 2 && layerGroup[0][5] != null))) || (gid == 3))
  490.     {
  491.         var prevLayer = activeDocument.activeLayer
  492.         var blackLayer = activeDocument.artLayers.add()
  493.         activeDocument.activeLayer = blackLayer
  494.         activeDocument.selection.selectAll()
  495.         var blackColor = new SolidColor
  496.         blackColor.rgb.red = 0
  497.         blackColor.rgb.green = 0
  498.         blackColor.rgb.blue = 0
  499.         activeDocument.selection.fill(blackColor)
  500.         if (gid == 3 && (id > 0))
  501.         { blackLayer.move(activeDocument.artLayers[0], ElementPlacement.PLACEBEFORE) }
  502.         else
  503.         { blackLayer.move(activeDocument.artLayers[activeDocument.artLayers.length - 1], ElementPlacement.PLACEAFTER) }
  504.         activeDocument.activeLayer = prevLayer
  505.        
  506.         //Release references
  507.         prevLayer = null
  508.         blackLayer = null
  509.         blackColor = null
  510.     }
  511.     //Merge layers
  512.     try { activeDocument.mergeVisibleLayers() } catch (err) {}
  513.     //Save composite
  514.     var saveOptions = new PNGSaveOptions()
  515.     saveOptions.interlaced = false
  516.     var compositeFile = new File(textureFolder.path + "\\" + textureFolder.name+ "\\" + file.name.substring(0, file.name.length - 4) + "_c.png")
  517.     activeDocument.saveAs(compositeFile, saveOptions, false, Extension.LOWERCASE)
  518.     activeDocument.close(SaveOptions.DONOTSAVECHANGES)
  519.    
  520.     //Release references
  521.     file = null
  522.     saveOptions = null
  523.     compositeFile = null
  524. }
  525.  
  526. function moveGroup (type, gid, sgid, id, move_gid, reqAnims)
  527. {
  528.         if (layerGroup[type][move_gid] != null) {
  529.         var i = 0
  530.         for (i = 0; i < layerGroup[type][move_gid].length; i++) {
  531.             if (layerGroup[type][move_gid][i] != null) {
  532.             var j = 0
  533.             for (j = 0; j < layerGroup[type][move_gid][i].length; j++) {
  534.                 var foreLayer = null
  535.                 var master = null
  536.                 if (layerGroup[type][move_gid][i][j] != layerGroup[type][gid][sgid][id]) //Layers in order
  537.                 {
  538.                     if (reqAnims)
  539.                     {
  540.                             var this_id = layerGroup[type][gid][sgid][id] >> 8
  541.                             this_id = this_id - (this_id % 4)
  542.                             var move_id = layerGroup[type][move_gid][i][j] >> 8
  543.                             move_id = move_id - (move_id % 4)                          
  544.                             var move_req_anim = false
  545.                             var p = 0
  546.                             for (p = 0; p < layerGroup[0][5].length; p++)
  547.                             {
  548.                                 var reqAnim = layerGroup[0][5][p] >> 8
  549.                                 var numAnims = layerGroup[0][5][p] & 255
  550.                                 if (move_id == reqAnim) move_req_anim = true
  551.                                 var nextAnim = reqAnim
  552.                                 var q = 0
  553.                                 if (reqAnim >= 900) q = q + 1
  554.                                 if (reqAnim >= 1412) q = q + 1
  555.                                 var r = 0
  556.                                 for (r = 0; r < numAnims; r++)
  557.                                 {
  558.                                     nextAnim = nextAnim + (256 << (r + q))
  559.                                     if (this_id == nextAnim) move_req_anim = false
  560.                                 }
  561.                                 if (move_req_anim == true)
  562.                                 {
  563.                                     master = activeDocument                                    
  564.                                     app.open(fileList[layerGroup[type][move_gid][i][j] & 255])
  565.                                     foreLayer = activeDocument.activeLayer.duplicate(master)
  566.                                     activeDocument.close(SaveOptions.DONOTSAVECHANGES)
  567.                                     foreLayer.move(master.artLayers[master.artLayers.length - 1], ElementPlacement.PLACEAFTER)
  568.                                 }
  569.                                
  570.                                 //Release references
  571.                                 r = null
  572.                                 reqAnim = null
  573.                                 numAnims = null
  574.                                 nextAnim = null
  575.                                 q = null
  576.                             }
  577.                        
  578.                             //Release references
  579.                             p = null
  580.                             this_id = null
  581.                             move_id = null
  582.                             move_req_anim = null
  583.                     }
  584.                     else if (gid != move_gid || i == sgid)
  585.                     {
  586.                         master = activeDocument
  587.                         app.open(fileList[layerGroup[type][move_gid][i][j] & 255])
  588.                         foreLayer = activeDocument.activeLayer.duplicate(master)
  589.                         activeDocument.close(SaveOptions.DONOTSAVECHANGES)
  590.                         foreLayer.move(master.artLayers[master.artLayers.length - 1], ElementPlacement.PLACEAFTER)                      
  591.                     }
  592.                 } else {
  593.                     master = activeDocument
  594.                     foreLayer = master.artLayers[0]
  595.                     foreLayer.move(master.artLayers[master.artLayers.length - 1], ElementPlacement.PLACEAFTER)
  596.                 }
  597.                 if (gid == 3 && layerGroup[type][move_gid][i].length > 1 && foreLayer != null)
  598.                 {
  599.                     foreLayer.blendMode = BlendMode.LINEARDODGE
  600.                 }
  601.            
  602.                 //Release references
  603.                 master = null
  604.                 foreLayer = null
  605.             }j = null}
  606.         }i = null}
  607. }
  608.  
  609. function facepalm (type, gid, sgid, id)
  610. {
  611.     //For any given image, the correct composite is:
  612.         //Background -> Background (00000000)
  613.         //Foreground -> Background (00000000)
  614.         //Anims -> Anim - (Anim % 4)
  615.         //Missing block -> Background (00000000)
  616.         //Parallax -> Parallax
  617.     var compositeFile = null
  618.     if (type == 0 && (gid == 0 || gid == 1 || gid == 4))
  619.     {
  620.         compositeFile = new File(textureFolder.path + "\\" + textureFolder.name + "\\" + fileList[0].name.substring(0, fileList[0].name.length - 4) + "_c.png")
  621.     } else {
  622.         var anim_id = layerGroup[type][gid][sgid][id] >> 8
  623.         if (!(gid == 3 && id > 0)) { anim_id = anim_id - (anim_id % 4) }
  624.         var anim_string = "" + anim_id
  625.         while (anim_string.length < 8)
  626.         {
  627.                 anim_string = "0" + anim_string
  628.         }
  629.         compositeFile = new File(textureFolder.path + "\\" + textureFolder.name + "\\" + fileList[0].name.substring(0, fileList[0].name.length - 15) + "_" + type + "_" + anim_string + "_c.png")
  630.        
  631.         //Release references
  632.         anim_id = null
  633.         anim_string = null
  634.     }
  635.     if (compositeFile != null)
  636.     {
  637.             app.open(compositeFile)
  638.             var compDoc = activeDocument
  639.             var cutDoc = null
  640.             var origLayer = null
  641.            
  642.             //Combine
  643.             if (gid == 1 || gid == 2 || gid == 4)
  644.             {
  645.                 app.open(fileList[layerGroup[type][gid][sgid][id] & 255])
  646.                 cutDoc = activeDocument
  647.                 origLayer = cutDoc.activeLayer  
  648.                 var cutState = cutDoc.activeHistoryState
  649.                 /*origLayer.duplicate()
  650.                      //origLayer.applyMedianNoise(1)
  651.                      //cutDoc.mergeVisibleLayers()*/
  652.                 if (gid != 4)
  653.                 {
  654.                     cutDoc.activeLayer.duplicate(compDoc)
  655.                     cutDoc.activeHistoryState = cutState
  656.                     activeDocument = compDoc
  657.                     compDoc.mergeVisibleLayers()
  658.                 }
  659.                 activeDocument = compDoc
  660.                
  661.                 //Release references
  662.                 cutState = null
  663.             }
  664.        
  665.             //-------------------------------------------------
  666.             resize()
  667.             //-------------------------------------------------
  668.            
  669.             //If white border, give edge smoothing via median noise
  670.             //ToDo
  671.            
  672.             //Cut
  673.             if (gid == 1 || gid == 2 || gid == 4)
  674.             {
  675.                 activeDocument = cutDoc
  676.                 cutDoc.resizeImage(cutDoc.width * 2, cutDoc.height * 2, cutDoc.resolution, ResampleMethod.NEARESTNEIGHBOR)
  677.                 origLayer = cutDoc.activeLayer
  678.                 origLayer.duplicate()
  679.                 origLayer.applyMedianNoise(1)
  680.                 cutDoc.mergeVisibleLayers()
  681.                 if (resizeFactor == 4)
  682.                 {
  683.                     cutDoc.resizeImage(cutDoc.width * 2, cutDoc.height * 2, cutDoc.resolution, ResampleMethod.NEARESTNEIGHBOR)
  684.                     origLayer = cutDoc.activeLayer
  685.                     origLayer.duplicate()
  686.                     origLayer.applyMedianNoise(1)
  687.                     cutDoc.mergeVisibleLayers()
  688.                 }
  689.                 selectTransparency()
  690.                 maskRevealSelection()
  691.                 showMaskChannel()
  692.                 cutDoc.selection.selectAll()
  693.                 cutDoc.selection.copy()
  694.                 cutDoc.close(SaveOptions.DONOTSAVECHANGES)
  695.                 activeDocument = compDoc
  696.                 maskRevealAll()
  697.                 showMaskChannel()
  698.                 compDoc.selection.selectAll()                
  699.                 compDoc.paste()        
  700.                 applyMask()
  701.             }
  702.  
  703.             //Save Options
  704.             var saveOptions = new PNGSaveOptions()
  705.             saveOptions.interlaced = false
  706.             //Save resized layer
  707.             //alert(fileList[layerGroup[type][gid][sgid][id] & 255].name)
  708.             var layerFile = new File(textureFolder.path + "\\" + textureFolder.name+ "\\" + fileList[layerGroup[type][gid][sgid][id] & 255].name)
  709.             compDoc.saveAs(layerFile, saveOptions, false, Extension.LOWERCASE)
  710.             compDoc.close(SaveOptions.DONOTSAVECHANGES)
  711.            
  712.             //Release references
  713.             compDoc = null
  714.             cutDoc = null
  715.             origLayer = null
  716.             saveOptions = null
  717.             layerFile = null
  718.     }
  719.  
  720.     //Release references
  721.     compositeFile = null
  722. }
  723.  
  724. //DEBUG FUNCTIONS
  725. function printTree ()
  726. {
  727.  
  728.     if (layerGroup != null) {
  729.     var treeString = ""
  730.     for (var j = 0; j < layerGroup.length; j++) {   //For all types
  731.         treeString = treeString + "Type " + j + "\n"
  732.         if (layerGroup[j] != null) {
  733.         for (var k = 0; k < layerGroup[j].length; k++) {    //For all groups
  734.             treeString = treeString + "      Group " + k + "\n"
  735.             if (layerGroup[j][k] != null) {
  736.             for (var l = 0; l < layerGroup[j][k].length; l++) { //For all subgroups
  737.             treeString = treeString + "            SubGroup " + l + "\n"
  738.                 if (layerGroup[j][k][l] != null) {
  739.                 for (var m = 0; m < layerGroup[j][k][l].length; m++) {  //For all images
  740.                     treeString  = treeString + "                  " + (layerGroup[j][k][l][m] >> 8) + " : " + (layerGroup[j][k][l][m] & 255) + "\n"
  741.                 }}
  742.             }}
  743.         }}
  744.     }alert(treeString)}
  745. }
  746.  
  747. function printRequiredAnims ()
  748. {
  749.         var animString = ""
  750.         if (layerGroup[0][5] != null)
  751.         {
  752.                 for (var i = 0; i < layerGroup[0][5].length; i++)
  753.                 {
  754.                         animString = animString + (layerGroup[0][5][i] >> 8) + " : " + (layerGroup[0][5][i] & 255) + "\n"
  755.                 }
  756.         }
  757.         alert (animString)
  758. }
  759.  
  760. function printParallaxAnims ()  //Must put blank ParallaxAnims.txt inside ff7TexturesOUT folder, restart photoshop each execution
  761. {
  762.         if (layerGroup[1][2] != null)
  763.         {
  764.                 for (var i = 0; i < layerGroup[1][2].length; i++)
  765.                 {
  766.                         if (layerGroup[1][2][i].length > 1)
  767.                         {
  768.                             var f = File(outputFolder.name + "\\ParallaxAnims.txt")
  769.                             f.open ("a")
  770.                             f.writeln(fileList[0].name.substring(0, fileList[0].name.length - 15))
  771.                             f.close()
  772.                             break;
  773.                         }
  774.                 }
  775.         }
  776.         else if (layerGroup[1][3] != null)
  777.         {
  778.                 for (var i = 0; i < layerGroup[1][3].length; i++)
  779.                 {
  780.                         if (layerGroup[1][3][i].length > 1)
  781.                         {
  782.                             var f = File(outputFolder.name + "\\ParallaxAnims.txt")
  783.                             f.open ("a")
  784.                             f.writeln(fileList[0].name.substring(0, fileList[0].name.length - 15))
  785.                             f.close()
  786.                             break;
  787.                         }
  788.                 }
  789.         }    
  790.         else if (layerGroup[2][2] != null)
  791.         {
  792.                 for (var i = 0; i < layerGroup[2][2].length; i++)
  793.                 {
  794.                         if (layerGroup[2][2][i].length > 1)
  795.                         {
  796.                             var f = File(outputFolder.name + "\\ParallaxAnims.txt")
  797.                             f.open ("a")
  798.                             f.writeln(fileList[0].name.substring(0, fileList[0].name.length - 15))
  799.                             f.close()
  800.                             break;
  801.                         }
  802.                 }
  803.         }
  804.         else if (layerGroup[2][3] != null)
  805.         {
  806.                 for (var i = 0; i < layerGroup[2][3].length; i++)
  807.                 {
  808.                         if (layerGroup[2][3][i].length > 1)
  809.                         {
  810.                             var f = File(outputFolder.name + "\\ParallaxAnims.txt")
  811.                             f.open ("a")
  812.                             f.writeln(fileList[0].name.substring(0, fileList[0].name.length - 15))
  813.                             f.close()
  814.                             break;
  815.                         }
  816.                 }
  817.         }    
  818. }
  819.  
  820. function printLightingTextures ()   //Must put blank LightingTextures.txt inside ff7TexturesOUT folder, restart photoshop each execution
  821. {    
  822.         if (layerGroup[0][3] != null)
  823.         {
  824.                 for (var i = 0; i < layerGroup[0][3].length; i++)
  825.                 {
  826.                         if (layerGroup[0][3][i].length > 1)
  827.                         {
  828.                             var f = File(outputFolder.name + "\\LightingTextures.txt")
  829.                             f.open ("a")
  830.                             f.writeln(fileList[0].name.substring(0, fileList[0].name.length - 15))
  831.                             f.close()
  832.                             break;
  833.                         }
  834.                 }
  835.         }
  836. }
  837.  
  838.  
  839. //RECORDED FUNCTIONS
  840.  
  841. //Perfect Resize function
  842. function perfectResize (se, sm, sr, sa, st, ss, bs, td, ts)
  843. {
  844.     var resizeWidth = activeDocument.width * resizeFactor
  845.     var resizeHeight = activeDocument.height * resizeFactor
  846.     if ((resizeWidth % 2) > 0) resizeWidth  = resizeWidth + 1   //Sometimes math is off and will calculate 1 less than the desired size
  847.     if ((resizeHeight % 2) > 0) resizeHeight = resizeHeight + 1    
  848.    
  849.     var idonOnePerfectResizesevenzeroProfessionalEdition = stringIDToTypeID( "onOne Perfect Resize 7.0 Professional Edition" );
  850.     var desc2 = new ActionDescriptor();
  851.     var idgfBP = charIDToTypeID( "gfBP" );
  852.     var idtyBP = charIDToTypeID( "tyBP" );
  853.     var idbpPD = charIDToTypeID( "bpPD" );
  854.     desc2.putEnumerated( idgfBP, idtyBP, idbpPD );
  855.     var idgfPW = charIDToTypeID( "gfPW" );  //Width in pixels
  856.     desc2.putInteger( idgfPW, resizeWidth );
  857.     var idgfPH = charIDToTypeID( "gfPH" );  //Height in pixels
  858.     desc2.putInteger( idgfPH, resizeHeight );
  859.     var idgfCP = charIDToTypeID( "gfCP" );  //Constrain proportions
  860.     desc2.putBoolean( idgfCP, true );
  861.     var idgfSE = charIDToTypeID( "gfSE" );  //Sharpen ON/OFF
  862.     desc2.putBoolean( idgfSE, se );
  863.     var idgfSM = charIDToTypeID( "gfSM" );  //Sharpen method
  864.     desc2.putInteger( idgfSM, sm );
  865.     var idgfSR = charIDToTypeID( "gfSR" );  //Sharpen radius
  866.     desc2.putInteger( idgfSR, sr );
  867.     var idgfSA = charIDToTypeID( "gfSA" );  //Sharpen amount
  868.     desc2.putInteger( idgfSA, sa );
  869.     var idgfST = charIDToTypeID( "gfST" );  //Sharpen highlights
  870.     desc2.putInteger( idgfST, st );
  871.     var idgfSS = charIDToTypeID( "gfSS" );  //Sharpen shadows
  872.     desc2.putInteger( idgfSS, ss );
  873.     var idgfBS = charIDToTypeID( "gfBS" );  //Texture control amount
  874.     desc2.putInteger( idgfBS, bs );
  875.     var idgfTD = charIDToTypeID( "gfTD" );  //Texture control threshold
  876.     desc2.putInteger( idgfTD, td );
  877.     var idgfTS = charIDToTypeID( "gfTS" );  //Texture control smoothness
  878.     desc2.putInteger( idgfTS, ts );
  879.     executeAction( idonOnePerfectResizesevenzeroProfessionalEdition, desc2, DialogModes.NO );
  880.    
  881. //Release references
  882. resizeWidth = null
  883. resizeHeight = null
  884. idonOnePerfectResizesevenzeroProfessionalEdition = null
  885. desc2 = null
  886. idgfBP = null
  887. idtyBP = null
  888. idbpPD = null
  889. idgfPW = null
  890. idgfPH = null
  891. idgfCP = null
  892. idgfSE = null
  893. idgfSM = null
  894. idgfSR = null
  895. idgfSA = null
  896. idgfST = null
  897. idgfSS = null
  898. idgfBS = null
  899. idgfTD = null
  900. idgfTS = null
  901. se = null
  902. sm = null
  903. sr = null
  904. sa = null
  905. st = null
  906. ss = null
  907. bs = null
  908. td = null
  909. ts = null
  910. }
  911.  
  912. //Reduce noise
  913. function reduceNoise (clnsprc, shrpprc, amnt, edgf )
  914. {
  915.     var iddenoise = stringIDToTypeID( "denoise" );
  916.     var desc2 = new ActionDescriptor();
  917.     var idClNs = charIDToTypeID( "ClNs" );
  918.     var idPrc = charIDToTypeID( "#Prc" );
  919.     desc2.putUnitDouble( idClNs, idPrc, clnsprc );
  920.     var idShrp = charIDToTypeID( "Shrp" );
  921.     var idPrc = charIDToTypeID( "#Prc" );
  922.     desc2.putUnitDouble( idShrp, idPrc, shrpprc );
  923.     var idremoveJPEGArtifact = stringIDToTypeID( "removeJPEGArtifact" );
  924.     desc2.putBoolean( idremoveJPEGArtifact, false );
  925.     var idchannelDenoise = stringIDToTypeID( "channelDenoise" );
  926.     var list1 = new ActionList();
  927.     var desc3 = new ActionDescriptor();
  928.     var idChnl = charIDToTypeID( "Chnl" );
  929.     var ref1 = new ActionReference();
  930.     var idChnl = charIDToTypeID( "Chnl" );
  931.     var idChnl = charIDToTypeID( "Chnl" );
  932.     var idCmps = charIDToTypeID( "Cmps" );
  933.     ref1.putEnumerated( idChnl, idChnl, idCmps );
  934.     desc3.putReference( idChnl, ref1 );
  935.     var idAmnt = charIDToTypeID( "Amnt" );
  936.     desc3.putInteger( idAmnt, amnt );
  937.     var idEdgF = charIDToTypeID( "EdgF" );
  938.     desc3.putInteger( idEdgF, edgf );
  939.     var idchannelDenoiseParams = stringIDToTypeID( "channelDenoiseParams" );
  940.     list1.putObject( idchannelDenoiseParams, desc3 );
  941.     var desc4 = new ActionDescriptor();
  942.     var idChnl = charIDToTypeID( "Chnl" );
  943.     var ref2 = new ActionReference();
  944.     var idChnl = charIDToTypeID( "Chnl" );
  945.     var idChnl = charIDToTypeID( "Chnl" );
  946.     var idRd = charIDToTypeID( "Rd  " );
  947.     ref2.putEnumerated( idChnl, idChnl, idRd );
  948.     desc4.putReference( idChnl, ref2 );
  949.     var idAmnt = charIDToTypeID( "Amnt" );
  950.     desc4.putInteger( idAmnt, 0 );
  951.     var idchannelDenoiseParams = stringIDToTypeID( "channelDenoiseParams" );
  952.     list1.putObject( idchannelDenoiseParams, desc4 );
  953.     var desc5 = new ActionDescriptor();
  954.     var idChnl = charIDToTypeID( "Chnl" );
  955.     var ref3 = new ActionReference();
  956.     var idChnl = charIDToTypeID( "Chnl" );
  957.     var idChnl = charIDToTypeID( "Chnl" );
  958.     var idGrn = charIDToTypeID( "Grn " );
  959.     ref3.putEnumerated( idChnl, idChnl, idGrn );
  960.     desc5.putReference( idChnl, ref3 );
  961.     var idAmnt = charIDToTypeID( "Amnt" );
  962.     desc5.putInteger( idAmnt, 0 );
  963.     var idchannelDenoiseParams = stringIDToTypeID( "channelDenoiseParams" );
  964.     list1.putObject( idchannelDenoiseParams, desc5 );
  965.     var desc6 = new ActionDescriptor();
  966.     var idChnl = charIDToTypeID( "Chnl" );
  967.     var ref4 = new ActionReference();
  968.     var idChnl = charIDToTypeID( "Chnl" );
  969.     var idChnl = charIDToTypeID( "Chnl" );
  970.     var idBl = charIDToTypeID( "Bl  " );
  971.     ref4.putEnumerated( idChnl, idChnl, idBl );
  972.     desc6.putReference( idChnl, ref4 );
  973.     var idAmnt = charIDToTypeID( "Amnt" );
  974.     desc6.putInteger( idAmnt, 0 );
  975.     var idchannelDenoiseParams = stringIDToTypeID( "channelDenoiseParams" );
  976.     list1.putObject( idchannelDenoiseParams, desc6 );
  977.     desc2.putList( idchannelDenoise, list1 );
  978.     var idpreset = stringIDToTypeID( "preset" );
  979.     desc2.putString( idpreset, "Default" );
  980.     executeAction( iddenoise, desc2, DialogModes.NO );
  981.    
  982. //Release references
  983. iddenoise = null
  984. desc2 = null
  985. idClNs = null
  986. idPrc = null
  987. idShrp = null
  988. idremoveJPEGArtifact = null
  989. idchannelDenoise = null
  990. list1 = null
  991. desc3 = null
  992. idChnl = null
  993. ref1 = null
  994. idCmps = null
  995. idAmnt = null
  996. idEdgF = null
  997. idchannelDenoiseParams = null
  998. desc4 = null
  999. ref2 = null
  1000. idRd = null
  1001. desc5 = null
  1002. ref3 = null
  1003. idGrn = null
  1004. desc6 = null
  1005. ref4 = null
  1006. idBl = null
  1007. idpreset = null
  1008. }
  1009.  
  1010. //Apply film grain
  1011. function applyFilmGrain(intn, cntr)
  1012. {
  1013.     selectNonBlack()
  1014.    
  1015.     var idGrn = charIDToTypeID( "Grn " );
  1016.     var desc2 = new ActionDescriptor();
  1017.     var idGEfk = charIDToTypeID( "GEfk" );
  1018.     var idGEft = charIDToTypeID( "GEft" );
  1019.     var idGrn = charIDToTypeID( "Grn " );
  1020.     desc2.putEnumerated( idGEfk, idGEft, idGrn );
  1021.     var idIntn = charIDToTypeID( "Intn" );
  1022.     desc2.putInteger( idIntn, intn );
  1023.     var idCntr = charIDToTypeID( "Cntr" );
  1024.     desc2.putInteger( idCntr, cntr );
  1025.     var idGrnt = charIDToTypeID( "Grnt" );
  1026.     var idGrnt = charIDToTypeID( "Grnt" );
  1027.     var idGrSf = charIDToTypeID( "GrSf" );
  1028.     desc2.putEnumerated( idGrnt, idGrnt, idGrSf );
  1029.     executeAction( idGrn, desc2, DialogModes.NO );
  1030.    
  1031.     deselect()
  1032. //Release references
  1033. idGrn = null
  1034. desc2 = null
  1035. idGEfk = null
  1036. idGEft = null
  1037. idGrn = null
  1038. idIntn = null
  1039. idCntr = null
  1040. idGrnt = null
  1041. idGrSf = null
  1042. }
  1043.  
  1044. //Select all non-black
  1045. function selectNonBlack ()
  1046. {
  1047.     var idClrR = charIDToTypeID( "ClrR" );
  1048.     var desc11 = new ActionDescriptor();
  1049.     var idFzns = charIDToTypeID( "Fzns" );
  1050.     desc11.putInteger( idFzns, 0 );
  1051.     var idMnm = charIDToTypeID( "Mnm " );
  1052.     var desc12 = new ActionDescriptor();
  1053.     var idLmnc = charIDToTypeID( "Lmnc" );
  1054.     desc12.putDouble( idLmnc, 0.000000 );
  1055.     var idA = charIDToTypeID( "A   " );
  1056.     desc12.putDouble( idA, 0.000000 );
  1057.     var idB = charIDToTypeID( "B   " );
  1058.     desc12.putDouble( idB, 0.000000 );
  1059.     var idLbCl = charIDToTypeID( "LbCl" );
  1060.     desc11.putObject( idMnm, idLbCl, desc12 );
  1061.     var idMxm = charIDToTypeID( "Mxm " );
  1062.     var desc13 = new ActionDescriptor();
  1063.     var idLmnc = charIDToTypeID( "Lmnc" );
  1064.     desc13.putDouble( idLmnc, 0.000000 );
  1065.     var idA = charIDToTypeID( "A   " );
  1066.     desc13.putDouble( idA, 0.000000 );
  1067.     var idB = charIDToTypeID( "B   " );
  1068.     desc13.putDouble( idB, 0.000000 );
  1069.     var idLbCl = charIDToTypeID( "LbCl" );
  1070.     desc11.putObject( idMxm, idLbCl, desc13 );
  1071.     var idInvr = charIDToTypeID( "Invr" );
  1072.     desc11.putBoolean( idInvr, true );
  1073.     var idcolorModel = stringIDToTypeID( "colorModel" );
  1074.     desc11.putInteger( idcolorModel, 0 );
  1075.     executeAction( idClrR, desc11, DialogModes.NO );
  1076.    
  1077. //Release references
  1078. idClrR = null
  1079. desc11 = null
  1080. idFzns = null
  1081. idMnm = null
  1082. desc12 = null
  1083. idLmnc = null
  1084. idA = null
  1085. idB = null
  1086. idLbCl = null
  1087. idMxm = null
  1088. desc13 = null
  1089. idA = null
  1090. idB = null
  1091. idInvr = null
  1092. idcolorModel = null
  1093. }
  1094.  
  1095. //Deselect
  1096. function deselect()
  1097. {
  1098.     var idsetd = charIDToTypeID( "setd" );
  1099.     var desc14 = new ActionDescriptor();
  1100.     var idnull = charIDToTypeID( "null" );
  1101.     var ref3 = new ActionReference();
  1102.     var idChnl = charIDToTypeID( "Chnl" );
  1103.     var idfsel = charIDToTypeID( "fsel" );
  1104.     ref3.putProperty( idChnl, idfsel );
  1105.     desc14.putReference( idnull, ref3 );
  1106.     var idT = charIDToTypeID( "T   " );
  1107.     var idOrdn = charIDToTypeID( "Ordn" );
  1108.     var idNone = charIDToTypeID( "None" );
  1109.     desc14.putEnumerated( idT, idOrdn, idNone );
  1110.     executeAction( idsetd, desc14, DialogModes.NO );
  1111.    
  1112. //Release references
  1113. idsetd = null
  1114. desc14 = null
  1115. idnull = null
  1116. ref3 = null
  1117. idChnl = null
  1118. idfsel = null
  1119. idT = null
  1120. idOrdn = null
  1121. idNone = null
  1122. }
  1123.  
  1124. //Perfectum smoothing
  1125. function perfectum (/*percent*/)
  1126. {
  1127.     var Perfectumonezerozero = stringIDToTypeID( "redfieldplugins.com/Perfectum1.00" );
  1128.     var desc3 = new ActionDescriptor();
  1129.     var idkkzerozero = charIDToTypeID( "kk00" );
  1130.     desc3.putInteger( idkkzerozero, 88915769 ); //These two seemingly random numbers somehow control %
  1131.     var idkkzeroone = charIDToTypeID( "kk01" );
  1132.     desc3.putInteger( idkkzeroone, -1607991020 );
  1133.     var idkkzerotwo = charIDToTypeID( "kk02" );
  1134.     desc3.putInteger( idkkzerotwo, 2064 );
  1135.     var idkkzerothree = charIDToTypeID( "kk03" );
  1136.     desc3.putInteger( idkkzerothree, 0 );
  1137.     var idkkzerofour = charIDToTypeID( "kk04" );
  1138.     desc3.putInteger( idkkzerofour, 0 );
  1139.     var idkkzerofive = charIDToTypeID( "kk05" );
  1140.     desc3.putInteger( idkkzerofive, 0 );
  1141.     var idkkzerosix = charIDToTypeID( "kk06" );
  1142.     desc3.putInteger( idkkzerosix, 0 );
  1143.     var idkkzeroseven = charIDToTypeID( "kk07" );
  1144.     desc3.putInteger( idkkzeroseven, 0 );
  1145.     var idkkzeroeight = charIDToTypeID( "kk08" );
  1146.     desc3.putInteger( idkkzeroeight, 0 );
  1147.     var idkkzeronine = charIDToTypeID( "kk09" );
  1148.     desc3.putInteger( idkkzeronine, 0 );
  1149.     var idkkzerocolon = charIDToTypeID( "kk0:" );
  1150.     desc3.putInteger( idkkzerocolon, 0 );
  1151.     var idkkzerosemi = charIDToTypeID( "kk0;" );
  1152.     desc3.putInteger( idkkzerosemi, 0 );
  1153.     var idkkzeroless = charIDToTypeID( "kk0<" );
  1154.     desc3.putInteger( idkkzeroless, 0 );
  1155.     var idkkzeroequal = charIDToTypeID( "kk0=" );
  1156.     desc3.putInteger( idkkzeroequal, 0 );
  1157.     var idkkzerogreater = charIDToTypeID( "kk0>" );
  1158.     desc3.putInteger( idkkzerogreater, 0 );
  1159.     var idkkzeroquestion = charIDToTypeID( "kk0?" );
  1160.     desc3.putInteger( idkkzeroquestion, 0 );
  1161.     executeAction( Perfectumonezerozero, desc3, DialogModes.NO );
  1162.    
  1163. //Release references
  1164. Perfectumonezerozero = null
  1165. desc3 = null
  1166. idkkzerozero = null
  1167. idkkzeroone = null
  1168. idkkzerotwo = null
  1169. idkkzerothree = null
  1170. idkkzerofour = null
  1171. idkkzerofive = null
  1172. idkkzerosix = null
  1173. idkkzeroseven = null
  1174. idkkzeroeight = null
  1175. idkkzeronine = null
  1176. idkkzerocolon = null
  1177. idkkzerosemi = null
  1178. idkkzeroless = null
  1179. idkkzeroequal = null
  1180. idkkzerogreater = null
  1181. idkkzeroquestion = null
  1182. }
  1183.  
  1184. //Select layer transparency only
  1185. function selectTransparency ()
  1186. {
  1187.     if(app.activeDocument.activeLayer.isBackgroundLayer)
  1188.     {
  1189.         return; // background doesn't have a transparency mask
  1190.     }
  1191.     var selection = charIDToTypeID( "setd" );
  1192.     var desc = new ActionDescriptor();
  1193.     var ref = new ActionReference();
  1194.     ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
  1195.     desc.putReference( charIDToTypeID( "null" ), ref );
  1196.     var ref1 = new ActionReference();
  1197.     ref1.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );
  1198.     desc.putReference( charIDToTypeID( "T   " ), ref1 );
  1199.     executeAction( selection, desc, DialogModes.NO );
  1200.    
  1201. //Release references
  1202. selection = null
  1203. desc = null
  1204. ref = null
  1205. ref1 = null
  1206. }
  1207.  
  1208. function maskRevealSelection ()
  1209. {
  1210.     var idMk = charIDToTypeID( "Mk  " );
  1211.     var desc3 = new ActionDescriptor();
  1212.     var idNw = charIDToTypeID( "Nw  " );
  1213.     var idChnl = charIDToTypeID( "Chnl" );
  1214.     desc3.putClass( idNw, idChnl );
  1215.     var idAt = charIDToTypeID( "At  " );
  1216.     var ref3 = new ActionReference();
  1217.     var idChnl = charIDToTypeID( "Chnl" );
  1218.     var idChnl = charIDToTypeID( "Chnl" );
  1219.     var idMsk = charIDToTypeID( "Msk " );
  1220.     ref3.putEnumerated( idChnl, idChnl, idMsk );
  1221.     desc3.putReference( idAt, ref3 );
  1222.     var idUsng = charIDToTypeID( "Usng" );
  1223.     var idUsrM = charIDToTypeID( "UsrM" );
  1224.     var idRvlS = charIDToTypeID( "RvlS" );
  1225.     desc3.putEnumerated( idUsng, idUsrM, idRvlS );
  1226.     executeAction( idMk, desc3, DialogModes.NO );
  1227.    
  1228. //Release references
  1229. idMk = null
  1230. desc3 = null
  1231. idNw = null
  1232. idChnl = null
  1233. idAt = null
  1234. ref3 = null
  1235. idMsk = null
  1236. idUsng = null
  1237. idUsrM = null
  1238. idRvlS = null
  1239. }
  1240.  
  1241. function maskRevealAll ()
  1242. {
  1243.     var idMk = charIDToTypeID( "Mk  " );
  1244.     var desc17 = new ActionDescriptor();
  1245.     var idNw = charIDToTypeID( "Nw  " );
  1246.     var idChnl = charIDToTypeID( "Chnl" );
  1247.     desc17.putClass( idNw, idChnl );
  1248.     var idAt = charIDToTypeID( "At  " );
  1249.     var ref12 = new ActionReference();
  1250.     var idChnl = charIDToTypeID( "Chnl" );
  1251.     var idChnl = charIDToTypeID( "Chnl" );
  1252.     var idMsk = charIDToTypeID( "Msk " );
  1253.     ref12.putEnumerated( idChnl, idChnl, idMsk );
  1254.     desc17.putReference( idAt, ref12 );
  1255.     var idUsng = charIDToTypeID( "Usng" );
  1256.     var idUsrM = charIDToTypeID( "UsrM" );
  1257.     var idRvlA = charIDToTypeID( "RvlA" );
  1258.     desc17.putEnumerated( idUsng, idUsrM, idRvlA );
  1259.     executeAction( idMk, desc17, DialogModes.NO );    
  1260.    
  1261. //Release references
  1262. idMk = null
  1263. desc17 = null
  1264. idNw = null
  1265. idChnl = null
  1266. idAt = null
  1267. ref12 = null
  1268. idMsk = null
  1269. idUsng = null
  1270. idUsrM = null
  1271. idRvlA = null
  1272. }
  1273.  
  1274. function showMaskChannel ()
  1275. {
  1276.     var idShw = charIDToTypeID( "Shw " );
  1277.     var desc4 = new ActionDescriptor();
  1278.     var idnull = charIDToTypeID( "null" );
  1279.     var list1 = new ActionList();
  1280.     var ref4 = new ActionReference();
  1281.     var idChnl = charIDToTypeID( "Chnl" );
  1282.     var idOrdn = charIDToTypeID( "Ordn" );
  1283.     var idTrgt = charIDToTypeID( "Trgt" );
  1284.     ref4.putEnumerated( idChnl, idOrdn, idTrgt );
  1285.     list1.putReference( ref4 );
  1286.     desc4.putList( idnull, list1 );
  1287.     executeAction( idShw, desc4, DialogModes.NO );
  1288.     var idHd = charIDToTypeID( "Hd  " );
  1289.     var desc5 = new ActionDescriptor();
  1290.     var idnull = charIDToTypeID( "null" );
  1291.     var list2 = new ActionList();
  1292.     var ref5 = new ActionReference();
  1293.     var idChnl = charIDToTypeID( "Chnl" );
  1294.     var idChnl = charIDToTypeID( "Chnl" );
  1295.     var idRd = charIDToTypeID( "Rd  " );
  1296.     ref5.putEnumerated( idChnl, idChnl, idRd );
  1297.     list2.putReference( ref5 );
  1298.     var ref6 = new ActionReference();
  1299.     var idChnl = charIDToTypeID( "Chnl" );
  1300.     var idChnl = charIDToTypeID( "Chnl" );
  1301.     var idGrn = charIDToTypeID( "Grn " );
  1302.     ref6.putEnumerated( idChnl, idChnl, idGrn );
  1303.     list2.putReference( ref6 );
  1304.     var ref7 = new ActionReference();
  1305.     var idChnl = charIDToTypeID( "Chnl" );
  1306.     var idChnl = charIDToTypeID( "Chnl" );
  1307.     var idBl = charIDToTypeID( "Bl  " );
  1308.     ref7.putEnumerated( idChnl, idChnl, idBl );
  1309.     list2.putReference( ref7 );
  1310.     desc5.putList( idnull, list2 );
  1311.     executeAction( idHd, desc5, DialogModes.NO );
  1312.    
  1313. //Release references
  1314. idShw = null
  1315. desc4 = null
  1316. idnull = null
  1317. list1 = null
  1318. ref4 = null
  1319. idChnl = null
  1320. idOrdn = null
  1321. idTrgt = null
  1322. idHd = null
  1323. desc5 = null
  1324. list2 = null
  1325. ref5 = null
  1326. idRd = null
  1327. ref6 = null
  1328. idGrn = null
  1329. ref7 = null
  1330. idBl = null
  1331. }
  1332.  
  1333. function applyMask ()
  1334. {
  1335.     var idDlt = charIDToTypeID( "Dlt " );
  1336.     var desc21 = new ActionDescriptor();
  1337.     var idnull = charIDToTypeID( "null" );
  1338.     var ref17 = new ActionReference();
  1339.     var idChnl = charIDToTypeID( "Chnl" );
  1340.     var idOrdn = charIDToTypeID( "Ordn" );
  1341.     var idTrgt = charIDToTypeID( "Trgt" );
  1342.     ref17.putEnumerated( idChnl, idOrdn, idTrgt );
  1343.     desc21.putReference( idnull, ref17 );
  1344.     var idAply = charIDToTypeID( "Aply" );
  1345.     desc21.putBoolean( idAply, true );
  1346.     executeAction( idDlt, desc21, DialogModes.NO );
  1347.    
  1348. //Release references
  1349. idDlt = null
  1350. desc21 = null
  1351. idnull = null
  1352. ref17 = null
  1353. idChnl = null
  1354. idOrdn = null
  1355. idTrgt = null
  1356. idAply = null
  1357. }
  1358.  
  1359. function pasteInPlace ()
  1360. {
  1361.     var idpast = charIDToTypeID( "past" );
  1362.     var desc6 = new ActionDescriptor();
  1363.     var idinPlace = stringIDToTypeID( "inPlace" );
  1364.     desc6.putBoolean( idinPlace, true );
  1365.     var idAntA = charIDToTypeID( "AntA" );
  1366.     var idAnnt = charIDToTypeID( "Annt" );
  1367.     var idAnno = charIDToTypeID( "Anno" );
  1368.     desc6.putEnumerated( idAntA, idAnnt, idAnno );
  1369.     executeAction( idpast, desc6, DialogModes.NO );
  1370.    
  1371. //Release references
  1372. idpast = null
  1373. desc6 = null
  1374. idinPlace = null
  1375. idAntA = null
  1376. idAnnt = null
  1377. idAnno = null
  1378. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top