7 static byte palmap
[32768];
8 static byte pallock
[256];
9 static int palrev
[256];
11 /* Course color mapping, for when palette is exhausted. */
12 static byte crsmap
[4][32768];
13 static int crsrev
[4][256];
14 static const int crsmask
[4] = { 0x7BDE, 0x739C, 0x6318, 0x4210 };
25 static byte
bestmatch(int c
)
32 r
= (c
& 0x001F) << 3;
33 g
= (c
& 0x03E0) >> 2;
34 b
= (c
& 0x7C00) >> 7;
41 r2
= (c2
& 0x001F) << 3;
42 g2
= (c2
& 0x03E0) >> 2;
43 b2
= (c2
& 0x7C00) >> 7;
44 err
= abs(r
-r2
) + abs(b
-b2
) + abs(g
-g2
);
54 static void makecourse(int c
, byte n
)
57 for (i
= 0; i
< 4; i
++)
65 static byte
findcourse(int c
)
69 for (i
= 0; i
< 4; i
++)
73 if (crsrev
[i
][n
] == c
)
83 if (pallock
[n
] >= pl_locked
)
85 else pallock
[n
] = pl_locked
;
88 byte
pal_getcolor(int c
, int r
, int g
, int b
)
93 if (n
&& pallock
[n
] && palrev
[n
] == c
)
98 for (n
= l
+1; n
!= l
; n
++)
100 if (!n
|| pallock
[n
] /* || n < 16 */) continue;
105 vid_setpal(n
, r
, g
, b
);
113 void pal_release(byte n
)
115 if (pallock
[n
] >= pl_locked
)
123 for (i
= 0; i
< 256; i
++)
124 if (pallock
[i
] && pallock
[i
] < pl_locked
)
142 for (b
= 0; b
< 4; b
++) for (g
= 0; g
< 8; g
++) for (r
= 0; r
< 8; r
++)
143 vid_setpal(i
++, (r
<<5)|(r
<<2)|(r
>>1),
144 (g
<<5)|(g
<<2)|(g
>>1), (b
<<6)|(b
<<4)|(b
<<2)|b
);