#!/usr/bin/env python3

# Use the proper idiom in the main module ...
# NOTE: See https://docs.python.org/3.12/library/multiprocessing.html#the-spawn-and-forkserver-start-methods
if __name__ == "__main__":
    # NOTE: The four PNGs that are used here are the output from my GitHub
    #       repository "hml", see:
    #         * https://github.com/Guymer/hml

    # Import standard modules ...
    import os

    # Import my modules ...
    try:
        import pyguymer3
        import pyguymer3.image
    except:
        raise Exception("\"pyguymer3\" is not installed; run \"pip install --user PyGuymer3\"") from None

    # Define constants ...
    datasets = [
        "alwaysOpen",
        "limitedAccess",
        "merged",
        "openAccess",
    ]

    # Loop over datasets ...
    for dataset in datasets:
        # Deduce PNG name ...
        pfile1 = f"{dataset}.png"

        # Loop over downscaled sizes ...
        for width in [256, 512, 1024, 2048, 4096]:
            # Deduce downscaled PNG file name ...
            pfile2 = f"{dataset}{width:04d}px.png"

            # Skip if downscaled PNG already exists
            if os.path.exists(pfile2):
                continue

            print(f"Creating \"{pfile2}\" ...")

            # Convert PNG to downscaled PNG ...
            pyguymer3.image.image2png(
                pfile1,
                pfile2,
                screenHeight = width,
                 screenWidth = width,
                       strip = True,
                     timeout = 3600.0,  # NOTE: Would normally be "60.0".
            )
