Imaging API - putLayerMask() bug

Hi,
when putting pixels into a Layer mask, black becomes white unless all pixels are black.

Test image:

Putting a full-black layer mask works fine:

const { imaging, app } = require("photoshop");
const { executeAsModal } = require("photoshop").core;
const doc = app.activeDocument;
const lay = app.activeDocument.activeLayers[0];

await executeAsModal(
    async () => {
        var arr = new Uint8Array(4);
        console.log(arr); // all initialised to 0
        var iData = await imaging.createImageDataFromBuffer(arr, {
            width: 4,
            height: 1,
            components: 1,
            chunky: false,
            colorSpace: "Grayscale",
            colorProfile: "Gray Gamma 2.2",
        });

        await imaging.putLayerMask({
            layerID: lay.id,
            imageData: iData,
        });
    },
    { commandName: "baa" }
);

Putting values that are non-zero works fine:

const { imaging, app } = require("photoshop");
const { executeAsModal } = require("photoshop").core;
const doc = app.activeDocument;
const lay = app.activeDocument.activeLayers[0];

var arr, iData;

await executeAsModal(
    async () => {
        arr = new Uint8Array(4);
        arr[0] = 10; // fine
        arr[1] = 20;
        arr[2] = 100;
        arr[3] = 255;
        console.log(arr);
        iData = await imaging.createImageDataFromBuffer(arr, {
            width: 4,
            height: 1,
            components: 1,
            chunky: false,
            colorSpace: "Grayscale",
            colorProfile: "Gray Gamma 2.2",
        });

        await imaging.putLayerMask({
            layerID: lay.id,
            imageData: iData,
        });
    },
    { commandName: "baa" }
);

Putting whatever AND black, turns black into white.

const { imaging, app } = require("photoshop");
const { executeAsModal } = require("photoshop").core;
const doc = app.activeDocument;
const lay = app.activeDocument.activeLayers[0];

var arr, iData;

await executeAsModal(
    async () => {
        arr = new Uint8Array(4);
        arr[0] = 0; // <- should be black, but it's 255 instead.
        arr[1] = 1;
        arr[2] = 2;
        arr[3] = 50;
        console.log(arr);
        iData = await imaging.createImageDataFromBuffer(arr, {
            width: 4,
            height: 1,
            components: 1,
            chunky: false,
            colorSpace: "Grayscale",
            colorProfile: "Gray Gamma 2.2",
        });

        await imaging.putLayerMask({
            layerID: lay.id,
            imageData: iData,
        });
    },
    { commandName: "baa" }
);

@samgannaway could you please take a look at this? I’m on Mac BTW.
Thanks!

I just started testing the imaging API 2 days ago so I haven’t had a chance to troubelshoot this too much yet. However, There is definitely something going on with putLayerMask.

The workaround I am using right now is to use putSelection and then using UXP to create the mask from the selection. That works flawlessly.

A couple of observations I have noticed.

  1. It is both Windows and Mac.

  2. It only happens when there are “blocks” of pixels where every pixel is set to 0. If there are any non-zero pixels mixed in the “block” then it doesn’t happen. It’s kind of difficult to explain. Here is a mask example. In this example, all of the white pixels around the edges are set to 0. When using putLayerMask, those pixels become white. However, the pixels in the middle work normally for 0, 255, or anything in between. The issues arises right on the edges of the cutout once all of the pixels are all zeros.

Using putSelection works perfectly and those pixels stay at 0 for the selection and the mask generated from the selection is fine. So for now, that is the workaround I guess.

If I can get time next week, I will create a sample UXP plugin with a sample image to upload to a bug report to recreate the issue.

I think I know what this is. It sounds related to bug fix we did for layer masks a little while ago.

Thank you. Please let us know when this is fixed. I have a few plugins in the works that I would like to output pixel data directly to the masks whenever it is fixed.

It’s not a huge deal right now though. Using putSelection and creating a mask is a great workaround until it gets fixed.

I would expect to see it fixed in Beta next week.

1 Like