Saving Curve Preset as ACV
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.

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...

// 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 >> 😎 & 0xFF);
}else{
self.writeByte((s >> 😎 & 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();
