Levels conversion error

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

Mikeal.Sim

Levels conversion error

Post by Mikeal.Sim »

I have found that levels do not translate well from actions into javascript.

it produces this:
Code: Select all  // Make
  function step2(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(PSClass.AdjustmentLayer);
    desc1.putReference(PSString.Null, ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(PSKey.Name, "blue be gone");
    var desc3 = new ActionDescriptor();
    var list1 = new ActionList();
    var desc4 = new ActionDescriptor();
    var ref2 = new ActionReference();
    ref2.putEnumerated(PSClass.Channel, PSClass.Channel, PSEnum.Blue);
    desc4.putReference(PSClass.Channel, ref2);
    var list2 = new ActionList();
    list2.putInteger(0);
    list2.putInteger(PSString.shapeburst, 127);
    desc4.putList(PSKey.Output, list2);
    list1.putObject(PSClass.LevelsAdjustment, desc4);
    desc3.putList(PSKey.Adjustment, list1);
    desc2.putObject(PSKey.Type, PSClass.Levels, desc3);
    desc1.putObject(PSKey.Using, PSClass.AdjustmentLayer, desc2);
    executeAction(PSEvent.Make, desc1, dialogMode);
  };


where the javascript produces a different end result then the action file. The output levels (end results) gets changed from the correct 0-127, to the wrong 0-1.
The offending code appears to be "PSString.shapeburst" when this is removed the results are correct.

FROM Broken:
Code: Select all    list2.putInteger(0);
    list2.putInteger(PSString.shapeburst, 127);

TO Working:
Code: Select all    list2.putInteger(0);
    list2.putInteger(127);

I have also seen the same bad code appear in "list3.putInteger" which is the input levels. Removing if from there also corrects the results.

as far as I can tell ever instance of "PSString.shapeburst" produces bad results.


I'm kind of surprised more people aren't complaining about bad results.

I run CS3 on vista 64.
xbytor

Levels conversion error

Post by xbytor »

Yep. That's a bug. Can you send me an atn file with an action that has just that action step? I want to make sure that I can reproduce your problem exactly, but I do think I know what the problem is.

-X
Mikeal.Sim

Levels conversion error

Post by Mikeal.Sim »

this should edit the levels of the blue channel. The output range is shrunk to 0-127.
the conversion bug will cause the end results to be a range of 0-1
xbytor

Levels conversion error

Post by xbytor »

This appears to fix the problem. Let me know if you see any other problems.

-X
Mikeal.Sim

Levels conversion error

Post by Mikeal.Sim »

several new errors with that adjustment. (lines 19, 23, and 25.)


it looks as though you removed every instance of "pskey.xxxx"
only PSString.shapeburst was the issue.

this is the code that it generates from the action file I posted.

Code: Select all//
// Generated Wed Sep 03 2008 20:34:04 GMT-0700
//

//
//==================== Action 1 ==============
//
function Action1() {
  // Levels
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var list1 = new ActionList();
    var desc2 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(PSClass.Channel, PSClass.Channel, PSEnum.Blue);
    desc2.putReference(ref1);
    var list2 = new ActionList();
    list2.putInteger(0);
    list2.putInteger(127);
    desc2.putList(list2);
    list1.putObject(PSClass.LevelsAdjustment, desc2);
    desc1.putList(list1);
    executeAction(PSEvent.Levels, desc1, dialogMode);
  };

  step1();      // Levels
};



cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

//
// Action1.loadSymbols
//   Loading up the symbol definitions like this makes it possible
//   to include several of these generated files in one master file
//   provided a prefix is specified other than the default. It also
//   skips the definitions if PSConstants has already been loaded.
//
Action1.loadSymbols = function() {
  var dbgLevel = $.level;
  $.level = 0;
  try {
    PSConstants;
    return; // only if PSConstants is defined
  } catch (e) {
  } finally {
    $.level = dbgLevel;
  }
  var needDefs = true;
  $.level = 0;
  try {
    PSClass;
    needDefs = false;
  } catch (e) {
  } finally {
    $.level = dbgLevel;
  }
  if (needDefs) {
    PSClass = function() {};
    PSEnum = function() {};
    PSEvent = function() {};
    PSForm = function() {};
    PSKey = function() {};
    PSType = function() {};
    PSUnit = function() {};
    PSString = function() {};
  }

  // We may still end up duplicating some of the following definitions
  // but at least we don't redefine PSClass, etc... and wipe out others
  PSClass.Channel = cTID('Chnl');
  PSClass.LevelsAdjustment = cTID('LvlA');
  PSEnum.Blue = cTID('Bl  ');
  PSEvent.Levels = cTID('Lvls');
};

Action1.loadSymbols(); // load up our symbols



//=========================================
//                    Action1.main
//=========================================
//

Action1.main = function () {
  Action1();
};

Action1.main();

// EOF
xbytor

Levels conversion error

Post by xbytor »

Try this one.

-X
Mikeal.Sim

Levels conversion error

Post by Mikeal.Sim »

looks good!
no errors and it duplicated the action perfectly.
xbytor

Levels conversion error

Post by xbytor »

graphxking wrote:looks good!
no errors and it duplicated the action perfectly.

Good to hear. Generating this code can be a bit dicey and the code could be a bit cleaner than it is. But, if it's working, I'll just leave it be for now.

-X