source: golgotha/src/i4/image/color.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.2 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef I4_COLOR_HH
10#define I4_COLOR_HH
11#include "arch.hh"
12
13inline w16 i4_32bpp_to_16bpp(w32 color)
14{
15  w32 r=(color>>16)&0xff, g=(color>>8)&0xff, b=(color>>0)&0xff;
16
17  r=(r>>3);
18  g=(g>>2);
19  b=(b>>3);
20
21  return (r<<(5+6)) | (g<<5) | b;
22}
23
24
25inline w16 i4_32bpp_to_15bpp(w32 color)
26{
27  w32 r=(color>>(16+3))   & (1 | 2 | 4 | 8 | 16);
28  w32 g=(color>>(8+3))    & (1 | 2 | 4 | 8 | 16);
29  w32 b=(color>>(0+3))    & (1 | 2 | 4 | 8 | 16);
30
31  return (r<<(5+5)) | (g<<5) | b;
32}
33
34inline void i4_32bpp_to_rgb(w32 color, w8 &r, w8 &g, w8 &b)
35{
36  r=(color>>16)&0xff;
37  g=(color>>8)&0xff;
38  b=color&0xff;
39}
40
41inline w32 i4_15bpp_to_32bpp(w32 color)
42{
43  return ((((color & ((1 | 2 | 4 | 8 | 16)<<0))  >> 0) << (3+0)) |
44          (((color & ((1 | 2 | 4 | 8 | 16)<<5))  >> 5) << (3+8)) |
45          (((color & ((1 | 2 | 4 | 8 | 16)<<10)) >> 10) << (3+16)));
46}
47
48inline w32 i4_16bpp_to_32bpp(w32 color)
49{
50  w32 r=((color>>11) & (1|2|4|8|16))   <<3;
51  w32 g=((color>>5)  & (1|2|4|8|16|32))<<2;
52  w32 b=((color>>0)  & (1|2|4|8|16))   <<3;
53  return (r<<16)|(g<<8)|b;
54}
55
56inline w32 i4_rgb_to_32bit(w8 r, w8 g, w8 b)
57{
58  return (r<<16) | (g<<8) | b;
59}
60
61#if (I4_SCREEN_DEPTH==15)
62inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
63{
64  return i4_32bpp_to_15bpp(color);
65}
66#endif
67
68
69
70#if (I4_SCREEN_DEPTH==16)
71inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
72{
73  return i4_32bpp_to_16bpp(color);
74}
75#endif
76
77
78
79#if (I4_SCREEN_DEPTH==32)
80inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
81{
82  return color;
83}
84#endif
85
86
87#if (I4_SCREEN_DEPTH==8)
88#error need to solve this problem
89inline w16 i4_32bpp_to_screen(w32 color, w32 *pal)
90{ return 0; }
91
92#endif
93
94
95
96
97#endif
Note: See TracBrowser for help on using the repository browser.