mirror of
https://github.com/esphome/esphome.git
synced 2026-08-31 10:06:03 +00:00
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@home-assistant.io> Co-authored-by: J. Nick Koston <nick@koston.org>
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/defines.h"
|
|
#ifdef USE_RUNTIME_IMAGE_BMP
|
|
|
|
#include <algorithm>
|
|
#include <memory>
|
|
|
|
#include "image_decoder.h"
|
|
#include "runtime_image.h"
|
|
|
|
namespace esphome::runtime_image {
|
|
|
|
/**
|
|
* @brief Image decoder specialization for BMP images.
|
|
*/
|
|
class BmpDecoder : public ImageDecoder {
|
|
public:
|
|
/**
|
|
* @brief Construct a new BMP Decoder object.
|
|
*
|
|
* @param image The RuntimeImage to decode the stream into.
|
|
*/
|
|
BmpDecoder(RuntimeImage *image) : ImageDecoder(image, BMP) {}
|
|
|
|
void reset() override;
|
|
int HOT decode(uint8_t *buffer, size_t size) override;
|
|
|
|
bool is_finished() const override {
|
|
if (this->bits_per_pixel_ == 0) {
|
|
// header not yet received, so dimensions not yet determined
|
|
return false;
|
|
}
|
|
// BMP is finished when we've decoded all pixel data
|
|
return this->paint_index_ >= static_cast<size_t>(this->width_ * this->height_);
|
|
}
|
|
|
|
protected:
|
|
std::unique_ptr<uint32_t[]> color_table_;
|
|
size_t current_index_{0};
|
|
size_t paint_index_{0};
|
|
ssize_t width_{0};
|
|
ssize_t height_{0};
|
|
size_t width_bytes_{0};
|
|
size_t data_offset_{0};
|
|
uint32_t compression_method_{0};
|
|
uint32_t image_data_size_{0};
|
|
uint32_t color_table_entries_{0};
|
|
uint32_t color_table_capacity_{0}; // Allocated entries in color_table_, kept across decodes
|
|
uint16_t bits_per_pixel_{0};
|
|
uint8_t padding_bytes_{0};
|
|
};
|
|
|
|
} // namespace esphome::runtime_image
|
|
|
|
#endif // USE_RUNTIME_IMAGE_BMP
|