2 #include "AudioTools/CoreAudio/AudioBasic/Collections/Vector.h"
3 #include "JPEGDecoder.h"
5 #include "Video/Video.h"
19 JpegTFT(TFT_eSPI &TFTscreen) { p_screen = &TFTscreen; }
22 void beginFrame(
size_t jpegSize)
override {
25 LOGI(
"jpegSize: %d", (
int)jpegSize);
27 if (img_vector.size() < jpegSize) {
28 img_vector.resize(jpegSize);
31 this->open = jpegSize;
32 this->size = jpegSize;
39 jpeg_decoder.decodeArray((
const uint8_t *)&img_vector[0], size);
45 size_t write(
const uint8_t *data,
size_t len)
override {
46 memcpy(&img_vector[pos], data, len);
53 Vector<uint8_t> img_vector;
58 JPEGDecoder jpeg_decoder;
59 TFT_eSPI *p_screen =
nullptr;
64 uint32_t renderJPEG(
int xpos,
int ypos) {
67 uint16_t mcu_w = jpeg_decoder.MCUWidth;
68 uint16_t mcu_h = jpeg_decoder.MCUHeight;
69 uint32_t max_x = jpeg_decoder.width;
70 uint32_t max_y = jpeg_decoder.height;
75 uint32_t min_w = std::min((uint32_t)mcu_w, max_x % mcu_w);
76 uint32_t min_h = std::min((uint32_t)mcu_h, max_y % mcu_h);
79 uint32_t win_w = mcu_w;
80 uint32_t win_h = mcu_h;
84 uint32_t drawTime =
millis();
92 while (jpeg_decoder.read()) {
94 pImg = jpeg_decoder.pImage;
97 int mcu_x = jpeg_decoder.MCUx * mcu_w + xpos;
98 int mcu_y = jpeg_decoder.MCUy * mcu_h + ypos;
102 if (mcu_x + mcu_w <= max_x)
106 if (mcu_y + mcu_h <= max_y)
112 uint32_t mcu_pixels = win_w * win_h;
115 if ((mcu_x + win_w) <= p_screen->width() &&
116 (mcu_y + win_h) <= p_screen->height()) {
120 p_screen->setAddrWindow(mcu_x, mcu_y, mcu_x + win_w - 1,
124 p_screen->pushColor(*pImg++);
129 else if ((mcu_y + win_h) >= p_screen->height())
130 jpeg_decoder.abort();
134 drawTime =
millis() - drawTime;