#include #include "lighting.h" /* Apply lighting and visibility effects to img, outputting to buf */ void combine_maps(BITMAP* light, BITMAP* vis, BITMAP* img, BITMAP* buf) { unsigned char* bp; unsigned char* bp_end; unsigned char* lp; unsigned char* vp; unsigned char* ip; int y; for (y = 0; y < SCREEN_H; y++) { bp = buf->line[y]; lp = light->line[y]; vp = vis->line[y]; ip = img->line[y]; bp_end = bp + SCREEN_W * 4; while (bp < bp_end) { switch (*vp) { case 0: /* Blind */ *(unsigned long*)bp = 0; /* Black */ break; case 1: /* Remembered */ bp[0] = bp[1] = bp[2] = /* Desaturate & dim */ (ip[0] + ip[1] + ip[2]) / 4; break; case 2: /* Visible */ #if 1 #define apply(i) (bp[i] = lp[i] < 192 ? /* Test */ \ (ip[i] * lp[i]) / 192 : /* Burn */ \ (ip[i] * (64 - (lp[i] - 192)) + 255 * (lp[i] - 192)) / 64) /* Overbright */ apply(0); apply(1); apply(2); #undef apply #else *(unsigned long*)bp = *(unsigned long*)ip; #endif } bp += 4;/* 32bpp */ lp += 4;/* 32bpp */ vp += 1;/* 8bpp */ ip += 4;/* 32bpp */ } } }