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

Issue with RGBColor with extendscript

New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

I was fiddling with RGBColor and noticed something strange.  I can't seem to figure out why it is behaving the way it is.  Can someone please take a look at the following and see if you can get me on the right track to success.

I manually assigned the color (RGBColor.red=1, RGBColor.geen=0, RGBColor.blue=0) and filled a 50X50 selection.  The color in the selection was actually r=2, g=0, b=0.  Should have been r=1, g=0, b=0.  I get the same behavior assigning green and blue color as well.  Assigning the color r=0,g=0,b=0 works OK, but all the other color assignments are off by 1 for every other color value in the range.  IE other than 0, RGBColor.red =x, actually is RGBColor.red = x+1 ln active document.  Same , same for green and blue.

below is the snippet of code that I am running along with a graphic that shows that the color is actually wrong (r=2, g=0, b=0) vice r=1, g=0, b=0.

Anyone seen this condition with RGBColor assignment before. 

I'm new to extendscript for photoshop.

Warren

extendscript snippet

preferences.rulerUnits = Units.PIXELS

mycolor = new RGBColor

mycolor.red = 1

mycolor.blue = 0

mycolor.green = 0

app.activeDocument.selection.select([[0,0],[50,0],[50,50],[0,50]])

app.activeDocument.selection.fill(mycolor)

mycolor.red = 2

mycolor.blue = 0

mycolor.green = 0

app.activeDocument.selection.select([[50,0],[100,0],[100,50],[50,50]])

app.activeDocument.selection.fill(mycolor)

The first image I have the eyedropper at 26,25 (about in the middle of the first block and it shows the color as r=2,g=0,b=0.  Should be r=1,g=0,b=0.

red should be 1.png

The next image I have the eyedropper at 76,26 (about in the middle of the second block and it shows the color as r=3,g=0,b=0.  Should be r=2,g=0,b=0.

What am I missing.....

red should be 2.png

TOPICS
Actions and scripting

Views

2.4K

Translate

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
Adobe
Advisor ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Selection.fill() requires a SolidColor object, not an RGBColor. Given this, you should be able to figure out a solution .

Votes

Translate

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
New Here ,
May 22, 2017 May 22, 2017

Copy link to clipboard

Copied

Thanks for the reply.  However I am getting the same results if I am using SolidColor correctly.  I find very little documentation on implementing SolidColor.

So again the script I am using is below with a screen shot.  The screen shot clearly shows that the foreground color is r=2,g=2,b=2, yet the block is showing as r=3,g=3,b=3.

Point me to some better docs on SolidColor.

ExtendScript

preferences.rulerUnits = Units.PIXELS

//mycolor = new RGBColor

app.foregroundColor = SolidColor

app.foregroundColor.rgb.red = 1.0

app.foregroundColor.rgb.green = 1.0

app.foregroundColor.rgb.blue = 1.0

app.activeDocument.selection.select([[0,0],[50,0],[50,50],[0,50]])

app.activeDocument.selection.fill(app.foregroundColor)

app.foregroundColor.rgb.red = 2

app.foregroundColor.rgb.green = 2

app.foregroundColor.rgb.blue = 2

app.activeDocument.selection.select([[50,0],[100,0],[100,50],[50,50]])

app.activeDocument.selection.fill(app.foregroundColor)

using SolidColor.png

Votes

Translate

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
Advisor ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Try this:

var clr = new SolidColor;

clr.rgb.red = 1;

clr.rgb.green = 1;

clr.rgb.blue = 1;

//... other stuff

app.activeDocument.selection.fill(clr);

Votes

Translate

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
New Here ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

Have tried that already and doesn't work.  Same result.  I have concluded it is a rounding error within extendscript or maybe some converting problem when setting things via extendscript and how extendscript converts that to the user interface.  It does the same with cmyk color, and though I haven't tested all the others I suspect all the color modes do the same.  If you do this with cmyk color, depending on the color you choose it rounds down or up.  For example, I did this with c=70, m=0,y=0,b=0 and it gave cyan a 69 vice a 70.  I tried other cmyk colors and some come out correct and some don't - always rounded up or down by 1.

If you set for example the foregroundColor to RGBColor like r=2,g=2,b=2 in extendscript and then with extendscript fill using  foregroundColor, the actual color you get in the document will be r=3,g=3,b=3, just like in your code snippet above.  However, if you look at the color in the color picker via the user interface in the document, it will show the foreground color to be r=2,g=2,b=2.  But if you then fill with that color somewhere within the document (using the paintbucket tool) it actually fills with r=3,g=3,b=3.  Now, if you go into the color picker and reset the RGB to r=2,g=2,b=2 and then fill with the paintbucket tool it will fill with the right color.  So depending if you set the color within extendscript or with the user interface it behaves differently.

If in the javascript console in extendscript, you create a RGB color and set to r=2,g=2,b=2. then do a $.writeln(RGBColor.red it will show a real number like 2.00000034342323 not an integer of 2.  Some strange things happening within extendscript.  I'm going to report it as a bug...

BTW, i'm using extendscript CC 2015 (I believe the latest...) with photoshop CC2017.1.1.  Haven't checked to see if it exhibits this same behavior with other versions of extendscript and/or photoshop.

Warren

Votes

Translate

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
Advisor ,
May 23, 2017 May 23, 2017

Copy link to clipboard

Copied

LATEST

It's been awhile since I've really looked at this stuff but there are some odd things with SolidColor etc... I know I had seen some odd things when using one Color Profile or another.

Good luck in working through this thicket.

Votes

Translate

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