Thread View: adobe.photoshop.scripting
8 messages
8 total messages
Started by Robin_Massey
Mon, 23 Feb 2009 13:31
How to load color table in a indexed mode file??
Author: Robin_Massey
Date: Mon, 23 Feb 2009 13:31
Date: Mon, 23 Feb 2009 13:31
2 lines
811 bytes
811 bytes
How to load color table in a indexed mode file?? Actually, if i opened a indexed file and want to edit color table by loading another color table from desktop (or any other location), any way to do this through java scripting??
Re: How to load color table in a indexed mode file??
Author: xbytor
Date: Mon, 23 Feb 2009 16:15
Date: Mon, 23 Feb 2009 16:15
162 lines
4363 bytes
4363 bytes
> How to load color table in a indexed mode file??
I just converted some code that I have to work without the rest of my libs. It's
untested, but the conversion was easy as was adding the 'apply' method.
It's fairly simple to use:
var clrTbl = new ColorTable();
clrTbl.apply("~/someTable.act");
It has a builtin assumption that the color table is always exactly 256 colors in
size, which is probably fine.
-X
//
// ColorTable
// This class reads and writes color table files from disk.
// This assumes that the index color table is (at most) 256 colors long.
// If the file contains less, toString will pad with 0,0,0 entries.
//
// $Id: ColorTable.jsx,v 1.3 2009/02/23 16:11:49 anonymous Exp $
// Copyright: (c)2007, xbytor
// License: http://creativecommons.org/licenses/LGPL/2.1
// Contact: xbytor@gmail.com
//
//
//============================= ColorTable ====================================
ColorTable = function() {
var self = this;
self.file = null;
self.colors = [];
};
ColorTable.RcsId = "$Id: ColorTable.jsx,v 1.3 2009/02/23 16:11:49 anonymous Exp $";
ColorTable.prototype.typename = "ColorTable";
//
// toString always returns 256 colors
//
ColorTable.prototype.toString = function() {
var self = this;
var str = '';
if (!self.colors || self.colors.length == 0) {
return undefined;
}
for (var i = 0; i < 256; i++) {
if (i >= self.colors.length) {
str += "0,0,0\n";
} else {
var sc = self.colors[i];
var rgb = sc.rgb;
str += rgb.red + ',' + rgb.green + ',' + rgb.blue + '\n';
}
};
return str;
};
ColorTable.prototype.read = function(str) {
var self = this;
self.colors = [];
for (var i = 0; i < 256; i++) {
var sc = new SolidColor();
var rgb = sc.rgb;
rgb.red = str.readByte();
rgb.green = str.readByte();
rgb.blue = str.readByte();
self.colors.push(sc);
if (str.eof()) {
break;
}
}
};
ColorTable.prototype.readFromFile = function(fptr) {
var self = this;
if (fptr.constructor == String) {
fptr = File(fptr);
}
self.file = fptr;
file.open("r");
file.encoding = 'BINARY';
var s = file.read();
file.close();
var str = {
str: s,
ptr: 0
}
str.readByte = function() {
var self = this;
if (self.ptr >= self.str.length) {
return -1;
}
return self.str.charCodeAt(self.ptr++);
}
str.eof = function() {
this.ptr = this.ptr.length;
}
self.read(str);
};
ColorTable.prototype.apply = function(fptr) {
var self = this;
self.readFromFile(fptr);
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty(cTID('Clr '), cTID('ClrT'));
desc.putReference(cTID('null'), ref);
var list = new ActionList();
for (var i = 0; i < colors.length; i++) {
var color = colors[i];
var cdesc = new ActionDescriptor();
cdesc.putDouble(cTID('Rd '), color.rgb.red);
cdesc.putDouble(cTID('Grn '), color.rgb.green);
cdesc.putDouble(cTID('Bl '), color.rgb.blue);
list.putObject(cTID('RGBC'), cdesc);
}
desc.putList(cTID('T '), list);
return executeAction(cTID('setd'), desc, DialogModes.NO);
};
/*
Sample Usage
var clrTbl = new ColorTable();
clrTbl.apply("~/someTable.act");
//include "xlib/stdlib.js"
//include "xlib/Stream.js"
var clrTbl = new ColorTable();
clrTbl.readFromFile("~/someTable.act");
var str = clrTbl.toString();
alert(str);
*/
"ColorTable.jsx";
// EOF
Re: How to load color table in a indexed mode file??
Author: Robin_Massey
Date: Tue, 24 Feb 2009 14:50
Date: Tue, 24 Feb 2009 14:50
142 lines
3640 bytes
3640 bytes
hi xbytor,
thanks for your response, but I didn't quiet get it.
When i run it, following error occurs:
"ColorTable does not have a constructor".
following is the script i have writted:
------
var clrTbl = new ColorTable();
clrTbl.apply("/Users/robin/Desktop/AC5.act");
//============================= ColorTable ====================================
ColorTable = function() {
var self = this;
self.file = null;
self.colors = [];
};
ColorTable.RcsId = "$Id: ColorTable.jsx,v 1.3 2009/02/23 16:11:49 anonymous Exp $";
ColorTable.prototype.typename = "ColorTable";
//
// toString always returns 256 colors
//
ColorTable.prototype.toString = function() {
var self = this;
var str = '';
if (!self.colors || self.colors.length == 0) {
return undefined;
}
for (var i = 0; i < 256; i++) { if (i >= self.colors.length) {
str += "0,0,0\n";
} else {
var sc = self.colors[i];
var rgb = sc.rgb;
str += rgb.red + ',' + rgb.green + ',' + rgb.blue + '\n';
}
};
return str;
};
ColorTable.prototype.read = function(str) {
var self = this;
self.colors = [];
for (var i = 0; i < 256; i++) { var sc = new SolidColor(); var rgb = sc.rgb;
rgb.red = str.readByte();
rgb.green = str.readByte();
rgb.blue = str.readByte();
self.colors.push(sc);
if (str.eof()) {
break;
}
}
};
ColorTable.prototype.readFromFile = function(fptr) {
var self = this;
if (fptr.constructor == String) {
fptr = File(fptr);
}
self.file = fptr;
file.open("r");
file.encoding = 'BINARY';
var s = file.read();
file.close();
var str = {
str: s,
ptr: 0
}
str.readByte = function() {
var self = this;
if (self.ptr >= self.str.length) {
return -1;
}
return self.str.charCodeAt(self.ptr++);
}
str.eof = function() {
this.ptr = this.ptr.length;
}
self.read(str);
};
ColorTable.prototype.apply = function(fptr) {
var self = this;
self.readFromFile(fptr);
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty(cTID('Clr '), cTID('ClrT'));
desc.putReference(cTID('null'), ref);
var list = new ActionList();
for (var i = 0; i < colors.length; i++) { var color = colors[i]; var cdesc = new ActionDescriptor(); cdesc.putDouble(cTID('Rd '), color.rgb.red); cdesc.putDouble(cTID('Grn '), color.rgb.green); cdesc.putDouble(cTID('Bl '), color.rgb.blue); list.putObject(cTID('RGBC'), cdesc); }
desc.putList(cTID('T '), list);
return executeAction(cTID('setd'), desc, DialogModes.NO);
};
/*
Sample Usage
var clrTbl = new ColorTable();
clrTbl.apply("~/someTable.act");
//include "xlib/stdlib.js"
//include "xlib/Stream.js"
var clrTbl = new ColorTable();
clrTbl.readFromFile("~/someTable.act");
var str = clrTbl.toString();
alert(str);
* /
"ColorTable.jsx";
// EOF
-------
Also, please tell where do I locate these files on mac: "//include "xlib/stdlib.js"
//include "xlib/Stream.js"".
Re: How to load color table in a indexed mode file??
Author: Robin_Massey
Date: Tue, 24 Feb 2009 14:52
Date: Tue, 24 Feb 2009 14:52
142 lines
3623 bytes
3623 bytes
hi xbytor,
thanks for your response, but I didn't quiet get it.
When i run it, following error occurs:
"ColorTable does not have a constructor".
following is the script i have writted:
------
var clrTbl = new ColorTable();
clrTbl.apply("/Users/robin/Desktop/AC5.act");
//============================= ColorTable ====================================
ColorTable = function() {
var self = this;
self.file = null;
self.colors = [];
};
ColorTable.RcsId = "$Id: ColorTable.jsx,v 1.3 2009/02/23 16:11:49 anonymous Exp $";
ColorTable.prototype.typename = "ColorTable";
//
// toString always returns 256 colors
//
ColorTable.prototype.toString = function() {
var self = this;
var str = '';
if (!self.colors || self.colors.length == 0) {
return undefined;
}
for (var i = 0; i < 256; i++) { if (i >= self.colors.length) {
str += "0,0,0\n";
} else {
var sc = self.colors[i];
var rgb = sc.rgb;
str += rgb.red + ',' + rgb.green + ',' + rgb.blue + '\n';
}
};
return str;
};
ColorTable.prototype.read = function(str) {
var self = this;
self.colors = [];
for (var i = 0; i < 256; i++) { var sc = new SolidColor(); var rgb = sc.rgb;
rgb.red = str.readByte();
rgb.green = str.readByte();
rgb.blue = str.readByte();
self.colors.push(sc);
if (str.eof()) {
break;
}
}
};
ColorTable.prototype.readFromFile = function(fptr) {
var self = this;
if (fptr.constructor == String) {
fptr = File(fptr);
}
self.file = fptr;
file.open("r");
file.encoding = 'BINARY';
var s = file.read();
file.close();
var str = {
str: s,
ptr: 0
}
str.readByte = function() {
var self = this;
if (self.ptr >= self.str.length) {
return -1;
}
return self.str.charCodeAt(self.ptr++);
}
str.eof = function() {
this.ptr = this.ptr.length;
}
self.read(str);
};
ColorTable.prototype.apply = function(fptr) {
var self = this;
self.readFromFile(fptr);
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty(cTID('Clr '), cTID('ClrT'));
desc.putReference(cTID('null'), ref);
var list = new ActionList();
for (var i = 0; i < colors.length; i++) { var color = colors[i]; var cdesc = new ActionDescriptor(); cdesc.putDouble(cTID('Rd '), color.rgb.red); cdesc.putDouble(cTID('Grn '), color.rgb.green); cdesc.putDouble(cTID('Bl '), color.rgb.blue); list.putObject(cTID('RGBC'), cdesc); }
desc.putList(cTID('T '), list);
return executeAction(cTID('setd'), desc, DialogModes.NO);
};
/*
Sample Usage
var clrTbl = new ColorTable();
clrTbl.apply("~/someTable.act");
//include "xlib/stdlib.js"
//include "xlib/Stream.js"
var clrTbl = new ColorTable();
clrTbl.readFromFile("~/someTable.act");
var str = clrTbl.toString();
alert(str);
* /
"ColorTable.jsx";
// EOF
-------
Also, please tell where do I locate these files on mac: "//include "xlib/stdlib.js"
//include "xlib/Stream.js"".
Re: How to load color table in a indexed mode file??
Author: xbytor
Date: Tue, 24 Feb 2009 15:22
Date: Tue, 24 Feb 2009 15:22
24 lines
1479 bytes
1479 bytes
Robin_Massey@adobeforums.com wrote:
> When i run it, following error occurs:
>
> "ColorTable does not have a constructor".
Try moving this bit of code from the beginning of the file to the end.
> var clrTbl = new ColorTable();
> clrTbl.apply("/Users/robin/Desktop/AC5.act");
>
>
> Also, please tell where do I locate these files on mac: "//include "xlib/stdlib.js"
> //include "xlib/Stream.js"".
You don't need them. I removed the dependencies on these two file from the
script. Those lines of code do nothing now.
They are a part of my xtools package that can be found at
ps-scripts.sourceforge.net. There is a massive amount of code out there. That's
where the original implementation of the ColorTable script can be found.
-X
Re: How to load color table in a indexed mode file??
Author: Robin_Massey
Date: Fri, 27 Feb 2009 14:26
Date: Fri, 27 Feb 2009 14:26
9 lines
939 bytes
939 bytes
Thanxs again xbytor,
but it's still not working for me,
it shows an error "file is undefined" in the below code line:
file.open("r");
It would be a really great help if you define where should i change/apply path of the color table in the script or what changes should be done before i run it on my mac.
Rgs
Robin
Re: How to load color table in a indexed mode file??
Author: Robin_Massey
Date: Mon, 16 Mar 2009 12:47
Date: Mon, 16 Mar 2009 12:47
6 lines
733 bytes
733 bytes
Hi xbytor, just wondering if you get a chance to look into this. rgs Robin
Re: How to load color table in a indexed mode file??
Author: xbytor
Date: Mon, 16 Mar 2009 14:03
Date: Mon, 16 Mar 2009 14:03
9 lines
1219 bytes
1219 bytes
> it shows an error "file is undefined" in the below code line:
> file.open("r");
Without looking at the code, the variable 'file' was either not assigned a valid
value or was not initialized at all. Or, it was misspelled, which I doubt. Put a
breakpoint on that line of code in ESTK and run the script. When the script
stops at that line, look at the 'Data Browser' panel to see if there are any
'File' objects in scope. If there are, 'file' should probably have been assigned
to one of them.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads