3#ifdef USE_RUNTIME_IMAGE_BMP
17static constexpr Color OPAQUE_BLACK(0, 0, 0, 0xFF);
53 ESP_LOGE(TAG,
"Not a BMP file");
88 ESP_LOGE(TAG,
"Invalid image dimensions: (%zdx%zd)", this->
width_, this->
height_);
110 size_t offset = 14 + header_size;
134 ESP_LOGE(TAG,
"Unsupported bits per pixel: %d", this->
bits_per_pixel_);
152 auto out_of_time = [start, &steps]() {
153 return ++steps % DECODE_TIME_CHECK_STEPS == 0 &&
millis() - start >= DECODE_TIME_LIMIT_MS;
156 const size_t total_pixels =
static_cast<size_t>(this->
width_) * this->
height_;
159 size_t width =
static_cast<size_t>(this->
width_);
160 while (index < size && this->
paint_index_ < total_pixels) {
163 size_t remaining_in_row = width -
x;
164 uint8_t pixels_in_byte = std::min<size_t>(remaining_in_row, 8);
165 bool end_of_row = remaining_in_row <= 8;
167 if (index + needed >
size || out_of_time()) {
171 uint8_t current_byte =
buffer[index];
172 for (uint8_t i = 0; i < pixels_in_byte; i++) {
174 this->
draw(x + i,
y, 1, 1, c);
188 size_t width =
static_cast<size_t>(this->
width_);
189 size_t last_col = width - 1;
190 while (index < size && this->
paint_index_ < total_pixels) {
194 if (index + needed >
size || out_of_time()) {
199 uint8_t color_index =
buffer[index];
201 ESP_LOGE(TAG,
"Invalid color index: %u", color_index);
206 uint8_t b = rgb & 0xff;
207 uint8_t g = (rgb >> 8) & 0xff;
208 uint8_t r = (rgb >> 16) & 0xff;
221 size_t width =
static_cast<size_t>(this->
width_);
222 size_t last_col = width - 1;
223 while (index < size && this->
paint_index_ < total_pixels) {
227 if (index + needed >
size || out_of_time()) {
231 uint8_t b =
buffer[index];
232 uint8_t g =
buffer[index + 1];
233 uint8_t r =
buffer[index + 2];
246 ESP_LOGE(TAG,
"Unsupported bits per pixel: %d", this->
bits_per_pixel_);
uint32_t image_data_size_
uint32_t color_table_entries_
std::unique_ptr< uint32_t[]> color_table_
uint32_t compression_method_
uint32_t color_table_capacity_
int HOT decode(uint8_t *buffer, size_t size) override
virtual void reset()
Reset the decoder state, ending any decoding session.
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.
constexpr Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
@ DECODE_ERROR_OUT_OF_MEMORY
@ DECODE_ERROR_UNSUPPORTED_FORMAT
@ DECODE_ERROR_INVALID_TYPE
ESPHOME_LOG_TAG(TAG, "image_decoder.bmp")
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
uint32_t IRAM_ATTR HOT millis()