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

Load colour table (index color)

Engaged ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

This should be straightforward, I want to load a colour table .ACT from a script only the code from the scriptlistener explicitly looks at each RGB entry:

// =======================================================
var idCnvM = charIDToTypeID( "CnvM" );
    var desc13758 = new ActionDescriptor();
    var idT = charIDToTypeID( "T   " );
        var desc13759 = new ActionDescriptor();
        var idCstP = charIDToTypeID( "CstP" );
            var list1363 = new ActionList();
                var desc13760 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc13760.putDouble( idRd, 196.000000 );
                var idGrn = charIDToTypeID( "Grn " );
                desc13760.putDouble( idGrn, 28.000000 );
                var idBl = charIDToTypeID( "Bl  " );
                desc13760.putDouble( idBl, 56.000000 );
            var idRGBC = charIDToTypeID( "RGBC" );
            list1363.putObject( idRGBC, desc13760 );
                var desc13761 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc13761.putDouble( idRd, 96.000000 );
                var idGrn = charIDToTypeID( "Grn " );
                desc13761.putDouble( idGrn, 96.000000 );
                var idBl = charIDToTypeID( "Bl  " );
                desc13761.putDouble( idBl, 128.000000 );
            var idRGBC = charIDToTypeID( "RGBC" );
            list1363.putObject( idRGBC, desc13761 );
                var desc13762 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc13762.putDouble( idRd, 129.000000 );
                var idGrn = charIDToTypeID( "Grn " );
                desc13762.putDouble( idGrn, 127.000000 );
                var idBl = charIDToTypeID( "Bl  " );
                desc13762.putDouble( idBl, 127.000000 );
            var idRGBC = charIDToTypeID( "RGBC" );
            list1363.putObject( idRGBC, desc13762 );
                var desc13763 = new ActionDescriptor();
                var idRd = charIDToTypeID( "Rd  " );
                desc13763.putDouble( idRd, 93.000000 );
                var idGrn = charIDToTypeID( "Grn " );
                desc13763.putDouble( idGrn, 93.000000 );
                var idBl = charIDToTypeID( "Bl  " );
                desc13763.putDouble( idBl, 93.000000 );
            var idRGBC = charIDToTypeID( "RGBC" );
            list1363.putObject( idRGBC, desc13763 );
        desc13759.putList( idCstP, list1363 );
    var idIndC = charIDToTypeID( "IndC" );
    desc13758.putObject( idT, idIndC, desc13759 );
executeAction( idCnvM, desc13758, DialogModes.NO );

 

Not what I'm after. Also the code is very ugly, and that's only for 4 colours and is incrementally longer for more colour values.

 

Is there the equivilant of  this?

Image > Mode > Color Table... > Custom > Load... (pick mypalette.act) :

 

load_palette("C:\mypalette.act";

function load_palette(apath)
{
	// magic code here
}

.

 

Cheers.

TOPICS
Actions and scripting

Views

732
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

People's Champ , Jan 05, 2022 Jan 05, 2022

Votes

Translate
People's Champ ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

Votes

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

He already knows that: second link

Votes

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
People's Champ ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

quote

He already knows that: second link


By Kukurykus

 

My link points to the specific code he(her) needs

Votes

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 ,
Jan 05, 2022 Jan 05, 2022

Copy link to clipboard

Copied

That's right. I mean he knew your exact post long time ago and even suggested to other user.

Votes

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
Engaged ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

That's expoting it. I can already do that. Trying to load an existing .act back in without having save a temporary .psd,  and get the data from it, that's something else.

Votes

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 ,
Jan 06, 2022 Jan 06, 2022

Copy link to clipboard

Copied

If .act loading snippet in that post is not what you look for, explain better what you mean.

Votes

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
Engaged ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

Sorry, I'm autistic and have trouble saying what I mean clearly to others somethimes.

Basically the equivilant of 

Image > Mode > Color Table... > Custom > Load... (pick a .ACT file)

Votes

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 ,
Jan 07, 2022 Jan 07, 2022

Copy link to clipboard

Copied

That snippet does it. I mean it automatically loads and sets the .act file. Show that on video?

Votes

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
Engaged ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

The snippet from here may work for r-bin, but it doesn't work for me in '22

var myPaletteFile = "D:\temp\4.act";
load_palette(myPaletteFile);

function load_palette(afilename)
{
   var d = new ActionDescriptor();
   var r = new ActionReference();
   r.putProperty(stringIDToTypeID("color"), stringIDToTypeID("colorTable"));
   d.putReference(stringIDToTypeID("null"), r);
   d.putPath(stringIDToTypeID("to"), new File(afilename));
   executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
}

 

I get the error:

Error 8800: General Photoshop error occurred.
This functionality may not be available in this version of Photoshop.
The command "Set" is not currently available.
-> Line 11 executeAction(stringIDToTypeID("set"), d, DialogModes.NO)

 

 

Votes

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Have you changed to 'Edit / Mode / Indexed Color' before ran the snippet?

Votes

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
Engaged ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

Yes, that's what I've just figureed out. - After getting soooo confused. 😞

 

The code above only works if the image is indexed mode. I was hoping it would force it to load the palette and change from RGB to index mode with said palette in one go.  

 

That said, I've managed to get around it by changing it to index prior to loading the palette.

index_colour_it("Adpt");

function index_colour_it(palettestyle, num)
{
  // forces image to be 256 colours
  // =======================================================
  if (num == undefined) num = 256;
  if (palettestyle == undefined) palettestyle = "Perc";
  // could be "Sele" selective or 
  // "Adpt" adaptive
  // "Perc" perceptual
 
  var idCnvM = charIDToTypeID( "CnvM" );
  var desc1729 = new ActionDescriptor();
  var idT = charIDToTypeID( "T   " );
  var desc1730 = new ActionDescriptor();
  var idPlt = charIDToTypeID( "Plt " );
  var idClrP = charIDToTypeID( "ClrP" );
  var idPerc = charIDToTypeID( palettestyle ); // Stye
  desc1730.putEnumerated( idPlt, idClrP, idPerc );
  var idClrs = charIDToTypeID( "Clrs" );
  desc1730.putInteger( idClrs, num ); // number of colours
  var idFrcC = charIDToTypeID( "FrcC" );
  var idFrcC = charIDToTypeID( "FrcC" );
  var idNone = charIDToTypeID( "None" );
  desc1730.putEnumerated( idFrcC, idFrcC, idNone );
  var idTrns = charIDToTypeID( "Trns" );
  desc1730.putBoolean( idTrns, false );
  var idIndC = charIDToTypeID( "IndC" );
  desc1729.putObject( idT, idIndC, desc1730 );
  executeAction( idCnvM, desc1729, DialogModes.NO );
}

 

Votes

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 ,
Jan 08, 2022 Jan 08, 2022

Copy link to clipboard

Copied

LATEST

It seems r-bin solution is correct. Fell free to mark it so 🙂

Votes

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