mirror of
https://github.com/wled/WLED.git
synced 2025-07-12 13:26:33 +00:00
GIF testing
This commit is contained in:
parent
1f25edc737
commit
3ad56ea103
@ -5,7 +5,6 @@
|
|||||||
* All globally accessible functions are declared here
|
* All globally accessible functions are declared here
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FX.h"
|
|
||||||
|
|
||||||
//alexa.cpp
|
//alexa.cpp
|
||||||
#ifndef WLED_DISABLE_ALEXA
|
#ifndef WLED_DISABLE_ALEXA
|
||||||
@ -127,6 +126,8 @@ void onHueConnect(void* arg, AsyncClient* client);
|
|||||||
void sendHuePoll();
|
void sendHuePoll();
|
||||||
void onHueData(void* arg, AsyncClient* client, void *data, size_t len);
|
void onHueData(void* arg, AsyncClient* client, void *data, size_t len);
|
||||||
|
|
||||||
|
#include "FX.h" // must be below colors.cpp declarations (potentially due to duplicate declarations of e.g. color_blend)
|
||||||
|
|
||||||
//image_loader.cpp
|
//image_loader.cpp
|
||||||
#ifndef WLED_DISABLE_GIF
|
#ifndef WLED_DISABLE_GIF
|
||||||
bool fileSeekCallback(unsigned long position);
|
bool fileSeekCallback(unsigned long position);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
File file;
|
File file;
|
||||||
char lastFilename[34] = "/";
|
char lastFilename[34] = "/";
|
||||||
GifDecoder<320,320,12,true>* decoder;
|
GifDecoder<32,32,12> decoder;
|
||||||
bool gifDecodeFailed = false;
|
bool gifDecodeFailed = false;
|
||||||
long lastFrameDisplayTime = 0, currentFrameDelay = 0;
|
long lastFrameDisplayTime = 0, currentFrameDelay = 0;
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ bool openGif(const char *filename) {
|
|||||||
|
|
||||||
Segment* activeSeg;
|
Segment* activeSeg;
|
||||||
uint16_t gifWidth, gifHeight;
|
uint16_t gifWidth, gifHeight;
|
||||||
uint16_t fillPixX, fillPixY;
|
//uint16_t fillPixX, fillPixY;
|
||||||
|
|
||||||
void screenClearCallback(void) {
|
void screenClearCallback(void) {
|
||||||
activeSeg->fill(0);
|
activeSeg->fill(0);
|
||||||
@ -66,6 +66,7 @@ void drawPixelCallback(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t
|
|||||||
#define IMAGE_ERROR_DECODER_ALLOC 5
|
#define IMAGE_ERROR_DECODER_ALLOC 5
|
||||||
#define IMAGE_ERROR_GIF_DECODE 6
|
#define IMAGE_ERROR_GIF_DECODE 6
|
||||||
#define IMAGE_ERROR_FRAME_DECODE 7
|
#define IMAGE_ERROR_FRAME_DECODE 7
|
||||||
|
#define IMAGE_ERROR_WAITING 254
|
||||||
#define IMAGE_ERROR_PREV 255
|
#define IMAGE_ERROR_PREV 255
|
||||||
|
|
||||||
// renders an image (.gif only; .bmp and .fseq to be added soon) from FS to a segment
|
// renders an image (.gif only; .bmp and .fseq to be added soon) from FS to a segment
|
||||||
@ -84,47 +85,48 @@ byte renderImageToSegment(Segment &seg) {
|
|||||||
if (file) file.close();
|
if (file) file.close();
|
||||||
openGif(lastFilename);
|
openGif(lastFilename);
|
||||||
if (!file) { gifDecodeFailed = true; return IMAGE_ERROR_FILE_MISSING; }
|
if (!file) { gifDecodeFailed = true; return IMAGE_ERROR_FILE_MISSING; }
|
||||||
if (!decoder) decoder = new GifDecoder<320,320,12,true>();
|
//if (!decoder) decoder = new GifDecoder<32,32,12>();
|
||||||
if (!decoder) { gifDecodeFailed = true; return IMAGE_ERROR_DECODER_ALLOC; }
|
//if (!decoder) { gifDecodeFailed = true; return IMAGE_ERROR_DECODER_ALLOC; }
|
||||||
decoder->setScreenClearCallback(screenClearCallback);
|
decoder.setScreenClearCallback(screenClearCallback);
|
||||||
decoder->setUpdateScreenCallback(updateScreenCallback);
|
decoder.setUpdateScreenCallback(updateScreenCallback);
|
||||||
decoder->setDrawPixelCallback(drawPixelCallback);
|
decoder.setDrawPixelCallback(drawPixelCallback);
|
||||||
decoder->setFileSeekCallback(fileSeekCallback);
|
decoder.setFileSeekCallback(fileSeekCallback);
|
||||||
decoder->setFilePositionCallback(filePositionCallback);
|
decoder.setFilePositionCallback(filePositionCallback);
|
||||||
decoder->setFileReadCallback(fileReadCallback);
|
decoder.setFileReadCallback(fileReadCallback);
|
||||||
decoder->setFileReadBlockCallback(fileReadBlockCallback);
|
decoder.setFileReadBlockCallback(fileReadBlockCallback);
|
||||||
decoder->setFileSizeCallback(fileSizeCallback);
|
decoder.setFileSizeCallback(fileSizeCallback);
|
||||||
Serial.println("Starting decoding");
|
Serial.println("Starting decoding");
|
||||||
if(decoder->startDecoding() < 0) { gifDecodeFailed = true; return IMAGE_ERROR_GIF_DECODE; }
|
if(decoder.startDecoding() < 0) { gifDecodeFailed = true; return IMAGE_ERROR_GIF_DECODE; }
|
||||||
Serial.println("Decoding started");
|
Serial.println("Decoding started");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gifDecodeFailed) return IMAGE_ERROR_PREV;
|
if (gifDecodeFailed) return IMAGE_ERROR_PREV;
|
||||||
if (!file) { gifDecodeFailed = true; return IMAGE_ERROR_FILE_MISSING; }
|
if (!file) { gifDecodeFailed = true; return IMAGE_ERROR_FILE_MISSING; }
|
||||||
if (!decoder) { gifDecodeFailed = true; return IMAGE_ERROR_DECODER_ALLOC; }
|
//if (!decoder) { gifDecodeFailed = true; return IMAGE_ERROR_DECODER_ALLOC; }
|
||||||
|
|
||||||
// speed 0 = half speed, 128 = normal, 255 = full FX FPS
|
// speed 0 = half speed, 128 = normal, 255 = full FX FPS
|
||||||
// TODO: 0 = 4x slow, 64 = 2x slow, 128 = normal, 192 = 2x fast, 255 = 4x fast
|
// TODO: 0 = 4x slow, 64 = 2x slow, 128 = normal, 192 = 2x fast, 255 = 4x fast
|
||||||
uint32_t wait = currentFrameDelay * 2 - seg.speed * currentFrameDelay / 128;
|
uint32_t wait = currentFrameDelay * 2 - seg.speed * currentFrameDelay / 128;
|
||||||
|
|
||||||
if((millis() - lastFrameDisplayTime) >= wait) {
|
if((millis() - lastFrameDisplayTime) < wait) return IMAGE_ERROR_WAITING;
|
||||||
decoder->getSize(&gifWidth, &gifHeight);
|
|
||||||
fillPixX = (seg.width()+(gifWidth-1)) / gifWidth;
|
decoder.getSize(&gifWidth, &gifHeight);
|
||||||
fillPixY = (seg.height()+(gifHeight-1)) / gifHeight;
|
//fillPixX = (seg.width()+(gifWidth-1)) / gifWidth;
|
||||||
int result = decoder->decodeFrame(false);
|
//fillPixY = (seg.height()+(gifHeight-1)) / gifHeight;
|
||||||
if (result < 0) { gifDecodeFailed = true; return IMAGE_ERROR_FRAME_DECODE; }
|
int result = decoder.decodeFrame(false);
|
||||||
long lastFrameDelay = currentFrameDelay;
|
if (result < 0) { gifDecodeFailed = true; return IMAGE_ERROR_FRAME_DECODE; }
|
||||||
currentFrameDelay = decoder->getFrameDelay_ms();
|
//long lastFrameDelay = currentFrameDelay;
|
||||||
long tooSlowBy = (millis() - lastFrameDisplayTime) - wait; // if last frame was longer than intended, compensate
|
currentFrameDelay = decoder.getFrameDelay_ms();
|
||||||
currentFrameDelay -= tooSlowBy;
|
//long tooSlowBy = (millis() - lastFrameDisplayTime) - wait; // if last frame was longer than intended, compensate
|
||||||
lastFrameDisplayTime = millis();
|
//currentFrameDelay -= tooSlowBy; // TODO this is broken
|
||||||
}
|
lastFrameDisplayTime = millis();
|
||||||
return true;
|
|
||||||
|
return IMAGE_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endImagePlayback() {
|
void endImagePlayback() {
|
||||||
if (file) file.close();
|
if (file) file.close();
|
||||||
delete decoder;
|
//delete decoder;
|
||||||
gifDecodeFailed = false;
|
gifDecodeFailed = false;
|
||||||
activeSeg = nullptr;
|
activeSeg = nullptr;
|
||||||
lastFilename[0] = '\0';
|
lastFilename[0] = '\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user