Loading poolpay/display/get_test_picture.py 0 → 100644 +34 −0 Original line number Diff line number Diff line def _append_pixel(red: int, green: int, blue: int, pixels: list[int]) -> None: """ Append a pixel with the given red, green and blue parts to the list of pixels. The pixel is represented as 16-bit, like this (5 bit for red, 6 bit for green, 5 bit for blue): RRRRRGGG|GGGBBBBB Two integers are appended to the list. - Bit order: Big endian (i.e. within one byte, the highest valued bit comes first; this is the normal way of writing down a number) - Byte order: Little endin (i.e. in a sequence of bytes, the highest valued byte comes last; this is the weird way of writing down a sequence) """ high_byte = red << 3 | green >> 3 # RRRRRGGG low_byte = (green << 5) & 0xFF | blue # GGGBBBBB pixels.append(low_byte) pixels.append(high_byte) def get_test_picture(width: int, height: int) -> bytes: """ Generate a test picture with a color gradient and return it. """ picture = [] 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) return bytes(picture) Loading
poolpay/display/get_test_picture.py 0 → 100644 +34 −0 Original line number Diff line number Diff line def _append_pixel(red: int, green: int, blue: int, pixels: list[int]) -> None: """ Append a pixel with the given red, green and blue parts to the list of pixels. The pixel is represented as 16-bit, like this (5 bit for red, 6 bit for green, 5 bit for blue): RRRRRGGG|GGGBBBBB Two integers are appended to the list. - Bit order: Big endian (i.e. within one byte, the highest valued bit comes first; this is the normal way of writing down a number) - Byte order: Little endin (i.e. in a sequence of bytes, the highest valued byte comes last; this is the weird way of writing down a sequence) """ high_byte = red << 3 | green >> 3 # RRRRRGGG low_byte = (green << 5) & 0xFF | blue # GGGBBBBB pixels.append(low_byte) pixels.append(high_byte) def get_test_picture(width: int, height: int) -> bytes: """ Generate a test picture with a color gradient and return it. """ picture = [] 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) return bytes(picture)