Skip to content

Commit cd823ad

Browse files
committed
Undo project-specific changes
- Reduce increased precisions - Switch back to Floyd-Steinberg
1 parent 30ee421 commit cd823ad

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

src/include/Image.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Image : virtual public NetworkClient, virtual public Adafruit_GFX
130130
#endif
131131

132132
#if defined(ARDUINO_INKPLATECOLOR) || defined(ARDUINO_INKPLATE4) || defined(ARDUINO_INKPLATE7)
133-
int32_t ditherBuffer[3][8][E_INK_WIDTH + 20];
133+
int16_t ditherBuffer[3][8][E_INK_WIDTH + 20];
134134

135135
const int kernelWidth = _kernelWidth;
136136
const int kernelHeight = _kernelHeight;
@@ -140,7 +140,7 @@ class Image : virtual public NetworkClient, virtual public Adafruit_GFX
140140

141141
const unsigned char (*kernel)[_kernelWidth] = _kernel;
142142
#elif ARDUINO_INKPLATE2
143-
int32_t ditherBuffer[3][8][E_INK_WIDTH + 20];
143+
int16_t ditherBuffer[3][8][E_INK_WIDTH + 20];
144144

145145
const int kernelWidth = _kernelWidth;
146146
const int kernelHeight = _kernelHeight;

src/include/ImageDitherColor.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ uint8_t Image::findClosestPalette(int16_t r, int16_t g, int16_t b)
6666
int16_t pr = RED8(pallete[i]);
6767
int16_t pg = GREEN8(pallete[i]);
6868
int16_t pb = BLUE8(pallete[i]);
69-
int64_t currentDistance = SQR(r - pr) + SQR(g - pg) + SQR(b - pb);
69+
int32_t currentDistance = SQR(r - pr) + SQR(g - pg) + SQR(b - pb);
7070
if (currentDistance < minDistance) {
7171
minDistance = currentDistance;
7272
contenderList[0] = i;
@@ -110,10 +110,6 @@ uint8_t Image::ditherGetPixelBmp(uint32_t px, int i, int j, int w, bool paletted
110110
int16_t g = GREEN8(px) + ditherBuffer[1][j % 8][i] / coef;
111111
int16_t b = BLUE8(px) + ditherBuffer[2][j % 8][i] / coef;
112112

113-
// r = max((int16_t)0, min((int16_t)255, r));
114-
// g = max((int16_t)0, min((int16_t)255, g));
115-
// b = max((int16_t)0, min((int16_t)255, b));
116-
117113
ditherBuffer[0][j % 8][i] = 0;
118114
ditherBuffer[1][j % 8][i] = 0;
119115
ditherBuffer[2][j % 8][i] = 0;

src/include/ImageDitherColorKernels.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
// one you want below
2424

2525
// Floyd Steinberg
26-
// const int _coef = 16;
27-
// const int _kernelX = 1;
28-
// const unsigned char _kernel[2][3] = {
29-
// {0, 0, 7},
30-
// {3, 5, 1},
31-
// };
26+
const int _coef = 16;
27+
const int _kernelX = 1;
28+
const unsigned char _kernel[2][3] = {
29+
{0, 0, 7},
30+
{3, 5, 1},
31+
};
3232

3333
/*
3434
//J F Jarvis, C N Judice, and W H Ninke "Minimized Average Error"
@@ -41,7 +41,7 @@ const unsigned char _kernel[3][5] = {
4141
};
4242
*/
4343

44-
44+
/*
4545
// Atkinson
4646
const int _coef = 8;
4747
const int _kernelX = 1;
@@ -50,6 +50,7 @@ const unsigned char _kernel[3][4] = {
5050
{1, 1, 1, 0},
5151
{0, 1, 0, 0},
5252
};
53+
*/
5354

5455

5556
/*
@@ -88,3 +89,4 @@ const int _kernelWidth = (sizeof _kernel[0] / sizeof _kernel[0][0]);
8889
const int _kernelHeight = (sizeof _kernel / sizeof _kernel[0]);
8990

9091
#endif
92+

src/include/defines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199

200200
#define DATA 0x0E8C0030
201201

202-
#define SQR(a) ((int64_t)(a) * (int64_t)(a))
202+
#define SQR(a) ((int32_t)(a) * (int32_t)(a))
203203
#define COLORDISTSQR(x, y) (SQR(RED8(x) - RED8(y)) + SQR(GREEN8(x) - GREEN8(y)) + SQR(BLUE8(x) - BLUE8(y)))
204204

205205
#endif

0 commit comments

Comments
 (0)