Verified Commit d33ec020 authored by Jakob Moser's avatar Jakob Moser
Browse files

Document alternative implementations

For potential research purposes in the future
parent 0c18af93
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -18,17 +18,34 @@ def _append_pixel(red: int, green: int, blue: int, pixels: list[int]) -> None:
    pixels.append(low_byte)
    pixels.append(high_byte)

    # Alternative implementation I:
    #
    # color = red << 11 | green << 5 | blue
    # return struct.pack("<H", color)
    #
    # instead of appending to a list of pixels.

    # Alternative implementation II:
    #
    # return bytes([low_bytes, high_byte])
    #
    # instead of appending to a list of pixels.


def get_test_picture(width: int, height: int) -> bytes:
    """
    Generate a test picture with a color gradient and return it.
    """
    picture = []
    picture: list[int] = []
    for y in range(height):
        for x in range(width):
            b = 10
            g = int(x * 31.0 / 480.0)
            r = int(x * 31.0 / 480)
            _append_pixel(red=r, green=g, blue=b, pixels=picture)
            # Alternative implementation:
            #
            # Have _append_pixel return a bytes object, store it in a list[bytes],
            # and then return b"".join(picture)

    return bytes(picture)