Skip to content

Fix split view errors and speed up rotation and text search - #12

Merged
hawkff merged 4 commits into
mainfrom
fix-split-errors-speed-up-rotation
Oct 1, 2026
Merged

hawkff merged 4 commits into
mainfrom
fix-split-errors-speed-up-rotation

Conversation

@hawkff

@hawkff hawkff commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Show the open error of a second command-line book instead of dropping it. Two paths now always start in split view, so the pane holds the error when its book fails to open.

Rotate pages through RGBA pixel rows instead of per-pixel At and Set calls, which boxed a color for every pixel. Encode laid-out text pages at best speed, matching the other PNG encoders in the pipeline. Scan book text pages in batches of 64 inside one update instead of one message per page, so a text search over a long book finishes in a few updates while input and progress stay live.

Add a rotation test covering all three quarter turns, offset bounds, the RGBA fast path on a sub-image, and a round trip.

Summary by CodeRabbit

  • Performance Improvements
    • EPUB pages render to images faster.
    • Image rotation and text-only page processing are more efficient, helping pages display and OCR results update sooner.
  • Bug Fixes
    • Split view is now enabled when multiple book paths are supplied, even if the second book cannot be opened.
    • Quarter-turn image rotation now handles images with offset bounds and sub-images consistently.

Note

Fix split-view opening errors and speed up rotation and text search

  • ui.New now decides split-pane mode by the number of command-line paths, not by whether the second book opened, so a failed second book still shows its error in its pane (ui.go)
  • render.rotate now uses direct RGBA pixel-buffer copies instead of per-pixel color-interface reads; non-RGBA images are converted once, and quarter-turn mappings are unchanged (transform.go)
  • ui.Model.updateOCR processes consecutive text pages in batches of up to 64 per update, requests OCR for non-text pages, and yields between batches while keeping hit tracking and navigation behavior
  • EPUB page PNGs are encoded with png.BestSpeed for faster serialization (epub_render.go)
  • Risk: rotated PNG output bytes differ due to the new compression level; split-view no longer restores webtoon resume state when multiple paths are supplied — check ui.New for that case

Macroscope summarized 3f0b979.

RetriggerConfidence Score: 5/5

The PR appears safe to merge, though dense text batches can still delay input briefly.

Findings

  1. P2 Search batches can delay input ▶
Fix with agent prompt
### Issue 1
internal/ui/ui.go:undefined-1394
A text-heavy book can make one update extract and search 65 pages before the reader handles another key or redraws progress. The fixed page count does not limit how long that work takes when pages contain substantial text. Consider yielding after a time or work budget so a dense batch does not stall the interface.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR keeps the error pane visible when a second command-line book fails to open, speeds up image rotation and EPUB PNG encoding, and scans text pages in batches during search. The latest changes make batches contain 64 pages and add a test for search progress across batch and image-page boundaries.

Reviews (2) · Last reviewed commit: "Yield text search after 64 pages and tes..."

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 30c6e55f-1d21-49c0-8a5e-e738219f7eaf

📥 Commits

Reviewing files that changed from the base of the PR and between 582df77 and 3f0b979.

📒 Files selected for processing (2)
  • internal/ui/ui.go
  • internal/ui/ui_test.go

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 09621e90-bc0c-46ac-aa10-955ab72cde0d

📥 Commits

Reviewing files that changed from the base of the PR and between 4581da6 and 582df77.

📒 Files selected for processing (4)
  • internal/book/epub_render.go
  • internal/render/transform.go
  • internal/render/transform_test.go
  • internal/ui/ui.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The changes update EPUB PNG encoding settings, image rotation pixel copying, split-mode selection, and OCR search processing.

Changes

EPUB PNG Encoding

Layer / File(s) Summary
PNG encoding
internal/book/epub_render.go
EPUB text-page PNG output now uses png.BestSpeed. Encoding errors continue to be returned.

Image Rotation

Layer / File(s) Summary
Rotation pixel copying
internal/render/transform.go, internal/render/transform_test.go
Rotation converts non-RGBA inputs to RGBA and copies pixel bytes directly. Tests check quarter-turn mappings, offset bounds, and sampled pixels after successive rotations.

