|
12 | 12 |
|
13 | 13 | SUMMARY
|
14 | 14 |
|
15 |
| - cute_asesprite.h is a single-file header that implements some functions to |
| 15 | + cute_aseprite.h is a single-file header that implements some functions to |
16 | 16 | parse .ase/.aseprite files. The entire file is parsed all at once and some
|
17 | 17 | structs are filled out then handed back to you.
|
18 | 18 |
|
|
65 | 65 |
|
66 | 66 | for (int i = 0; i < ase->frame_count; ++i) {
|
67 | 67 | ase_frame_t* frame = ase->frames + i;
|
68 |
| - anim.add_frame(frame->duration, frame->pixels); |
| 68 | + anim.add_frame(frame->duration_milliseconds, frame->pixels); |
69 | 69 | }
|
70 | 70 |
|
71 | 71 |
|
@@ -123,7 +123,6 @@ typedef struct ase_udata_t ase_udata_t;
|
123 | 123 | typedef struct ase_cel_extra_chunk_t ase_cel_extra_chunk_t;
|
124 | 124 | typedef struct ase_color_profile_t ase_color_profile_t;
|
125 | 125 | typedef struct ase_fixed_t ase_fixed_t;
|
126 |
| -typedef struct ase_cel_extra_chunk_t ase_cel_extra_chunk_t; |
127 | 126 |
|
128 | 127 | struct ase_color_t
|
129 | 128 | {
|
@@ -838,10 +837,9 @@ static char* s_fopen(const char* path, int* size, void* mem_ctx)
|
838 | 837 | CUTE_ASEPRITE_FILE* fp = CUTE_ASEPRITE_FOPEN(path, "rb");
|
839 | 838 | int sz = 0;
|
840 | 839 |
|
841 |
| - if (fp) |
842 |
| - { |
| 840 | + if (fp) { |
843 | 841 | CUTE_ASEPRITE_FSEEK(fp, 0, CUTE_ASEPRITE_SEEK_END);
|
844 |
| - sz = CUTE_ASEPRITE_FTELL(fp); |
| 842 | + sz = (int)CUTE_ASEPRITE_FTELL(fp); |
845 | 843 | CUTE_ASEPRITE_FSEEK(fp, 0, CUTE_ASEPRITE_SEEK_SET);
|
846 | 844 | data = (char*)CUTE_ASEPRITE_ALLOC(sz + 1, mem_ctx);
|
847 | 845 | CUTE_ASEPRITE_FREAD(data, sz, 1, fp);
|
@@ -930,7 +928,7 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
|
930 | 928 | ase_t* ase = (ase_t*)CUTE_ASEPRITE_ALLOC(sizeof(ase_t), mem_ctx);
|
931 | 929 | CUTE_ASEPRITE_MEMSET(ase, 0, sizeof(*ase));
|
932 | 930 |
|
933 |
| - ase_state_t state = { 0 }; |
| 931 | + ase_state_t state = { 0, 0, 0 }; |
934 | 932 | ase_state_t* s = &state;
|
935 | 933 | s->in = (uint8_t*)memory;
|
936 | 934 | s->end = s->in + size;
|
@@ -996,22 +994,22 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
|
996 | 994 | switch (chunk_type) {
|
997 | 995 | case 0x0004: // Old Palette chunk (used when there are no colors with alpha in the palette)
|
998 | 996 | {
|
999 |
| - int nbPackets = (int)s_read_uint16(s); |
1000 |
| - for (int k = 0; k < nbPackets ; k++ ) { |
1001 |
| - uint16_t maxColor=0; |
1002 |
| - uint8_t skip = s_read_uint8(s); |
1003 |
| - uint16_t nbColors = s_read_uint8(s); |
| 997 | + uint16_t nbPackets = s_read_uint16(s); |
| 998 | + for (uint16_t k = 0; k < nbPackets; k++) { |
| 999 | + uint16_t maxColor = 0; |
| 1000 | + uint16_t skip = (uint16_t)s_read_uint8(s); |
| 1001 | + uint16_t nbColors = (uint16_t)s_read_uint8(s); |
1004 | 1002 | if (nbColors == 0) nbColors = 256;
|
1005 | 1003 |
|
1006 |
| - for (int l = 0; l < nbColors; l++) { |
| 1004 | + for (uint16_t l = 0; l < nbColors; l++) { |
1007 | 1005 | ase_palette_entry_t entry;
|
1008 | 1006 | entry.color.r = s_read_uint8(s);
|
1009 | 1007 | entry.color.g = s_read_uint8(s);
|
1010 | 1008 | entry.color.b = s_read_uint8(s);
|
1011 | 1009 | entry.color.a = 255;
|
1012 | 1010 | entry.color_name = NULL;
|
1013 |
| - ase->palette.entries[skip+l] = entry; |
1014 |
| - if (skip+l > maxColor) maxColor = skip+l; |
| 1011 | + ase->palette.entries[skip + l] = entry; |
| 1012 | + if (skip + l > maxColor) maxColor = skip + l; |
1015 | 1013 | }
|
1016 | 1014 |
|
1017 | 1015 | ase->palette.entry_count = maxColor+1;
|
@@ -1122,18 +1120,16 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
|
1122 | 1120 | s_skip(s, 8); // For future (set to zero).
|
1123 | 1121 | CUTE_ASEPRITE_ASSERT(ase->tag_count < CUTE_ASEPRITE_MAX_TAGS);
|
1124 | 1122 | for (int k = 0; k < ase->tag_count; ++k) {
|
1125 |
| - ase_tag_t tag; |
1126 |
| - tag.from_frame = (int)s_read_uint16(s); |
1127 |
| - tag.to_frame = (int)s_read_uint16(s); |
1128 |
| - tag.loop_animation_direction = (ase_animation_direction_t)s_read_uint8(s); |
1129 |
| - tag.repeat = s_read_uint16(s); |
| 1123 | + ase->tags[k].from_frame = (int)s_read_uint16(s); |
| 1124 | + ase->tags[k].to_frame = (int)s_read_uint16(s); |
| 1125 | + ase->tags[k].loop_animation_direction = (ase_animation_direction_t)s_read_uint8(s); |
| 1126 | + ase->tags[k].repeat = s_read_uint16(s); |
1130 | 1127 | s_skip(s, 6); // For future (set to zero).
|
1131 |
| - tag.r = s_read_uint8(s); |
1132 |
| - tag.g = s_read_uint8(s); |
1133 |
| - tag.b = s_read_uint8(s); |
| 1128 | + ase->tags[k].r = s_read_uint8(s); |
| 1129 | + ase->tags[k].g = s_read_uint8(s); |
| 1130 | + ase->tags[k].b = s_read_uint8(s); |
1134 | 1131 | s_skip(s, 1); // Extra byte (zero).
|
1135 |
| - tag.name = s_read_string(s); |
1136 |
| - ase->tags[k] = tag; |
| 1132 | + ase->tags[k].name = s_read_string(s); |
1137 | 1133 | }
|
1138 | 1134 | was_on_tags = 1;
|
1139 | 1135 | } break;
|
@@ -1190,7 +1186,8 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
|
1190 | 1186 | s_skip(s, sizeof(uint32_t)); // Reserved.
|
1191 | 1187 | const char* name = s_read_string(s);
|
1192 | 1188 | for (int k = 0; k < (int)slice_count; ++k) {
|
1193 |
| - ase_slice_t slice = { 0 }; |
| 1189 | + ase_slice_t slice; |
| 1190 | + CUTE_ASEPRITE_MEMSET(&slice, 0, sizeof(slice)); |
1194 | 1191 | slice.name = name;
|
1195 | 1192 | slice.frame_number = (int)s_read_uint32(s);
|
1196 | 1193 | slice.origin_x = (int)s_read_int32(s);
|
|
0 commit comments