1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-13 14:18:14 +00:00

order: webp after png

This commit is contained in:
Ian Foster 2025-02-23 18:04:04 +00:00
parent 7c36474db0
commit eb950f7783
3 changed files with 22 additions and 27 deletions

View File

@ -2,6 +2,7 @@ import logging
from esphome import automation
import esphome.codegen as cg
from esphome.components.animation import Animation_
from esphome.components.http_request import CONF_HTTP_REQUEST_ID, HttpRequestComponent
from esphome.components.image import (
CONF_INVERT_ALPHA,
@ -11,9 +12,6 @@ from esphome.components.image import (
get_image_type_enum,
get_transparency_enum,
)
from esphome.components.animation import (
Animation_,
)
import esphome.config_validation as cv
from esphome.const import (
CONF_BUFFER_SIZE,
@ -72,15 +70,6 @@ class JPEGFormat(Format):
cg.add_library("JPEGDEC", None, "https://github.com/bitbank2/JPEGDEC#ca1e0f2")
class WEBPFormat(Format):
def __init__(self):
super().__init__("WEBP")
def actions(self):
cg.add_define("USE_ONLINE_IMAGE_WEBP_SUPPORT")
cg.add_library("libwebp", None, "https://github.com/acvigue/libwebp#26b0c4b")
class PNGFormat(Format):
def __init__(self):
super().__init__("PNG")
@ -90,6 +79,15 @@ class PNGFormat(Format):
cg.add_library("pngle", "1.0.2")
class WEBPFormat(Format):
def __init__(self):
super().__init__("WEBP")
def actions(self):
cg.add_define("USE_ONLINE_IMAGE_WEBP_SUPPORT")
cg.add_library("libwebp", None, "https://github.com/acvigue/libwebp#26b0c4b")
IMAGE_FORMATS = {
x.image_type: x
for x in (

View File

@ -124,16 +124,16 @@ void OnlineImage::update() {
accept_mime_type = "image/jpeg";
break;
#endif // USE_ONLINE_IMAGE_JPEG_SUPPORT
#ifdef USE_ONLINE_IMAGE_WEBP_SUPPORT
case ImageFormat::WEBP:
accept_mime_type = "image/webp";
break;
#endif // USE_ONLINE_IMAGE_WEBP_SUPPORT
#ifdef USE_ONLINE_IMAGE_PNG_SUPPORT
case ImageFormat::PNG:
accept_mime_type = "image/png";
break;
#endif // ONLINE_IMAGE_PNG_SUPPORT
#ifdef USE_ONLINE_IMAGE_WEBP_SUPPORT
case ImageFormat::WEBP:
accept_mime_type = "image/webp";
break;
#endif // USE_ONLINE_IMAGE_WEBP_SUPPORT
default:
accept_mime_type = "image/*";
}
@ -178,18 +178,18 @@ void OnlineImage::update() {
this->decoder_ = esphome::make_unique<JpegDecoder>(this);
}
#endif // USE_ONLINE_IMAGE_JPEG_SUPPORT
#ifdef USE_ONLINE_IMAGE_WEBP_SUPPORT
if (this->format_ == ImageFormat::WEBP) {
ESP_LOGD(TAG, "Allocating WEBP decoder");
this->decoder_ = esphome::make_unique<WebpDecoder>(this);
}
#endif // USE_ONLINE_IMAGE_WEBP_SUPPORT
#ifdef USE_ONLINE_IMAGE_PNG_SUPPORT
if (this->format_ == ImageFormat::PNG) {
ESP_LOGD(TAG, "Allocating PNG decoder");
this->decoder_ = make_unique<PngDecoder>(this);
}
#endif // ONLINE_IMAGE_PNG_SUPPORT
#ifdef USE_ONLINE_IMAGE_WEBP_SUPPORT
if (this->format_ == ImageFormat::WEBP) {
ESP_LOGD(TAG, "Allocating WEBP decoder");
this->decoder_ = esphome::make_unique<WebpDecoder>(this);
}
#endif // USE_ONLINE_IMAGE_WEBP_SUPPORT
if (!this->decoder_) {
ESP_LOGE(TAG, "Could not instantiate decoder. Image format unsupported: %d", this->format_);

View File

@ -32,10 +32,7 @@ void draw_frame(ImageDecoder *decoder, const uint8_t *pix, uint32_t width, uint3
for (unsigned int y = 0; y < height; y++) {
for (unsigned int x = 0; x < width; x++) {
const uint8_t *p = &pix[(y * width + x) * channels];
uint8_t r = p[ix_r];
uint8_t g = p[ix_g];
uint8_t b = p[ix_b];
Color color(r, g, b, p[ix_a]);
Color color(p[ix_r], p[ix_g], p[ix_b], p[ix_a]);
decoder->draw(x, y, 1, 1, color, frame);
}
}