2025-11-28 14:41:35 -06:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "pxl8_types.h"
|
|
|
|
|
|
2025-11-28 23:42:57 -06:00
|
|
|
static inline i32 pxl8_bytes_per_pixel(pxl8_pixel_mode mode) {
|
2026-01-17 22:52:36 -06:00
|
|
|
return (i32)mode;
|
2025-11-28 14:41:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u16 pxl8_rgb565_pack(u8 r, u8 g, u8 b) {
|
|
|
|
|
return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void pxl8_rgb565_unpack(u16 color, u8* r, u8* g, u8* b) {
|
|
|
|
|
*r = (color >> 11) << 3;
|
|
|
|
|
*g = ((color >> 5) & 0x3F) << 2;
|
|
|
|
|
*b = (color & 0x1F) << 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u16 pxl8_rgba32_to_rgb565(u32 rgba) {
|
|
|
|
|
return pxl8_rgb565_pack(rgba & 0xFF, (rgba >> 8) & 0xFF, (rgba >> 16) & 0xFF);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u32 pxl8_rgb565_to_rgba32(u16 color) {
|
|
|
|
|
u8 r, g, b;
|
|
|
|
|
pxl8_rgb565_unpack(color, &r, &g, &b);
|
refactor: reorganize pxl8 into client/src/ module structure
- core/: main entry, types, logging, I/O, RNG
- asset/: ase loader, cart, save, embed
- gfx/: graphics, animation, atlas, fonts, tilemap, transitions
- sfx/: audio
- script/: lua/fennel runtime, REPL
- hal/: platform abstraction (SDL3)
- world/: BSP, world, procedural gen
- math/: math utilities
- game/: GUI, replay
- lua/: Lua API modules
2026-01-12 21:46:31 -06:00
|
|
|
return r | ((u32)g << 8) | ((u32)b << 16) | 0xFF000000;
|
2025-11-28 14:41:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void pxl8_rgba32_unpack(u32 color, u8* r, u8* g, u8* b, u8* a) {
|
|
|
|
|
*r = color & 0xFF;
|
|
|
|
|
*g = (color >> 8) & 0xFF;
|
|
|
|
|
*b = (color >> 16) & 0xFF;
|
|
|
|
|
*a = (color >> 24) & 0xFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u32 pxl8_rgba32_pack(u8 r, u8 g, u8 b, u8 a) {
|
refactor: reorganize pxl8 into client/src/ module structure
- core/: main entry, types, logging, I/O, RNG
- asset/: ase loader, cart, save, embed
- gfx/: graphics, animation, atlas, fonts, tilemap, transitions
- sfx/: audio
- script/: lua/fennel runtime, REPL
- hal/: platform abstraction (SDL3)
- world/: BSP, world, procedural gen
- math/: math utilities
- game/: GUI, replay
- lua/: Lua API modules
2026-01-12 21:46:31 -06:00
|
|
|
return r | ((u32)g << 8) | ((u32)b << 16) | ((u32)a << 24);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u32 pxl8_color_to_rgba(u32 abgr) {
|
|
|
|
|
u8 r = abgr & 0xFF;
|
|
|
|
|
u8 g = (abgr >> 8) & 0xFF;
|
|
|
|
|
u8 b = (abgr >> 16) & 0xFF;
|
|
|
|
|
u8 a = (abgr >> 24) & 0xFF;
|
|
|
|
|
return ((u32)r << 24) | ((u32)g << 16) | ((u32)b << 8) | a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u32 pxl8_color_from_rgba(u32 rgba) {
|
|
|
|
|
u8 r = (rgba >> 24) & 0xFF;
|
|
|
|
|
u8 g = (rgba >> 16) & 0xFF;
|
|
|
|
|
u8 b = (rgba >> 8) & 0xFF;
|
|
|
|
|
u8 a = rgba & 0xFF;
|
|
|
|
|
return r | ((u32)g << 8) | ((u32)b << 16) | ((u32)a << 24);
|
2025-11-28 14:41:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u8 pxl8_color_lerp_channel(u8 c1, u8 c2, f32 t) {
|
|
|
|
|
return c1 + (i32)((c2 - c1) * t);
|
|
|
|
|
}
|
refactor: reorganize pxl8 into client/src/ module structure
- core/: main entry, types, logging, I/O, RNG
- asset/: ase loader, cart, save, embed
- gfx/: graphics, animation, atlas, fonts, tilemap, transitions
- sfx/: audio
- script/: lua/fennel runtime, REPL
- hal/: platform abstraction (SDL3)
- world/: BSP, world, procedural gen
- math/: math utilities
- game/: GUI, replay
- lua/: Lua API modules
2026-01-12 21:46:31 -06:00
|
|
|
|
|
|
|
|
static inline u8 pxl8_rgb332_pack(u8 r, u8 g, u8 b) {
|
|
|
|
|
return ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void pxl8_rgb332_unpack(u8 c, u8* r, u8* g, u8* b) {
|
|
|
|
|
u8 ri = (c >> 5) & 0x07;
|
|
|
|
|
u8 gi = (c >> 2) & 0x07;
|
|
|
|
|
u8 bi = c & 0x03;
|
|
|
|
|
*r = (ri << 5) | (ri << 2) | (ri >> 1);
|
|
|
|
|
*g = (gi << 5) | (gi << 2) | (gi >> 1);
|
|
|
|
|
*b = (bi << 6) | (bi << 4) | (bi << 2) | bi;
|
|
|
|
|
}
|