Skip to content

Commit

Permalink
Update to v5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RobLoach committed Apr 8, 2024
1 parent 81924be commit 967a972
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.11)
project (raylib_aseprite
VERSION 4.5.0
VERSION 5.0.0
DESCRIPTION "raylib_aseprite: Use Aseprite files in raylib"
HOMEPAGE_URL "https://github.com/robloach/raylib-aseprite"
LANGUAGES C)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ See the [examples directory](examples) for more demonstrations of how to use *ra
``` c
// Aseprite functions
Aseprite LoadAseprite(const char* fileName); // Load an .aseprite file
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size); // Load an aseprite file from memory
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, int size); // Load an aseprite file from memory
bool IsAsepriteReady(Aseprite aseprite); // Check if the given Aseprite was loaded successfully
void UnloadAseprite(Aseprite aseprite); // Unloads the aseprite file
void TraceAseprite(Aseprite aseprite); // Display all information associated with the aseprite
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (NOT raylib_FOUND)
FetchContent_Declare(
raylib
GIT_REPOSITORY https://github.com/raysan5/raylib.git
GIT_TAG 4.5.0
GIT_TAG 5.0
)
FetchContent_GetProperties(raylib)
if (NOT raylib_POPULATED) # Have we downloaded raylib yet?
Expand Down
35 changes: 32 additions & 3 deletions include/cute_aseprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Licensing information can be found at the end of the file.
------------------------------------------------------------------------------
cute_aseprite.h - v1.02
cute_aseprite.h - v1.04
To create implementation (the function definitions)
#define CUTE_ASEPRITE_IMPLEMENTATION
Expand Down Expand Up @@ -45,6 +45,8 @@
1.01 (08/31/2020) fixed memleaks, tag parsing bug (crash), blend bugs
1.02 (02/05/2022) fixed icc profile parse bug, support transparent pal-
ette index, can parse 1.3 files (no tileset support)
1.03 (11/27/2023) fixed slice pivot parse bug
1.04 (02/20/2024) chunck 0x0004 support
*/

/*
Expand Down Expand Up @@ -212,6 +214,7 @@ struct ase_tag_t
int from_frame;
int to_frame;
ase_animation_direction_t loop_animation_direction;
int repeat;
uint8_t r, g, b;
const char* name;
ase_udata_t udata;
Expand Down Expand Up @@ -991,6 +994,30 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
uint8_t* chunk_start = s->in;

switch (chunk_type) {
case 0x0004: // Old Palette chunk (used when there are no colors with alpha in the palette)
{
int nbPackets = (int)s_read_uint16(s);
for (int k = 0; k < nbPackets ; k++ ) {
uint16_t maxColor=0;
uint8_t skip = s_read_uint8(s);
uint16_t nbColors = s_read_uint8(s);
if (nbColors == 0) nbColors = 256;

for (int l = 0; l < nbColors; l++) {
ase_palette_entry_t entry;
entry.color.r = s_read_uint8(s);
entry.color.g = s_read_uint8(s);
entry.color.b = s_read_uint8(s);
entry.color.a = 255;
entry.color_name = NULL;
ase->palette.entries[skip+l] = entry;
if (skip+l > maxColor) maxColor = skip+l;
}

ase->palette.entry_count = maxColor+1;
}

} break;
case 0x2004: // Layer chunk.
{
CUTE_ASEPRITE_ASSERT(ase->layer_count < CUTE_ASEPRITE_MAX_LAYERS);
Expand Down Expand Up @@ -1099,7 +1126,8 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
tag.from_frame = (int)s_read_uint16(s);
tag.to_frame = (int)s_read_uint16(s);
tag.loop_animation_direction = (ase_animation_direction_t)s_read_uint8(s);
s_skip(s, 8); // For future (set to zero).
tag.repeat = s_read_uint16(s);
s_skip(s, 6); // For future (set to zero).
tag.r = s_read_uint8(s);
tag.g = s_read_uint8(s);
tag.b = s_read_uint8(s);
Expand Down Expand Up @@ -1176,7 +1204,8 @@ ase_t* cute_aseprite_load_from_memory(const void* memory, int size, void* mem_ct
slice.center_y = (int)s_read_int32(s);
slice.center_w = (int)s_read_uint32(s);
slice.center_h = (int)s_read_uint32(s);
} else if (flags & 2) {
}
if (flags & 2) {
// Has pivot information.
slice.has_pivot = 1;
slice.pivot_x = (int)s_read_int32(s);
Expand Down
10 changes: 5 additions & 5 deletions include/raylib-aseprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright 2021 Rob Loach (@RobLoach)
*
* DEPENDENCIES:
* raylib 4.2+ https://www.raylib.com/
* raylib 5.0+ https://www.raylib.com/
*
* LICENSE: zlib/libpng
*
Expand Down Expand Up @@ -44,7 +44,7 @@ typedef struct AsepriteSlice AsepriteSlice; // A slice i

// Aseprite functions
Aseprite LoadAseprite(const char* fileName); // Load an .aseprite file
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size); // Load an aseprite file from memory
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, int size); // Load an aseprite file from memory
bool IsAsepriteReady(Aseprite aseprite); // Check if the given Aseprite was loaded successfully
void UnloadAseprite(Aseprite aseprite); // Unloads the aseprite file
void TraceAseprite(Aseprite aseprite); // Display all information associated with the aseprite
Expand Down Expand Up @@ -100,7 +100,7 @@ extern "C" {

#define CUTE_ASEPRITE_ASSERT(condition) do { if (!(condition)) { TraceLog(LOG_WARNING, "ASEPRITE: Failed assert \"%s\" in %s:%i", #condition, __FILE__, __LINE__); } } while(0)

#define CUTE_ASEPRITE_ALLOC(size, ctx) MemAlloc((int)(size))
#define CUTE_ASEPRITE_ALLOC(size, ctx) MemAlloc((unsigned int)(size))
#define CUTE_ASEPRITE_FREE(mem, ctx) MemFree((void*)(mem))

#define CUTE_ASEPRITE_SEEK_SET 0
Expand Down Expand Up @@ -163,7 +163,7 @@ struct AsepriteSlice {
* @see UnloadAseprite()
* @see LoadAseprite()
*/
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size) {
Aseprite LoadAsepriteFromMemory(unsigned char* fileData, int size) {
struct Aseprite aseprite;
aseprite.ase = 0;

Expand Down Expand Up @@ -240,7 +240,7 @@ Aseprite LoadAsepriteFromMemory(unsigned char* fileData, unsigned int size) {
* @see IsAsepriteReady()
*/
Aseprite LoadAseprite(const char* fileName) {
unsigned int bytesRead;
int bytesRead;
unsigned char* fileData = LoadFileData(fileName, &bytesRead);
if (bytesRead == 0 || fileData == 0) {
TraceLog(LOG_ERROR, "ASEPRITE: Failed to load aseprite file \"%s\"", fileName);
Expand Down

0 comments on commit 967a972

Please sign in to comment.