Skip to content

Commit 993401a

Browse files
fix(ui): hide layer when previewing filter
Previously, when previewing a filter on a layer with some transparency or a filter that changes the alpha, the preview was rendered on top of the layer. The preview blended with the layer, which isn't right. In this change, the layer is hidden during the preview, and when the filter finishes (having been applied or canceled - the two possible paths), the layer is shown. Technically, we are hiding and showing the layer's object renderer's konva group, which contains the layer's "real" data. Another small change was made to prevent a flash of empty layer, by waiting to destroy a previous filter preview image until the new preview image is ready to display.
1 parent 8d570dc commit 993401a

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityFilterer.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,9 @@ export class CanvasEntityFilterer extends CanvasModuleBase {
297297
const imageState = imageDTOToImageObject(filterResult.value);
298298
this.$imageState.set(imageState);
299299

300-
// Destroy any existing masked image and create a new one
301-
if (this.imageModule) {
302-
this.imageModule.destroy();
303-
}
300+
// Stash the existing image module - we will destroy it after the new image is rendered to prevent a flash
301+
// of an empty layer
302+
const oldImageModule = this.imageModule;
304303

305304
this.imageModule = new CanvasObjectImage(imageState, this);
306305

@@ -309,6 +308,16 @@ export class CanvasEntityFilterer extends CanvasModuleBase {
309308

310309
this.konva.group.add(this.imageModule.konva.group);
311310

311+
// The filtered image have some transparency, so we need to hide the objects of the parent entity to prevent the
312+
// two images from blending. We will show the objects again in the teardown method, which is always called after
313+
// the filter finishes (applied or canceled).
314+
this.parent.renderer.hideObjects();
315+
316+
if (oldImageModule) {
317+
// Destroy the old image module now that the new one is rendered
318+
oldImageModule.destroy();
319+
}
320+
312321
// The porcessing is complete, set can set the last processed hash and isProcessing to false
313322
this.$lastProcessedHash.set(hash);
314323

@@ -424,6 +433,8 @@ export class CanvasEntityFilterer extends CanvasModuleBase {
424433

425434
teardown = () => {
426435
this.unsubscribe();
436+
// Re-enable the objects of the parent entity
437+
this.parent.renderer.showObjects();
427438
this.konva.group.remove();
428439
// The reset must be done _after_ unsubscribing from listeners, in case the listeners would otherwise react to
429440
// the reset. For example, if auto-processing is enabled and we reset the state, it may trigger processing.

invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityObjectRenderer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ export class CanvasEntityObjectRenderer extends CanvasModuleBase {
185185
return didRender;
186186
};
187187

188+
hideObjects = () => {
189+
this.konva.objectGroup.hide();
190+
};
191+
192+
showObjects = () => {
193+
this.konva.objectGroup.show();
194+
};
195+
188196
adoptObjectRenderer = (renderer: AnyObjectRenderer) => {
189197
this.renderers.set(renderer.id, renderer);
190198
renderer.konva.group.moveTo(this.konva.objectGroup);

0 commit comments

Comments
 (0)