[online_image] Support image format auto-detection (#16337)

Co-authored-by: J. Nick Koston <nick@koston.org>
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>
This commit is contained in:
guillempages
2026-08-23 19:58:01 +00:00
committed by GitHub
co-authored by J. Nick Koston pre-commit-ci-lite[bot] J. Nick Koston
parent 2c32ac2221
commit d84293931b
16 changed files with 513 additions and 104 deletions
@@ -171,22 +171,27 @@ void RuntimeImage::draw(int x, int y, display::Display *display, Color color_on,
// If no image is loaded and no placeholder, nothing to draw
}
bool RuntimeImage::begin_decode(size_t expected_size) {
bool RuntimeImage::begin_decode(size_t expected_size, ImageFormat format) {
if (this->is_decoding()) {
ESP_LOGW(TAG, "Decoding already in progress");
return false;
}
if (format == AUTO && this->format_ != AUTO) {
// Fall back to the configured format before the reuse check below
format = this->format_;
}
// An idle decoder for a different format cannot be reused
if (this->decoder_ != nullptr && this->decoder_->get_format() != this->format_) {
ESP_LOGD(TAG, "Decoder format mismatch: current: %d, new: %d", this->decoder_->get_format(), this->format_);
if (this->decoder_ != nullptr && this->decoder_->get_format() != format) {
ESP_LOGD(TAG, "Decoder format mismatch: current: %d, new: %d", this->decoder_->get_format(), format);
this->decoder_ = nullptr;
}
if (!this->decoder_) {
this->decoder_ = this->create_decoder_(this->format_);
this->decoder_ = this->create_decoder_(format);
if (!this->decoder_) {
ESP_LOGE(TAG, "Failed to create decoder for format %d", this->format_);
ESP_LOGE(TAG, "Failed to create decoder for format %d", format);
return false;
}
}
@@ -364,6 +369,9 @@ std::unique_ptr<ImageDecoder> RuntimeImage::create_decoder_(ImageFormat format)
case PNG:
return make_unique<PngDecoder>(this);
#endif
case AUTO:
ESP_LOGE(TAG, "Image format could not be determined; set `format:` explicitly in the configuration");
return nullptr;
default:
ESP_LOGE(TAG, "Unsupported image format: %d", format);
return nullptr;