3#ifdef USE_RUNTIME_IMAGE_QOI
36 return (color.
r * 3 + color.
g * 5 + color.
b * 7 + color.
w * 11) &
69 ESP_LOGE(TAG,
"Not a QOI file");
76 ESP_LOGE(TAG,
"Invalid image dimensions: (%zux%zu)", this->
width_, this->
height_);
79 uint8_t channels =
buffer[12];
80 if (channels < 3 || channels > 4) {
81 ESP_LOGE(TAG,
"Unsupported number of channels: %d", channels);
85 uint8_t colorspace =
buffer[13];
87 ESP_LOGE(TAG,
"Unsupported colorspace value: %d", colorspace);
90 ESP_LOGD(TAG,
"QOI image header: width=%zu, height=%zu, channels=%d, colorspace=%d", this->
width_, this->
height_,
91 channels, colorspace);
110 while (index < size && this->
paint_index_ < total_pixels) {
111 if (++steps % DECODE_TIME_CHECK_STEPS == 0 &&
millis() - start >= DECODE_TIME_LIMIT_MS)
114 uint8_t
byte =
buffer[index];
125 }
else if (
byte == QOI_OP_RGBA) {
136 }
else if ((
byte & QOI_MASK_OP) ==
QOI_OP_RUN) {
140 while (run_length > 0) {
142 const size_t count = std::min(run_length, this->
width_ - x);
153 uint8_t byte2 =
buffer[index++];
155 color.
r += delta_g - 8 + ((byte2 >> 4) & 0x0f);
157 color.
b += delta_g - 8 + (byte2 & 0x0f);
162 color.
r += ((
byte >> 4) & 0x03) - 2;
163 color.
g += ((
byte >> 2) & 0x03) - 2;
164 color.
b += (
byte & 0x03) - 2;
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.
int HOT decode(uint8_t *buffer, size_t size) override
std::unique_ptr< Color[]> color_table_
@ DECODE_ERROR_OUT_OF_MEMORY
@ DECODE_ERROR_UNSUPPORTED_FORMAT
@ DECODE_ERROR_INVALID_TYPE
constexpr uint8_t QOI_LUMA_CHUNK_SIZE
constexpr uint8_t QOI_RGB_CHUNK_SIZE
ESPHOME_LOG_TAG(TAG, "image_decoder.bmp")
size_t qoi_color_table_index(const Color &color)
constexpr uint8_t QOI_OP_RUN
constexpr uint8_t QOI_OP_RGBA
constexpr uint8_t QOI_RGBA_CHUNK_SIZE
constexpr uint8_t QOI_OP_DIFF
constexpr uint8_t QOI_MASK_VALUE
constexpr uint8_t QOI_OP_LUMA
constexpr uint8_t QOI_MASK_OP
constexpr size_t QOI_HEADER_SIZE
constexpr size_t QOI_COLOR_TABLE_SIZE
constexpr uint8_t QOI_OP_RGB
constexpr uint8_t QOI_OP_INDEX
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.
uint32_t IRAM_ATTR HOT millis()