Dither kernels
What this example shows
Draw the same picture from the microSD card once with each of the seven dithering kernels the library offers, so you can compare them. A kernel controls how the error from reducing the picture to the panel's six colors is spread to neighboring pixels; the kernels trade off sharpness, noise and speed. The screen shows the kernel's name above the picture and refreshes once per kernel, five seconds apart.
You need a FAT or FAT32 formatted microSD card with a file named picture1.jpg on it, inserted in Inkplate.
Example code
#include "Inkplate.h"
Inkplate display;
SdFile file;
ImageColor::DitherKernel kernels[] = {
ImageColor::FloydSteinberg, ImageColor::JarvisJudiceNinke, ImageColor::Atkinson, ImageColor::Burkes,
ImageColor::Stucki, ImageColor::SierraLite, ImageColor::ReducedDiffusion,
};
const char *kernelNames[] = {
"Floyd-Steinberg", "Jarvis-Judice-Ninke", "Atkinson", "Burkes", "Stucki", "Sierra Lite", "Reduced Diffusion",
};
const uint8_t kernelCount = sizeof(kernels) / sizeof(kernels[0]);
void setup()
{
display.begin();
if (!display.sdCardInit())
{
display.println("SD card error!");
display.display();
return;
}
for (uint8_t i = 0; i < kernelCount; i++)
{
display.clearDisplay();
display.setCursor(0, 0);
display.setTextColor(BLACK);
display.setTextSize(2);
display.print("Kernel: ");
display.println(kernelNames[i]);
// Select the kernel used for all subsequent dithered draws
display.image.setDitherKernel(kernels[i]);
if (!display.image.draw("picture1.jpg", 0, 30, true))
{
display.println("Image open error");
}
display.display();
delay(5000);
}
display.sdCardSleep();
}
void loop()
{
// Nothing...
}
Functions used
Inkplate()returns NoneCreates the Inkplate object. Inkplate 7SPECTRA has a single six-color mode, so the constructor takes no mode argument.
ReturnsConstructor; no return value.
display.begin()returns voidInitializes the library, the peripherals and the frame buffer. Call it once in setup().
ReturnsNothing.
SdFile()returns NoneSdFat class, bundled with the Inkplate library: a file object on the microSD card. The sketch creates one as `file` and does not use it further.
ReturnsConstructor; no return value.
display.sdCardInit()returns int16_tSwitches on the microSD card's supply, starts its SPI bus and mounts the card.
Returns1 if the card was initialized, 0 if it failed.
display.image.setDitherKernel(const DitherKernel kernel)returns voidSelects the error-diffusion kernel used by dithered draws made afterwards. The kernels are ImageColor::FloydSteinberg (the default), ImageColor::JarvisJudiceNinke, ImageColor::Atkinson, ImageColor::Burkes, ImageColor::Stucki, ImageColor::SierraLite and ImageColor::ReducedDiffusion.
ReturnsNothing.
display.image.draw(const char *path, int x, int y, bool dither = 1, bool invert = 0)returns boolOpens an image file on the microSD card by name and draws it into the frame buffer with its top-left corner at (x, y). The sketch draws picture1.jpg at (0, 30) with dithering on.
Returnstrue if the image was drawn, false if the file could not be opened or decoded.
display.clearDisplay()returns voidFills the frame buffer with white. It does not change the panel.
ReturnsNothing.
display.setCursor(int16_t x, int16_t y)returns voidSets where the next printed text starts.
ReturnsNothing.
display.setTextColor(uint16_t c)returns voidSets the text color, here BLACK.
ReturnsNothing.
display.setTextSize(uint8_t s)returns voidSets the text magnification, here 2.
ReturnsNothing.
display.print(value)returns size_tPrints text into the frame buffer, like Serial.print().
ReturnsNumber of bytes printed.
display.println(text)returns size_tPrints text into the frame buffer and moves to the next line.
ReturnsNumber of bytes printed.
display.display(bool _leaveOn = 0)returns voidSends the whole frame buffer to the panel and refreshes it.
ReturnsNothing.
delay(ms)returns voidArduino core function: waits for the given number of milliseconds, here 5000.
ReturnsNothing.
display.sdCardSleep()returns voidSets the card's SPI pins to inputs and switches off the card's supply, to save power in deep sleep.
ReturnsNothing.
What to expect
The screen shows Kernel: Floyd-Steinberg above picture1.jpg. Every five seconds it refreshes with the next kernel's name and the same picture, in this order: Floyd-Steinberg, Jarvis-Judice-Ninke, Atkinson, Burkes, Stucki, Sierra Lite, Reduced Diffusion. After the last one the card is switched off and the last picture stays on the screen.
If the card cannot be started, the screen shows SD card error!; if the picture cannot be opened, Image open error appears under the kernel name. The sketch prints nothing to the Serial Monitor.
🔗Open the complete example
examples/Inkplate7SPECTRA/Advanced/Other/Inkplate7SPECTRA_Dither_Kernels