4
0

make_splash.py 1.2 KB

123456789101112131415161718192021222324
  1. # Generates src/ui/SplashData.h: the pepper from resources/lynx_logo.png, cropped and scaled for the splash screen.
  2. # Usage: python3 tools/make_splash.py (from the repository root)
  3. import io
  4. from PIL import Image
  5. HEIGHT = 420 # px: sharp up to 175% display scaling at the splash's drawn size
  6. pepper = Image.open("resources/lynx_logo.png").convert("RGBA")
  7. pepper = pepper.crop(pepper.getbbox())
  8. width = round(pepper.width * HEIGHT / pepper.height)
  9. pepper = pepper.resize((width, HEIGHT), Image.LANCZOS)
  10. out = io.BytesIO()
  11. pepper.save(out, "PNG", optimize=True)
  12. data = out.getvalue()
  13. lines = ["#pragma once", "",
  14. "// The pepper for the splash screen (resources/lynx_logo.png cropped to its outline, %dx%d PNG with transparency)." % (width, HEIGHT),
  15. "// Generated by tools/make_splash.py - do not edit by hand.", "",
  16. "namespace lynx::splashdata", "{", "inline constexpr unsigned char pepperPng[] = {"]
  17. for i in range(0, len(data), 24):
  18. lines.append(", ".join(str(b) for b in data[i:i + 24]) + ",")
  19. lines += ["};", "} // namespace lynx::splashdata", ""]
  20. open("src/ui/SplashData.h", "w").write("\n".join(lines))
  21. print(width, HEIGHT, len(data), "bytes")