Ok, this script assumes
There is an open document that is 8bit Lab mode
The script will create a CSV file in the same location as the open document (if it had not been saved it will be saved to the desktop) with the same name as the open document.
File.prototype.readByte = function() {
return this.read(1).charCodeAt(0);
};
function convertByteToSignedByte(num){
var dec = (num | (num % 256))-128
return dec;
};
function convertByteToLum( num){
var dec = Math.round((num/256)*100);
return dec;
};
function main(){
if(!documents.length) return;
if(activeDocument.mode != DocumentMode.LAB) {
alert("Please convert this document to Lab mode\r Then re-run this script");
return;
}
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
try{
var Path = activeDocument.path;
}catch(e){var Path = '~/Desktop';}
var rawFile = new File(Path +"/"+Name +".raw");
saveAsRaw(rawFile);
var csvFile = new File(Path +"/"+Name +".csv");
var len = 0;
var W = activeDocument.width.as('px');
CountW=0;
CountH=0;
rawFile.encoding = 'BINARY';
rawFile.open('r');
csvFile.open('w');
csvFile.writeln('X,Y,L,a,b');
while(!rawFile.eof){
csvFile.write(CountW+',');
csvFile.write(CountH+',');
csvFile.write(convertByteToLum(rawFile.readByte())+',');
csvFile.write(convertByteToSignedByte(rawFile.readByte())+',');
csvFile.writeln(convertByteToSignedByte(rawFile.readByte()));
len++;
if(len % W == 0){
CountH++;
CountW=0;
}else{
CountW++;
}
}
rawFile.close();
csvFile.close();
rawFile.remove();
}
main();
function saveAsRaw(file) {
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putString( charIDToTypeID('FlCr'), "8BIM" );
desc2.putBoolean( charIDToTypeID('ChnI'), true );
desc1.putObject( charIDToTypeID('As '), charIDToTypeID('Rw '), desc2 );
desc1.putPath( charIDToTypeID('In '), new File( file ) );
desc1.putBoolean( charIDToTypeID('Cpy '), true );
executeAction( charIDToTypeID('save'), desc1, DialogModes.NO );
};