Copy link to clipboard
Copied
Is there an easy way of populating a grid with 256 colors from a color table or swatch group in a Photoshop document?
A grid similar to the 16 x 16 large thumbnail display in the swatch group panel would be ideal.
I tried taking a screen shot of the swatch group and pasting it into a Photoshop document, but the colors are all shifted.
I’m guessing the shift is based on a conversion from 16 bit to 8 bit.
Perhaps a template or a script is required to get all 256 colors into a Photoshop document.
Something like this, but with the colors still matching the original color table colors is what I'm after:
Thy this
try {
var w = 32;
var h = 32;
var gap = 2;
var idx = 1;
for (var y = 0; y < 16; y++)
{
for (var x = 0; x < 16; x++)
{
var x0 = x*(w+gap);
var y0 = y*(h+gap);
var x1 = x0 + w;
var y1 = y0 + h;
app.activeDocument.selection.select([[x0, y0], [x1, y0], [x1, y1], [x0, y1]], SelectionType.REPLACE);
// select color by index
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIndex(strin
...
My idea was:
Create a new document, 32x32 px or 64x64 px in size.
Use the spectrum or grascale gradient tool to fill the image with more than 256 discreet RGB colours.
Convert to Indexed Color mode (256 colours, no dither).
Image > Mode > Color Table can then be used to change colour palettes.
Use nearest neighbour interpolation and multiples of 200%, 400% etc. to resize larger.
There are no gaps to separate the grid though.
Copy link to clipboard
Copied
Thy this
try {
var w = 32;
var h = 32;
var gap = 2;
var idx = 1;
for (var y = 0; y < 16; y++)
{
for (var x = 0; x < 16; x++)
{
var x0 = x*(w+gap);
var y0 = y*(h+gap);
var x1 = x0 + w;
var y1 = y0 + h;
app.activeDocument.selection.select([[x0, y0], [x1, y0], [x1, y1], [x0, y1]], SelectionType.REPLACE);
// select color by index
var d = new ActionDescriptor();
var r = new ActionReference();
r.putIndex(stringIDToTypeID("colors"), idx);
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
++idx;
// fill selection
var d = new ActionDescriptor();
d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("fillContents"), stringIDToTypeID("foregroundColor"));
d.putUnitDouble(stringIDToTypeID("opacity"), stringIDToTypeID("percentUnit"), 100);
d.putEnumerated(stringIDToTypeID("mode"), stringIDToTypeID("blendMode"), stringIDToTypeID("normal"));
executeAction(stringIDToTypeID("fill"), d, DialogModes.NO);
app.activeDocument.selection.deselect();
}
}
} catch (e) { alert(e.line+ "\n\n" +e); }
Copy link to clipboard
Copied
Thanks! I took break from this project to learn just enough UXP to be dangerous.
Is it possible to use a color table from an ACT file as the source for the 256 colors?
Or the selected swatch group?
Also, should this script use the document color profile by default, or should a color profile be designated?
Thanks again!
Copy link to clipboard
Copied
My idea was:
Create a new document, 32x32 px or 64x64 px in size.
Use the spectrum or grascale gradient tool to fill the image with more than 256 discreet RGB colours.
Convert to Indexed Color mode (256 colours, no dither).
Image > Mode > Color Table can then be used to change colour palettes.
Use nearest neighbour interpolation and multiples of 200%, 400% etc. to resize larger.
There are no gaps to separate the grid though.