Fix ImageEditor brush preview dead area on vertical images#12981
Open
MaxwellCalkin wants to merge 1 commit intogradio-app:mainfrom
Open
Fix ImageEditor brush preview dead area on vertical images#12981MaxwellCalkin wants to merge 1 commit intogradio-app:mainfrom
MaxwellCalkin wants to merge 1 commit intogradio-app:mainfrom
Conversation
When a new image is loaded into the ImageEditor, the canvas dimensions change but the brush stroke/preview textures are not recreated. This causes a 'dead area' where the real-time brush preview doesn't render, because the preview sprite's texture is smaller than the actual image. The bug is most visible with vertical (portrait) images, where the canvas height increases significantly beyond the initial canvas size. The bottom portion of the image becomes a dead zone where drawing still works (visible on mouse release) but the real-time preview is clipped to the old texture dimensions. Fix: In BrushTool.set_tool(), detect when the image container's local bounds differ from the stored texture dimensions and reinitialize the textures. Also fix BrushTextures.reinitialize() to correctly compare local bounds instead of the scale-affected container width/height. Fixes gradio-app#12380
|
cc @pngwn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12380
When a new image is loaded into the
ImageEditor, the canvas dimensions change but the brush stroke/preview textures are not recreated. This causes a "dead area" where the real-time brush preview doesn't render — the user can draw (the stroke appears on mouse release) but cannot see the preview while drawing.Root cause
BrushTool.set_tool()only reinitializes brush textures when the draw/erase mode changes or textures are not yet initialized. When an image is loaded andset_tool("draw")is called again (fromImageEditor.reset()), neither condition is true — the mode hasn't changed and textures are already initialized from the initial setup. So the textures keep their old dimensions (from the initial canvas size), and thepreview_spriteonly covers part of the image.This is most visible with vertical (portrait) images because the canvas height increases significantly beyond the initial canvas size, leaving a large dead zone at the bottom of the image.
Fix
BrushTool.set_tool(), add a dimension check: compare the currentimage_container.getLocalBounds()against the stored texture dimensions. If they differ, reinitialize the textures.BrushTextures.reinitialize()to usegetLocalBounds()instead ofimage_container.width/height, which includes the container's scale transform and would give incorrect comparisons.Changes
js/imageeditor/shared/brush/brush.ts: Adddimensions_changedcheck inset_tool()to trigger texture reinitialization when canvas dimensions change.js/imageeditor/shared/brush/brush-textures.ts: Fixreinitialize()to correctly compare local bounds dimensions instead of scale-affected container dimensions.Test plan
gr.ImageEditorReproduction script from the issue: