18#include "cdc_image/Dither.h"
19#include "cdc_image/ImageDecoder.h"
21#include <goodisplay/gdey029T94.h>
25static const char*
TAG =
"ImageView";
33 strncpy(titleBuf_, title, MAX_TITLE_LEN - 1);
34 titleBuf_[MAX_TITLE_LEN - 1] =
'\0';
49 uint16_t w = 0, h = 0;
50 const char* err =
nullptr;
51 auto gray = cdc::image::decodeToGray(data, len,
MAX_PIXELS, w, h, err);
53 errorKey_ = err ? err :
"core.img_decode_failed";
59 errorKey_ =
"core.img_decode_failed";
68 fullBmp_.stride = cdc::image::MonoBitmap::strideFor(w);
69 fullBmp_.bits = fullBits_.get();
70 cdc::image::ditherImage(gray.get(), w, h, fullBmp_.bits, scratch.get());
77 const uint16_t areaH =
static_cast<uint16_t
>(scrH -
FOOTER_HEIGHT);
79 uint16_t fw = w, fh = h;
80 if (w > scrW || h > areaH) {
81 const uint32_t sx = (
static_cast<uint32_t
>(scrW) * 1000) / w;
82 const uint32_t sy = (
static_cast<uint32_t
>(areaH) * 1000) / h;
83 const uint32_t s = sx < sy ? sx : sy;
84 fw =
static_cast<uint16_t
>((
static_cast<uint32_t
>(w) * s) / 1000);
85 fh =
static_cast<uint16_t
>((
static_cast<uint32_t
>(h) * s) / 1000);
92 if (fitBits_ && fitGray) {
95 fitBmp_.stride = cdc::image::MonoBitmap::strideFor(fw);
96 fitBmp_.bits = fitBits_.get();
97 cdc::image::downscaleGrayBox(gray.get(), w, h, fitGray.get(), fw, fh);
98 cdc::image::ditherImage(fitGray.get(), fw, fh, fitBmp_.bits, scratch.get());
101 LOG_D(
TAG,
"init: %ux%u -> fit %ux%u", w, h, fw, fh);
113void ImageView::clampPan() {
118 const int maxX = fullBmp_.width > scrW ? fullBmp_.width - scrW : 0;
119 const int maxY = fullBmp_.height > areaH ? fullBmp_.height - areaH : 0;
120 if (panX_ < 0) panX_ = 0;
121 if (panY_ < 0) panY_ = 0;
122 if (panX_ > maxX) panX_ = maxX;
123 if (panY_ > maxY) panY_ = maxY;
127 return ui::tr(
"core.hint_image");
138 mode_ = (mode_ == Mode::Fit) ? Mode::Actual : Mode::Fit;
146 if (mode_ == Mode::Actual) {
161 auto* gfx =
static_cast<Gdey029T94*
>(
display->getNativeHandle());
164 const uint16_t width =
display->getWidth();
165 const uint16_t height =
display->getHeight();
168 gfx->fillScreen(EPD_WHITE);
169 gfx->setFont(
nullptr);
170 gfx->setTextColor(EPD_BLACK);
174 gfx->setCursor(8, areaBottom / 2);
182 if (mode_ == Mode::Fit && fitBmp_.bits) {
183 int x = (
static_cast<int>(width) - fitBmp_.width) / 2;
184 int y = (areaBottom - fitBmp_.height) / 2;
187 gfx->drawBitmap(x, y, fitBmp_.bits, fitBmp_.width, fitBmp_.height, EPD_BLACK);
188 }
else if (fullBmp_.bits) {
189 gfx->drawBitmap(-panX_, -panY_, fullBmp_.bits, fullBmp_.width, fullBmp_.height, EPD_BLACK);
Internationalization with English fallbacks in code and overlay translations loaded at runtime from a...
constexpr int FOOTER_HEIGHT
Footer bar height in pixels (used by drawFooterBar).
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_D(tag, fmt,...)
Full-screen viewer for a decoded PNG/JPEG, dithered to the e-paper.
static constexpr uint32_t MAX_PIXELS
~1 megapixel cap.
void init(const char *title, const uint8_t *data, size_t len)
Decodes and lays out an image.
const char * getFooterHint() const override
void render(bool partial) override
InputResult onKey(char key) override
static ViewStack & instance()
Returns singleton view-stack instance.
void push(IView *view, void *context=nullptr)
PsramUniquePtr< T > psramAlloc(std::size_t count) noexcept
Allocate count elements of T in PSRAM (8-bit capable region).
IDisplay * getDisplayInstance()
Returns lazily created singleton display instance.
constexpr int FOOTER_HEIGHT
Footer bar height in pixels (used by drawFooterBar).
void drawFooterBar(Gdey029T94 *gfx, uint16_t width, uint16_t height, const char *prefix, const char *hint, bool force=false)
Draws footer bar with optional prefix and hint text.
void printText(Adafruit_GFX *gfx, const char *text)
Draws CP437 text with the built-in 6x8 glyph font, byte-for-byte.
Centralized key-code constants for cdc_views.
const char * tr(const char *key)
Look up a translation by string key.
static ImageView s_sharedImageView
static constexpr char KEY_SELECT
Center select / digit '5'.
static constexpr char KEY_DOWN
Move selection down (numeric '8').
static constexpr char KEY_NO
Cancel / Back / Backspace.
ImageView * showImage(const char *title, const uint8_t *data, size_t len)
Decodes and shows an image on the view stack.
static constexpr char KEY_UP
Move selection up (numeric '2').