3#ifdef USE_RUNTIME_IMAGE_QOI
34 return (color.
r * 3 + color.
g * 5 + color.
b * 7 + color.
w * 11) &
67 ESP_LOGE(TAG,
"Not a QOI file");
74 ESP_LOGE(TAG,
"Invalid image dimensions: (%zux%zu)", this->
width_, this->
height_);
77 uint8_t channels =
buffer[12];
78 if (channels < 3 || channels > 4) {
79 ESP_LOGE(TAG,
"Unsupported number of channels: %d", channels);
83 uint8_t colorspace =
buffer[13];
85 ESP_LOGE(TAG,
"Unsupported colorspace value: %d", colorspace);
88 ESP_LOGD(TAG,
"QOI image header: width=%zu, height=%zu, channels=%d, colorspace=%d", this->
width_, this->
height_,
89 channels, colorspace);
105 while (index < size && this->
paint_index_ < total_pixels) {
107 uint8_t
byte =
buffer[index];
118 }
else if (
byte == QOI_OP_RGBA) {
129 }
else if ((
byte & QOI_MASK_OP) ==
QOI_OP_RUN) {
132 for (
size_t i = 0; i < run_length; i++) {
143 uint8_t byte2 =
buffer[index++];
145 color.
r += delta_g - 8 + ((byte2 >> 4) & 0x0f);
147 color.
b += delta_g - 8 + (byte2 & 0x0f);
152 color.
r += ((
byte >> 4) & 0x03) - 2;
153 color.
g += ((
byte >> 2) & 0x03) - 2;
154 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.