Web application for creating images for e-ink displays and conversion images to any palette containing from 2 to 256 colors. The application is part of a project for GooDisplay GDEP073E01 with ESP32 Wemos Lolin32 board.
First: buttons at the top change arrangement of the panels, Center button has three positions, Left and Right buttons have two positions each. Selecting fonts in text layers is only available in the locally running (saved to disk) version. The application does not require internet connection. Function upload to display works only in the application launched from the microcontroller's web server, there is no image receiving endpoint on my site, there will be an error that does not affect the operation of the application.
Converting palette: open an image file with the palette you want to convert other images to, check “File palette” (then you can uncheck), open other images and select original palette from first image. Select a dithering method, select ratio value and adjust color channels to improve the result. In this way, images can be prepared for use in a single palette as in older systems. The result can be saved as binary file, as well as binary file containing palette, and as .bmp file.
When working on microcontrollers with small displays, you can abandon the storage of images palettes and switch to universal generated one.
An example of creating palettes consisting of the basic color combinations used in the application. These palettes are best suited for dithering and are universal for any images.
uint8_t cmp(int a) {
return (a < 0 ? 0 : a > 255 ? 255 : a);
}
void basicPalette(uint32_t colors[], uint8_t divider) {
uint8_t k = round(255 / divider);
uint8_t i = 0;
for (uint16_t r = 0; r <= k * divider; r += k) {
for (uint16_t g = 0; g <= k * divider; g += k) {
for (uint16_t b = 0; b <= k * divider; b += k) {
colors[i] = (cmp(r) << 16) + (cmp(g) << 8) + cmp(b);
i++;
}
}
}
}
uint32_t colors8[8];
uint32_t colors27[27];
uint32_t colors64[64];
uint32_t colors125[125];
uint32_t colors216[216];
void setup() {
basicPalette(colors8, 1);
basicPalette(colors27, 2);
basicPalette(colors64, 3);
basicPalette(colors125, 4);
basicPalette(colors216, 5);
}
Variant without palette generation, function for calculating color by index (filling arrays with palette colors is given as an example of using the function)
uint8_t cmp(int a) {
return (a < 0 ? 0 : a > 255 ? 255 : a);
}
uint32_t getPaletteColor(uint8_t colorId, uint8_t divider) {
uint8_t k = round(255 / divider);
divider++;
uint8_t b = colorId / divider;
uint32_t color = cmp((colorId - b * divider) * k);
uint8_t g = b / divider;
color += cmp((b - g * divider) * k) << 8;
uint8_t r = g / divider;
color += cmp((g - r * divider) * k) << 16;
return color;
}
uint32_t colors8[8];
uint32_t colors27[27];
uint32_t colors64[64];
uint32_t colors125[125];
uint32_t colors216[216];
void setup() {
for (uint8_t i = 0; i < 8; i++) {
colors8[i] = getPaletteColor(i, 1);
}
for (uint8_t i = 0; i < 27; i++) {
colors27[i] = getPaletteColor(i, 2);
}
for (uint8_t i = 0; i < 64; i++) {
colors64[i] = getPaletteColor(i, 3);
}
for (uint8_t i = 0; i < 125; i++) {
colors125[i] = getPaletteColor(i, 4);
}
for (uint8_t i = 0; i < 216; i++) {
colors216[i] = getPaletteColor(i, 5);
}
}
Output image to e-ink display must always occur sequentially from one corner of the screen. Use 90 or -90 degree image rotation for upload vertical images to display or to save them. This method will also be useful for displays of other models, sequential image output to display memory will provide performance benefits.
Adapting application to your display: find the beginning of the script block
<script>
const def={w:800,h:480,p:5,b:4,mw:4000,mh:4000,nw:8,nh:8},
pG=[{n:"E-Ink Displays"},{n:"Basic"},{n:"Hardware & Software"}],
pP=[
{n:"Black and white",
p:[0,0xffffff]},
def.w and def.h - display resolution
def.p - display palette from array pP
def.b - default dithering method
def.mw and def.mh - maximum image resolution
def.nw and def.nh - minimum image resolution
Add palette to array pP, to create an unused color, repeat any previously declared color or explicitly specify null
{n:"GooDisplay 4 colors",g:0,
p:[0,0,0,0,0,0xffffff,0,0,0,0,0xffff00,0,0,0,0,0xff0000]},
n - palette name
g - palette group from array pG (not set - without group)
p - array of three-byte color values (rgb)
Creating your own dithering matrices: find declaration of array mF to add Floyd-Steinberg algorithms
const mF=[
{
n:"Floyd-Steinberg",
m:[[1,0,7/16],
[3/16,5/16,1/16]]
},
find declaration of array mB to add Bayer matrices
const mB=[
{
n:"Bayer 2x2",
m(){return BM(1)}
},
add the calculated matrices by analogy
{
n:"Matrix 8x8 1/256",
d:256,
m(){return this.a.map(j=>j.map(i=>i))},
a:[[0,128,32,160,8,136,40,168],
[192,64,224,96,200,72,232,104],
[48,176,16,144,56,184,24,152],
[240,112,208,80,248,120,216,88],
[12,140,44,172,4,132,36,164],
[204,76,236,108,196,68,228,100],
[60,188,28,156,52,180,20,148],
[252,124,220,92,244,116,212,84]]
},
API usage example: weather station on router MikroTik






