Advertisement
boogalooper

Untitled

Apr 14th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. #target photoshop
  2.  
  3. var targetRGB = [128, 128, 128]
  4.  
  5. if ((new AM('application')).getProperty('numberOfDocuments')) {
  6. var lr = new AM('layer'),
  7. doc = new AM('document'),
  8. bounds = doc.descToObject(lr.getProperty('bounds'));
  9. doc.makeSelection(bounds)
  10. makeCurves()
  11. }
  12.  
  13. function makeCurves() {
  14. var doc = new AM('document');
  15. if (doc.hasProperty('selection') && doc.getProperty('mode')[1] == 'RGBColor') {
  16. var midtone = []
  17. if (targetRGB instanceof Array) {
  18. var ch = new AM('channel')
  19. for (var i = 0; i < 3; i++) {
  20. midtone.push(getMidTone(ch.getProperty('histogram', i + 1, true)))
  21. }
  22. }
  23. doc.deselect()
  24. doc.makeCurves(targetRGB, midtone)
  25. }
  26. }
  27. function getMidTone(h) {
  28. var pixels = 0,
  29. sum = 0;
  30. for (var i = 0; i < h.count; i++) {
  31. var key = h.getInteger(i)
  32. pixels += key
  33. sum += key * i
  34. }
  35. $.writeln(sum / pixels)
  36. return sum / pixels
  37. }
  38. function AM(target) {
  39. var s2t = stringIDToTypeID,
  40. t2s = typeIDToStringID;
  41. target = s2t(target)
  42. this.getProperty = function (property, id, idxMode) {
  43. property = s2t(property);
  44. (r = new ActionReference()).putProperty(s2t('property'), property);
  45. id ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id))
  46. : r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
  47. return getDescValue(executeActionGet(r), property)
  48. }
  49. this.hasProperty = function (property, id, idxMode) {
  50. property = s2t(property);
  51. (r = new ActionReference()).putProperty(s2t('property'), property);
  52. id ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id))
  53. : r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
  54. return executeActionGet(r).hasKey(property)
  55. }
  56. this.descToObject = function (d) {
  57. var o = {}
  58. for (var i = 0; i < d.count; i++) {
  59. var k = d.getKey(i)
  60. o[t2s(k)] = getDescValue(d, k)
  61. }
  62. return o
  63. }
  64. switch (t2s(target)) {
  65. case 'document':
  66. this.makeSelection = function (bounds) {
  67. (r = new ActionReference()).putProperty(s2t('channel'), s2t('selection'));
  68. (d = new ActionDescriptor()).putReference(s2t('null'), r);
  69. (d1 = new ActionDescriptor()).putUnitDouble(s2t('top'), s2t('pixelsUnit'), bounds.top);
  70. d1.putUnitDouble(s2t('left'), s2t('pixelsUnit'), bounds.left);
  71. d1.putUnitDouble(s2t('bottom'), s2t('pixelsUnit'), bounds.bottom);
  72. d1.putUnitDouble(s2t('right'), s2t('pixelsUnit'), bounds.right);
  73. d.putObject(s2t('to'), s2t('rectangle'), d1);
  74. executeAction(s2t('set'), d, DialogModes.NO);
  75. }
  76. this.deselect = function () {
  77. (r = new ActionReference()).putProperty(s2t('channel'), s2t('selection'));
  78. (d = new ActionDescriptor()).putReference(s2t('null'), r);
  79. d.putEnumerated(s2t('to'), s2t('ordinal'), s2t('none'));
  80. executeAction(s2t('set'), d, DialogModes.NO);
  81. }
  82. this.makeCurves = function (to, from) {
  83. (r = new ActionReference()).putClass(s2t('adjustmentLayer'));
  84. (d = new ActionDescriptor()).putReference(s2t('null'), r);
  85. (d2 = new ActionDescriptor()).putEnumerated(s2t('presetKind'), s2t('presetKindType'), s2t('presetKindDefault'));
  86. (d1 = new ActionDescriptor()).putObject(s2t('type'), s2t('curves'), d2);
  87. d.putObject(s2t('using'), s2t('adjustmentLayer'), d1);
  88. executeAction(s2t('make'), d, DialogModes.NO);
  89. (r = new ActionReference()).putEnumerated(s2t('adjustmentLayer'), s2t('ordinal'), s2t('targetEnum'));
  90. (d = new ActionDescriptor()).putReference(s2t('null'), r);
  91. (d1 = new ActionDescriptor()).putEnumerated(s2t('presetKind'), s2t('presetKindType'), s2t('presetKindCustom'));
  92. var mode = to.length == 1 ? ['composite'] : ['red', 'green', 'blue'],
  93. l = new ActionList();
  94. for (var i = 0; i < to.length; i++) {
  95. (r1 = new ActionReference()).putEnumerated(s2t('channel'), s2t('channel'), s2t(mode[i]));
  96. (d2 = new ActionDescriptor()).putReference(s2t('channel'), r1);
  97. (d3 = new ActionDescriptor()).putDouble(s2t('horizontal'), 0);
  98. d3.putDouble(s2t('vertical'), 0);
  99. (l1 = new ActionList()).putObject(s2t('Pnt '), d3);
  100. (d4 = new ActionDescriptor()).putDouble(s2t('horizontal'), from[i]);
  101. d4.putDouble(s2t('vertical'), to[i]);
  102. l1.putObject(s2t('Pnt '), d4);
  103. (d5 = new ActionDescriptor()).putDouble(s2t('horizontal'), 255);
  104. d5.putDouble(s2t('vertical'), 255);
  105. l1.putObject(s2t('Pnt '), d5);
  106. d2.putList(s2t('curve'), l1);
  107. l.putObject(s2t('curvesAdjustment'), d2);
  108. }
  109. d1.putList(s2t('adjustment'), l);
  110. d.putObject(s2t('to'), s2t('curves'), d1);
  111. executeAction(s2t('set'), d, DialogModes.NO);
  112. }
  113. break;
  114. }
  115. function getDescValue(d, p) {
  116. switch (d.getType(p)) {
  117. case DescValueType.OBJECTTYPE: return (d.getObjectValue(p));
  118. case DescValueType.LISTTYPE: return d.getList(p);
  119. case DescValueType.REFERENCETYPE: return d.getReference(p);
  120. case DescValueType.BOOLEANTYPE: return d.getBoolean(p);
  121. case DescValueType.STRINGTYPE: return d.getString(p);
  122. case DescValueType.INTEGERTYPE: return d.getInteger(p);
  123. case DescValueType.LARGEINTEGERTYPE: return d.getLargeInteger(p);
  124. case DescValueType.DOUBLETYPE: return d.getDouble(p);
  125. case DescValueType.ALIASTYPE: return d.getPath(p);
  126. case DescValueType.CLASSTYPE: return d.getClass(p);
  127. case DescValueType.UNITDOUBLE: return (d.getUnitDoubleValue(p));
  128. case DescValueType.ENUMERATEDTYPE: return [t2s(d.getEnumerationType(p)), t2s(d.getEnumerationValue(p))];
  129. default: break;
  130. };
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement