refactor atlas implementation

This commit is contained in:
asrael 2025-10-05 16:25:17 -05:00
parent 6008ebf5ed
commit c662c550df
12 changed files with 867 additions and 303 deletions

View file

@ -260,16 +260,11 @@ pxl8_result pxl8_ase_load(const char* filepath, pxl8_ase_file* ase_file) {
chunk_header.chunk_type = read_u16_le(chunk_data + 4);
const u8* chunk_payload = chunk_data + 6;
pxl8_debug("Found chunk: type=0x%04X, size=%d", chunk_header.chunk_type, chunk_header.chunk_size);
switch (chunk_header.chunk_type) {
case PXL8_ASE_CHUNK_OLD_PALETTE: // 0x0004
if (!ase_file->palette.colors) {
result = parse_old_palette_chunk(chunk_payload, &ase_file->palette);
pxl8_debug("Parsed old palette: %d colors, indices %d-%d",
ase_file->palette.entry_count, ase_file->palette.first_color, ase_file->palette.last_color);
} else {
pxl8_debug("Ignoring old palette (0x0004) - new palette (0x2019) already loaded");
}
break;
@ -284,11 +279,6 @@ pxl8_result pxl8_ase_load(const char* filepath, pxl8_ase_file* ase_file) {
result = parse_layer_chunk(chunk_payload, &ase_file->layers[ase_file->layer_count]);
if (result == PXL8_OK) {
pxl8_debug("Parsed layer %d: '%s', blend_mode=%d, opacity=%d",
ase_file->layer_count,
ase_file->layers[ase_file->layer_count].name ? ase_file->layers[ase_file->layer_count].name : "(unnamed)",
ase_file->layers[ase_file->layer_count].blend_mode,
ase_file->layers[ase_file->layer_count].opacity);
ase_file->layer_count++;
}
break;
@ -296,14 +286,11 @@ pxl8_result pxl8_ase_load(const char* filepath, pxl8_ase_file* ase_file) {
case PXL8_ASE_CHUNK_CEL: { // 0x2005
pxl8_ase_cel cel = {0};
pxl8_debug("Found CEL chunk: size=%d", chunk_header.chunk_size - 6);
result = parse_cel_chunk(chunk_payload, chunk_header.chunk_size - 6, &cel);
if (result == PXL8_OK && cel.pixel_data) {
pxl8_debug("CEL data loaded: %dx%d, type=%d, first pixel = %d", cel.width, cel.height, cel.cel_type, cel.pixel_data[0]);
u32 copy_width = (cel.width < frame->width) ? cel.width : frame->width;
u32 copy_height = (cel.height < frame->height) ? cel.height : frame->height;
pxl8_debug("Copying cel to frame: cel_pos=(%d,%d), copy_size=%dx%d", cel.x, cel.y, copy_width, copy_height);
for (u32 y = 0; y < copy_height; y++) {
u32 src_offset = y * cel.width;
u32 dst_offset = (y + cel.y) * frame->width + cel.x;
@ -311,20 +298,16 @@ pxl8_result pxl8_ase_load(const char* filepath, pxl8_ase_file* ase_file) {
for (u32 x = 0; x < copy_width; x++) {
u8 src_pixel = cel.pixel_data[src_offset + x];
bool is_transparent = false;
if (src_pixel < ase_file->palette.entry_count && ase_file->palette.colors) {
u32 color = ase_file->palette.colors[src_pixel];
is_transparent = ((color >> 24) & 0xFF) == 0;
}
if (!is_transparent) {
frame->pixels[dst_offset + x] = src_pixel;
}
}
if (y < 3) {
pxl8_debug("Row %d: cel[%d]=%d, frame[%d]=%d",
y, src_offset, cel.pixel_data[src_offset], dst_offset, frame->pixels[dst_offset]);
}
}
}
SDL_free(cel.pixel_data);
@ -337,8 +320,6 @@ pxl8_result pxl8_ase_load(const char* filepath, pxl8_ase_file* ase_file) {
SDL_free(ase_file->palette.colors);
}
result = parse_palette_chunk(chunk_payload, &ase_file->palette);
pxl8_debug("Parsed new palette: %d colors, indices %d-%d",
ase_file->palette.entry_count, ase_file->palette.first_color, ase_file->palette.last_color);
break;
default: