"""Convert the existing licensed 64px XFE icon to the integer-only boot renderer's data."""
import hashlib
import json
import math
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
source = ROOT / 'assets/branding/console/icon.rgba'
raw = source.read_bytes()
assert len(raw) == 64 * 64 * 4
values = []
for index in range(0, len(raw), 4):
red, green, blue, alpha = raw[index:index + 4]
values.extend((((red * 31 // 255) << 11) | ((green * 63 // 255) << 5) | (blue * 31 // 255), alpha + 32))
lines = ['namespace XFESystem.Branding;', '', '// Exact existing XFE icon, RGB565 + alpha. Generated by Tools/BuildBootLogo.py.',
'internal static class BootLogoData', '{', ' internal const string Pixels =']
for offset in range(0, len(values), 64):
lines.append(' "' + ''.join('\\u%04x' % value for value in values[offset:offset+64]) + ('";' if offset+64 >= len(values) else '" +'))
lines += [' internal const string QuarterSine = "' + ''.join('\\u%04x' % round(math.sin(index * math.pi / 128) * 1024) for index in range(65)) + '";', '}']
mono = (ROOT / 'assets/branding/console/xfe-mono.bin').read_bytes()
assert len(mono) == 96 * 12 * 20
mark = b''.join(mono[(ord(char)-32)*240:(ord(char)-31)*240] for char in 'XFESystem')
lines[-1:-1] = [' internal const string Wordmark = "' + ''.join('\\u%04x' % (value+32) for value in mark) + '";']
target = ROOT / 'Source/XFESystem.NativeKernel/BootLogoData.cs'
target.write_text('\n'.join(lines) + '\n', encoding='utf-8')
print(json.dumps({'Source': str(source.relative_to(ROOT)), 'SourceSha256': hashlib.sha256(raw).hexdigest(),
'Output': str(target.relative_to(ROOT)), 'OutputSha256': hashlib.sha256(target.read_bytes()).hexdigest()}))
"""Convert the existing licensed 64px XFE icon to the integer-only boot renderer's data."""
import hashlib
import json
import math
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
source = ROOT / 'assets/branding/console/icon.rgba'
raw = source.read_bytes()
assert len(raw) == 64 * 64 * 4
values = []
for index in range(0, len(raw), 4):
red, green, blue, alpha = raw[index:index + 4]
values.extend((((red * 31 // 255) << 11) | ((green * 63 // 255) << 5) | (blue * 31 // 255), alpha + 32))
lines = ['namespace XFESystem.Branding;', '', '// Exact existing XFE icon, RGB565 + alpha. Generated by Tools/BuildBootLogo.py.',
'internal static class BootLogoData', '{', ' internal const string Pixels =']
for offset in range(0, len(values), 64):
lines.append(' "' + ''.join('\\u%04x' % value for value in values[offset:offset+64]) + ('";' if offset+64 >= len(values) else '" +'))
lines += [' internal const string QuarterSine = "' + ''.join('\\u%04x' % round(math.sin(index * math.pi / 128) * 1024) for index in range(65)) + '";', '}']
mono = (ROOT / 'assets/branding/console/xfe-mono.bin').read_bytes()
assert len(mono) == 96 * 12 * 20
mark = b''.join(mono[(ord(char)-32)*240:(ord(char)-31)*240] for char in 'XFESystem')
lines[-1:-1] = [' internal const string Wordmark = "' + ''.join('\\u%04x' % (value+32) for value in mark) + '";']
target = ROOT / 'Source/XFESystem.NativeKernel/BootLogoData.cs'
target.write_text('\n'.join(lines) + '\n', encoding='utf-8')
print(json.dumps({'Source': str(source.relative_to(ROOT)), 'SourceSha256': hashlib.sha256(raw).hexdigest(),
'Output': str(target.relative_to(ROOT)), 'OutputSha256': hashlib.sha256(target.read_bytes()).hexdigest()}))