MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / generateCoverBmp

Method generateCoverBmp

lib/Txt/Txt.cpp:100–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98std::string Txt::getCoverBmpPath() const { return cachePath + "/cover.bmp"; }
99
100bool Txt::generateCoverBmp() const {
101 // Already generated, return true
102 if (Storage.exists(getCoverBmpPath().c_str())) {
103 return true;
104 }
105
106 std::string coverImagePath = findCoverImage();
107 if (coverImagePath.empty()) {
108 LOG_DBG("TXT", "No cover image found for TXT file");
109 return false;
110 }
111
112 // Setup cache directory
113 setupCacheDir();
114
115 if (FsHelpers::hasBmpExtension(coverImagePath)) {
116 // Copy BMP file to cache
117 LOG_DBG("TXT", "Copying BMP cover image to cache");
118 HalFile src, dst;
119 if (!Storage.openFileForRead("TXT", coverImagePath, src)) {
120 return false;
121 }
122 if (!Storage.openFileForWrite("TXT", getCoverBmpPath(), dst)) {
123 return false;
124 }
125 uint8_t buffer[1024];
126 while (src.available()) {
127 size_t bytesRead = src.read(buffer, sizeof(buffer));
128 dst.write(buffer, bytesRead);
129 }
130 LOG_DBG("TXT", "Copied BMP cover to cache");
131 return true;
132 } else if (FsHelpers::hasJpgExtension(coverImagePath)) {
133 // Convert JPG/JPEG to BMP (same approach as Epub)
134 LOG_DBG("TXT", "Generating BMP from JPG cover image");
135 HalFile coverJpg, coverBmp;
136 if (!Storage.openFileForRead("TXT", coverImagePath, coverJpg)) {
137 return false;
138 }
139 if (!Storage.openFileForWrite("TXT", getCoverBmpPath(), coverBmp)) {
140 return false;
141 }
142 const bool success = JpegToBmpConverter::jpegFileToBmpStream(coverJpg, coverBmp);
143
144 if (!success) {
145 LOG_ERR("TXT", "Failed to generate BMP from JPG cover image");
146 Storage.remove(getCoverBmpPath().c_str());
147 } else {
148 LOG_DBG("TXT", "Generated BMP from JPG cover image");
149 }
150 return success;
151 }
152
153 // PNG files are not supported (would need a PNG decoder)
154 LOG_ERR("TXT", "Cover image format not supported (only BMP/JPG/JPEG)");
155 return false;
156}
157

Callers

nothing calls this directly

Calls 10

hasBmpExtensionFunction · 0.85
existsMethod · 0.80
openFileForReadMethod · 0.80
openFileForWriteMethod · 0.80
removeMethod · 0.80
hasJpgExtensionFunction · 0.50
emptyMethod · 0.45
availableMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected