44 lines
1 KiB
C
44 lines
1 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include "pxl8_dither.h"
|
||
|
|
#include "pxl8_types.h"
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
extern "C" {
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#define PXL8_LIGHT_LEVELS 64
|
||
|
|
#define PXL8_COLORMAP_SIZE (256 * PXL8_LIGHT_LEVELS)
|
||
|
|
|
||
|
|
#define PXL8_FULLBRIGHT_START 240
|
||
|
|
#define PXL8_TRANSPARENT 0
|
||
|
|
#define PXL8_DYNAMIC_RANGE_START 144
|
||
|
|
#define PXL8_DYNAMIC_RANGE_COUNT 16
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
u8 table[PXL8_COLORMAP_SIZE];
|
||
|
|
} pxl8_colormap;
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
u8 dark_r, dark_g, dark_b;
|
||
|
|
u8 tint_r, tint_g, tint_b;
|
||
|
|
f32 tint_strength;
|
||
|
|
} pxl8_level_tint;
|
||
|
|
|
||
|
|
void pxl8_colormap_generate(pxl8_colormap* cm, const u32* palette, const pxl8_level_tint* tint);
|
||
|
|
|
||
|
|
static inline u8 pxl8_colormap_lookup(const pxl8_colormap* cm, u8 pal_idx, u8 light) {
|
||
|
|
u32 light_idx = light >> 2;
|
||
|
|
return cm->table[light_idx * 256 + pal_idx];
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline u8 pxl8_colormap_lookup_dithered(const pxl8_colormap* cm, u8 pal_idx, u8 light, u32 x, u32 y) {
|
||
|
|
u8 dithered = pxl8_dither_light(light, x, y);
|
||
|
|
u32 light_idx = dithered >> 2;
|
||
|
|
return cm->table[light_idx * 256 + pal_idx];
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
}
|
||
|
|
#endif
|