Files
esphome/esphome/components/runtime_image/png_decoder.h
T
5177972c04 [runtime_image] keep decoder allocated (#18488)
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>
2026-08-20 17:27:44 -05:00

47 lines
1.1 KiB
C++

#pragma once
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include "image_decoder.h"
#include "runtime_image.h"
#ifdef USE_RUNTIME_IMAGE_PNG
#include <pngle.h>
namespace esphome::runtime_image {
/**
* @brief Image decoder specialization for PNG images.
*/
class PngDecoder : public ImageDecoder {
public:
/**
* @brief Construct a new PNG Decoder object.
*
* @param image The RuntimeImage to decode the stream into.
*/
PngDecoder(RuntimeImage *image);
~PngDecoder() override;
void reset() override {
ImageDecoder::reset();
if (this->pngle_) {
pngle_reset(this->pngle_);
}
this->pixels_decoded_ = 0;
}
int prepare(size_t expected_size) override;
int HOT decode(uint8_t *buffer, size_t size) override;
void increment_pixels_decoded(uint32_t count) { this->pixels_decoded_ += count; }
uint32_t get_pixels_decoded() const { return this->pixels_decoded_; }
protected:
pngle_t *pngle_{nullptr};
uint32_t pixels_decoded_{0};
};
} // namespace esphome::runtime_image
#endif // USE_RUNTIME_IMAGE_PNG