0

I omitted this earlier to avoid confusion. Written communication doesn't come easily to us all #actuallyautistic.

This is part of a larger script in Photoshop taken from here

I'm trying to extract the palette values in the image as hexadecimal colours or RGB values.

var msg = "";

for (var i = 0; i < 256; i++)
{
    var bin = String.fromCharCode(table.charCodeAt(i), table.charCodeAt(256+i), table.charCodeAt(512+i))
    msg += bin.toString(2);
    // msg += (table.charCodeAt(i), table.charCodeAt(256+i), table.charCodeAt(512+i));
    // msg += "\n";
}

The version commented out collects the Blue data, but not the Red or Green. I don't know why.

msg is then written to a file. In Notepad it looks like this:

@@ `@ €` @ @¿©Ð´€€aà€@€  DDD    

Which seems meaningless. In Sublime Text I can see it's a series of hex numbers.

0000 0020 4040 0060 4020 8060 0040 2040
bf7f a9d0 b480 8061 e080 4080 2000 4444
4420 2020 0000...

In pure Javascript (or ECMA rather), how can I convert the former to the latter?

Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
  • This very much depends on how you get the text into Javascript in the first place. Where does it come from, how might it be pre-interpreted before your Javascript gets its hands on it? – deceze Nov 13 '20 at 11:34
  • This is part of a much more complicated chain. Currently there's no easy method to extract the colours from an index colour image in Photoshop as shown [here](https://community.adobe.com/t5/photoshop/how-do-i-export-the-color-table-act-file-using-a-script/td-p/11081410?page=1) The file is binary encoded `tmp_file.encoding = "BINARY";` – Ghoul Fool Nov 13 '20 at 11:44
  • Instead of writing them out as an act I want to write them out as text (hex/RGB) - that's the plan. – Ghoul Fool Nov 13 '20 at 11:46
  • Not fully sure but this might be what you're looking for: https://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hexadecimal-in-javascript – malarres Nov 13 '20 at 11:47
  • 1
    So you're trying to read a binary file (an image?) and extract its colours? Then anything with Notepad and text encoding is a red herring, forget about that. Presumably you'd try to use some library which can read out that colour information first and foremost. And if/how that's possible very much depends on the context. Browser? Node? Photoshop? – deceze Nov 13 '20 at 11:58
  • This is all in Photoshop. incidentally, when alerting the string within photoshop it reads the same as in notepad. – Ghoul Fool Nov 13 '20 at 12:06
  • Please [clarify](https://stackoverflow.com/posts/64820054/edit) your question with these details. You want colour information, and you're running in Photoshop. Those are rather crucial details. – deceze Nov 13 '20 at 12:10

0 Answers0