2020-09-24 10:43:08 +02:00
|
|
|
/*
|
|
|
|
Image.h
|
|
|
|
Inkplate 6 Arduino library
|
|
|
|
David Zovko, Borna Biro, Denis Vajak, Zvonimir Haramustek @ e-radionica.com
|
|
|
|
September 24, 2020
|
|
|
|
https://github.com/e-radionicacom/Inkplate-6-Arduino-library
|
|
|
|
|
|
|
|
For support, please reach over forums: forum.e-radionica.com/en
|
|
|
|
For more info about the product, please check: www.inkplate.io
|
|
|
|
|
|
|
|
This code is released under the GNU Lesser General Public License v3.0: https://www.gnu.org/licenses/lgpl-3.0.en.html
|
|
|
|
Please review the LICENSE file included with this example.
|
|
|
|
If you have any questions about licensing, please contact techsupport@e-radionica.com
|
|
|
|
Distributed as-is; no warranty is given.
|
|
|
|
*/
|
|
|
|
|
2020-09-07 11:40:01 +02:00
|
|
|
#ifndef __IMAGE_H__
|
|
|
|
#define __IMAGE_H__
|
|
|
|
|
2020-09-11 09:35:36 +02:00
|
|
|
#include "../libs/Adafruit-GFX-Library/Adafruit_GFX.h"
|
2020-09-07 11:40:01 +02:00
|
|
|
#include "../libs/SdFat/SdFat.h"
|
|
|
|
#include "Arduino.h"
|
2020-09-11 12:28:42 +02:00
|
|
|
#include "NetworkClient.h"
|
2020-09-07 11:40:01 +02:00
|
|
|
#include "WiFiClient.h"
|
|
|
|
#include "defines.h"
|
|
|
|
|
2020-09-11 12:28:42 +02:00
|
|
|
class Image : virtual public NetworkClient, virtual public Adafruit_GFX
|
2020-09-07 11:40:01 +02:00
|
|
|
{
|
2020-09-18 10:16:14 +02:00
|
|
|
public:
|
2020-09-11 09:35:36 +02:00
|
|
|
Image(int16_t w, int16_t h);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
|
|
|
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
|
|
|
|
|
|
|
|
virtual void selectDisplayMode(uint8_t _mode) = 0;
|
|
|
|
virtual uint8_t getDisplayMode() = 0;
|
|
|
|
virtual int16_t width() = 0;
|
|
|
|
virtual int16_t height() = 0;
|
|
|
|
|
|
|
|
bool drawImage(const char *path, int x, int y, bool dither = 1, bool invert = 0);
|
|
|
|
bool drawImage(const String path, int x, int y, bool dither = 1, bool invert = 0);
|
2020-09-10 15:22:56 +02:00
|
|
|
bool drawImage(const uint8_t *buf, int x, int y, int16_t w, int16_t h, uint8_t c = BLACK, uint8_t bg = 0xFF);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-11 09:35:36 +02:00
|
|
|
// Defined in Adafruit-GFX-Library, but should fit here
|
|
|
|
// void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
|
|
|
|
// void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color,
|
|
|
|
// uint16_t bg);
|
|
|
|
|
2020-09-07 11:40:01 +02:00
|
|
|
void drawBitmap3Bit(int16_t _x, int16_t _y, const unsigned char *_p, int16_t _w, int16_t _h);
|
|
|
|
|
2020-09-10 08:04:45 +02:00
|
|
|
bool drawBitmapFromBuffer(uint8_t *buf, int x, int y, bool dither, bool invert);
|
|
|
|
|
2020-09-18 10:16:14 +02:00
|
|
|
[[deprecated("Use drawImage, as this will soon become a private method.")]] bool drawBitmapFromSd(
|
|
|
|
const char *fileName, int x, int y, bool dither = 0, bool invert = 0);
|
2020-09-10 08:04:45 +02:00
|
|
|
bool drawBitmapFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-21 15:21:25 +02:00
|
|
|
bool drawBitmapFromWeb(const char *url, int x, int y, bool dither = 0, bool invert = 0);
|
2020-09-10 08:04:45 +02:00
|
|
|
bool drawBitmapFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0);
|
|
|
|
|
|
|
|
bool drawJpegFromBuffer(uint8_t *buf, int32_t len, int x, int y, bool dither, bool invert);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-18 10:16:14 +02:00
|
|
|
[[deprecated("Use drawImage, as this will soon become a private method.")]] bool drawJpegFromSd(
|
|
|
|
const char *fileName, int x, int y, bool dither = 0, bool invert = 0);
|
2020-09-10 08:04:45 +02:00
|
|
|
bool drawJpegFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-18 10:16:14 +02:00
|
|
|
[[deprecated("Use drawImage, as this will soon become a private method.")]] bool drawJpegFromWeb(const char *url,
|
|
|
|
int x, int y,
|
|
|
|
bool dither = 0,
|
|
|
|
bool invert = 0);
|
2020-09-10 08:04:45 +02:00
|
|
|
bool drawJpegFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-18 10:16:14 +02:00
|
|
|
[[deprecated("Use drawImage, as this will soon become a private method.")]] bool drawPngFromSd(const char *fileName,
|
|
|
|
int x, int y,
|
|
|
|
bool dither = 0,
|
|
|
|
bool invert = 0);
|
2020-09-14 15:44:57 +02:00
|
|
|
bool drawPngFromSd(SdFile *p, int x, int y, bool dither = 0, bool invert = 0);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-18 10:16:14 +02:00
|
|
|
[[deprecated("Use drawImage, as this will soon become a private method.")]] bool drawPngFromWeb(const char *url,
|
|
|
|
int x, int y,
|
|
|
|
bool dither = 0,
|
|
|
|
bool invert = 0);
|
2020-09-14 15:44:57 +02:00
|
|
|
bool drawPngFromWeb(WiFiClient *s, int x, int y, int32_t len, bool dither = 0, bool invert = 0);
|
|
|
|
|
2020-09-18 10:16:14 +02:00
|
|
|
// Should be private, but needed in a png callback :(
|
|
|
|
void ditherSwap(int w);
|
|
|
|
uint8_t ditherGetPixelBmp(uint8_t px, int i, int w, bool paletted);
|
|
|
|
|
|
|
|
private:
|
2020-09-07 11:40:01 +02:00
|
|
|
virtual void startWrite(void) = 0;
|
|
|
|
virtual void writePixel(int16_t x, int16_t y, uint16_t color) = 0;
|
|
|
|
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) = 0;
|
|
|
|
virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) = 0;
|
|
|
|
virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) = 0;
|
|
|
|
virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) = 0;
|
|
|
|
virtual void endWrite(void) = 0;
|
|
|
|
|
2020-09-10 08:04:45 +02:00
|
|
|
static bool drawJpegChunk(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap, bool dither, bool invert);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
|
|
|
uint8_t pixelBuffer[800 * 4 + 5];
|
2020-09-10 13:17:24 +02:00
|
|
|
uint8_t ditherBuffer[2][800 + 20];
|
|
|
|
uint8_t jpegDitherBuffer[18][18];
|
|
|
|
int16_t blockW = 0, blockH = 0;
|
|
|
|
int16_t lastY = -1;
|
|
|
|
|
2020-09-09 14:18:37 +02:00
|
|
|
uint8_t ditherPalette[256]; // 8 bit colors
|
|
|
|
uint8_t palette[128]; // 2 3 bit colors per byte, _###_###
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-09 10:27:49 +02:00
|
|
|
bool legalBmp(bitmapHeader *bmpHeader);
|
|
|
|
|
2020-09-10 13:17:24 +02:00
|
|
|
uint8_t ditherGetPixelJpeg(uint8_t px, int i, int j, int x, int y, int w, int h);
|
|
|
|
void ditherSwapBlockJpeg(int x);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
2020-09-07 15:34:51 +02:00
|
|
|
void readBmpHeader(uint8_t *buf, bitmapHeader *_h);
|
2020-09-07 11:40:01 +02:00
|
|
|
void readBmpHeaderSd(SdFile *_f, bitmapHeader *_h);
|
2020-09-07 15:34:51 +02:00
|
|
|
|
|
|
|
inline void displayBmpLine(int16_t x, int16_t y, bitmapHeader *bmpHeader, bool dither, bool invert);
|
2020-09-07 11:40:01 +02:00
|
|
|
|
|
|
|
// FUTURE COMPATIBILITY FUNCTIONS; DO NOT USE!
|
|
|
|
|
|
|
|
void drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color);
|
|
|
|
|
|
|
|
void drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h);
|
|
|
|
void drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap, uint8_t *mask, int16_t w, int16_t h);
|
|
|
|
|
|
|
|
void drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h);
|
|
|
|
void drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, uint8_t *mask, int16_t w, int16_t h);
|
|
|
|
// -------------------------------------------
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|