Skip to content

Fix full preview in Inspect image matches#10566

Merged
niksedk merged 3 commits intoSubtitleEdit:mainfrom
HellbringerOnline:codex/inspect-image-matches-full-preview
Apr 8, 2026
Merged

Fix full preview in Inspect image matches#10566
niksedk merged 3 commits intoSubtitleEdit:mainfrom
HellbringerOnline:codex/inspect-image-matches-full-preview

Conversation

@HellbringerOnline
Copy link
Copy Markdown
Contributor

Summary

This fixes OCR inspect windows so grouped matches (ExpandCount > 1) render the full combined image instead of only the first split segment.

Problem

When Inspect image matches opened a grouped match such as do, the right-hand Current image preview and the red rectangle on the sentence preview were based on the first ImageSplitterItem2 only.

This happened for two different reasons:

OCR: OcrViewModel rebuilt inspect matches as reduced NOcrChar objects, which dropped ExpandCount, dimensions, MarginTop, and draw-line metadata before the inspect dialog opened.

  • Binary OCR: the inspect dialog still had ExpandCount, but always rendered _splitItem.NikseBitmap, so the UI still showed only the first split bitmap.

The same issue also leaked into inspect additions/history flows, where preview items for expanded matches were stored as the first segment instead of the combined preview bitmap.

Changes

  • Preserve full NOcrChar metadata when building the inspect match list in OcrViewModel.
  • In BinaryOcrInspectViewModel, track the display bitmap, display bounds, and preview top margin independently from the first split item.
  • For grouped matches, use ExpandedOcrGroup.Create(...) so the inspect dialog now:
    • renders the full grouped bitmap in Current image
    • draws the red rectangle around the full grouped bounds in the sentence preview
    • shows grouped dimensions and grouped top margin in the resolution labels
    • uses grouped bitmap data for exact-match checks in Add better match
  • Keep
    OCR inspect preview top-margin handling aligned with grouped previews.
  • Store preview bitmap/top-margin data in nOCR/Binary OCR additions history items so inspect additions/history windows show the same combined preview that was used during add/inspect flows.

Result

After this change, grouped OCR matches like do are displayed consistently across:

  • Inspect image matches
  • Inspect additions / history windows
  • grouped preview and sentence highlight calculations

Single-character matches keep the old behavior.

Verification

  • dotnet build SubtitleEdit.sln -c Debug
  • Manual UI verification with grouped OCR matches to confirm:
    • the right-side preview shows the full grouped bitmap
    • the red sentence rectangle covers the full grouped match
    • grouped resolution/top-margin info matches the combined preview
    • additions/history views use the same grouped preview instead of the first segment

Screenshot

Inspect image matches grouped preview

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes OCR “Inspect image matches” (and related additions/history flows) so grouped matches (where ExpandCount > 1) render and highlight using the full combined bitmap/bounds rather than only the first split segment.

Changes:

  • Preserve full NOcrChar metadata (width/height/margins/lines + ExpandCount) when building the inspect match list.
  • Update nOCR and Binary OCR inspect view models to track a separate “display” bitmap/bounds/top-margin for grouped matches via ExpandedOcrGroup.
  • Store the combined preview bitmap (and top margin for Binary OCR) in additions history so Inspect Additions/History windows show the same combined preview.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/UI/Features/Ocr/OcrViewModel.cs Keeps richer match metadata for inspect and stores preview bitmaps for history.
src/UI/Features/Ocr/NOcr/NOcrInspectViewModel.cs Uses display bitmap/rect/top-margin so grouped matches preview/highlight correctly.
src/UI/Features/Ocr/NOcr/NOcrCharacterHistoryViewModel.cs Uses stored preview bitmap when showing history items.
src/UI/Features/Ocr/NOcr/NOcrAddHistoryManager.cs Renames stored bitmap parameter to preview bitmap for clarity/consistency.
src/UI/Features/Ocr/NOcr/NOcrAddHistoryItem.cs Stores a cloned PreviewBitmap instead of Bitmap.
src/UI/Features/Ocr/BinaryOcr/BinaryOcrInspectViewModel.cs Tracks display bitmap/bounds/top-margin and performs exact-match checks for expanded groups.
src/UI/Features/Ocr/BinaryOcr/BinaryOcrCharacterHistoryViewModel.cs Uses stored preview bitmap + preview top margin when displaying expanded-history items.
src/UI/Features/Ocr/BinaryOcr/BinaryOcrAddHistoryManager.cs Extends history add API to include preview top margin.
src/UI/Features/Ocr/BinaryOcr/BinaryOcrAddHistoryItem.cs Stores cloned PreviewBitmap + PreviewTopMargin.
patches-github/0001-Fix-nOCR-two-byte-character-load-save-handling.patch Adds a git patch file (currently appears unrelated/out-of-date vs current code).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +12
From cf2d41ec49863362fc0e876f1cf20a26a3b1a20e Mon Sep 17 00:00:00 2001
From: "Hellgringer.Online" <Hellbringer.Online@gmail.com>
Date: Mon, 6 Apr 2026 21:43:29 +0400
Subject: [PATCH] Fix nOCR two-byte character load/save handling

---
src/UI/Logic/Ocr/NOcrChar.cs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/UI/Logic/Ocr/NOcrChar.cs b/src/UI/Logic/Ocr/NOcrChar.cs
index d53a2a070..30fb539bb 100644
--- a/src/UI/Logic/Ocr/NOcrChar.cs
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch file appears unrelated to the PR’s stated goal (inspect preview rendering) and the changes it describes (e.g., incrementing position in the long-format reader and fixing IsAllByteValues to check LinesBackground) are already present in src/UI/Logic/Ocr/NOcrChar.cs. Keeping an unapplied/out-of-date patch here is likely to confuse future maintenance; consider removing it or updating the patch series mechanism/documentation if this folder is meant to be consumed by tooling.

Copilot uses AI. Check for mistakes.
@niksedk niksedk merged commit 60118ca into SubtitleEdit:main Apr 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants