WIP: Animations now use only three bytes per color instead of four.

This commit is contained in:
2019-05-24 23:51:50 +02:00
parent 959024ede8
commit d39e4975a1
2 changed files with 158 additions and 151 deletions

View File

@ -230,31 +230,37 @@ class Animation : public Effect {
Serial.printf("Animation.loop. Animation is %p.", (void *)animation);
CRGB colors[animation->color_count];
int led_index = 0;
for (int i = 0; i < animation->color_count; i++) colors[i] = CRGB(animation->colors[i]);
uint8_t *color_data = new uint8_t[animation->color_count * 3];
memcpy_P(color_data, animation->colors, animation->color_count * 3);
for (int i = 0; i < animation->color_count; i++) colors[i] = CRGB(color_data[i * 3], color_data[i * 3 + 1], color_data[i * 3 + 2]);
free(color_data);
// 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++) {
uint8_t color_index;
uint8_t count;
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[data[i + 2]]);
} else if (color==1) {
set(led_index, background_color);
}
led_index++;
}
color_index = data[i + 2];
count = data[i + 1];
i += 2;
} else {
uint8_t color = data[i];
if (color > 1) {
set(led_index, colors[data[i]]);
} else if (color == 1) {
set(led_index, background_color);
color_index = data[i];
count = 1;
}
if (color_index == 0) { // color #0 = skip this pixels
led_index += count;
} else {
CRGB* color;
if (color_index == 1) {
color = &background_color;
} else if (color_index >= 2) {
color = &colors[color_index - 2];
}
led_index++;
for (int j = 0; j < count; j++) set(led_index++, color);
}
}
free(data);