# Save as icc-profile-fixture.py and install Pillow (python3 -m pip install Pillow). # Run with the source sRGB and destination Display P3 ICC files as arguments. # On the measured macOS setup they were in /System/Library/ColorSync/Profiles/ # as "sRGB Profile.icc" and "Display P3.icc", respectively. import argparse from PIL import Image, ImageCms parser = argparse.ArgumentParser() parser.add_argument("srgb_profile") parser.add_argument("display_p3_profile") options = parser.parse_args() srgb = ImageCms.getOpenProfile(options.srgb_profile) p3 = ImageCms.getOpenProfile(options.display_p3_profile) intent = ImageCms.Intent.RELATIVE_COLORIMETRIC swatch = Image.new("RGB", (2, 2), (45, 116, 170)) converted = ImageCms.profileToProfile(swatch, srgb, p3, renderingIntent=intent) for filename, pixels, profile in [ ("original-srgb.png", swatch, srgb), ("assigned-display-p3.png", swatch, p3), ("converted-display-p3.png", converted, p3), ]: pixels.save(filename, icc_profile=profile.tobytes()) proof = ImageCms.profileToProfile(pixels, profile, srgb, renderingIntent=intent) print(filename, "stored", pixels.getpixel((0, 0)), "sRGB proof", proof.getpixel((0, 0)))