Add Epub::getCoverBmpPath

This commit is contained in:
Dave Allie 2025-12-21 18:24:26 +11:00
parent f1a8e4e00a
commit c50257c9da
No known key found for this signature in database
GPG Key ID: F2FDDB3AD8D0276F
2 changed files with 10 additions and 2 deletions

View File

@ -219,9 +219,11 @@ const std::string& Epub::getPath() const { return filepath; }
const std::string& Epub::getTitle() const { return title; } const std::string& Epub::getTitle() const { return title; }
std::string Epub::getCoverBmpPath() const { return cachePath + "/cover.bmp"; }
bool Epub::generateCoverBmp() const { bool Epub::generateCoverBmp() const {
// Already generated, return true // Already generated, return true
if (SD.exists((getCachePath() + "/cover.bmp").c_str())) { if (SD.exists(getCoverBmpPath().c_str())) {
return true; return true;
} }
@ -238,11 +240,16 @@ bool Epub::generateCoverBmp() const {
coverJpg.close(); coverJpg.close();
coverJpg = SD.open((getCachePath() + "/.cover.jpg").c_str(), FILE_READ); coverJpg = SD.open((getCachePath() + "/.cover.jpg").c_str(), FILE_READ);
File coverBmp = SD.open((getCachePath() + "/cover.bmp").c_str(), FILE_WRITE, true); File coverBmp = SD.open(getCoverBmpPath().c_str(), FILE_WRITE, true);
const bool success = JpegToBmpConverter::jpegFileToBmpStream(coverJpg, coverBmp); const bool success = JpegToBmpConverter::jpegFileToBmpStream(coverJpg, coverBmp);
coverJpg.close(); coverJpg.close();
coverBmp.close(); coverBmp.close();
SD.remove((getCachePath() + "/.cover.jpg").c_str()); SD.remove((getCachePath() + "/.cover.jpg").c_str());
if (!success) {
Serial.printf("[%lu] [EBP] Failed to generate BMP from JPG cover image\n", millis());
SD.remove(getCoverBmpPath().c_str());
}
Serial.printf("[%lu] [EBP] Generated BMP from JPG cover image, success: %s\n", millis(), success ? "yes" : "no"); Serial.printf("[%lu] [EBP] Generated BMP from JPG cover image, success: %s\n", millis(), success ? "yes" : "no");
return success; return success;
} else { } else {

View File

@ -48,6 +48,7 @@ class Epub {
const std::string& getCachePath() const; const std::string& getCachePath() const;
const std::string& getPath() const; const std::string& getPath() const;
const std::string& getTitle() const; const std::string& getTitle() const;
std::string getCoverBmpPath() const;
bool generateCoverBmp() const; bool generateCoverBmp() const;
uint8_t* readItemContentsToBytes(const std::string& itemHref, size_t* size = nullptr, uint8_t* readItemContentsToBytes(const std::string& itemHref, size_t* size = nullptr,
bool trailingNullByte = false) const; bool trailingNullByte = false) const;