• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Saving Curve Preset as ACV

Contributor ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

Looking for someone who has any idea how to debug the following script by Mike Hale. Any ideas or even method of were to start would be great, this script is a little beyond my knowledge base....

 

The Script follows through and saves a ACV file, but it flags the following warning when you try and load the curve. Presumable something has changed in the syntax of the curve preset since CS4 when this script was written. 

Screenshot 2021-11-19 at 10.08.01.png

 

 

I opened an . acv of the same curve saved both via photoshop and via the script see below the difference in binary via Synalze pro, i dont really understand how to interpret this data though... 

 

Screenshot 2021-11-19 at 10.18.06.png

 

 

// Works with RGB or CMYK images. 
// Does not work at all with greyscale, or indexColor
// Does not work correctly with Lab
File.prototype.writeByte = function(b) {
  this.write(String.fromCharCode(b));
};
File.prototype.writeShort = function(ET,s) {
  var self = this;
if(ET == "BE"){
  self.writeByte(s & 0xFF);
  self.writeByte((s >> 8) & 0xFF);
}else{
  self.writeByte((s >> 8) & 0xFF);
  self.writeByte(s & 0xFF);
}
  return self;
};
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] ] );
}
var myACV = new File('~/desktop/myCurve.acv');
myACV.open('w');
myACV.writeShort( 'LE','4' );// acv header
myACV.writeShort( 'LE','5' );// acv header
for( var i = 0; i< 5; i++ ) {
    var numberOfPoints = acvArray.length;
    myACV.writeShort( 'LE', numberOfPoints.toString() );
    for( var p = 0; p < numberOfPoints; p++ ){
        myACV.writeShort( 'LE', acvArray
[0].toString() );
        myACV.writeShort( 'LE', acvArray
[1].toString() );
    }
}
myACV.close();

 

TOPICS
Actions and scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 20, 2021 Nov 20, 2021

I thought there might be lack of myACV.encoding = 'binary', but that doesn't help as well. You may try with 'destructive' Curves you're going to call by script and set to some values manually. Then use fromStream() method on actionDescriptor and write the file to the disk, which you're going to compare with .acv you make from Adjustement Layer to find differences. There's also toStream() method you can read how to use on this forum.

Votes

Translate

Translate
Adobe
LEGEND ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

Remove 'Code: Select '?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

I removed "Code: Select all" and it now runs but still produces acv that cannot be opened

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 19, 2021 Nov 19, 2021

Copy link to clipboard

Copied

Same message error on my side, so it seems something has changed since CS4.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

Maybe this works for you...

File.prototype.writeByte = function(b) {
    this.write(String.fromCharCode(b));
};
File.prototype.writeShort = function(ET,s) {
    var self = this;
if(ET == "BE"){
    self.writeByte(s & 0xFF);
    self.writeByte((s >> 8) & 0xFF);
}else{
    self.writeByte((s >> 8) & 0xFF);
    self.writeByte(s & 0xFF);
}  return self;
};
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] ] );
}
var myACV = new File('~/desktop/myCurve.acv');
myACV.open('w');
myACV.writeShort( 'LE','4' );// acv header
myACV.writeShort( 'LE','5' );// acv header
for( var i = 0; i< 5; i++ ) {
    var numberOfPoints = acvArray[i].length;
    myACV.writeShort( 'LE', numberOfPoints.toString() );
    for( var p = 0; p < numberOfPoints; p++ ){
        myACV.writeShort( 'LE', acvArray[i][p][0].toString() );
        myACV.writeShort( 'LE', acvArray[i][p][1].toString() );
        }
}
myACV.close();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

It doesn't work too. Have you tried it on your own, and how you knew what to change?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines