Animation now uses .pia files from SPIFFS instead of hardcoded C stuff.

This commit is contained in:
2019-06-18 18:10:58 +02:00
parent 1912772da3
commit 3c0e7a116a
9 changed files with 234 additions and 286 deletions

View File

@ -38,24 +38,33 @@ it contains only one entry and .individual_delays will be false.
class Animation {
protected:
AnimationData* data;
unsigned long currentFrameSince;
uint8_t currentFrame = 0;
uint8_t* animation_data;
CRGB* colors;
CRGB** _colors;
CRGB* fgColor = NULL;
CRGB* bgColor = new CRGB(0x000000);
int8_t xOffset = 0;
int8_t yOffset = 0;
uint8_t startFrame = 0;
uint8_t endFrame = 0;
uint8_t _startFrame = 0;
uint8_t _endFrame = 0;
Window* _window;
uint8_t _width;
uint8_t _height;
uint8_t _frame_count;
uint8_t _color_count;
uint16_t* _frame_times;
uint16_t* _frame_data_lengths;
uint8_t** _frame_data;
bool _data_valid = false;
virtual CRGB* getColor(uint8_t color_index);
void drawFrame(Window* w, uint8_t frame_index);
void drawPixel(Window* w, int index, CRGB* color);
void drawPixel(int index, CRGB* color);
uint16_t getFrameDelay(int frame);
bool _load_from_file(const char* c);
public:
Animation(AnimationData* d);
Animation(const char* filename, Window* win);
void setFgColor(CRGB*);
void setBgColor(CRGB* bg_color);
bool invert();
@ -65,7 +74,8 @@ public:
void setFrameRange(uint8_t sf, uint8_t ef);
void setSingleFrame(uint8_t frame);
virtual ~Animation();
void draw(Window* w);
void drawFrame(Window* w);
void draw();
void drawFrame();
void drawFrame(uint8_t frame_index);
virtual bool advance();
};

View File

@ -1,42 +0,0 @@
/**
Animations are structured in AnimationData as follows:
.colors contains .color_count*3 uint8_t values for R, G and B.
.offsets contains the frame start offsets within .data + the length of the data. (So
you can always do something like `for (int i=anim.offsets[i]; i<anim.offsets[i+1]; i++)`.
Accordingly it has a length of .frame_count+1.
.data contains all frames data with a run-length compression with escape char 255.
This data references the index of one or multiple pixels in .colors. It starts at the
top left pixel and walks each row to the right before starting the next row.
To decode it: Start at a frame (indicated by .offsets). Get one byte as x.
If x is <255: This is a single pixel of color x.
if x is 255: Run-length-encoding. The next byte indicates of often the byte after that
will be repeated. So, {255, 4, 10} is equal to {10, 10, 10, 10}.
A special case that may happen in larger GIFs is that there are more than 255 repetitions
of a color. Those will be split, so 355*color #10 will be: {255, 255, 10, 255, 100, 10},
e.g. 255*10 + 100*10. Usually this shouldn't need special handling within a decoder.
Regarding colors in .data:
Color 0 means "keep the color from the previous frame". This color should never appear on frame #0.
Color 1 means "show the background color".
All other color values point to a color in .colors - with an offset of 2.
So if in .data there's a color 3, paint this pixel in .colors[1].
.individual_delays contains either 1 or .frame_count delays. They are given in ms and
indicate how long the matching frame should be displayed. If all times are equal, then
it contains only one entry and .individual_delays will be false.
.w and .h contain the dimensions of the image.
**/
#pragma once
#include <Arduino.h>
#include "prototypes.h"
extern AnimationData animation_koopa;
extern AnimationData animation_couple_rain;
extern AnimationData animation_couple_snow;
extern AnimationData animation_heart;
extern AnimationData animation_weather_icons;
extern AnimationData animation_cake;

View File

@ -8,15 +8,13 @@
class AnimationEffect : public Effect {
private:
Animation *animation;
AnimationData *animation_data;
CRGB *bg_color;
uint16_t xOffset;
uint16_t yOffset;
public:
AnimationEffect(AnimationData* anim) : AnimationEffect(anim, new CRGB(0x000000), 0, 0) {}
AnimationEffect(AnimationData* anim, CRGB* background_color) : AnimationEffect(anim, background_color, 0, 0) {}
AnimationEffect(AnimationData* anim, CRGB* bg_color, int x, int y);
void start();
void stop();
AnimationEffect(const char* name) : AnimationEffect(name, new CRGB(0x000000), 0, 0) {}
AnimationEffect(const char* name, CRGB* background_color) : AnimationEffect(name, background_color, 0, 0) {}
AnimationEffect(const char* name, CRGB* bg_color, int x, int y);
~AnimationEffect();
void loop();
};