Consider this script:
#include <pjsr/SampleType.jsh>
#include <pjsr/UndoFlag.jsh>
var win = ImageWindow.activeWindow; // no err checking
var v = win.mainView;
// extract luminance
var luma = new Image;
v.image.extractLuminance (luma);
// create a window for it
var luma_w = new ImageWindow (
500, 500, 1, v.image.bitsPerSample,
v.image.sampleType == SampleType_Real,
false, "MST_luma"
);
// transfer the luminance to the new window
with (luma_w.mainView) {
beginProcess (UndoFlag_NoSwapFile);
image.transfer (luma);
endProcess();
}
luma_w.show();
// add this to the main window as a mask
win.maskVisible = false;
win.maskInverted = true;
win.mask = luma_w;
// create some process
var hist = new HistogramTransform;
hist.H = [
// shadows, midtones, highlights, ext_shadows, ext_hilights
[0, 0.5, 1, 0, 1], // R
[0, 0.5, 1, 0, 1], // G
[0, 0.5, 1, 0, 1], // B
[0, 0.2, 1, 0, 1], // RGB
[0, 0.5, 1, 0, 1], // Alpha
];
// execute it on the mask, and then on the image
hist.executeOn (luma_w.mainView);
hist.executeOn (win.mainView);
// cleanup
luma_w.removeMaskReferences();
//luma_w.undoAll();
//luma_w.purge();
luma_w.close();
luma_w = null;
It is a reduced version of masked-stretch-transform.js. When you run it, you get two confirmation dialogs, and the resulting image can be undone. If you uncomment the lines:
//luma_w.undoAll();
//luma_w.purge();
then you get no confirmation dialogs (as expected) but you can't undo the final image. That's strange, since the purge() operation was applied onto luma_w, not win. I think the fact that luma_w is the mask for win has something to do with this.
Is it a bug? Or am I doing something wrong?
[Edit: corrected "Image" --> "ImageWindow" in the title]