Skip to content

Commit ea8620f

Browse files
committed
Update cute_aseprite
1 parent 90502a9 commit ea8620f

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

include/cute_aseprite.h

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,43 @@ struct ase_t
347347
#define CUTE_ASEPRITE_ASSERT assert
348348
#endif
349349

350-
#if !defined(CUTE_ASEPRITE_STDIO)
351-
#include <stdio.h> // fopen
352-
#define CUTE_ASEPRITE_STDIO
350+
#if !defined(CUTE_ASEPRITE_SEEK_SET)
351+
#include <stdio.h> // SEEK_SET
353352
#define CUTE_ASEPRITE_SEEK_SET SEEK_SET
353+
#endif
354+
355+
#if !defined(CUTE_ASEPRITE_SEEK_END)
356+
#include <stdio.h> // SEEK_END
354357
#define CUTE_ASEPRITE_SEEK_END SEEK_END
358+
#endif
359+
360+
#if !defined(CUTE_ASEPRITE_FILE)
361+
#include <stdio.h> // FILE
355362
#define CUTE_ASEPRITE_FILE FILE
363+
#endif
364+
365+
#if !defined(CUTE_ASEPRITE_FOPEN)
366+
#include <stdio.h> // fopen
356367
#define CUTE_ASEPRITE_FOPEN fopen
368+
#endif
369+
370+
#if !defined(CUTE_ASEPRITE_FSEEK)
371+
#include <stdio.h> // fseek
357372
#define CUTE_ASEPRITE_FSEEK fseek
373+
#endif
374+
375+
#if !defined(CUTE_ASEPRITE_FREAD)
376+
#include <stdio.h> // fread
358377
#define CUTE_ASEPRITE_FREAD fread
378+
#endif
379+
380+
#if !defined(CUTE_ASEPRITE_FTELL)
381+
#include <stdio.h> // ftell
359382
#define CUTE_ASEPRITE_FTELL ftell
383+
#endif
384+
385+
#if !defined(CUTE_ASEPRITE_FCLOSE)
386+
#include <stdio.h> // fclose
360387
#define CUTE_ASEPRITE_FCLOSE fclose
361388
#endif
362389

@@ -501,7 +528,7 @@ static uint32_t s_build(deflate_t* s, uint32_t* tree, uint8_t* lens, int sym_cou
501528
first[n] = first[n - 1] + counts[n - 1];
502529
}
503530

504-
for (int i = 0; i < sym_count; ++i)
531+
for (uint32_t i = 0; i < (uint32_t)sym_count; ++i)
505532
{
506533
uint8_t len = lens[i];
507534

@@ -529,7 +556,8 @@ static int s_stored(deflate_t* s)
529556
// read LEN and NLEN, should complement each other
530557
uint16_t LEN = (uint16_t)s_read_bits(s, 16);
531558
uint16_t NLEN = (uint16_t)s_read_bits(s, 16);
532-
CUTE_ASEPRITE_CHECK(LEN == (uint16_t)(~NLEN), "Failed to find LEN and NLEN as complements within stored (uncompressed) stream.");
559+
uint16_t TILDE_NLEN = ~NLEN;
560+
CUTE_ASEPRITE_CHECK(LEN == TILDE_NLEN, "Failed to find LEN and NLEN as complements within stored (uncompressed) stream.");
533561
CUTE_ASEPRITE_CHECK(s->bits_left / 8 <= (int)LEN, "Stored block extends beyond end of input stream.");
534562
p = s_ptr(s);
535563
CUTE_ASEPRITE_MEMCPY(s->out, p, LEN);
@@ -656,7 +684,7 @@ static int s_inflate(const void* in, int in_bytes, void* out, int out_bytes, voi
656684
s->bits_left = in_bytes * 8;
657685

658686
// s->words is the in-pointer rounded up to a multiple of 4
659-
int first_bytes = (int)((((size_t)in + 3) & ~3) - (size_t)in);
687+
int first_bytes = (int)((((size_t)in + 3) & (size_t)(~3)) - (size_t)in);
660688
s->words = (uint32_t*)((char*)in + first_bytes);
661689
s->word_count = (in_bytes - first_bytes) / 4;
662690
int last_bytes = ((in_bytes - first_bytes) & 3);
@@ -770,8 +798,8 @@ static uint64_t s_read_uint64(ase_state_t* s)
770798
}
771799
#endif
772800

773-
static int16_t s_read_int16(ase_state_t* s) { return (int16_t)s_read_uint16(s); }
774-
static int16_t s_read_int32(ase_state_t* s) { return (int32_t)s_read_uint32(s); }
801+
#define s_read_int16(s) (int16_t)s_read_uint16(s)
802+
#define s_read_int32(s) (int32_t)s_read_uint32(s)
775803

776804
#ifdef CUTE_ASPRITE_S_READ_BYTES
777805
// s_read_bytes() is not currently used.

include/raylib-aseprite.h

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,40 +96,21 @@ extern "C" {
9696
// Have cute_aseprite report warnings through raylib.
9797
#define CUTE_ASEPRITE_WARNING(msg) TraceLog(LOG_WARNING, "ASEPRITE: %s (cute_headers.h:%i)", msg, __LINE__)
9898

99-
// Have failed cute_aseprite assertions report an error through raylib.
100-
#define CUTE_ASEPRITE_ASSERT(condition) if (!(condition)) { TraceLog(LOG_WARNING, "ASEPRITE: Failed assert \"%s\" in %s:%i", #condition, __FILE__, __LINE__); }
99+
#define CUTE_ASEPRITE_ASSERT(condition) do { if (!(condition)) { TraceLog(LOG_WARNING, "ASEPRITE: Failed assert \"%s\" in %s:%i", #condition, __FILE__, __LINE__); } } while(0)
100+
101+
#define CUTE_ASEPRITE_ALLOC(size, ctx) MemAlloc((int)(size))
102+
#define CUTE_ASEPRITE_FREE(mem, ctx) MemFree((void*)(mem))
101103

102-
// Override how Cute attempts to load files.
103-
#ifndef CUTE_ASEPRITE_STDIO
104-
#define CUTE_ASEPRITE_STDIO
105104
#define CUTE_ASEPRITE_SEEK_SET 0
106105
#define CUTE_ASEPRITE_SEEK_END 0
107106
#define CUTE_ASEPRITE_FILE void
108-
#define CUTE_ASEPRITE_FOPEN(file, property) (0)
107+
#define CUTE_ASEPRITE_FOPEN(file, property) (CUTE_ASEPRITE_FILE*)file
109108
#define CUTE_ASEPRITE_FSEEK(fp, sz, pos) TraceLog(LOG_ERROR, "ASEPRITE: fseek() was removed")
110109
#define CUTE_ASEPRITE_FREAD(data, sz, num, fp) TraceLog(LOG_ERROR, "ASEPRITE: fread() was removed")
111110
#define CUTE_ASEPRITE_FTELL(fp) (0)
112111
#define CUTE_ASEPRITE_FCLOSE(fp) TraceLog(LOG_ERROR, "ASEPRITE: fclose() was removed")
113-
#endif // CUTE_ASEPRITE_STDIO
114-
115-
// Have cute_aseprite use raylib's memory functions.
116-
#define CUTE_ASEPRITE_ALLOC(size, ctx) MemAlloc((int)(size))
117-
#define CUTE_ASEPRITE_FREE(mem, ctx) MemFree((void*)(mem))
118112

119-
// Include cute_aseprite.h while ignoring the warnings.
120-
#pragma GCC diagnostic push
121-
#pragma GCC diagnostic ignored "-Wsign-conversion"
122-
#pragma GCC diagnostic push
123-
#pragma GCC diagnostic ignored "-Wconversion"
124-
#pragma GCC diagnostic push
125-
#pragma GCC diagnostic ignored "-Wsign-compare"
126-
#pragma GCC diagnostic push
127-
#pragma GCC diagnostic ignored "-Wunused-parameter"
128113
#include "cute_aseprite.h" // NOLINT
129-
#pragma GCC diagnostic pop
130-
#pragma GCC diagnostic pop
131-
#pragma GCC diagnostic pop
132-
#pragma GCC diagnostic pop
133114

134115
/**
135116
* Aseprite object containing a pointer to the ase_t* from cute_aseprite.h.

0 commit comments

Comments
 (0)