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

+21
View File
@@ -105,6 +105,27 @@ class Render(unittest.TestCase):
self.assertEqual(len(gauge_needle(58, 58, 69, 8)), 265)
self.assertEqual(gauge_needle(58, 58, 0, 2), {(x, y) for x in range(1, 30) for y in (28, 29)})
def test_intelligent_alpha_blend(self):
# measured in the Intelligent simulator: page blue, picture (255, 0, 41) with 7-bit alpha 97
import io
from PIL import Image
from nxhmi import project
from nxhmi.page import Page
from nxhmi.render import Renderer, rgb
self.assertEqual(rgb(0xC618, 3), (197, 194, 197))
h = project.new_project("NX4827P043_011")
im = Image.new("RGBA", (3, 1), (255, 0, 40, 195)) # 3 px: 1-2 px pictures stay format 0
im.putpixel((1, 0), (255, 0, 40, 255))
b = io.BytesIO(); im.save(b, "PNG")
pid = project.add_picture(h, b.getvalue())
p = Page.parse(h.read("0.pa"))
p.components[0].set("bco", 0x001F)
C.add(p, "picture", x=0, y=0, w=3, h=1, pic=pid)
h.write("0.pa", p.pack())
img = Renderer(h).render("page0")
self.assertEqual(img.getpixel((0, 0)), (194, 0, 92))
self.assertEqual(img.getpixel((1, 0)), (255, 0, 41))
def test_demo_pages_render(self):
from nxhmi.render import Renderer
r = Renderer(HMIFile.load(FIXTURE))