Skip to content

Commit

Permalink
cute_tiled: Use uint32_t for hex color values (#364)
Browse files Browse the repository at this point in the history
Co-authored-by: RandyGaul <[email protected]>
  • Loading branch information
RobLoach and RandyGaul authored Nov 7, 2023
1 parent 3a89769 commit 613c978
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cute_tiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@

#if !defined(CUTE_TILED_H)

#include <stdint.h> // uint32_t

// Read this in the event of errors
extern const char* cute_tiled_error_reason;
extern int cute_tiled_error_line;
Expand Down Expand Up @@ -320,8 +322,8 @@ struct cute_tiled_layer_t
float opacity; // Value between 0 and 1.
int property_count; // Number of elements in the `properties` array.
cute_tiled_property_t* properties; // Array of properties.
int transparentcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
int tintcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
uint32_t transparentcolor; // Hex-formatted color (#AARRGGBB) (optional).
uint32_t tintcolor; // Hex-formatted color (#AARRGGBB) (optional).
cute_tiled_string_t type; // `tilelayer`, `objectgroup`, `imagelayer` or `group`.
cute_tiled_string_t image; // An image filepath. Used if layer is type `imagelayer`.
int visible; // 0 or 1. Whether layer is shown or hidden in editor.
Expand Down Expand Up @@ -393,7 +395,7 @@ struct cute_tiled_tileset_t
int tileoffset_y; // Pixel offset to align tiles to the grid.
cute_tiled_tile_descriptor_t* tiles; // Linked list of tile descriptors. Can be NULL.
int tilewidth; // Maximum width of tiles in this set.
int transparentcolor; // Hex-formatted color (#RRGGBB or #AARRGGBB) (optional).
uint32_t transparentcolor; // Hex-formatted color (#AARRGGBB) (optional).
cute_tiled_string_t type; // `tileset` (for tileset files, since 1.0).
cute_tiled_string_t source; // Relative path to tileset, when saved externally from the map file.
cute_tiled_tileset_t* next; // Pointer to next tileset. NULL if final tileset.
Expand Down Expand Up @@ -1642,8 +1644,22 @@ static int cute_tiled_read_hex_int_internal(cute_tiled_map_internal_t* m, int* o

val = CUTE_TILED_STRTOULL(m->in, &end, 16);
CUTE_TILED_CHECK(m->in != end, "Invalid integer found during parse.");

// Count the length to determine if we need to force AARRGGBB, instead of RRGGBB.
int length = 0;
while (m->in != end) {
m->in++;
length++;
}
*out = (uint32_t)val;

// When less than 6 characters, force an alpha channel of 0xFF.
if (length <= 6) {
uint32_t alpha = 0xFF << 24;
*out = (*out & 0x00FFFFFF) | alpha;
}

m->in = end;
*out = (int)val;
return 1;

cute_tiled_err:
Expand Down

3 comments on commit 613c978

@waldnercharles
Copy link

@waldnercharles waldnercharles commented on 613c978 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this commit is breaking cute_tiled_read_hex_int_internal which seems to expect an int* but is receiving a uint32_t*

Edit: The call to that function seems to happen via the macro cute_tiled_read_hex_int Lines 2208 and 2214 are where the errors show up for me compiling with MSVC C++17

@RandyGaul
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there was a merge conflict — looks like I chose the wrong type. Should it be uint32_t? PR would be very helpful — I’m away from computer for the evening

@RobLoach
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put up a PR in order to fix this #375

Please sign in to comment.