Skip to main content
July 6, 2010
Answered

How to turn off color management for a document from a script?

  • July 6, 2010
  • 4 replies
  • 1624 views

Hello.  I am running an old script that worked fine in CS2.  But now in CS4, it messes up.  The script generates an image, and inserts certain codes into certain pixel's RGB values for later processing by my own C program.  For example, it should write a color value of 014B96, but instead it plays with the value first, and writes 024C96 .  I don't know why it plays with the value, but I guess it could be related to the color management.  After creating a new document, I try to disable the color management with doc.colorProfileType = ColorProfile.NONE, but when it executes that line, it says "User cancelled the operation".

I've made a simple minimal test script to illustrate what I'm talking about.  In the test script, it tries to draw a 10x10 block of 014B96, but it ends up being 024C96 for some strange reason.  The offending lines are commented out.  Please tell me what I am doing wrong!  Thanks!

----------

#target photoshop

var doc = documents.add(
        90,
        90,
        72.0,
        "Test",
        NewDocumentMode.RGB,
        DocumentFill.BACKGROUNDCOLOR
        );

//The following yields the error "User cancelled the operation":       
//doc.colorProfileType = ColorProfile.NONE;

//The following yields the error "ColorProfileType is undefined.":       
//doc.colorProfileType = ColorProfileType.NONE;

var color = new SolidColor;

color.model = ColorModel.RGB;
color.rgb.red = 1;
color.rgb.green = 75;
color.rgb.blue = 150;

var x = 5;
var y = 5;

var size = 10;

doc.selection.select ( Array (
        Array ( x, y ),
        Array ( x+size, y ),
        Array ( x+size, y+size ),
        Array ( x, y+size ),
        Array ( x, y )
        ) );
doc.selection.fill ( color, ColorBlendMode.NORMAL, 100 );
doc.selection.deselect ();

This topic has been closed for replies.
Correct answer Michael_L_Hale

I also get that error if I try to set the type to the existing type so add a test to make sure the type needs to be changed before changing.

if(app.activeDocument.colorProfileType != ColorProfile.NONE) app.activeDocument.colorProfileType = ColorProfile.NONE;

4 replies

July 6, 2010

Since I have no idea what's causing the alteration of the values, I'm going to store my data in the upper 6 bits of the RGB values, and retrieve them by adding 2 and then shifting right by 2.  That way it will tolerate an error of ±1.  Though I'd still prefer a solution where the color doesn't change.

Chris Cox
Legend
July 6, 2010

The script generates an image, and inserts certain codes into certain pixel's RGB values for later processing by my own C program.  For example, it should write a color value of 014B96, but instead it plays with the value first, and writes 024C96 .  I don't know why it plays with the value, but I guess it could be related to the color management. 

You need to solve that problem first.

If you specify RGB values, and write them into an RGB document -- there will be no conversion.

If you specify color values in a different color model than the document - then there can be a conversion.

And a document cannot have a profile of "None" - documents always have profiles (otherwise how would the color be displayed?).

Your color values are off by 1, and that could be caused by rounding problems in the scripting support code (wouldn't be the first time they've had similar problems).

Inspiring
July 6, 2010

Chris Cox wrote:


... And a document cannot have a profile of "None" - documents always have profiles (otherwise how would the color be displayed?).

Perhaps the scripting support code is using the wrong terms but to turn color management off for a document you set the colorProfileType property to ColorProfile.NONE. ColorProfie.UNMANAGED may have been a better choice but that is what is used in the scripting DOM.

I don't think that the scripting support code is the cause of the color problems the OP has. The script creates a patch of the correct color when I run it and check using the eyedropper tool set to point sample in the GUI. With larger sample sizes the color can appear to be different because the background color may be part of the sample. But if I place a colorSampler in the patch I get the correct color.

#target photoshop
var doc = documents.add(
        90,
        90,
        72.0,
        "Test",
        NewDocumentMode.RGB,
        DocumentFill.BACKGROUNDCOLOR
        );
var color = new SolidColor;
color.model = ColorModel.RGB;
color.rgb.red = 1;
color.rgb.green = 75;
color.rgb.blue = 150;
var x = 5;
var y = 5;
var size = 10;
doc.selection.select ( Array (
        Array ( x, y ),
        Array ( x+size, y ),
        Array ( x+size, y+size ),
        Array ( x, y+size ),
        Array ( x, y )
        ) );
doc.selection.fill ( color, ColorBlendMode.NORMAL, 100 );
doc.selection.deselect ();
var sample = activeDocument.colorSamplers.add( [ new UnitValue( 7, 'px' ), new UnitValue( 7, 'px' ) ] );
alert(sample.color.rgb.hexValue);// 014B96

Muppet_Mark-QAl63s
Inspiring
July 6, 2010

Im back to using CS2 now. I added this line before your new doc is created but it made no difference if I comment it out? This should be how to turn it off although Im not convinced its your problem…

app.colorSettings = 'Color Management Off';

Oh yes I remember that too now… Mike I have NOT been able to access your site today is it down for any reason?

Inspiring
July 6, 2010

I think it would be better to turn off color management for the doc instead of the whole app. But I agree with Mark that color management may not be your problem. When I run your script I get a block of the correct color with or without color management.

How are you checking the color? What is your eyedropper tool sample size settings?

July 6, 2010

>How are you checking the color? What is your eyedropper tool sample size  settings?

I'm using the eyedropper with point sample.  I'm hovering the mouse over it and looking at the info panel.  I'm saving the file as a .png and reading the value from my C program.  In all cases, it adds 1 to the component value if the value is less than 128.  I deliberately set the size of the block to 10x10 to eliminate these kinds of errors.

Michael_L_HaleCorrect answer
Inspiring
July 6, 2010

I also get that error if I try to set the type to the existing type so add a test to make sure the type needs to be changed before changing.

if(app.activeDocument.colorProfileType != ColorProfile.NONE) app.activeDocument.colorProfileType = ColorProfile.NONE;

July 6, 2010

> I also get that error if I try to set the type to the existing type so  add a test to make sure the type needs to be changed before changing.

You're right.  I guess this doesn't need mentioning, but I changed it to include the "if" statement, and it doesn't give an error mesage anymore, which means that color management was already off, and also means that my problem is unrelated to color management (unless there is another setting).