gif2c: Save animation data in PROGMEM to keep RAM free.
This commit is contained in:
parent
678d0dbe8a
commit
959024ede8
@ -44,7 +44,7 @@ typedef struct {
|
||||
|
||||
|
||||
uint32_t koopa_colors[] = {0x000000, 0x000000, 0xB69A11, 0x000000, 0x303030, 0x8E0406, 0xFEFCFF, 0x03018A, 0x11EF12};
|
||||
uint8_t koopa_data[] = {
|
||||
uint8_t koopa_data[] PROGMEM = {
|
||||
255,4,1,6,255,14,1,6,6,6,255,12,1,2,6,6,6,255,11,1,2,2,3,6,6,2,255,10,1,2,2,3,6,6,2,1,1,8,8,8,6,1,1,1,2,3,2,6,6,2,2,1,8,3,8,8,3,6,1,1,255,7,2,1,8,8,3,3,8,8,6,1,2,2,2,4,2,2,4,8,8,3,8,8,3,8,6,1,2,2,4,2,2,2,7,8,3,255,4,8,3,8,1,1,1,255,4,2,7,3,8,3,8,8,3,8,3,2,1,1,1,2,2,2,7,8,8,8,3,3,8,8,8,255,5,1,2,2,7,7,8,3,8,8,3,8,7,7,1,1,1,255,4,5,7,7,255,4,8,7,7,1,1,1,5,5,5,4,2,2,255,6,7,2,255,6,1,255,4,2,1,5,5,5,2,2,255,6,1,2,2,2,255,4,1,2,2,2,1,
|
||||
255,4,0,1,255,14,0,1,0,1,255,12,0,1,255,14,0,1,0,6,0,0,1,255,18,0,255,4,1,0,0,0,1,2,0,3,0,6,0,0,1,8,0,0,6,1,0,0,0,3,0,6,6,255,4,0,3,8,8,3,6,1,255,4,0,2,0,0,2,1,0,8,3,3,8,255,5,0,2,4,0,0,4,0,8,3,0,0,3,8,6,0,2,2,4,255,4,0,8,3,8,0,0,8,3,8,1,0,0,2,255,4,0,3,0,3,8,8,3,0,3,2,0,0,0,2,0,0,0,8,0,8,3,3,8,0,8,1,0,0,0,1,2,2,7,0,8,3,0,0,3,8,0,7,0,0,255,4,1,5,7,0,255,4,8,0,7,255,6,0,5,0,0,255,6,7,255,6,0,5,5,0,0,2,2,0,5,5,0,0,2,
|
||||
255,4,0,6,255,14,0,6,0,6,255,12,0,2,255,14,0,2,0,3,0,0,2,255,25,0,2,3,0,6,0,2,255,11,0,2,0,2,2,255,17,0,1,255,11,0,1,1,0,0,1,255,9,0,255,4,1,255,14,0,1,1,255,14,0,2,255,35,0,2,255,14,0,2,255,14,0,2,2,0,0,1,1,0,1,1,255,3,0,
|
||||
@ -58,7 +58,7 @@ AnimationData koopa = {&koopa_colors[0], &koopa_data[0], &koopa_offsets[0], &koo
|
||||
|
||||
|
||||
uint32_t couple_rain_colors[] = {0x000000, 0x000000, 0x000000, 0x028BDA, 0xB5ABFF, 0xFFFFFF, 0xFF4C0B, 0xDCCEB4, 0x313131, 0x1501AF, 0x641B00, 0x514225, 0x3319FD, 0x2E0C00, 0xDA0256, 0x25AFFD, 0x80683C};
|
||||
uint8_t couple_rain_data[] = {
|
||||
uint8_t couple_rain_data[] PROGMEM = {
|
||||
255,6,2,3,255,7,2,3,255,14,2,3,255,8,2,3,255,7,2,3,255,14,2,3,255,25,2,3,255,5,2,3,255,12,2,3,255,12,2,3,255,18,2,3,255,12,2,3,255,18,2,3,255,12,2,3,255,18,2,3,255,12,2,3,255,10,2,3,255,7,2,3,255,23,2,3,255,11,2,3,255,19,2,3,255,11,2,3,255,15,2,3,2,2,2,3,255,11,2,3,255,5,2,15,255,9,2,3,2,2,2,3,255,11,2,3,2,2,2,3,255,11,2,3,255,15,2,3,5,2,15,3,255,7,2,3,2,2,2,3,255,8,2,3,255,4,2,255,7,5,255,7,2,3,2,2,2,3,255,8,2,3,2,2,2,5,5,12,12,5,12,12,5,5,255,6,2,3,255,12,2,3,2,2,5,5,12,12,5,5,5,12,12,5,5,255,5,2,3,255,12,2,3,2,4,4,9,9,12,5,5,5,12,9,9,4,4,255,4,2,3,255,8,2,3,2,2,2,3,2,4,4,9,9,9,4,4,4,9,9,9,4,4,255,13,2,3,255,11,2,9,255,6,2,3,255,12,2,3,255,7,2,6,6,6,2,9,255,6,2,3,255,12,2,3,255,7,2,6,6,6,2,9,2,10,10,10,2,2,3,255,12,2,3,255,7,2,10,10,10,2,9,255,5,10,2,3,255,19,2,255,5,6,12,10,7,7,7,10,2,3,255,6,2,3,255,13,2,11,7,11,2,12,10,11,7,11,10,255,8,2,3,255,13,2,7,7,7,2,7,10,7,7,7,10,255,8,2,3,255,6,2,3,255,6,2,255,5,6,13,13,16,13,13,255,8,2,3,255,6,2,3,255,5,2,255,4,6,2,2,2,14,14,14,255,9,2,3,255,6,2,3,255,5,2,7,10,10,10,2,2,7,14,14,14,7,255,15,2,3,255,6,2,6,6,6,2,2,255,5,14,2,2,2,15,255,11,2,3,255,6,2,6,2,6,2,2,2,7,2,7,255,6,2,15,255,15,2,8,8,2,8,8,2,2,8,2,8,255,6,2,3,255,37,2,
|
||||
255,19,0,3,255,31,0,3,255,18,0,3,255,7,0,3,255,8,0,2,255,14,0,3,0,0,0,2,0,0,0,3,255,8,0,2,255,5,0,3,255,12,0,2,255,18,0,3,255,68,0,2,255,20,0,3,255,10,0,2,255,7,0,3,0,0,0,2,255,8,0,3,255,18,0,3,0,0,0,2,255,15,0,2,255,21,0,2,15,255,8,0,2,255,14,0,15,0,0,0,15,2,255,15,0,3,255,14,0,2,2,255,7,0,2,255,7,0,3,255,4,0,2,255,18,0,2,255,12,0,2,255,22,0,3,255,31,0,3,255,36,0,2,255,22,0,3,255,8,0,2,0,0,0,3,255,14,0,2,0,0,0,3,255,12,0,3,255,14,0,2,255,76,0,3,255,25,0,2,255,5,0,3,255,18,0,3,255,6,0,2,255,24,0,3,255,13,0,2,255,31,0,2,255,50,0,15,255,5,0,3,255,5,0,15,255,20,0,2,0,15,0,0,3,255,7,0,15,255,20,0,2,255,9,0,3,255,21,0,2,255,37,0,
|
||||
255,6,0,2,255,7,0,2,255,14,0,2,255,31,0,2,255,21,0,3,255,31,0,3,255,18,0,3,255,7,0,3,255,8,0,2,255,14,0,3,0,0,0,2,0,0,0,3,255,8,0,2,255,5,0,3,255,12,0,2,255,18,0,3,255,68,0,2,255,20,0,3,255,10,0,2,255,7,0,3,0,15,0,2,15,0,15,0,0,0,2,0,3,255,18,0,3,0,0,2,2,0,0,2,255,4,0,15,255,7,0,2,255,31,0,2,255,35,0,3,255,23,0,2,255,7,0,3,255,4,0,2,255,18,0,2,255,12,0,2,255,22,0,3,255,31,0,3,255,36,0,2,255,22,0,3,255,8,0,2,0,0,0,3,255,14,0,2,0,0,0,3,255,12,0,3,255,14,0,2,255,76,0,3,255,25,0,2,255,5,0,3,255,18,0,3,255,6,0,2,255,24,0,3,255,11,0,15,0,2,255,18,0,2,0,0,15,255,8,0,2,2,0,15,255,19,0,2,255,10,0,2,255,23,0,3,255,31,0,3,255,34,0,
|
||||
@ -98,7 +98,7 @@ AnimationData couple_rain = {&couple_rain_colors[0], &couple_rain_data[0], &coup
|
||||
|
||||
|
||||
uint32_t couple_snow_colors[] = {0x000000, 0x000000, 0x000000, 0xFFFFFF, 0xFF3C00, 0xF8E6C4, 0x432F09, 0x22B20A, 0x008EF6, 0xF60049, 0x5C0000, 0x1B00FF};
|
||||
uint8_t couple_snow_data[] = {
|
||||
uint8_t couple_snow_data[] PROGMEM = {
|
||||
2,3,255,39,2,3,255,14,2,3,255,11,2,3,255,10,2,3,255,45,2,3,255,24,2,3,255,47,2,3,255,6,2,3,255,36,2,3,255,10,2,3,255,4,2,3,255,21,2,3,255,16,2,3,255,84,2,3,255,20,2,3,255,18,2,3,255,7,2,3,255,40,2,3,255,42,2,3,255,25,2,3,255,12,2,3,255,9,2,3,255,27,2,3,255,8,2,3,255,6,2,3,2,2,2,3,255,9,2,5,2,2,2,5,255,25,2,4,4,4,2,2,2,9,9,9,255,22,2,255,5,4,2,255,5,9,255,4,2,3,255,16,2,255,5,4,2,9,10,10,5,9,255,16,2,3,255,4,2,4,6,5,6,4,2,9,6,5,6,9,255,12,2,3,255,9,2,5,5,5,2,2,10,5,5,5,10,255,7,2,3,255,14,2,7,7,7,2,2,2,11,11,11,255,22,2,4,4,7,4,4,2,9,9,11,9,255,4,2,3,255,17,2,4,4,7,4,4,9,9,9,11,9,9,255,8,2,3,2,2,2,3,255,8,2,5,8,8,8,2,5,2,9,9,9,5,255,18,2,3,2,2,2,8,2,8,2,2,2,8,2,8,255,22,2,6,6,2,6,6,2,2,6,2,6,255,12,2,255,32,3,
|
||||
0,2,255,13,0,3,255,10,0,3,255,6,0,3,255,7,0,2,255,14,0,2,255,11,0,2,255,4,0,3,255,5,0,2,255,8,0,3,255,11,0,3,255,10,0,3,255,13,0,2,255,24,0,2,255,6,0,3,255,24,0,3,255,15,0,2,255,6,0,2,255,24,0,3,255,6,0,3,255,4,0,2,255,10,0,2,255,4,0,2,255,15,0,3,255,5,0,2,255,4,0,3,255,4,0,3,255,6,0,2,255,14,0,3,255,16,0,3,255,52,0,2,255,20,0,2,255,10,0,3,255,7,0,2,255,7,0,2,255,4,0,3,255,18,0,3,255,7,0,3,255,8,0,2,255,31,0,3,255,10,0,2,255,25,0,2,255,5,0,3,255,6,0,2,255,9,0,2,255,8,0,3,255,12,0,3,255,5,0,2,0,0,0,3,255,4,0,2,255,6,0,2,0,0,0,2,255,11,0,3,255,8,0,3,255,6,0,3,0,0,0,3,255,53,0,2,255,31,0,3,255,11,0,2,255,27,0,2,0,0,0,3,255,22,0,2,255,4,0,3,255,26,0,3,255,27,0,2,255,31,0,3,255,4,0,2,0,0,0,2,255,27,0,3,0,0,0,3,255,5,0,2,255,31,0,3,255,56,0,
|
||||
255,15,0,2,255,4,0,3,255,5,0,2,255,6,0,2,255,13,0,3,255,10,0,3,255,6,0,3,255,7,0,2,255,14,0,2,255,11,0,2,255,4,0,3,255,5,0,2,255,8,0,3,255,11,0,3,255,10,0,3,255,13,0,2,255,24,0,2,255,6,0,3,255,24,0,3,255,15,0,2,255,6,0,2,255,24,0,3,255,6,0,3,255,4,0,2,255,10,0,2,255,4,0,2,255,15,0,3,255,5,0,2,255,4,0,3,255,4,0,3,255,6,0,2,255,14,0,3,255,16,0,3,255,52,0,2,255,20,0,2,255,10,0,3,255,7,0,2,255,7,0,2,255,4,0,3,255,18,0,3,255,7,0,3,255,8,0,2,255,31,0,3,255,10,0,2,255,25,0,2,255,5,0,3,255,6,0,2,255,9,0,2,255,8,0,3,255,12,0,3,255,5,0,2,0,0,0,3,255,4,0,2,255,6,0,2,0,0,0,2,255,20,0,3,255,6,0,3,0,0,0,3,255,53,0,2,255,31,0,3,255,11,0,2,255,27,0,2,0,0,0,3,255,22,0,2,255,4,0,3,255,26,0,3,255,27,0,2,255,31,0,3,255,4,0,2,0,0,0,2,255,27,0,3,0,0,0,3,255,5,0,2,255,56,0,
|
||||
@ -138,7 +138,7 @@ AnimationData couple_snow = {&couple_snow_colors[0], &couple_snow_data[0], &coup
|
||||
|
||||
|
||||
uint32_t heart_colors[] = {0x000000, 0x000000, 0x000000, 0xAB2121, 0xFF1E00, 0xFF6A07};
|
||||
uint8_t heart_data[] = {
|
||||
uint8_t heart_data[] PROGMEM = {
|
||||
255,167,2,3,255,5,4,3,255,4,2,3,255,5,4,3,255,13,2,255,9,4,2,2,255,9,4,255,11,2,4,4,4,5,5,255,17,4,255,9,2,3,4,4,255,4,5,255,16,4,3,255,8,2,4,4,4,255,4,5,255,17,4,255,7,2,3,4,4,4,255,4,5,255,17,4,3,255,6,2,3,255,4,4,5,5,255,18,4,3,255,6,2,3,255,24,4,3,255,6,2,3,255,24,4,3,255,7,2,255,24,4,255,8,2,3,255,22,4,3,255,9,2,3,255,20,4,3,255,11,2,255,20,4,255,13,2,255,18,4,255,15,2,255,16,4,255,17,2,255,14,4,255,19,2,255,12,4,255,21,2,255,10,4,255,23,2,255,8,4,255,25,2,255,6,4,255,27,2,255,4,4,255,29,2,4,4,255,175,2,
|
||||
255,136,0,255,5,3,255,6,0,255,5,3,255,15,0,4,255,5,0,4,255,4,0,4,255,5,0,4,255,75,0,4,255,22,0,4,255,39,0,4,255,24,0,4,255,6,0,4,255,24,0,4,255,6,0,4,255,24,0,4,255,6,0,4,255,24,0,4,255,62,0,4,255,30,0,4,255,10,0,3,255,32,0,3,255,18,0,3,255,13,0,3,255,16,0,3,255,15,0,3,255,14,0,3,255,17,0,3,255,12,0,3,255,19,0,3,255,10,0,3,255,21,0,3,255,8,0,3,255,23,0,3,255,6,0,3,255,25,0,3,255,4,0,3,255,27,0,3,0,0,3,255,174,0,
|
||||
255,103,0,255,6,3,255,6,0,255,6,3,255,13,0,255,7,4,3,255,4,0,3,255,6,4,3,255,11,0,4,4,255,7,0,3,0,0,3,255,7,0,4,3,255,9,0,4,4,255,9,0,4,4,255,9,0,4,3,255,8,0,4,0,0,5,0,4,255,17,0,4,255,7,0,3,0,0,5,0,0,0,4,255,17,0,3,255,6,0,4,0,0,5,0,0,0,4,255,17,0,4,255,9,0,5,0,0,0,4,255,28,0,5,0,4,255,89,0,4,255,24,0,4,255,6,0,3,4,255,23,0,3,255,7,0,4,4,255,21,0,4,255,9,0,4,255,20,0,4,255,10,0,4,4,255,18,0,4,4,255,11,0,4,4,255,16,0,4,4,255,12,0,4,4,4,255,14,0,4,4,4,255,13,0,4,4,4,255,12,0,4,4,4,255,15,0,4,4,4,255,10,0,4,4,4,255,17,0,4,4,4,255,8,0,4,4,4,255,19,0,4,4,4,255,6,0,4,4,4,255,21,0,4,4,4,255,4,0,4,4,4,255,23,0,4,4,4,0,0,4,4,4,255,25,0,3,255,4,4,3,255,141,0,
|
||||
|
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();
|
||||
|
@ -143,7 +143,7 @@ end
|
||||
|
||||
data = frames_data.map{|d| compress(d, true)}
|
||||
|
||||
puts "uint8_t #{name}_data[] = {\n #{data.map{|d| d.join(",")}.join(",\n ")}\n};"
|
||||
puts "uint8_t #{name}_data[] PROGMEM = {\n #{data.map{|d| d.join(",")}.join(",\n ")}\n};"
|
||||
puts "uint16_t #{name}_delays[] = {#{times.join(",")}};"
|
||||
s=0
|
||||
puts "uint16_t #{name}_offsets[] = {#{(data.map{|d| t=s; s+=d.count; t} + [s]).join(",")}};"
|
||||
|
Loading…
Reference in New Issue
Block a user