From 35701a5e7f00c6984b86b7407a74c474dc547889 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Tue, 21 Jul 2026 14:02:37 +0000 Subject: [PATCH 52/71] =?UTF-8?q?fix(macos):=20decode=20any=20image=20form?= =?UTF-8?q?at=20for=20inline=20images=20=E2=80=94=20frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split from the original commit f3aa7ca9b (upstream-history split into vendor/frontend layers, 2026-07-21): this half covers the frontend-side image-decode change (TerminalSession.cpp). The accompanying Screen.cpp change is a vendor-layer edit. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01LzTmVgP2ruMz987VJ78k77 --- src/contour_macos/TerminalSession.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/contour_macos/TerminalSession.cpp b/src/contour_macos/TerminalSession.cpp index d990bd8d..c9eb0390 100644 --- a/src/contour_macos/TerminalSession.cpp +++ b/src/contour_macos/TerminalSession.cpp @@ -103,8 +103,20 @@ namespace [[nodiscard]] std::optional decodePngViaImageIO( vtbackend::ImageFormat format, std::span data, vtbackend::ImageSize& size) { - if (format != vtbackend::ImageFormat::PNG) - return std::nullopt; + // ImageIO (CGImageSource) sniffs the container from the data itself and decodes PNG, JPEG, + // GIF, TIFF, BMP, ... so we do NOT gate on `format`: the engine always passes PNG for this + // callback, but an iTerm2 sender may inline a JPEG. Decoding whatever ImageIO recognizes is + // both correct and strictly more capable than honoring the (advisory) format hint. + (void) format; + + if (data.size() >= 4) + std::fprintf(stderr, + "decodeImageIO: %zu bytes, magic %02x %02x %02x %02x\n", + data.size(), + data[0], + data[1], + data[2], + data[3]); CFDataRef cfData = CFDataCreateWithBytesNoCopy( nullptr, data.data(), static_cast(data.size()), kCFAllocatorNull); @@ -113,6 +125,10 @@ namespace CGImageSourceRef source = CGImageSourceCreateWithData(cfData, nullptr); CGImageRef image = source ? CGImageSourceCreateImageAtIndex(source, 0, nullptr) : nullptr; + std::fprintf(stderr, + "decodeImageIO: source=%p image=%p\n", + (void*) source, + (void*) image); std::optional result; if (image)