gif2c: Save animation data in PROGMEM to keep RAM free.
This commit is contained in:
19
effects.h
19
effects.h
@ -231,12 +231,16 @@ class Animation : public Effect {
|
||||
CRGB colors[animation->color_count];
|
||||
int led_index = 0;
|
||||
for (int i = 0; i < animation->color_count; i++) colors[i] = CRGB(animation->colors[i]);
|
||||
for (int i = animation->offsets[frame]; i < animation->offsets[frame + 1]; i++) {
|
||||
if (animation->data[i] == 255) { // Run-length encoded data
|
||||
uint8_t color = animation->data[i + 2];
|
||||
for (int j = 0; j < animation->data[i + 1]; j++) {
|
||||
// Data is stored in progmem, so get it from there.
|
||||
int length = animation->offsets[frame + 1] - animation->offsets[frame];
|
||||
uint8_t *data = new uint8_t[length];
|
||||
memcpy_P(data, animation->data + animation->offsets[frame], length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (data[i] == 255) { // Run-length encoded data
|
||||
uint8_t color = data[i + 2];
|
||||
for (int j = 0; j < data[i + 1]; j++) {
|
||||
if (color > 1) {
|
||||
set(led_index, colors[animation->data[i + 2]]);
|
||||
set(led_index, colors[data[i + 2]]);
|
||||
} else if (color==1) {
|
||||
set(led_index, background_color);
|
||||
}
|
||||
@ -244,15 +248,16 @@ class Animation : public Effect {
|
||||
}
|
||||
i += 2;
|
||||
} else {
|
||||
uint8_t color = animation->data[i];
|
||||
uint8_t color = data[i];
|
||||
if (color > 1) {
|
||||
set(led_index, colors[animation->data[i]]);
|
||||
set(led_index, colors[data[i]]);
|
||||
} else if (color == 1) {
|
||||
set(led_index, background_color);
|
||||
}
|
||||
led_index++;
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
if (frameSince == 0 || frameSince + frameDelay(animation, frame) < millis() || frameSince > millis()) {
|
||||
frame = (frame + 1) % animation->frame_count;
|
||||
frameSince = millis();
|
||||
|
Reference in New Issue
Block a user