add pp gif
This commit is contained in:
parent
55d26d4949
commit
6a313c1cc9
@ -20,3 +20,4 @@ lib_deps =
|
||||
Wire
|
||||
fastled/FastLED
|
||||
https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-I2S-DMA.git
|
||||
bitbank2/AnimatedGIF
|
||||
|
||||
@ -2,15 +2,19 @@
|
||||
#include "xtensa/core-macros.h"
|
||||
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
|
||||
|
||||
#include <AnimatedGIF.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "constants.h"
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
#include "pp.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
MatrixPanel_I2S_DMA *matrix = nullptr;
|
||||
AnimatedGIF gif;
|
||||
|
||||
void setup(){
|
||||
Serial.begin(BAUD_RATE);
|
||||
@ -34,8 +38,10 @@ void setup(){
|
||||
|
||||
matrix = new MatrixPanel_I2S_DMA(mxconfig);
|
||||
matrix->begin();
|
||||
matrix->setBrightness8(64);
|
||||
matrix->setBrightness8(255);
|
||||
matrix->fillScreenRGB888(0, 0, 0);
|
||||
|
||||
gif.begin(LITTLE_ENDIAN_PIXELS);
|
||||
}
|
||||
|
||||
void draw_title(const std::string& title, uint16_t color) {
|
||||
@ -98,6 +104,88 @@ void draw_location(const std::string &location) {
|
||||
matrix->print(location.c_str());
|
||||
}
|
||||
|
||||
void GIFDraw(GIFDRAW *pDraw) {
|
||||
uint8_t *s;
|
||||
uint16_t *d, *usPalette, usTemp[320];
|
||||
int x, y, iWidth;
|
||||
|
||||
usPalette = pDraw->pPalette;
|
||||
y = pDraw->iY + pDraw->y; // current line
|
||||
|
||||
s = pDraw->pPixels;
|
||||
if (pDraw->ucDisposalMethod == 2) // restore to background color
|
||||
{
|
||||
for (x = 0; x < iWidth; x++)
|
||||
{
|
||||
if (s[x] == pDraw->ucTransparent)
|
||||
s[x] = pDraw->ucBackground;
|
||||
}
|
||||
pDraw->ucHasTransparency = 0;
|
||||
}
|
||||
// Apply the new pixels to the main image
|
||||
if (pDraw->ucHasTransparency) // if transparency used
|
||||
{
|
||||
Serial.println("Transparency!");
|
||||
uint8_t *pEnd, c, ucTransparent = pDraw->ucTransparent;
|
||||
int x, iCount;
|
||||
pEnd = s + pDraw->iWidth;
|
||||
//x = 0;
|
||||
x = pDraw->iX;
|
||||
iCount = 0; // count non-transparent pixels
|
||||
while (x < pDraw->iWidth)
|
||||
{
|
||||
c = ucTransparent - 1;
|
||||
d = usTemp;
|
||||
while (c != ucTransparent && s < pEnd)
|
||||
{
|
||||
c = *s++;
|
||||
if (c == ucTransparent) // done, stop
|
||||
{
|
||||
s--; // back up to treat it like transparent
|
||||
}
|
||||
else // opaque
|
||||
{
|
||||
*d++ = usPalette[c];
|
||||
iCount++;
|
||||
}
|
||||
} // while looking for opaque pixels
|
||||
if (iCount) // any opaque pixels?
|
||||
{
|
||||
for (int xOffset = 0; xOffset < iCount; xOffset++)
|
||||
{
|
||||
matrix->drawPixel(28 + x + xOffset, 25 + y, usTemp[xOffset]);
|
||||
}
|
||||
x += iCount;
|
||||
iCount = 0;
|
||||
}
|
||||
// no, look for a run of transparent pixels
|
||||
c = ucTransparent;
|
||||
while (c == ucTransparent && s < pEnd)
|
||||
{
|
||||
c = *s++;
|
||||
if (c == ucTransparent)
|
||||
iCount++;
|
||||
else
|
||||
s--;
|
||||
}
|
||||
if (iCount)
|
||||
{
|
||||
x += iCount; // skip these
|
||||
iCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s = pDraw->pPixels;
|
||||
// Translate the 8-bit pixels through the RGB565 palette (already byte reversed)
|
||||
for (x = 0; x < pDraw->iWidth; x++)
|
||||
{
|
||||
matrix->drawPixel(28 + x, 25 + y, usPalette[*s++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
std::string title = "THE ART OF TEXT RENDERING";
|
||||
std::string time = "11:00";
|
||||
@ -106,5 +194,10 @@ void loop() {
|
||||
draw_time(time);
|
||||
draw_location(loc);
|
||||
|
||||
delay(100);
|
||||
if (gif.open((uint8_t *)reallytinypp, sizeof(reallytinypp), GIFDraw)) {
|
||||
while (gif.playFrame(true, NULL)) {
|
||||
;
|
||||
}
|
||||
gif.close();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user