Skip to content

Commit 7032f31

Browse files
authored
Merge pull request #293 from SolderedElectronics/new-color-dither-method
Add new reduced diffusion Floyd steinberg kernel for brighter colors when showing paintings
2 parents b64a74d + 58364fd commit 7032f31

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/graphics/ImageColor/ImageColor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class ImageColor
5858
Atkinson,
5959
Burkes,
6060
Stucki,
61-
SierraLite
61+
SierraLite,
62+
ReducedDiffusion // Floyd-Steinberg pattern at ~69% strength — more vibrant, less washed-out
6263
} DitherKernel;
6364

6465
struct bitmapHeader

src/graphics/ImageColor/ImageDitherColor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ uint8_t ImageColor::findClosestPalette(int16_t r, int16_t g, int16_t b)
4646
int32_t dg = g - pg;
4747
int32_t db = b - pb;
4848

49-
// Perceptual weighted RGB distance (Rec.601)
50-
int32_t currentDistance = 30 * dr * dr + 59 * dg * dg + 11 * db * db;
49+
// Perceptual weighted RGB distance.
50+
// Rec.601 weights (30,59,11) give green a dominant 59% share, which causes
51+
// yellow (high R+G, zero B) to win far too often on limited e-ink palettes.
52+
// Using (30,40,30) reduces green dominance and raises the blue penalty,
53+
// so yellow only wins when a pixel genuinely has negligible blue content.
54+
int32_t currentDistance = 30 * dr * dr + 40 * dg * dg + 30 * db * db;
5155

5256
if (currentDistance < minDistance)
5357
{

src/graphics/ImageColor/ImageDitherColorKernels.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ static const unsigned char _kernelSierraLite[] = {
5757
0, 0, 2, 1, 1, 0, 0, 0, 0,
5858
};
5959

60+
static const unsigned char _kernelReducedDiffusion[] = {
61+
0, 0, 5, 2, 3, 1,
62+
};
63+
6064
static const DitherKernelDef DITHER_KERNELS[] = {
61-
{3, 2, 1, 16, _kernelFloydSteinberg}, {5, 3, 2, 48, _kernelJarvisJudiceNinke},
62-
{4, 3, 1, 8, _kernelAtkinson}, {5, 3, 2, 32, _kernelBurkes},
63-
{5, 3, 2, 42, _kernelStucki}, {3, 3, 1, 4, _kernelSierraLite},
65+
{3, 2, 1, 16, _kernelFloydSteinberg}, {5, 3, 2, 48, _kernelJarvisJudiceNinke},
66+
{4, 3, 1, 8, _kernelAtkinson}, {5, 3, 2, 32, _kernelBurkes},
67+
{5, 3, 2, 42, _kernelStucki}, {3, 3, 1, 4, _kernelSierraLite},
68+
{3, 2, 1, 26, _kernelReducedDiffusion},
6469
};
6570

6671
static const uint8_t DITHER_KERNEL_COUNT = sizeof DITHER_KERNELS / sizeof DITHER_KERNELS[0];

0 commit comments

Comments
 (0)