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

Raster mask background color detection

Participant ,
Dec 21, 2023 Dec 21, 2023

I noticed some pixel masks change when the canvas size is increased.

An example, if you have a 100% black mask, some masks stay filled black when the canvas increases, or the mask is moved. But some mask seem to have a white background, making the increased canvas size appear white in the mask, or when dragged, the surrounding becomes white.

 

I noticed how this difference is created. When you create a new mask, it's white, you can invert the mask, and it becomes black, and stays black. But if you take the new mask, select all, and fill it black, than it doesn't stay black when adjusted. So while these masks appear the same, they act differently.

 

Is there a way to detect if it's an "empty" mask, white or black. Or if a mask is just filled white or black?

Maybe some action manager code can identify some parameter that shows this difference in mask type?

I could make a script that moves the mask, and then reads back the histogram to detect a change, but I'm hoping there is a more elegant solution. I didn't even know about this mask type difference untill today.

 

My goal is to create a script that makes sure all masks that are 100% white of black are truly "infinite" masks that stay the same after a canvas size change.

TOPICS
Actions and scripting
272
Translate
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
Community Expert ,
Dec 21, 2023 Dec 21, 2023

Can you post a layered PSD that clearly demonstrates the issues?

Translate
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
People's Champ ,
Dec 21, 2023 Dec 21, 2023

del.

 

p.s. Wrong way

Translate
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
People's Champ ,
Dec 21, 2023 Dec 21, 2023
The mask can be filled with white or black and it will remain “infinite”.
It all depends on what mode the mask was created, show or hide.
I think the only way is to parse the PSD file and analyze this value
rbin_0-1703181053280.png
I'm not ready to face this.
 
 
 
Translate
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
People's Champ ,
Dec 21, 2023 Dec 21, 2023
LATEST

You can recreate a mask from the current one with a guaranteed black color outside.

 

// selection from mask
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
d.putReference(stringIDToTypeID("null"), r);
var r1 = new ActionReference();
r1.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
d.putReference(stringIDToTypeID("to"), r1);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

// delete mask
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
d.putReference(stringIDToTypeID("null"), r);
executeAction(stringIDToTypeID("delete"), d, DialogModes.NO);

try {  // mask from selection
    var d = new ActionDescriptor();
    d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
    var r = new ActionReference();
    r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
    d.putReference(stringIDToTypeID("at"), r);
    d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskOptions"), stringIDToTypeID("revealSelection"));
    executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
    }
catch (e)  // no selection, black mask
    {
    try {
        var d = new ActionDescriptor();
        d.putClass(stringIDToTypeID("new"), stringIDToTypeID("channel"));
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("mask"));
        d.putReference(stringIDToTypeID("at"), r);
        d.putEnumerated(stringIDToTypeID("using"), stringIDToTypeID("userMaskOptions"), stringIDToTypeID("hideAll"));
        executeAction(stringIDToTypeID("make"), d, DialogModes.NO);
        }
    catch (e) { alert(e); }
    }

 

 

 

UPD.

Not a very good option either. There may be a problem with the all-white mask.
Translate
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