diff --git a/lib/Epub/Epub/Section.cpp b/lib/Epub/Epub/Section.cpp index 8a157bce..98e2c162 100644 --- a/lib/Epub/Epub/Section.cpp +++ b/lib/Epub/Epub/Section.cpp @@ -189,6 +189,7 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c const uint8_t paragraphAlignment, const uint16_t viewportWidth, const uint16_t viewportHeight, const bool hyphenationEnabled, const bool embeddedStyle, const uint8_t imageRendering, const std::function& progressFn) { + const uint32_t phaseTotalStart = millis(); const auto localPath = epub->getSpineItem(spineIndex).href; const auto tmpHtmlPath = epub->getCachePath() + "/.tmp_" + std::to_string(spineIndex) + ".html"; @@ -199,6 +200,7 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c } // Retry logic for SD card timing issues + const uint32_t phaseStreamStart = millis(); bool success = false; uint32_t fileSize = 0; for (int attempt = 0; attempt < 3 && !success; attempt++) { @@ -232,8 +234,10 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c return false; } + const uint32_t streamMs = millis() - phaseStreamStart; LOG_DBG("SCT", "Streamed temp HTML to %s (%d bytes)", tmpHtmlPath.c_str(), fileSize); + const uint32_t phaseSetupStart = millis(); if (!Storage.openFileForWrite("SCT", filePath, file)) { return false; } @@ -275,8 +279,12 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c [this, &lut](std::unique_ptr page) { lut.emplace_back(this->onPageComplete(std::move(page))); }, embeddedStyle, contentBase, imageBasePath, imageRendering, std::move(tocAnchors), progressFn, cssParser); Hyphenator::setPreferredLanguage(epub->getLanguage()); + const uint32_t setupMs = millis() - phaseSetupStart; + const uint32_t phaseParseStart = millis(); success = visitor.parseAndBuildPages(); + const uint32_t parseMs = millis() - phaseParseStart; + const uint32_t phaseFinalizeStart = millis(); Storage.remove(tmpHtmlPath.c_str()); if (!success) { LOG_ERR("SCT", "Failed to parse XML and build pages"); @@ -353,6 +361,10 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c return false; } this->lut = std::move(lut); + const uint32_t finalizeMs = millis() - phaseFinalizeStart; + const uint32_t totalMs = millis() - phaseTotalStart; + LOG_DBG("SCT", "createSectionFile spine=%d total=%ums (stream=%u setup=%u parse=%u finalize=%u) pages=%u bytes=%u", + spineIndex, totalMs, streamMs, setupMs, parseMs, finalizeMs, pageCount, fileSize); return true; } diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 64f12878..424efea4 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -1373,10 +1373,11 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() { const size_t len = file.read(buf, PARSE_BUFFER_SIZE); bytesRead += len; - // Report progress in 5% increments to limit e-ink refreshes. + // Report progress in 25% increments. Each progressFn callback triggers a full e-ink + // refresh (~650ms); 4 updates total adds ~2.6s, vs ~13s at the previous 5% granularity. if (progressFn && totalFileSize >= MIN_SIZE_FOR_POPUP) { const int progress = static_cast(bytesRead * 100 / totalFileSize); - if (progress / 5 > lastReportedProgress / 5) { + if (progress / 25 > lastReportedProgress / 25) { lastReportedProgress = progress; progressFn(progress); } diff --git a/src/activities/util/BmpViewerActivity.cpp b/src/activities/util/BmpViewerActivity.cpp index 54c4d60d..6285ef3b 100644 --- a/src/activities/util/BmpViewerActivity.cpp +++ b/src/activities/util/BmpViewerActivity.cpp @@ -131,8 +131,7 @@ bool BmpViewerActivity::renderBmpImage(const bool showControls) { FsFile file; const auto pageWidth = renderer.getScreenWidth(); const auto pageHeight = renderer.getScreenHeight(); - Rect popupRect = GUI.drawPopup(renderer, tr(STR_LOADING_POPUP)); - GUI.fillPopupProgress(renderer, popupRect, 20); + GUI.drawPopup(renderer, tr(STR_LOADING_POPUP)); if (!Storage.openFileForRead("BMP", filePath, file)) { return false; @@ -148,8 +147,6 @@ bool BmpViewerActivity::renderBmpImage(const bool showControls) { computeCenteredImagePlacement(bitmap.getWidth(), bitmap.getHeight(), pageWidth, pageHeight, x, y, renderWidth, renderHeight); - GUI.fillPopupProgress(renderer, popupRect, 50); - bmpHasGreyscale = bitmap.hasGreyscale(); // Only render in grayscale when the bitmap actually carries greyscale data AND the user has it enabled. const bool renderGrayscale = bmpHasGreyscale && grayscaleDisplay; @@ -196,8 +193,7 @@ bool BmpViewerActivity::renderDecodedImage(const bool showControls) { RenderLock lock(*this); const auto pageWidth = renderer.getScreenWidth(); const auto pageHeight = renderer.getScreenHeight(); - Rect popupRect = GUI.drawPopup(renderer, tr(STR_LOADING_POPUP)); - GUI.fillPopupProgress(renderer, popupRect, 20); + GUI.drawPopup(renderer, tr(STR_LOADING_POPUP)); ImageToFramebufferDecoder* decoder = ImageDecoderFactory::getDecoder(filePath); if (!decoder) { @@ -212,8 +208,6 @@ bool BmpViewerActivity::renderDecodedImage(const bool showControls) { int x, y, renderWidth, renderHeight; computeCenteredImagePlacement(dims.width, dims.height, pageWidth, pageHeight, x, y, renderWidth, renderHeight); - GUI.fillPopupProgress(renderer, popupRect, 50); - RenderConfig config{}; config.x = x; config.y = y;