GIF Error codes
This commit is contained in:
parent
ed69692f08
commit
2f9c126d34
@ -106,12 +106,14 @@ void sendHuePoll();
|
|||||||
void onHueData(void* arg, AsyncClient* client, void *data, size_t len);
|
void onHueData(void* arg, AsyncClient* client, void *data, size_t len);
|
||||||
|
|
||||||
//image_loader.cpp
|
//image_loader.cpp
|
||||||
|
#ifndef WLED_DISABLE_GIF
|
||||||
bool fileSeekCallback(unsigned long position);
|
bool fileSeekCallback(unsigned long position);
|
||||||
unsigned long filePositionCallback(void);
|
unsigned long filePositionCallback(void);
|
||||||
int fileReadCallback(void);
|
int fileReadCallback(void);
|
||||||
int fileReadBlockCallback(void * buffer, int numberOfBytes);
|
int fileReadBlockCallback(void * buffer, int numberOfBytes);
|
||||||
int fileSizeCallback(void);
|
int fileSizeCallback(void);
|
||||||
bool renderImageToSegment(Segment &seg);
|
byte renderImageToSegment(Segment &seg);
|
||||||
|
#endif
|
||||||
|
|
||||||
//improv.cpp
|
//improv.cpp
|
||||||
enum ImprovRPCType {
|
enum ImprovRPCType {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#ifndef WLED_DISABLE_GIF
|
||||||
|
|
||||||
#include "GifDecoder.h"
|
#include "GifDecoder.h"
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
|
|
||||||
@ -56,26 +58,34 @@ void drawPixelCallback(int16_t x, int16_t y, uint8_t red, uint8_t green, uint8_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define IMAGE_ERROR_NONE 0
|
||||||
|
#define IMAGE_ERROR_NO_NAME 1
|
||||||
|
#define IMAGE_ERROR_SEG_LIMIT 2
|
||||||
|
#define IMAGE_ERROR_UNSUPPORTED_FORMAT 3
|
||||||
|
#define IMAGE_ERROR_FILE_MISSING 4
|
||||||
|
#define IMAGE_ERROR_DECODER_ALLOC 5
|
||||||
|
#define IMAGE_ERROR_GIF_DECODE 6
|
||||||
|
#define IMAGE_ERROR_FRAME_DECODE 7
|
||||||
|
#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
|
||||||
bool renderImageToSegment(Segment &seg) {
|
byte renderImageToSegment(Segment &seg) {
|
||||||
if (!seg.name) return false;
|
if (!seg.name) return IMAGE_ERROR_NO_NAME;
|
||||||
|
if (activeSeg && activeSeg != &seg) return IMAGE_ERROR_SEG_LIMIT; // only one segment at a time
|
||||||
activeSeg = &seg;
|
activeSeg = &seg;
|
||||||
|
|
||||||
if (strncmp(lastFilename +1, seg.name, 32) != 0) {
|
if (strncmp(lastFilename +1, seg.name, 32) != 0) { // segment name changed, load new image
|
||||||
//Serial.println("segname changed");
|
|
||||||
strncpy(lastFilename +1, seg.name, 32);
|
strncpy(lastFilename +1, seg.name, 32);
|
||||||
gifDecodeFailed = false;
|
gifDecodeFailed = false;
|
||||||
if (strcmp(lastFilename + strlen(lastFilename) - 4, ".gif") != 0) {
|
if (strcmp(lastFilename + strlen(lastFilename) - 4, ".gif") != 0) {
|
||||||
//DEBUG_PRINTLN(F("Image file not found or not a .gif"));
|
|
||||||
gifDecodeFailed = true;
|
gifDecodeFailed = true;
|
||||||
return false;
|
return IMAGE_ERROR_UNSUPPORTED_FORMAT;
|
||||||
}
|
}
|
||||||
if (file) file.close();
|
if (file) file.close();
|
||||||
//Serial.print("opening gif: ");
|
|
||||||
//Serial.println(openGif(lastFilename));
|
|
||||||
openGif(lastFilename);
|
openGif(lastFilename);
|
||||||
if (!file) { gifDecodeFailed = true; return false; }
|
if (!file) { gifDecodeFailed = true; return IMAGE_ERROR_FILE_MISSING; }
|
||||||
if (!decoder) decoder = new GifDecoder<320,320,12,true>();
|
if (!decoder) decoder = new GifDecoder<320,320,12,true>();
|
||||||
|
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);
|
||||||
@ -85,12 +95,13 @@ bool renderImageToSegment(Segment &seg) {
|
|||||||
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 false; }
|
if(decoder->startDecoding() < 0) { gifDecodeFailed = true; return IMAGE_ERROR_GIF_DECODE; }
|
||||||
Serial.println("Decoding started");
|
Serial.println("Decoding started");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gifDecodeFailed) return false;
|
if (gifDecodeFailed) return IMAGE_ERROR_PREV;
|
||||||
if (!file || !decoder) { gifDecodeFailed = true; return false; }
|
if (!file) { gifDecodeFailed = true; return IMAGE_ERROR_FILE_MISSING; }
|
||||||
|
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
|
||||||
@ -101,19 +112,21 @@ bool renderImageToSegment(Segment &seg) {
|
|||||||
fillPixX = (seg.width()+(gifWidth-1)) / gifWidth;
|
fillPixX = (seg.width()+(gifWidth-1)) / gifWidth;
|
||||||
fillPixY = (seg.height()+(gifHeight-1)) / gifHeight;
|
fillPixY = (seg.height()+(gifHeight-1)) / gifHeight;
|
||||||
int result = decoder->decodeFrame(false);
|
int result = decoder->decodeFrame(false);
|
||||||
if (result < 0) { gifDecodeFailed = true; return false; }
|
if (result < 0) { gifDecodeFailed = true; return IMAGE_ERROR_FRAME_DECODE; }
|
||||||
long lastFrameDelay = currentFrameDelay;
|
long lastFrameDelay = currentFrameDelay;
|
||||||
currentFrameDelay = decoder->getFrameDelay_ms();
|
currentFrameDelay = decoder->getFrameDelay_ms();
|
||||||
long tooSlowBy = (millis() - lastFrameDisplayTime) - wait; // if last frame was longer than intended, compensate
|
long tooSlowBy = (millis() - lastFrameDisplayTime) - wait; // if last frame was longer than intended, compensate
|
||||||
currentFrameDelay -= tooSlowBy;
|
currentFrameDelay -= tooSlowBy;
|
||||||
//currentFrameDelay -= LASTFRAMEDELAY;
|
|
||||||
lastFrameDisplayTime = millis();
|
lastFrameDisplayTime = millis();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endPlayback() {
|
void endImagePlayback() {
|
||||||
if (file) file.close();
|
if (file) file.close();
|
||||||
delete decoder;
|
delete decoder;
|
||||||
gifDecodeFailed = false;
|
gifDecodeFailed = false;
|
||||||
}
|
activeSeg = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -78,6 +78,8 @@
|
|||||||
#ifndef WLED_DISABLE_ESPNOW
|
#ifndef WLED_DISABLE_ESPNOW
|
||||||
#include <espnow.h>
|
#include <espnow.h>
|
||||||
#endif
|
#endif
|
||||||
|
#undef WLED_DISABLE_GIF
|
||||||
|
#define WLED_DISABLE_GIF
|
||||||
#else // ESP32
|
#else // ESP32
|
||||||
#include <HardwareSerial.h> // ensure we have the correct "Serial" on new MCUs (depends on ARDUINO_USB_MODE and ARDUINO_USB_CDC_ON_BOOT)
|
#include <HardwareSerial.h> // ensure we have the correct "Serial" on new MCUs (depends on ARDUINO_USB_MODE and ARDUINO_USB_CDC_ON_BOOT)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user