Cherry-pick merge from pablohc/crosspoint-reader@2d8cbcf, based on upstream PR #556 by martinbrook with pablohc's refresh optimization. - Add JPEG decoder (picojpeg) and PNG decoder (PNGdec) with 4-level grayscale Bayer dithering for e-ink display - Add pixel caching system (.pxc files) for fast image re-rendering - Integrate image extraction from EPUB HTML parser (<img> tag support) - Add ImageBlock/PageImage types with serialization support - Add image-aware refresh optimization (double FAST_REFRESH technique) - Add experimental displayWindow() partial refresh support - Bump section cache version 12->13 to invalidate stale caches - Resolve TAG_PageImage=3 to avoid conflict with mod's TAG_PageTableRow=2 Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include "ImageDecoderFactory.h"
|
|
|
|
#include <HardwareSerial.h>
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "JpegToFramebufferConverter.h"
|
|
#include "PngToFramebufferConverter.h"
|
|
|
|
std::unique_ptr<JpegToFramebufferConverter> ImageDecoderFactory::jpegDecoder = nullptr;
|
|
std::unique_ptr<PngToFramebufferConverter> ImageDecoderFactory::pngDecoder = nullptr;
|
|
|
|
ImageToFramebufferDecoder* ImageDecoderFactory::getDecoder(const std::string& imagePath) {
|
|
std::string ext = imagePath;
|
|
size_t dotPos = ext.rfind('.');
|
|
if (dotPos != std::string::npos) {
|
|
ext = ext.substr(dotPos);
|
|
for (auto& c : ext) {
|
|
c = tolower(c);
|
|
}
|
|
} else {
|
|
ext = "";
|
|
}
|
|
|
|
if (JpegToFramebufferConverter::supportsFormat(ext)) {
|
|
if (!jpegDecoder) {
|
|
jpegDecoder.reset(new JpegToFramebufferConverter());
|
|
}
|
|
return jpegDecoder.get();
|
|
} else if (PngToFramebufferConverter::supportsFormat(ext)) {
|
|
if (!pngDecoder) {
|
|
pngDecoder.reset(new PngToFramebufferConverter());
|
|
}
|
|
return pngDecoder.get();
|
|
}
|
|
|
|
Serial.printf("[%lu] [DEC] No decoder found for image: %s\n", millis(), imagePath.c_str());
|
|
return nullptr;
|
|
}
|
|
|
|
bool ImageDecoderFactory::isFormatSupported(const std::string& imagePath) { return getDecoder(imagePath) != nullptr; }
|