ESPHome 2026.3.0
Loading...
Searching...
No Matches
image_decoder.cpp
Go to the documentation of this file.
1#include "image_decoder.h"
2#include "runtime_image.h"
3#include "esphome/core/log.h"
4#include <algorithm>
5#include <cmath>
6
8
9static const char *const TAG = "image_decoder";
10
11bool ImageDecoder::set_size(int width, int height) {
12 bool success = this->image_->resize(width, height) > 0;
13 this->x_scale_ = static_cast<double>(this->image_->get_buffer_width()) / width;
14 this->y_scale_ = static_cast<double>(this->image_->get_buffer_height()) / height;
15 return success;
16}
17
18void ImageDecoder::draw(int x, int y, int w, int h, const Color &color) {
19 auto width = std::min(this->image_->get_buffer_width(), static_cast<int>(std::ceil((x + w) * this->x_scale_)));
20 auto height = std::min(this->image_->get_buffer_height(), static_cast<int>(std::ceil((y + h) * this->y_scale_)));
21 for (int i = x * this->x_scale_; i < width; i++) {
22 for (int j = y * this->y_scale_; j < height; j++) {
23 this->image_->draw_pixel(i, j, color);
24 }
25 }
26}
27
28} // namespace esphome::runtime_image
uint8_t h
Definition bl0906.h:2
void draw(int x, int y, int w, int h, const Color &color)
Fill a rectangle on the display_buffer using the defined color.
bool set_size(int width, int height)
Request the image to be resized once the actual dimensions are known.
int resize(int width, int height)
Resize the image buffer to the requested dimensions.
void draw_pixel(int x, int y, const Color &color)
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6