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!