How can I set the colour of a SOLIDFILL layer?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

miked

How can I set the colour of a SOLIDFILL layer?

Post by miked »

Thanks X. You might want to fix the code you posted above to reflect the fix.

...Mike
miked

How can I set the colour of a SOLIDFILL layer?

Post by miked »

I have noticed errors in the colour that is being determined for the solidfill layer using the following modified function:

Code: Select allfunction getAdjustmentLayerColor(doc, layer) {
   var desc = Stdlib.getLayerDescriptor(doc, layer);
   var adjs = desc.getList(cTID('Adjs'));
   var clrDesc = adjs.getObjectValue(0);
   var color= clrDesc.getObjectValue(cTID('Clr '));
   var red = color.getDouble(cTID('Rd  '));
   var green = color.getDouble(cTID('Grn '));
   var blue = color.getDouble(cTID('Bl  '));
   return Stdlib.createRGBColor(red, green, blue);
}


Basically it is returning a colour that is a bit off from what the layer colour actually is.

For example, the solidfill layer colour is #428C9F but the function returns #428B9F, another example is the layer fill is #A8D0DA and the function returns #A7CFD9.

Is this something to do with an assumed colour space (everything is in sRGB) or an error in conversion from rgb to hex? I notice that the function is called "getDouble" which implies that the colour being returned is a double...should this not be an int?

Any help is greatly appreciated.

...Mike
xbytor

How can I set the colour of a SOLIDFILL layer?

Post by xbytor »

When dealing with RGB (and other) colors at the ActionManager level, you need to be a bit careful. The numbers are typically doubles because the color space may be 8bit or 16bit per color. You need better resolution than 0..255.

Do some testing with some known values to see how the numbers map out. They may range 0..100 or 0..1 or something else that you'll have to map back to 0..255.

I've done some mappings in the past. I'll try to dig them out tomorrow.

-X
Mike Hale

How can I set the colour of a SOLIDFILL layer?

Post by Mike Hale »

X is right, 16bit RGB would need to use doubles. Even in 8bit doubles are still needed for LAB mode.

I have a function similar to X's. The only times it does not return the expected value is when the doc is in 16bit mode or the doc has been converted into a different color mode then back again.

In both of your examples the differences could be explained by 16 to 8 bit rounding errors.

Mike

ps. I forgot to add that I don't think it's RGB to HEX. If the hex is off, the R,G, and B values would also be off. Most likely because of the reasons above.
miked

How can I set the colour of a SOLIDFILL layer?

Post by miked »

It's a rounding error. Specifically, PS does not appear to round the double R, G ad B values. So when 167.9961141... is determined as the R value, 167 is assigned, resulting in A7 and not A8. I guess I'll have to add a rounding fix to the function.

...Mike