#include "game_types.h"

/* Image_LoadCompressed @ 0x08013488 (real 48B) -- color-ramp blend leaf (args in r4/r5). Mirrors src/matched/Image_LoadCompressed.c. */
/* Color-ramp blend leaf: mixes two palette bytes by the signed ramp in
   p[20] scaled by p[18], clamped to 255, into p[2]/p[3]. Args arrive in
   r4/r5 by leaf convention (BLS unsigned clamp). */
void Image_LoadCompressed(char *p, char *q)
{
    int b = (unsigned char)p[18];
    int s = *(signed char *)(p + 20);
    int t = (128 + s) * b;
    int v = ((unsigned char)q[16] * t) >> 14;
    p[2] = (char)(v > 255 ? 255 : v);
    t = (127 - s) * b;
    v = ((unsigned char)q[17] * t) >> 14;
    p[3] = (char)(v > 255 ? 255 : v);
}
