🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #293

Re: How to load color table in a indexed mode file??

#293
From: Robin_Massey
Date: Tue, 24 Feb 2009 14:52
142 lines
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"".
Technical Details
Message-ID: <59b806b8.2@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
References: <59b806b8.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,8878efe6e0d3c58e
X-Google-Attributes: gidf5839,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Robin_Massey@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.photoshop.scripting
Subject: Re: How to load color table in a indexed mode file??
Message-ID: <59b806b8.2@webcrossing.la2eafNXanI>
Date: Tue, 24 Feb 2009 06:52:48 -0800
References: <59b806b8.-1@webcrossing.la2eafNXanI>
Lines: 155
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit