@@ -344,9 +344,9 @@ struct ase_t
344
344
#define CUTE_ASEPRITE_ASSERT assert
345
345
#endif
346
346
347
- #if !defined(CUTE_ASEPRITE_FILEIO )
347
+ #if !defined(CUTE_ASEPRITE_STDIO )
348
348
#include <stdio.h> // fopen
349
- #define CUTE_ASEPRITE_FILEIO
349
+ #define CUTE_ASEPRITE_STDIO
350
350
#define CUTE_ASEPRITE_SEEK_SET SEEK_SET
351
351
#define CUTE_ASEPRITE_SEEK_END SEEK_END
352
352
#define CUTE_ASEPRITE_FILE FILE
@@ -357,13 +357,13 @@ struct ase_t
357
357
#define CUTE_ASEPRITE_FCLOSE fclose
358
358
#endif
359
359
360
- static int s_error_cline ; // The line in cute_aseprite.h where the error was triggered.
361
360
static const char * s_error_file = NULL ; // The filepath of the file being parsed. NULL if from memory.
362
361
static const char * s_error_reason ; // Used to capture errors during DEFLATE parsing.
363
362
364
363
#if !defined(CUTE_ASEPRITE_WARNING )
365
364
#define CUTE_ASEPRITE_WARNING (msg ) cute_aseprite_warning(msg, __LINE__)
366
365
366
+ static int s_error_cline ; // The line in cute_aseprite.h where the error was triggered.
367
367
void cute_aseprite_warning (const char * warning , int line )
368
368
{
369
369
s_error_cline = line ;
@@ -453,7 +453,7 @@ static uint64_t s_peak_bits(deflate_t* s, int num_bits_to_read)
453
453
static uint32_t s_consume_bits (deflate_t * s , int num_bits_to_read )
454
454
{
455
455
CUTE_ASEPRITE_ASSERT (s -> count >= num_bits_to_read );
456
- uint32_t bits = s -> bits & (((uint64_t )1 << num_bits_to_read ) - 1 );
456
+ uint32_t bits = ( uint32_t )( s -> bits & (((uint64_t )1 << num_bits_to_read ) - 1 ) );
457
457
s -> bits >>= num_bits_to_read ;
458
458
s -> count -= num_bits_to_read ;
459
459
s -> bits_left -= num_bits_to_read ;
@@ -482,9 +482,10 @@ static uint32_t s_rev16(uint32_t a)
482
482
}
483
483
484
484
// RFC 1951 section 3.2.2
485
- static int s_build (deflate_t * s , uint32_t * tree , uint8_t * lens , int sym_count )
485
+ static uint32_t s_build (deflate_t * s , uint32_t * tree , uint8_t * lens , int sym_count )
486
486
{
487
487
int n , codes [16 ], first [16 ], counts [16 ] = { 0 };
488
+ CUTE_ASEPRITE_UNUSED (s );
488
489
489
490
// Frequency count
490
491
for (n = 0 ; n < sym_count ; n ++ ) counts [lens [n ]]++ ;
@@ -499,19 +500,18 @@ static int s_build(deflate_t* s, uint32_t* tree, uint8_t* lens, int sym_count)
499
500
500
501
for (int i = 0 ; i < sym_count ; ++ i )
501
502
{
502
- int len = lens [i ];
503
+ uint8_t len = lens [i ];
503
504
504
505
if (len != 0 )
505
506
{
506
507
CUTE_ASEPRITE_ASSERT (len < 16 );
507
- uint32_t code = codes [len ]++ ;
508
- uint32_t slot = first [len ]++ ;
509
- tree [slot ] = (code << (32 - len )) | (i << 4 ) | len ;
508
+ uint32_t code = ( uint32_t ) codes [len ]++ ;
509
+ uint32_t slot = ( uint32_t ) first [len ]++ ;
510
+ tree [slot ] = (code << (32 - ( uint32_t ) len )) | (i << 4 ) | len ;
510
511
}
511
512
}
512
513
513
- int max_index = first [15 ];
514
- return max_index ;
514
+ return (uint32_t )first [15 ];
515
515
}
516
516
517
517
static int s_stored (deflate_t * s )
@@ -561,8 +561,7 @@ static int s_decode(deflate_t* s, uint32_t* tree, int hi)
561
561
uint32_t len = (32 - (key & 0xF ));
562
562
CUTE_ASEPRITE_ASSERT ((search >> len ) == (key >> len ));
563
563
564
- int code = s_consume_bits (s , key & 0xF );
565
- (void )code ;
564
+ s_consume_bits (s , key & 0xF );
566
565
return (key >> 4 ) & 0xFFF ;
567
566
}
568
567
@@ -571,31 +570,31 @@ static int s_dynamic(deflate_t* s)
571
570
{
572
571
uint8_t lenlens [19 ] = { 0 };
573
572
574
- int nlit = 257 + s_read_bits (s , 5 );
575
- int ndst = 1 + s_read_bits (s , 5 );
576
- int nlen = 4 + s_read_bits (s , 4 );
573
+ uint32_t nlit = 257 + s_read_bits (s , 5 );
574
+ uint32_t ndst = 1 + s_read_bits (s , 5 );
575
+ uint32_t nlen = 4 + s_read_bits (s , 4 );
577
576
578
- for (int i = 0 ; i < nlen ; ++ i )
577
+ for (uint32_t i = 0 ; i < nlen ; ++ i )
579
578
lenlens [s_permutation_order [i ]] = (uint8_t )s_read_bits (s , 3 );
580
579
581
580
// Build the tree for decoding code lengths
582
581
s -> nlen = s_build (0 , s -> len , lenlens , 19 );
583
582
uint8_t lens [288 + 32 ];
584
583
585
- for (int n = 0 ; n < nlit + ndst ;)
584
+ for (uint32_t n = 0 ; n < nlit + ndst ;)
586
585
{
587
- int sym = s_decode (s , s -> len , s -> nlen );
586
+ int sym = s_decode (s , s -> len , ( int ) s -> nlen );
588
587
switch (sym )
589
588
{
590
- case 16 : for (int i = 3 + s_read_bits (s , 2 ); i ; -- i , ++ n ) lens [n ] = lens [n - 1 ]; break ;
591
- case 17 : for (int i = 3 + s_read_bits (s , 3 ); i ; -- i , ++ n ) lens [n ] = 0 ; break ;
592
- case 18 : for (int i = 11 + s_read_bits (s , 7 ); i ; -- i , ++ n ) lens [n ] = 0 ; break ;
589
+ case 16 : for (uint32_t i = 3 + s_read_bits (s , 2 ); i ; -- i , ++ n ) lens [n ] = lens [n - 1 ]; break ;
590
+ case 17 : for (uint32_t i = 3 + s_read_bits (s , 3 ); i ; -- i , ++ n ) lens [n ] = 0 ; break ;
591
+ case 18 : for (uint32_t i = 11 + s_read_bits (s , 7 ); i ; -- i , ++ n ) lens [n ] = 0 ; break ;
593
592
default : lens [n ++ ] = (uint8_t )sym ; break ;
594
593
}
595
594
}
596
595
597
- s -> nlit = s_build (s , s -> lit , lens , nlit );
598
- s -> ndst = s_build (0 , s -> dst , lens + nlit , ndst );
596
+ s -> nlit = s_build (s , s -> lit , lens , ( int ) nlit );
597
+ s -> ndst = s_build (0 , s -> dst , lens + nlit , ( int ) ndst );
599
598
return 1 ;
600
599
}
601
600
@@ -604,7 +603,7 @@ static int s_block(deflate_t* s)
604
603
{
605
604
while (1 )
606
605
{
607
- int symbol = s_decode (s , s -> lit , s -> nlit );
606
+ int symbol = s_decode (s , s -> lit , ( int ) s -> nlit );
608
607
609
608
if (symbol < 256 )
610
609
{
@@ -616,9 +615,9 @@ static int s_block(deflate_t* s)
616
615
else if (symbol > 256 )
617
616
{
618
617
symbol -= 257 ;
619
- int length = s_read_bits (s , s_len_extra_bits [symbol ]) + s_len_base [symbol ];
620
- int distance_symbol = s_decode (s , s -> dst , s -> ndst );
621
- int backwards_distance = s_read_bits (s , s_dist_extra_bits [distance_symbol ]) + s_dist_base [distance_symbol ];
618
+ uint32_t length = s_read_bits (s , ( int )( s_len_extra_bits [symbol ]) ) + s_len_base [symbol ];
619
+ int distance_symbol = s_decode (s , s -> dst , ( int ) s -> ndst );
620
+ uint32_t backwards_distance = s_read_bits (s , s_dist_extra_bits [distance_symbol ]) + s_dist_base [distance_symbol ];
622
621
CUTE_ASEPRITE_CHECK (s -> out - backwards_distance >= s -> begin , "Attempted to write before out buffer (invalid backwards distance)." );
623
622
CUTE_ASEPRITE_CHECK (s -> out + length <= s -> out_end , "Attempted to overwrite out buffer while outputting a string." );
624
623
char * src = s -> out - backwards_distance ;
@@ -628,7 +627,7 @@ static int s_block(deflate_t* s)
628
627
switch (backwards_distance )
629
628
{
630
629
case 1 : // very common in images
631
- CUTE_ASEPRITE_MEMSET (dst , * src , length );
630
+ CUTE_ASEPRITE_MEMSET (dst , * src , ( size_t ) length );
632
631
break ;
633
632
default : while (length -- ) * dst ++ = * src ++ ;
634
633
}
@@ -646,6 +645,7 @@ static int s_block(deflate_t* s)
646
645
// 3.2.3
647
646
static int s_inflate (const void * in , int in_bytes , void * out , int out_bytes , void * mem_ctx )
648
647
{
648
+ CUTE_ASEPRITE_UNUSED (mem_ctx );
649
649
deflate_t * s = (deflate_t * )CUTE_ASEPRITE_ALLOC (sizeof (deflate_t ), mem_ctx );
650
650
s -> bits = 0 ;
651
651
s -> count = 0 ;
@@ -664,7 +664,7 @@ static int s_inflate(const void* in, int in_bytes, void* out, int out_bytes, voi
664
664
s -> final_word_available = last_bytes ? 1 : 0 ;
665
665
s -> final_word = 0 ;
666
666
for (int i = 0 ; i < last_bytes ; i ++ )
667
- s -> final_word |= ((uint8_t * )in )[in_bytes - last_bytes + i ] << (i * 8 );
667
+ s -> final_word |= ((uint8_t * )in )[in_bytes - last_bytes + i ] << (i * 8 );
668
668
669
669
s -> count = first_bytes * 8 ;
670
670
@@ -673,11 +673,11 @@ static int s_inflate(const void* in, int in_bytes, void* out, int out_bytes, voi
673
673
s -> begin = (char * )out ;
674
674
675
675
int count = 0 ;
676
- int bfinal ;
676
+ uint32_t bfinal ;
677
677
do
678
678
{
679
679
bfinal = s_read_bits (s , 1 );
680
- int btype = s_read_bits (s , 2 );
680
+ uint32_t btype = s_read_bits (s , 2 );
681
681
682
682
switch (btype )
683
683
{
@@ -747,6 +747,8 @@ static uint32_t s_read_uint32(ase_state_t* s)
747
747
return value ;
748
748
}
749
749
750
+ #ifdef CUTE_ASPRITE_S_READ_UINT64
751
+ // s_read_uint64() is not currently used.
750
752
static uint64_t s_read_uint64 (ase_state_t * s )
751
753
{
752
754
CUTE_ASEPRITE_ASSERT (s -> in <= s -> end + sizeof (uint64_t ));
@@ -763,23 +765,27 @@ static uint64_t s_read_uint64(ase_state_t* s)
763
765
* p += 8 ;
764
766
return value ;
765
767
}
768
+ #endif
766
769
767
770
static int16_t s_read_int16 (ase_state_t * s ) { return (int16_t )s_read_uint16 (s ); }
768
771
static int16_t s_read_int32 (ase_state_t * s ) { return (int32_t )s_read_uint32 (s ); }
769
772
773
+ #ifdef CUTE_ASPRITE_S_READ_BYTES
774
+ // s_read_bytes() is not currently used.
770
775
static void s_read_bytes (ase_state_t * s , uint8_t * bytes , int num_bytes )
771
776
{
772
777
for (int i = 0 ; i < num_bytes ; ++ i ) {
773
778
bytes [i ] = s_read_uint8 (s );
774
779
}
775
780
}
781
+ #endif
776
782
777
783
static const char * s_read_string (ase_state_t * s )
778
784
{
779
785
int len = (int )s_read_uint16 (s );
780
786
char * bytes = (char * )CUTE_ASEPRITE_ALLOC (len + 1 , s -> mem_ctx );
781
787
for (int i = 0 ; i < len ; ++ i ) {
782
- bytes [i ] = s_read_uint8 (s );
788
+ bytes [i ] = ( char ) s_read_uint8 (s );
783
789
}
784
790
bytes [len ] = 0 ;
785
791
return bytes ;
@@ -836,7 +842,7 @@ static int s_mul_un8(int a, int b)
836
842
837
843
static ase_color_t s_blend (ase_color_t src , ase_color_t dst , uint8_t opacity )
838
844
{
839
- src .a = s_mul_un8 (src .a , opacity );
845
+ src .a = ( uint8_t ) s_mul_un8 (src .a , opacity );
840
846
int a = src .a + dst .a - s_mul_un8 (src .a , dst .a );
841
847
int r , g , b ;
842
848
if (a == 0 ) {
@@ -919,8 +925,8 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
919
925
ase -> grid_h = (int )s_read_uint16 (s );
920
926
s_skip (s , 84 ); // For future use (set to zero).
921
927
922
- ase -> frames = (ase_frame_t * )CUTE_ASEPRITE_ALLOC (sizeof (ase_frame_t ) * ase -> frame_count , mem_ctx );
923
- CUTE_ASEPRITE_MEMSET (ase -> frames , 0 , sizeof (ase_frame_t ) * ase -> frame_count );
928
+ ase -> frames = (ase_frame_t * )CUTE_ASEPRITE_ALLOC (( int )( sizeof (ase_frame_t ) ) * ase -> frame_count , mem_ctx );
929
+ CUTE_ASEPRITE_MEMSET (ase -> frames , 0 , sizeof (ase_frame_t ) * ( size_t ) ase -> frame_count );
924
930
925
931
ase_udata_t * last_udata = NULL ;
926
932
@@ -935,13 +941,13 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
935
941
frame -> duration_milliseconds = s_read_uint16 (s );
936
942
if (frame -> duration_milliseconds == 0 ) frame -> duration_milliseconds = speed ;
937
943
s_skip (s , 2 ); // For future use (set to zero).
938
- int new_chunk_count = s_read_uint32 (s );
939
- if (new_chunk_count ) chunk_count = new_chunk_count ;
944
+ uint32_t new_chunk_count = s_read_uint32 (s );
945
+ if (new_chunk_count ) chunk_count = ( int ) new_chunk_count ;
940
946
941
947
for (int j = 0 ; j < chunk_count ; ++ j ) {
942
948
uint32_t chunk_size = s_read_uint32 (s );
943
949
uint16_t chunk_type = s_read_uint16 (s );
944
- chunk_size -= sizeof (uint32_t ) + sizeof (uint16_t );
950
+ chunk_size -= ( uint32_t )( sizeof (uint32_t ) + sizeof (uint16_t ) );
945
951
uint8_t * chunk_start = s -> in ;
946
952
947
953
switch (chunk_type ) {
@@ -978,7 +984,7 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
978
984
cel -> w = s_read_uint16 (s );
979
985
cel -> h = s_read_uint16 (s );
980
986
cel -> pixels = CUTE_ASEPRITE_ALLOC (cel -> w * cel -> h * bpp , mem_ctx );
981
- CUTE_ASEPRITE_MEMCPY (cel -> pixels , s -> in , cel -> w * cel -> h * bpp );
987
+ CUTE_ASEPRITE_MEMCPY (cel -> pixels , s -> in , ( size_t )( cel -> w * cel -> h * bpp ) );
982
988
s_skip (s , cel -> w * cel -> h * bpp );
983
989
break ;
984
990
@@ -993,7 +999,7 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
993
999
cel -> h = s_read_uint16 (s );
994
1000
int zlib_byte0 = s_read_uint8 (s );
995
1001
int zlib_byte1 = s_read_uint8 (s );
996
- int deflate_bytes = chunk_size - (int )(s -> in - chunk_start );
1002
+ int deflate_bytes = ( int ) chunk_size - (int )(s -> in - chunk_start );
997
1003
void * pixels = s -> in ;
998
1004
CUTE_ASEPRITE_ASSERT ((zlib_byte0 & 0x0F ) == 0x08 ); // Only zlib compression method (RFC 1950) is supported.
999
1005
CUTE_ASEPRITE_ASSERT ((zlib_byte0 & 0xF0 ) <= 0x70 ); // Innapropriate window size detected.
@@ -1059,8 +1065,8 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
1059
1065
case 0x2019 : // Palette chunk.
1060
1066
{
1061
1067
ase -> palette .entry_count = (int )s_read_uint32 (s );
1062
- int first_index = s_read_uint32 (s );
1063
- int last_index = s_read_uint32 (s );
1068
+ int first_index = ( int ) s_read_uint32 (s );
1069
+ int last_index = ( int ) s_read_uint32 (s );
1064
1070
s_skip (s , 8 ); // For future (set to zero).
1065
1071
for (int k = first_index ; k <= last_index ; ++ k ) {
1066
1072
int has_name = s_read_uint16 (s );
@@ -1087,7 +1093,6 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
1087
1093
last_udata -> text = s_read_string (s );
1088
1094
}
1089
1095
if (flags & 2 ) {
1090
- last_udata -> has_color ;
1091
1096
last_udata -> color .r = s_read_uint8 (s );
1092
1097
last_udata -> color .g = s_read_uint8 (s );
1093
1098
last_udata -> color .b = s_read_uint8 (s );
@@ -1098,8 +1103,8 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
1098
1103
1099
1104
case 0x2022 : // Slice chunk.
1100
1105
{
1101
- int slice_count = s_read_uint32 (s );
1102
- int flags = s_read_uint32 (s );
1106
+ int slice_count = ( int ) s_read_uint32 (s );
1107
+ int flags = ( int ) s_read_uint32 (s );
1103
1108
s_skip (s , sizeof (uint32_t )); // Reserved.
1104
1109
const char * name = s_read_string (s );
1105
1110
for (int k = 0 ; k < (int )slice_count ; ++ k ) {
@@ -1130,7 +1135,7 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
1130
1135
} break ;
1131
1136
1132
1137
default :
1133
- s_skip (s , chunk_size );
1138
+ s_skip (s , ( int ) chunk_size );
1134
1139
break ;
1135
1140
}
1136
1141
}
@@ -1139,8 +1144,8 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
1139
1144
// Blend all cel pixels into each of their respective frames, for convenience.
1140
1145
for (int i = 0 ; i < ase -> frame_count ; ++ i ) {
1141
1146
ase_frame_t * frame = ase -> frames + i ;
1142
- frame -> pixels = (ase_color_t * )CUTE_ASEPRITE_ALLOC (sizeof (ase_color_t ) * ase -> w * ase -> h , mem_ctx );
1143
- CUTE_ASEPRITE_MEMSET (frame -> pixels , 0 , sizeof (ase_color_t ) * ase -> w * ase -> h );
1147
+ frame -> pixels = (ase_color_t * )CUTE_ASEPRITE_ALLOC (( int )( sizeof (ase_color_t ) ) * ase -> w * ase -> h , mem_ctx );
1148
+ CUTE_ASEPRITE_MEMSET (frame -> pixels , 0 , sizeof (ase_color_t ) * ( size_t ) ase -> w * ( size_t ) ase -> h );
1144
1149
ase_color_t * dst = frame -> pixels ;
1145
1150
for (int j = 0 ; j < frame -> cel_count ; ++ j ) {
1146
1151
ase_cel_t * cel = frame -> cels + j ;
0 commit comments