Intelligent colour expansion and alpha blending, measured in the simulator

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-15 23:56:58 +01:00
1 parent 193bcd5d97
commit 56062e1a3e
5 files changed
+78 -25

No files matched your search

+8
View File
@@ -87,6 +87,14 @@ class Format4(unittest.TestCase):
self.assertEqual(tuple(v >> 3 for v in img.getpixel((x, y))[:3]), (r >> 3, g >> 3, b >> 3))
self.assertLess(img.getpixel((0, 3))[3], 255)
def test_intelligent_colours_and_alpha(self):
# Intelligent simulator: channels scaled v*255//31, alpha 8-bit = 2 * stored 7-bit (127 = 255)
blob = pictures.encode_format4(lambda x, y: (198, 195, 198, [255, 227, 3][x]), 3, 1, 0)
img = pictures.to_image(blob)
self.assertEqual(img.getpixel((0, 0)), (197, 194, 197, 255))
self.assertEqual(img.getpixel((1, 0))[3], 226) # 227 * 127 // 255 = 113 -> 226
self.assertEqual(img.getpixel((2, 0))[3], 2)
@unittest.skipUnless(HAVE_PIL, "needs Pillow")
def test_image_roundtrip(self):
from PIL import Image