]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blob - displayio/_structs.py
More bug fixes
[hackapet/Adafruit_Blinka_Displayio.git] / displayio / _structs.py
1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams
2 #
3 # SPDX-License-Identifier: MIT
4
5 """
6 `displayio._structs`
7 ================================================================================
8
9 Struct Data Classes for Blinka Displayio
10
11 **Software and Dependencies:**
12
13 * Adafruit Blinka:
14   https://github.com/adafruit/Adafruit_Blinka/releases
15
16 * Author(s): Melissa LeBlanc-Williams
17
18 """
19
20 from dataclasses import dataclass
21
22 __version__ = "0.0.0+auto.0"
23 __repo__ = "https://github.com/adafruit/Adafruit_Blinka_Displayio.git"
24
25
26 @dataclass
27 class TransformStruct:
28     # pylint: disable=invalid-name
29     """Transform Struct Dataclass"""
30     x: int = 0
31     y: int = 0
32     dx: int = 1
33     dy: int = 1
34     scale: int = 1
35     transpose_xy: bool = False
36     mirror_x: bool = False
37     mirror_y: bool = False
38
39
40 @dataclass
41 class ColorspaceStruct:
42     # pylint: disable=invalid-name, too-many-instance-attributes
43     """Colorspace Struct Dataclass"""
44     depth: int
45     bytes_per_cell: int = 0
46     tricolor_hue: int = 0
47     tricolor_luma: int = 0
48     grayscale_bit: int = 0
49     grayscale: bool = False
50     tricolor: bool = False
51     sevencolor: bool = False  # Acep e-ink screens.
52     pixels_in_byte_share_row: bool = False
53     reverse_pixels_in_byte: bool = False
54     reverse_bytes_in_word: bool = False
55     dither: bool = False
56
57
58 @dataclass
59 class InputPixelStruct:
60     """InputPixel Struct Dataclass"""
61
62     pixel: int = 0
63     x: int = 0
64     y: int = 0
65     tile: int = 0
66     tile_x: int = 0
67     tile_y: int = 0
68
69
70 @dataclass
71 class OutputPixelStruct:
72     """OutputPixel Struct Dataclass"""
73
74     pixel: int = 0
75     opaque: bool = False
76
77
78 @dataclass
79 class ColorStruct:
80     """Color Struct Dataclass"""
81
82     rgb888: int = 0
83     cached_colorspace: ColorspaceStruct = None
84     cached_color: int = 0
85     cached_colorspace_grayscale_bit: int = 0
86     cached_colorspace_grayscale: bool = False
87     transparent: bool = False
88
89     def rgba(self) -> tuple[int, int, int, int]:
90         """Return the color as a tuple of red, green, blue, alpha"""
91         return (
92             self.rgb888 >> 16,
93             (self.rgb888 >> 8) & 0xFF,
94             self.rgb888 & 0xFF,
95             0 if self.transparent else 0xFF,
96         )