Split Mode

Layer / File(s) Summary
Split-mode selection
internal/ui/ui.go
Split mode now depends on the number of supplied paths, including when the second book fails to open.

OCR Scanning

Layer / File(s) Summary
Consecutive-page scanning
internal/ui/ui.go
OCR search processes consecutive text pages, caches successful text, records matches and skipped pages, and updates scan progress. It schedules the next page after 64 pages or when the next page requires OCR.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 582df

The rendering optimizations preserve image handling, split view displays failed book opens, and search processing remains bounded. No actionable merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: fixing split-view errors and improving rotation and text-search performance. It is concise and specific.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread internal/ui/ui.go
// Book text needs no OCR: read it here in batches instead of one message
// per page, and yield between batches so input and progress stay live.
next := msg.page + 1
if batch == 64 || !p.book.IsTextPage(next) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium ui/ui.go:1394

updateOCR processes 65 contiguous text pages before yielding, so a 65th large page can keep input and progress blocked beyond the intended 64-page responsiveness bound. Because the current message is processed before checking batch == 64, change the threshold to 63.

Suggested change
if batch == 64 || !p.book.IsTextPage(next) {
if batch == 63 || !p.book.IsTextPage(next) {
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @internal/ui/ui.go around line 1394:

`updateOCR` processes 65 contiguous text pages before yielding, so a 65th large page can keep input and progress blocked beyond the intended 64-page responsiveness bound. Because the current message is processed before checking `batch == 64`, change the threshold to `63`.

Evidence trail:
Reviewed commit 582df77: `internal/ui/ui.go:1369-1398`, especially lines 1391-1397, shows the zero-based batch loop, current-message processing before the `batch == 64` check, and synchronous text-page loading. `internal/ui/ui.go:1329-1357` shows `ocrPage` returning text-page messages and the OCR command chain.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 3f0b979: the counter now starts at 1 and counts pages handled, so an update yields after the 64th page.

Comment thread internal/ui/ui.go
// Book text needs no OCR: read it here in batches instead of one message
// per page, and yield between batches so input and progress stay live.
next := msg.page + 1
if batch == 64 || !p.book.IsTextPage(next) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Search batches can delay input A text-heavy book can make one update extract and search 65 pages before the reader handles another key or redraws progress. The fixed page count does not limit how long that work takes when pages contain substantial text. Consider yielding after a time or work budget so a dense batch does not stall the interface.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/ui/ui.go
Line: 1394

Comment:
**Search batches can delay input** A text-heavy book can make one update extract and search 65 pages before the reader handles another key or redraws progress. The fixed page count does not limit how long that work takes when pages contain substantial text. Consider yielding after a time or work budget so a dense batch does not stall the interface.

**Knowledge Base Used:**
- [Terminal UI navigation](https://app.greptile.com/looneytunes/-/custom-context/knowledge-base/hawkff/cbzr/-/docs/terminal-ui-navigation.md)
- [OCR integration](https://app.greptile.com/looneytunes/-/custom-context/knowledge-base/hawkff/cbzr/-/docs/ocr-integration.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Page geometry bounds the work here. A laid-out text page is 900×1200 px at 32 px, about 25 lines of 60 characters, so 64 pages is roughly 150 KB of string scanning per update, well under a millisecond. A clock read per page would add cost without a measurable gain. 3f0b979 corrects the count to 64.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That’s a fair correction. With batch starting at 1 and yielding when it reaches 64, each update handles at most 64 pages (not 65). Given the fixed 900×1200 layout and the resulting bounded text volume, the batch is small enough that a per-page clock check would add overhead without addressing a practical stall. I’m withdrawing the “Search batches can delay input” finding; no time-based yield is needed here.

Comment thread internal/ui/ui.go
@hawkff
hawkff merged commit 65cf5f9 into main Oct 1, 2026
9 checks passed
@hawkff
hawkff deleted the fix-split-errors-speed-up-rotation branch October 1, 2026 18:59
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.

1 participant