Various fixes applied. See PR for more details.#1
Open
ChrisMenning wants to merge 3 commits into
Open
Conversation
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.
Fixes applied
paginate_html — per-word Image allocation (epub_reader_controller.py)
A fresh Image.new("1", (1, 1)) + ImageDraw.Draw(...) was created for every word during word-wrap measurement. A single _measure_draw object is now created once per call and reused — eliminating thousands of object allocations per chapter.
_extract_pages — entire book paginated at startup (epub_reader_controller.py)
All chapters were paginated upfront before showing anything. Now only the first chapter is loaded; next_page / prev_page already had chapter-transition logic that was dead code — it's now live. load_chapter() caches chapters to avoid re-paginating on revisit.
display_Partial — sends full 48 000-byte frame over SPI (epd7in5_V2.py)
The buffer was allocated as int(self.width * self.height / 8) (full frame) and transmitted in full over SPI even for a tiny radio-button region. It now allocates and sends only Width × Height bytes for the actual region.
init_part() called on every encoder tick (epaper_display_output.py, reader_modal_view.py)
init_part() performs a hardware reset + full SPI init sequence. It was called on every rotary encoder step. Both call sites now guard with if _display_mode != "partial" so the hardware is only initialised once when entering partial mode.
_display_mode tracking + ensure_full_mode() (epaper_display_output.py, tomereader.py)
EPaperDisplay now tracks display mode ("full" / "partial"). A new ensure_full_mode() method reinitialises hardware only when actually switching back from partial mode, replacing the two display.init_display() calls after modal close that triggered a full e-paper clear+reinit (and visible blank-flash) unconditionally.
CBZReaderView — 4-gray mode on a 1-bit framebuffer (cbz_reader_view.py)
The CBZ reader called update_display(mode="4gray"), which is significantly slower than 1-bit mode. The display framebuffer is Image.new("1", ...), so pasting onto it already converts to binary — the 4-gray encode loop runs for no quality benefit. Changed to mode="1".
show_page() — re-parses chapter HTML on every page turn (epub_reader_controller.py)
show_page() called BeautifulSoup(item.get_content(), ...) and searched headings on every single page turn just to populate the footer title. Results are now stored in _chapter_title_cache and parsed at most once per chapter.
cbz_reader_view.py — display_page now composes a fresh "L"-mode canvas locally, pastes the grayscale page onto it, draws the footer directly on that canvas, then passes it to the new display_gray_direct() method. The 1-bit shared framebuffer is never touched.
epaper_display_output.py — new display_gray_direct(img_L) method rotates the L-mode image and sends it straight to display_4Gray / getbuffer_4Gray, preserving all gray levels end-to-end.