Report content_rect from the CPU engine - #893
Merged
Merged
Conversation
Only the GPU engine wrote content_rect, and the controller merges each render's metrics into last_metrics rather than replacing them, so the key kept the previous GPU render's value through a CPU render. With a crop active the two disagree: the GPU upscales the cropped region to the preview render size and reports that rect, while the CPU returns native cropped pixels, so the inherited rect described an area twice the buffer. The canvas maps picker and overlay coordinates through it (widget.get_pixel_rgb clamps, overlay maps content-normalized coords), so after a GPU-to-CPU switch the colour readout sampled the wrong pixel. The automatic GPU fallback reaches this too, not just the manual toggle. No paper layout runs on the CPU path, so it reports None. Both engines now always publish the key, and a render's metrics no longer inherit a stale one.
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.
The bug
Only the GPU engine writes
content_rect._on_render_finisheddoeslast_metrics.update(metrics)— a merge, not a replace — so the key kept the previous GPU render's value straight through a CPU render.That is harmless while the two agree, and they usually do. With a crop active they do not: the GPU crops and then upscales the cropped region to the preview render size (
gpu_engine.py:1673), reporting a rect for the upscaled buffer, while the CPU returns native cropped pixels. Measured onsamples/20260619SP_EKTAR100_120_1_09_ME_4000PPI.tif:main_windowpasses that rect tocanvas.update_bufferwhenever no border or paper aspect is set, which is the common case — the border branch is the only one that recomputes it.widget.py:362get_pixel_rgbthen maps normalized coords through the rect and clamps, so with the rect above every sample past 50% width pinned to the right edge: the white-balance picker and the colour readout sampled the wrong pixel.overlay.py:966,1425map overlay coordinates through the same rect.Reachable on any GPU-to-CPU switch with a crop active, including the automatic
"GPU acceleration failed — using CPU"fallback, not only the manual toggle.The fix
DarkroomEngine.processpublishescontent_recttoo. No paper layout runs on that path —FinishProcessor/apply_carrierdraw inside the frame rather than padding it — so the whole buffer is the picture and the honest report isNone. Both engines now always write the key, so a render's metrics cannot inherit a stale one.Verification
make allgreen.tests/test_engine.py::test_the_engine_always_reports_content_rectseeds a stale rect into the context and asserts the engine clears it. Confirmed it fails without the one-line change and passes with it.End to end on the real app, driving the exact switch that triggered it:
Context
Found while chasing what looked like a CPU/GPU disagreement over
crop_rect, flagged in #889. That part turned out to be a misreading on my side — both engines crop, they differ only in output resolution (correlation of the displayed picture +0.9995). This is the real defect that investigation turned up.