"""Read actual boot scanout; only the logo, XFESystem wordmark and loader may have ink."""
import hashlib
import re
from PIL import Image, ImageChops
def ink(image):
red, green, blue = image.convert('RGB').split()
histogram = ImageChops.lighter(ImageChops.lighter(red, green), blue).histogram()
return image.width * image.height - histogram[0]
def inspect_boot_frame(image):
width, height = image.size
assert (width, height) == (1280, 800), 'Boot scanout has unexpected dimensions'
size = max(80, min(288, min(width, height) // 5))
cx, cy = width // 2, height * 42 // 100
loader_y = cy + size // 2 + size // 12 * 20 // 12 + 62
allowed = (cx-size-12, max(0, cy-size-12), cx+size+13, min(height, loader_y+32))
outside = image.copy(); outside.paste((0, 0, 0), allowed)
assert ink(outside) == 0, 'Boot screen contains text, progress bars or other pixels outside the branded animation'
word_top = cy + size // 2 + 20
return {'Size': [width, height], 'AllowedBounds': list(allowed), 'OutsideNonBlackPixels': 0,
'LogoPixels': ink(image.crop((cx-size//2, cy-size//2, cx+size//2, cy+size//2))),
'WordmarkPixels': ink(image.crop((cx-size//2, word_top, cx+size//2, word_top+size//12*20//12))),
'LoaderPixels': ink(image.crop((cx-40, loader_y-28, cx+40, loader_y+28)))}
class BootAnimationCapture:
def __init__(self, directory):
self.directory = directory
self.frames = []
def capture(self, qmp, serial):
if 'XFE_BOOT_VISUAL_START|' not in serial or 'XFE_BOOT_VISUAL_RELEASED|' in serial:
return
name = f'Boot-Animation-{len(self.frames):02}'
ppm, png = self.directory / (name+'.ppm'), self.directory / (name+'.png')
qmp.call('screendump', {'filename': str(ppm)})
with Image.open(ppm) as source:
frame = source.convert('RGB'); stats = inspect_boot_frame(frame); frame.save(png)
self.frames.append({'Path': png.name, 'Sha256': hashlib.sha256(png.read_bytes()).hexdigest(), **stats,
'ApplicationFrameAlreadyReady': 'XFE_BOOT_VISUAL_APPLICATION_FRAME_READY' in serial,
'Phase': 'Waiting' if 'XFE_BOOT_VISUAL_WAITING' in serial else 'Intro'})
def finish(self, serial, first_frame_marker):
start = serial.find('XFE_BOOT_VISUAL_START|')
intro = serial.find('XFE_BOOT_VISUAL_INTRO_COMPLETE')
ready = serial.find('XFE_BOOT_VISUAL_APPLICATION_FRAME_READY')
released = re.search(r'XFE_BOOT_VISUAL_RELEASED\|ElapsedMs\|(\d+)\|Frames\|(\d+)\|LoadingShown\|([01])', serial)
assert start >= 0 and released and min(intro, ready) > start
assert intro < released.start() and ready < released.start() < serial.find(first_frame_marker)
assert int(released[1]) >= 2400 and int(released[2]) >= 2
assert len(self.frames) >= 2 and any(frame['LogoPixels'] > 100 for frame in self.frames), 'No actual animated boot logo was captured'
assert any(frame['WordmarkPixels'] > 20 for frame in self.frames), 'The actual XFESystem wordmark was not captured'
assert len({frame['Sha256'] for frame in self.frames}) >= 2, 'Boot animation scanout never changed'
loader_shown = released[3] == '1'
if loader_shown:
assert start < intro <= serial.find('XFE_BOOT_VISUAL_WAITING') < ready
else:
assert 'XFE_BOOT_VISUAL_WAITING' not in serial, 'A ready system displayed an unnecessary loading stage'
return {'Kind': 'XfeActualBrandedBootAnimation', 'Passed': True,
'Input': 'Actual QMP framebuffer captures and source-bound native readiness markers',
'OnlyBrandAndLoaderDuringInitialization': True, 'ProductWordmark': 'XFESystem',
'IntroMinimumMilliseconds': 2400, 'ReleaseElapsedMilliseconds': int(released[1]),
'NativeFramesDrawn': int(released[2]), 'ApplicationFrameReadyBeforeRelease': True,
'LoaderShown': loader_shown,
'ActualLoaderPixelsCaptured': any(frame['Phase'] == 'Waiting' and frame['LoaderPixels'] > 3 for frame in self.frames),
'FrameCaptures': self.frames}
def finish_waiting_diagnostic(self, serial):
assert 'XFE_BOOT_VISUAL_WAITING' in serial and 'XFE_BOOT_VISUAL_APPLICATION_FRAME_READY' not in serial
assert 'XFE_BOOT_VISUAL_RELEASED|' not in serial, 'An unready application was released'
assert len(self.frames) >= 3 and any(frame['WordmarkPixels'] > 20 for frame in self.frames)
assert any(frame['Phase'] == 'Waiting' and frame['LoaderPixels'] > 3 for frame in self.frames), 'Actual waiting spinner pixels were not captured'
return {'Kind': 'XfeBootWaitingVisualDiagnostic', 'Passed': True, 'ApplicationAcceptance': False,
'UnreadyApplicationWasNotReleased': True, 'ActualLoaderPixelsCaptured': True,
'ProductWordmark': 'XFESystem', 'FrameCaptures': self.frames}
"""Read actual boot scanout; only the logo, XFESystem wordmark and loader may have ink."""
import hashlib
import re
from PIL import Image, ImageChops
def ink(image):
red, green, blue = image.convert('RGB').split()
histogram = ImageChops.lighter(ImageChops.lighter(red, green), blue).histogram()
return image.width * image.height - histogram[0]
def inspect_boot_frame(image):
width, height = image.size
assert (width, height) == (1280, 800), 'Boot scanout has unexpected dimensions'
size = max(80, min(288, min(width, height) // 5))
cx, cy = width // 2, height * 42 // 100
loader_y = cy + size // 2 + size // 12 * 20 // 12 + 62
allowed = (cx-size-12, max(0, cy-size-12), cx+size+13, min(height, loader_y+32))
outside = image.copy(); outside.paste((0, 0, 0), allowed)
assert ink(outside) == 0, 'Boot screen contains text, progress bars or other pixels outside the branded animation'
word_top = cy + size // 2 + 20
return {'Size': [width, height], 'AllowedBounds': list(allowed), 'OutsideNonBlackPixels': 0,
'LogoPixels': ink(image.crop((cx-size//2, cy-size//2, cx+size//2, cy+size//2))),
'WordmarkPixels': ink(image.crop((cx-size//2, word_top, cx+size//2, word_top+size//12*20//12))),
'LoaderPixels': ink(image.crop((cx-40, loader_y-28, cx+40, loader_y+28)))}
class BootAnimationCapture:
def __init__(self, directory):
self.directory = directory
self.frames = []
def capture(self, qmp, serial):
if 'XFE_BOOT_VISUAL_START|' not in serial or 'XFE_BOOT_VISUAL_RELEASED|' in serial:
return
name = f'Boot-Animation-{len(self.frames):02}'
ppm, png = self.directory / (name+'.ppm'), self.directory / (name+'.png')
qmp.call('screendump', {'filename': str(ppm)})
with Image.open(ppm) as source:
frame = source.convert('RGB'); stats = inspect_boot_frame(frame); frame.save(png)
self.frames.append({'Path': png.name, 'Sha256': hashlib.sha256(png.read_bytes()).hexdigest(), **stats,
'ApplicationFrameAlreadyReady': 'XFE_BOOT_VISUAL_APPLICATION_FRAME_READY' in serial,
'Phase': 'Waiting' if 'XFE_BOOT_VISUAL_WAITING' in serial else 'Intro'})
def finish(self, serial, first_frame_marker):
start = serial.find('XFE_BOOT_VISUAL_START|')
intro = serial.find('XFE_BOOT_VISUAL_INTRO_COMPLETE')
ready = serial.find('XFE_BOOT_VISUAL_APPLICATION_FRAME_READY')
released = re.search(r'XFE_BOOT_VISUAL_RELEASED\|ElapsedMs\|(\d+)\|Frames\|(\d+)\|LoadingShown\|([01])', serial)
assert start >= 0 and released and min(intro, ready) > start
assert intro < released.start() and ready < released.start() < serial.find(first_frame_marker)
assert int(released[1]) >= 2400 and int(released[2]) >= 2
assert len(self.frames) >= 2 and any(frame['LogoPixels'] > 100 for frame in self.frames), 'No actual animated boot logo was captured'
assert any(frame['WordmarkPixels'] > 20 for frame in self.frames), 'The actual XFESystem wordmark was not captured'
assert len({frame['Sha256'] for frame in self.frames}) >= 2, 'Boot animation scanout never changed'
loader_shown = released[3] == '1'
if loader_shown:
assert start < intro <= serial.find('XFE_BOOT_VISUAL_WAITING') < ready
else:
assert 'XFE_BOOT_VISUAL_WAITING' not in serial, 'A ready system displayed an unnecessary loading stage'
return {'Kind': 'XfeActualBrandedBootAnimation', 'Passed': True,
'Input': 'Actual QMP framebuffer captures and source-bound native readiness markers',
'OnlyBrandAndLoaderDuringInitialization': True, 'ProductWordmark': 'XFESystem',
'IntroMinimumMilliseconds': 2400, 'ReleaseElapsedMilliseconds': int(released[1]),
'NativeFramesDrawn': int(released[2]), 'ApplicationFrameReadyBeforeRelease': True,
'LoaderShown': loader_shown,
'ActualLoaderPixelsCaptured': any(frame['Phase'] == 'Waiting' and frame['LoaderPixels'] > 3 for frame in self.frames),
'FrameCaptures': self.frames}
def finish_waiting_diagnostic(self, serial):
assert 'XFE_BOOT_VISUAL_WAITING' in serial and 'XFE_BOOT_VISUAL_APPLICATION_FRAME_READY' not in serial
assert 'XFE_BOOT_VISUAL_RELEASED|' not in serial, 'An unready application was released'
assert len(self.frames) >= 3 and any(frame['WordmarkPixels'] > 20 for frame in self.frames)
assert any(frame['Phase'] == 'Waiting' and frame['LoaderPixels'] > 3 for frame in self.frames), 'Actual waiting spinner pixels were not captured'
return {'Kind': 'XfeBootWaitingVisualDiagnostic', 'Passed': True, 'ApplicationAcceptance': False,
'UnreadyApplicationWasNotReleased': True, 'ActualLoaderPixelsCaptured': True,
'ProductWordmark': 'XFESystem', 'FrameCaptures': self.frames}