#!/usr/bin/env python3 """Batch-build DXT1 DDS loading screens from Wikimedia public-domain oil paintings. Downloads each source painting, center-crops to 16:9, resizes to 2560x1440 (Lanczos), and compresses to DXT1 (BC1) via texconv. Downloads are cached in temp/loadingscreen_sources/ so re-runs skip fetching. Usage: python build_loadingscreens.py Requires tools/bin/texconv.exe and Pillow. """ import os import subprocess import sys import tempfile import time import urllib.request from PIL import Image HERE = os.path.dirname(os.path.abspath(__file__)) TEXCONV = os.path.join(HERE, "bin", "texconv.exe") MOD_ROOT = os.path.dirname(HERE) OUT_DIR = os.path.join(MOD_ROOT, "gfx", "loadingscreens") CACHE_DIR = os.path.join(MOD_ROOT, "temp", "loadingscreen_sources") TARGET_W, TARGET_H = 2560, 1440 USER_AGENT = "AbIntegroMod/1.0 (EU4 mod; public-domain art processing)" Image.MAX_IMAGE_PIXELS = None # some Bruegel scans are 40K+ px PAINTINGS = [ {"n": 1, "title": "The Harvesters", "author": "Pieter Bruegel the Elder", "year": "1565", "medium": "木板油画", "museum": "Metropolitan Museum of Art", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Pieter%20Bruegel%20the%20Elder-%20The%20Harvesters%20-%20Google%20Art%20Project.jpg"}, {"n": 2, "title": "Battle of Öland", "author": "Claus Møinichen", "year": "1686", "medium": "布面油画", "museum": "Statens Museum for Kunst, Copenhagen", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Claus%20M%C3%B8inichen%20-%20Slaget%20ved%20%C3%98land%201.%20juni%201676.png"}, {"n": 3, "title": "The Bucintoro at the Molo on Ascension Day", "author": "Canaletto", "year": "~1732", "medium": "布面油画", "museum": "Private collection", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Canaletto%20%28Giovanni%20Antonio%20Canal%29%2C%20Italian%20%28active%20Venice%2C%20Rome%2C%20and%20England%29%20-%20The%20Bucintoro%20at%20the%20Molo%20on%20Ascension%20Day%20-%20Google%20Art%20Project.jpg"}, {"n": 4, "title": "Election of Stanisław August", "author": "Bernardo Bellotto", "year": "1778", "medium": "布面油画", "museum": "Royal Castle, Warsaw", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Bellotto%20Election%20of%20Stanislas%20Augustus.jpg"}, {"n": 5, "title": "Armenian Wedding", "author": "Jean-Baptiste Vanmour", "year": "1720-1737", "medium": "布面油画", "museum": "Rijksmuseum, Amsterdam", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Armenian%20Wedding%20by%20Jean%20Baptiste%20Vanmour.jpg"}, {"n": 6, "title": "Turkish Wedding / Wedding Procession on the Bosphorus", "author": "Jean-Baptiste Vanmour", "year": "1720-1737", "medium": "布面油画", "museum": "Rijksmuseum, Amsterdam", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Turkse%20bruiloft%20Rijksmuseum%20SK-A-2000.jpeg"}, {"n": 7, "title": "Reception of the French Ambassador by Sultan Ahmed III", "author": "Jean-Baptiste Vanmour", "year": "1724", "medium": "布面油画", "museum": "Musée du Louvre, Paris", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Jean-Baptiste%20van%20Mour%20-%20R%C3%A9ception%20de%20l%27ambassadeur%20de%20France%20par%20le%20sultan%20Ahmed%20III%2001.jpg"}, {"n": 8, "title": "The Grand Vizier Crossing the Atmeydanı", "author": "Jean-Baptiste Vanmour", "year": "1720-1737", "medium": "布面油画", "museum": "Rijksmuseum, Amsterdam", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/De%20grootvizier%20steekt%20de%20Atmeydan%C4%B1%20%28hippodroom%29%20over%20Rijksmuseum%20SK-A-1998.jpeg"}, {"n": 9, "title": "A VOC Fleet off the Coast of West Africa", "author": "Adam Willaerts", "year": "1608", "medium": "布面油画", "museum": "Rijksmuseum, Amsterdam", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/SA%2025825-Een%20vloot%20van%20de%20Verenigde%20Oostindische%20Compagnie%20voor%20de%20kust%20van%20West-Afrika-Een%20vloot%20van%20de%20Verenigde%20Oostindische%20Compagnie%20voor%20een%20eiland.jpg"}, {"n": 10, "title": "Table Bay", "author": "Aernout Smit", "year": "1683", "medium": "布面油画", "museum": "Iziko Museums of South Africa", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Aernout%20Smit-Aernout%20Smit-0666.jpg"}, {"n": 11, "title": "Action off the Cape of Good Hope", "author": "Samuel Scott", "year": "~1750s", "medium": "布面油画", "museum": "National Maritime Museum, Greenwich", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Samuel%20Scott%20-%20Action%20off%20the%20Cape%20of%20Good%20Hope%20-%20Google%20Art%20Project%20%282326447%29.jpg"}, {"n": 12, "title": "Mausoleum at Outatori near Trichinopoly", "author": "Francis Swain Ward", "year": "~1788", "medium": "布面油画", "museum": "British Library / Yale Center for British Art", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Francis%20Swain%20Ward%20-%20Mausoleum%20at%20Outatori%20near%20Trichinopoly%20-%20Google%20Art%20Project.jpg"}, {"n": 13, "title": "The Fort of Bidjegur", "author": "William Hodges", "year": "~1784", "medium": "布面油画", "museum": "Yale Center for British Art", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/William%20Hodges%20-%20The%20Fort%20of%20Bidjegur%20-%20Google%20Art%20Project.jpg"}, {"n": 14, "title": "Storm on the Ganges, with Mrs. Hastings near the Col-gon Rocks", "author": "William Hodges", "year": "~1790", "medium": "布面油画", "museum": "Yale Center for British Art", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/William%20Hodges%20-%20Storm%20on%20the%20Ganges%2C%20with%20Mrs.%20Hastings%20near%20the%20Col-gon%20Rocks%20-%20Google%20Art%20Project.jpg"}, {"n": 15, "title": "The Castle of Batavia", "author": "Andries Beeckman", "year": "~1662", "medium": "布面油画", "museum": "Rijksmuseum, Amsterdam", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Het%20kasteel%20van%20Batavia%20Rijksmuseum%20SK-A-19.jpeg"}, {"n": 16, "title": "View of Batavia", "author": "Hendrick Dubbels", "year": "1640-1676", "medium": "布面油画", "museum": "Rijksmuseum, Amsterdam", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Gezicht%20op%20Batavia%20Rijksmuseum%20SK-A-2513.jpeg"}, {"n": 17, "title": "Panorama of Macau", "author": "Attributed to William Anderson", "year": "late 1700s", "medium": "布面油画", "museum": "Museu do Oriente, Lisbon", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Panorama%20of%20Macau%2C%20attributed%20to%20William%20Anderson%20of%20Scotland%2C%20late%201700s%2C%20oil%20on%20canvas%20-%20Museu%20do%20Oriente%20-%20Lisbon%2C%20Portugal%20-%20DSC07020.JPG"}, {"n": 18, "title": "Tea Production in China", "author": "Anonymous Chinese export painter", "year": "~1800", "medium": "布面油画", "museum": "Peabody Essex Museum, Salem", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Tea%20production%20in%20China%2C%20Guangzhou%2C%20c.%201800%20AD%2C%20oil%20on%20canvas%20-%20Peabody%20Essex%20Museum%20-%20Salem%2C%20MA%20-%20DSC05278.jpg"}, {"n": 19, "title": "The Hongs at Canton", "author": "Anonymous Chinese School", "year": "~1780", "medium": "布面油画", "museum": "Private collection", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/The%20Hongs%20of%20Canton%201780.jpg"}, {"n": 20, "title": "Los tres mulatos de Esmeraldas", "author": "Andrés Sánchez Gallque", "year": "1599", "medium": "布面油画", "museum": "Museo del Prado, Madrid", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Los%20tres%20mulatos%20de%20Esmeraldas%20%28S%C3%A1nchez%20Galque%29.jpg"}, {"n": 21, "title": "View of Olinda, Brazil", "author": "Frans Post", "year": "1662", "medium": "布面油画", "museum": "Rijksmuseum, Amsterdam", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Gezicht%20op%20Olinda%2C%20Brazili%C3%AB%20Rijksmuseum%20SK-A-742.jpeg"}, {"n": 22, "title": "View of the Plaza Mayor of Mexico City", "author": "Cristóbal de Villalpando", "year": "1695", "medium": "布面油画", "museum": "Private collection / Museo de América", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Vista%20de%20la%20Plaza%20Mayor%20de%20la%20Ciudad%20de%20M%C3%A9xico%20-%20Cristobal%20de%20Villalpando.jpg"}, {"n": 23, "title": "Entry of Viceroy Archbishop Morcillo into Potosí", "author": "Melchor Pérez de Holguín", "year": "1716", "medium": "布面油画", "museum": "Museo de Casa de la Moneda, Potosí", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Entrada%20Virrey%20Arzobispo%20Morcillo.jpg"}, {"n": 24, "title": "The Death of General Wolfe", "author": "Benjamin West", "year": "1770", "medium": "布面油画", "museum": "National Gallery of Canada, Ottawa", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/The%20Death%20of%20General%20Wolfe%20B.West%2C1770.jpg"}, {"n": 25, "title": "Tahitian War Galleys in Matavai Bay", "author": "William Hodges", "year": "1776", "medium": "布面油画", "museum": "National Maritime Museum, Greenwich", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/William%20Hodges%20-%20Tahitian%20War%20Galleys%20in%20Matavai%20Bay%2C%20Tahiti%20-%20Google%20Art%20Project.jpg"}, {"n": 26, "title": "HMS Resolution and Adventure in Matavai Bay", "author": "William Hodges", "year": "1776", "medium": "布面油画", "museum": "National Maritime Museum, Greenwich", "url": "https://commons.wikimedia.org/wiki/Special:Redirect/file/Hodges%2C%20Resolution%20and%20Adventure%20in%20Matavai%20Bay.jpg"}, ] def center_crop_to_aspect(im, w, h): sw, sh = im.size target_ar = w / h src_ar = sw / sh if src_ar > target_ar: new_w = round(sh * target_ar) x0 = (sw - new_w) // 2 box = (x0, 0, x0 + new_w, sh) else: new_h = round(sw / target_ar) y0 = (sh - new_h) // 2 box = (0, y0, sw, y0 + new_h) return im.crop(box) def download(url, dest, max_retries=4): # Construct a direct upload.wikimedia.org thumbnail URL using the file # name's MD5 hash, bypassing commons.wikimedia.org entirely. The CDN does # not rate-limit thumbnail requests. Wikimedia only serves standard # thumbnail widths; 3840 is the smallest standard size >= 2560. # MediaWiki stores files with underscores replacing spaces, so the MD5 # hash must be computed against the underscored name. import hashlib from urllib.parse import unquote, quote filename = unquote(url.split("Special:Redirect/file/", 1)[1]).replace(" ", "_") digest = hashlib.md5(filename.encode("utf-8")).hexdigest() thumb_url = ( "https://upload.wikimedia.org/wikipedia/commons/thumb/" f"{digest[0]}/{digest[:2]}/" f"{quote(filename, safe='')}/3840px-{quote(filename, safe='')}" ) for attempt in range(max_retries): try: req = urllib.request.Request(thumb_url, headers={"User-Agent": USER_AGENT}) with urllib.request.urlopen(req, timeout=180) as resp, open(dest, "wb") as f: f.write(resp.read()) return except urllib.error.HTTPError as e: if attempt < max_retries - 1: wait = 10 * (attempt + 1) print(f" HTTP {e.code}, retrying in {wait}s (attempt {attempt+1}/{max_retries})") time.sleep(wait) continue raise def process_one(p): n = p["n"] slot = n - 1 # load_0 .. load_25 ext = ".jpg" if p["url"].endswith(".jpg") else (".jpeg" if p["url"].endswith(".jpeg") else (".png" if p["url"].endswith(".png") else ".jpg")) cached = os.path.join(CACHE_DIR, f"item_{n:02d}{ext}") out_dds = os.path.join(OUT_DIR, f"load_{slot}.dds") try: if not os.path.isfile(cached): print(f"[{n:02d}/{len(PAINTINGS)}] downloading: {p['title']}") download(p["url"], cached) time.sleep(2) else: print(f"[{n:02d}/{len(PAINTINGS)}] cached: {p['title']}") im = Image.open(cached) if im.mode not in ("RGB", "RGBA"): im = im.convert("RGB") sw, sh = im.size print(f" source: {sw}x{sh} {im.mode}") if min(sw, sh) < 2000: print(f" WARNING: low resolution ({sw}x{sh}) - may need museum master") im = center_crop_to_aspect(im, TARGET_W, TARGET_H) im = im.resize((TARGET_W, TARGET_H), Image.LANCZOS) if im.mode != "RGB": im = im.convert("RGB") with tempfile.TemporaryDirectory() as tmp: stage = os.path.join(tmp, "stage.png") im.save(stage, format="PNG") cmd = [TEXCONV, "-f", "DXT1", "-m", "1", "-ft", "dds", "-y", "-o", tmp, stage] r = subprocess.run(cmd, capture_output=True, text=True) if r.returncode != 0: sys.stdout.write(r.stdout) sys.stderr.write(r.stderr) return False produced = os.path.join(tmp, "stage.dds") if not os.path.isfile(produced): print(" error: texconv produced no output", file=sys.stderr) return False os.replace(produced, out_dds) sz = os.path.getsize(out_dds) print(f" wrote: load_{slot}.dds ({sz} bytes, {sz/1024/1024:.1f}MB)") return True except Exception as e: print(f" FAILED: {e}") if os.path.isfile(cached): os.remove(cached) # remove partial/failed download so retry re-fetches return False def main(): if not os.path.isfile(TEXCONV): print(f"error: texconv not found at {TEXCONV}", file=sys.stderr) return 1 os.makedirs(CACHE_DIR, exist_ok=True) os.makedirs(OUT_DIR, exist_ok=True) ok = 0 failed = [] for p in PAINTINGS: if process_one(p): ok += 1 else: failed.append(p["n"]) print(f"\nDone: {ok}/{len(PAINTINGS)} succeeded") if failed: print(f"FAILED items: {failed}") total = sum(os.path.getsize(os.path.join(OUT_DIR, f"load_{p['n']-1}.dds")) for p in PAINTINGS if os.path.isfile(os.path.join(OUT_DIR, f"load_{p['n']-1}.dds"))) print(f"Total loadingscreen DDS size: {total/1024/1024:.1f}MB") return 0 if ok == len(PAINTINGS) else 1 if __name__ == "__main__": raise SystemExit(main())