Skip to content

Commit 4e9711a

Browse files
committed
feat: add GRAYSCALE_8 and GRAYSCALE_16
1 parent d8efba1 commit 4e9711a

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ See [`packages/javascript/README.md`](packages/javascript/README.md) for detaile
8686
## Features
8787

8888
- **9 Dithering Algorithms**: NONE, BURKES, ORDERED, FLOYD_STEINBERG, ATKINSON, STUCKI, SIERRA, SIERRA_LITE, JARVIS_JUDICE_NINKE
89-
- **6 Color Schemes**: MONO, BWR, BWY, BWRY, BWGBRY (Spectra 6), GRAYSCALE_4
89+
- **8 Color Schemes**: MONO, BWR, BWY, BWRY, BWGBRY (Spectra 6), GRAYSCALE_4, GRAYSCALE_8, GRAYSCALE_16
9090
- **Multiple Languages**: Python and JavaScript/TypeScript implementations
9191
- **Universal**: Works in Python, Node.js, and browser environments
9292
- **Type-Safe**: Full type coverage in both languages

packages/python/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pip install epaper-dithering
2424

2525
- **Perceptually Correct**: Uses linear RGB color space with gamma correction for accurate error diffusion
2626
- **8 Dithering Algorithms**: From simple ordered dithering to high-quality Jarvis-Judice-Ninke
27-
- **6 Color Schemes**: Support for mono, 3-color, 4-color, and 6-color e-paper displays
27+
- **8 Color Schemes**: Support for mono, 3-color, 4-color, 6-color, and grayscale e-paper displays
2828
- **Tone Mapping**: Dynamic range compression maps image luminance to the display's actual range for smoother dithering
2929
- **Serpentine Scanning**: Reduces directional artifacts in error diffusion (enabled by default)
3030
- **RGBA Support**: Automatic compositing on white background for transparent images
@@ -52,7 +52,9 @@ dithered.save("output.png")
5252
- **BWY** - Black, white, yellow (3-color)
5353
- **BWRY** - Black, white, red, yellow (4-color)
5454
- **BWGBRY** - Black, white, green, blue, red, yellow (6-color Spectra)
55-
- **GRAYSCALE_4** - 4-level grayscale
55+
- **GRAYSCALE_4** - 4-level grayscale (2-bit)
56+
- **GRAYSCALE_8** - 8-level grayscale (3-bit, e.g. Inkplate 10)
57+
- **GRAYSCALE_16** - 16-level grayscale (4-bit, e.g. Waveshare 6" HD)
5658

5759
## Dithering Algorithms
5860

packages/python/src/epaper_dithering/palettes.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,49 @@ class ColorScheme(Enum):
104104
),
105105
)
106106

107+
# NOTE: Values 6 and 7 are placeholders pending firmware assignment.
108+
GRAYSCALE_8 = (
109+
6,
110+
ColorPalette(
111+
colors={
112+
"black": (0, 0, 0),
113+
"gray1": (36, 36, 36),
114+
"gray2": (73, 73, 73),
115+
"gray3": (109, 109, 109),
116+
"gray4": (146, 146, 146),
117+
"gray5": (182, 182, 182),
118+
"gray6": (219, 219, 219),
119+
"white": (255, 255, 255),
120+
},
121+
accent="black",
122+
),
123+
)
124+
125+
GRAYSCALE_16 = (
126+
7,
127+
ColorPalette(
128+
colors={
129+
"black": (0, 0, 0),
130+
"gray1": (17, 17, 17),
131+
"gray2": (34, 34, 34),
132+
"gray3": (51, 51, 51),
133+
"gray4": (68, 68, 68),
134+
"gray5": (85, 85, 85),
135+
"gray6": (102, 102, 102),
136+
"gray7": (119, 119, 119),
137+
"gray8": (136, 136, 136),
138+
"gray9": (153, 153, 153),
139+
"gray10": (170, 170, 170),
140+
"gray11": (187, 187, 187),
141+
"gray12": (204, 204, 204),
142+
"gray13": (221, 221, 221),
143+
"gray14": (238, 238, 238),
144+
"white": (255, 255, 255),
145+
},
146+
accent="black",
147+
),
148+
)
149+
107150
def __init__(self, value: int, palette: ColorPalette):
108151
self._value_ = value # type: ignore[assignment]
109152
self.palette = palette
@@ -123,7 +166,7 @@ def from_value(cls, value: int) -> ColorScheme:
123166
"""Get ColorScheme from firmware int value.
124167
125168
Args:
126-
value: Firmware color scheme value (0-5)
169+
value: Firmware color scheme value (0-7)
127170
128171
Returns:
129172
Matching ColorScheme

packages/python/tests/test_palettes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def test_scheme_has_correct_palette(self):
1616
assert ColorScheme.BWRY.color_count == 4
1717
assert ColorScheme.BWGBRY.color_count == 6
1818
assert ColorScheme.GRAYSCALE_4.color_count == 4
19+
assert ColorScheme.GRAYSCALE_8.color_count == 8
20+
assert ColorScheme.GRAYSCALE_16.color_count == 16
1921

2022
def test_palette_colors_valid(self):
2123
"""Test all palette colors are valid RGB tuples."""

0 commit comments

Comments
 (0)