From 34bc037e8de6f394efe1be2658cce7adaa5942c5 Mon Sep 17 00:00:00 2001 From: WEIREN FENG Date: Thu, 1 Oct 2026 23:03:45 -0700 Subject: [PATCH] Screenshots: bring iOS 27's 16-bit P3 screenshots down to 8 bits On iOS 27 a device screenshot is 16-bit Display P3, and `sips --setProperty bitsPerSample 8` writes nothing for it while still exiting 0, so the pixel reader was handed the 16-bit file and stopped. Matching the image to its own colour profile writes it at 8 bits with its colours unchanged; the depth is now read back instead of trusting sips's exit code. Co-Authored-By: Claude Opus 5.5 (1M context) --- ios-native/scripts/device-screenshot.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ios-native/scripts/device-screenshot.sh b/ios-native/scripts/device-screenshot.sh index 0c4bb747..62f4fba9 100755 --- a/ios-native/scripts/device-screenshot.sh +++ b/ios-native/scripts/device-screenshot.sh @@ -54,14 +54,20 @@ fi xcrun devicectl device capture screenshot --device "$UDID" --destination "$OUT" >/dev/null -# Device screenshots are 16-bit and the pixel reader needs 8. sips refuses the -# conversion on a file that is already 8-bit, which is a success for our -# purposes, so its exit code is not a failure here. -DEPTH=$(sips -g bitsPerSample "$OUT" 2>/dev/null | awk -F': ' '/bitsPerSample/ {print $2}') -if [ "${DEPTH:-16}" != "8" ]; then - sips -s format png --setProperty bitsPerSample 8 "$OUT" --out "$OUT" >/dev/null 2>&1 || { +# Device screenshots are 16-bit and the pixel reader needs 8. On an iOS 27 +# screenshot (16-bit Display P3), `sips --setProperty bitsPerSample 8` writes +# nothing and still exits 0, so sips's exit code says nothing either way. +# Matching the image to its own colour profile writes it at 8 bits without +# changing its colours; the depth is read back to know whether that worked. +depth() { sips -g bitsPerSample "$1" 2>/dev/null | awk -F': ' '/bitsPerSample/ {print $2}'; } +if [ "$(depth "$OUT")" != "8" ]; then + PROFILE=$(sips -g profile "$OUT" 2>/dev/null | awk -F': ' '/profile/ {print $2}') + ICC="/System/Library/ColorSync/Profiles/${PROFILE}.icc" + [ -n "$PROFILE" ] && [ -f "$ICC" ] || ICC="/System/Library/ColorSync/Profiles/Display P3.icc" + sips --matchTo "$ICC" "$OUT" --out "$OUT" >/dev/null 2>&1 || true + if [ "$(depth "$OUT")" != "8" ]; then echo "Could not reduce $OUT to 8-bit; sample-pixels.py will say so." >&2 - } + fi fi echo "wrote $OUT"