Decode Windows WebP images without an AVX requirement (by Codex)

This commit is contained in:
Codex committed 2026-10-23 09:55:01 +02:00
1 parent a7aa1d3713
commit 678fce47f6
3 files changed
+29

No files matched your search

+3
View File
@@ -7,6 +7,9 @@ pinned RmlUI Direct3D 11 renderer with automatic WARP software fallback. No
additional graphics runtime download is needed on the supported Windows systems.
Linux/macOS retain their existing OpenGL rendering.
Windows also uses the portable WebP decoder, avoiding illegal AVX instructions
when displaying imported club images on older CPUs or virtual machines.
Windows startup failures now produce a native dialog and a log in
`%LOCALAPPDATA%/OpenBMH/OpenBMHEditor-startup.log`. Console redirection is
retained and headless/MCP errors remain nonmodal. Native GUI startup, screenshots,
+6
View File
@@ -21,6 +21,12 @@ endforeach()
set(SDL2IMAGE_PNG ON CACHE BOOL "" FORCE)
set(SDL2IMAGE_JPG ON CACHE BOOL "" FORCE)
set(SDL2IMAGE_WEBP ON CACHE BOOL "" FORCE)
if(MSVC)
# The pinned WebP build applies /arch:AVX to its SSE2 sources as well.
# Runtime SSE2 detection cannot make those AVX instructions safe on older
# CPUs or virtual machines. Small editor images use the portable decoder.
set(WEBP_ENABLE_SIMD OFF CACHE BOOL "Portable Windows WebP decoding" FORCE)
endif()
set(SDL2IMAGE_PNG_SAVE OFF CACHE BOOL "" FORCE)
set(SDL2IMAGE_JPG_SAVE OFF CACHE BOOL "" FORCE)
FetchContent_Declare(editor_images GIT_REPOSITORY https://github.com/libsdl-org/SDL_image.git
+20
View File
@@ -3,6 +3,7 @@
#include "editor/mcp.hpp"
#include "editor/session.hpp"
#include <httplib.h>
#include <cstdlib>
#include <iostream>
#include <thread>
#ifdef _WIN32
@@ -108,6 +109,25 @@ int main() {
const auto png = images::encode_png(image);
write_atomic(root / "input.png", png);
check(images::decode(png, ".png").pixels == image.pixels, "PNG lossless RGBA");
// Authored synthetic pixels: a solid teal 17x19 VP8 image and the
// same four RGBA pixels as above encoded as VP8L, including alpha.
const std::string webp_lossy(
"\x52\x49\x46\x46\x4a\x00\x00\x00\x57\x45\x42\x50\x56\x50\x38\x20"
"\x3e\x00\x00\x00\x90\x03\x00\x9d\x01\x2a\x11\x00\x13\x00\x3e\x31"
"\x18\x8a\x43\xa2\x21\xa1\x14\x04\x00\x20\x03\x04\xb2\x80\x3b\x00"
"\x7e\x00\x7e\x00\x00\x49\x95\x7c\x00\x00\xfe\xe8\x38\xbf\xff\xf6"
"\x96\x42\x15\xd7\xfc\x95\x7f\xff\xee\x9e\x90\x81\xa3\xfe\x4a\x00\x00\x00", 82);
const std::string webp_lossless(
"\x52\x49\x46\x46\x30\x00\x00\x00\x57\x45\x42\x50\x56\x50\x38\x4c"
"\x23\x00\x00\x00\x2f\x01\x40\x00\x10\x1f\x20\x10\x48\xde\x1f\x3a"
"\x8d\xf9\x17\x10\x14\xfc\x1f\x9d\x80\xa0\xe8\xba\xe5\x22\x66\x0f"
"\xc2\x0d\x18\x22\xfa\x1f\x02\x00", 56);
const auto webp = images::decode(webp_lossy, ".webp");
check(webp.width == 17 && webp.height == 19 && webp.pixels.size() == 17 * 19 * 4 &&
std::abs(int(webp.pixels[0]) - 40) <= 4 && std::abs(int(webp.pixels[1]) - 140) <= 4 &&
std::abs(int(webp.pixels[2]) - 200) <= 4 && webp.pixels[3] == 255,
"WebP lossy colour and dimensions");
check(images::decode(webp_lossless, ".webp").pixels == image.pixels, "WebP lossless RGBA");
check(images::transform(png, ".png", Json::object()).bytes == png, "identity preserves exact bytes");
auto flip = images::decode(images::transform(png, ".png", {{"flip_x", true}}).bytes, ".png");
check(flip.pixels[1] == 255 && flip.pixels[4] == 255, "horizontal mirror pixels");