]> Repositories - hackapet/Adafruit_Blinka_Displayio.git/blob - displayio/_structs.py
3603295bbeb4bb0a306a33db810e14f8e27ea352
[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     width: int = 0
36     height: int = 0
37     mirror_x: bool = False
38     mirror_y: bool = False
39     transpose_xy: bool = False
40
41
42 @dataclass
43 class ColorspaceStruct:
44     # pylint: disable=invalid-name, too-many-instance-attributes
45     """Colorspace Struct Dataclass"""
46     depth: int
47     bytes_per_cell: int = 0
48     tricolor_hue: int = 0
49     tricolor_luma: int = 0
50     grayscale_bit: int = 0
51     grayscale: bool = False
52     tricolor: bool = False
53     sevencolor: bool = False  # Acep e-ink screens.
54     pixels_in_byte_share_row: bool = False
55     reverse_pixels_in_byte: bool = False
56     reverse_bytes_in_word: bool = False
57     dither: bool = False
58
59
60 @dataclass
61 class InputPixelStruct:
62     """InputPixel Struct Dataclass"""
63
64     pixel: int = 0
65     x: int = 0
66     y: int = 0
67     tile: int = 0
68     tile_x: int = 0
69     tile_y: int = 0
70
71
72 @dataclass
73 class OutputPixelStruct:
74     """OutputPixel Struct Dataclass"""
75
76     pixel: int = 0
77     opaque: bool = False
78
79
80 @dataclass
81 class ColorStruct:
82     """Color Struct Dataclass"""
83
84     rgb888: int = 0
85     cached_colorspace: ColorspaceStruct = None
86     cached_color: int = 0
87     cached_colorspace_grayscale_bit: int = 0
88     cached_colorspace_grayscale: bool = False
89     transparent: bool = False
90
91     def rgba(self) -> tuple[int, int, int, int]:
92         """Return the color as a tuple of red, green, blue, alpha"""
93         return (
94             self.rgb888 >> 16,
95             (self.rgb888 >> 8) & 0xFF,
96             self.rgb888 & 0xFF,
97             0 if self.transparent else 0xFF,
98         )
99
100
101 null_transform = TransformStruct()  # Use defaults