2 #ifdef USE_ONLINE_IMAGE_JPEG_SUPPORT 10 static const char *
const TAG =
"online_image.jpeg";
13 namespace online_image {
21 static int draw_callback(JPEGDRAW *jpeg) {
22 ImageDecoder *decoder = (ImageDecoder *) jpeg->pUser;
28 for (
size_t y = 0;
y < jpeg->iHeight;
y++) {
29 for (
size_t x = 0;
x < jpeg->iWidth;
x++) {
32 Color color(rg[1], rg[0], ba[1], ba[0]);
35 ESP_LOGE(TAG,
"Decoder pointer is null!");
38 decoder->draw(jpeg->x +
x, jpeg->y +
y, 1, 1, color);
47 if (size < download_size) {
48 ESP_LOGE(TAG,
"Download buffer resize failed!");
56 ESP_LOGV(TAG,
"Download not complete. Size: %d/%d", size, this->download_size_);
60 if (!this->
jpeg_.openRAM(buffer, size, draw_callback)) {
61 ESP_LOGE(TAG,
"Could not open image for decoding: %d", this->
jpeg_.getLastError());
64 auto jpeg_type = this->
jpeg_.getJPEGType();
65 if (jpeg_type == JPEG_MODE_INVALID) {
66 ESP_LOGE(TAG,
"Unsupported JPEG image");
68 }
else if (jpeg_type == JPEG_MODE_PROGRESSIVE) {
69 ESP_LOGE(TAG,
"Progressive JPEG images not supported");
72 ESP_LOGD(TAG,
"Image size: %d x %d, bpp: %d", this->
jpeg_.getWidth(), this->
jpeg_.getHeight(), this->
jpeg_.getBpp());
74 this->
jpeg_.setUserPointer(
this);
75 this->
jpeg_.setPixelType(RGB8888);
79 if (!this->
jpeg_.decode(0, 0, 0)) {
80 ESP_LOGE(TAG,
"Error while decoding.");
92 #endif // USE_ONLINE_IMAGE_JPEG_SUPPORT
int prepare(size_t download_size) override
virtual int prepare(size_t download_size)
Initialize the decoder.
constexpr14 std::array< uint8_t, sizeof(T)> decode_value(T val)
Decode a value into its constituent bytes (from most to least significant).
Application App
Global storage of Application pointer - only one Application can exist.
size_t resize_download_buffer(size_t size)
Resize the download buffer.
bool set_size(int width, int height)
Request the image to be resized once the actual dimensions are known.
Implementation of SPI Controller mode.
int HOT decode(uint8_t *buffer, size_t size) override