From 96ecabc38b9bc2205ce225c5cf797c098aec4bb9 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Wed, 17 Jun 2026 07:26:15 +0800 Subject: [PATCH] [Fix] (trace-replay): write opaque Android actual images --- .../app/src/trace/cpp/trace_replay_core.cpp | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/android-plugin/app/src/trace/cpp/trace_replay_core.cpp b/android-plugin/app/src/trace/cpp/trace_replay_core.cpp index 1abde701..b814fba9 100644 --- a/android-plugin/app/src/trace/cpp/trace_replay_core.cpp +++ b/android-plugin/app/src/trace/cpp/trace_replay_core.cpp @@ -279,6 +279,12 @@ bool WritePngRgba(const std::string& path, const RgbaImage& image, std::string& return true; } +void ForceOpaqueAlpha(RgbaImage& image) { + for (std::size_t i = 3; i < image.pixels.size(); i += 4) { + image.pixels[i] = 0xff; + } +} + bool ReadPpmRgbAsRgba(const std::string& path, RgbaImage& image, std::string& error) { std::ifstream file(path, std::ios::binary); if (!file) { @@ -440,9 +446,21 @@ bool RunRetrace(const Request& request, bool usePresentDump, Result& result) { return false; } if (hasSnapshot && !hasPresentDump) { - if (!CopyFile(snapshotPath, result.actualPath)) { + RgbaImage snapshot; + std::string imageError; + if (!ReadPngRgba(snapshotPath, snapshot, imageError)) { result.statusCode = STATUS_IO_ERROR; - result.message = "failed to copy snapshot to " + result.actualPath; + result.message = imageError.empty() + ? "failed to decode snapshot PNG: " + snapshotPath + : imageError; + return false; + } + ForceOpaqueAlpha(snapshot); + if (!WritePngRgba(result.actualPath, snapshot, imageError)) { + result.statusCode = STATUS_IO_ERROR; + result.message = imageError.empty() + ? "failed to write snapshot to actual PNG" + : imageError; return false; } }