OpenClonk
StdColors.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CStdPalette
 

Macros

#define C4RGB(r, g, b)   (((DWORD)(0xff)<<24)|(((DWORD)(r)&0xff)<<16)|(((DWORD)(g)&0xff)<<8)|((b)&0xff))
 
#define GetBlueValue(rgb)   ((unsigned char)(rgb))
 
#define GetGreenValue(rgb)   ((unsigned char)(((unsigned short)(rgb)) >> 8))
 
#define GetRedValue(rgb)   ((unsigned char)((rgb)>>16))
 

Functions

uint32_t RGBA (uint32_t r, uint32_t g, uint32_t b, uint32_t a)
 
void BltAlpha (DWORD &dwDst, DWORD dwSrc)
 
void BltAlphaAdd (DWORD &dwDst, DWORD dwSrc)
 
void ModulateClr (DWORD &dwDst, DWORD dwMod)
 
void ModulateClrA (DWORD &dwDst, DWORD dwMod)
 
void ModulateClrMOD2 (DWORD &dwDst, DWORD dwMod)
 
DWORD LightenClrBy (DWORD &dwDst, int iBy)
 
DWORD DarkenClrBy (DWORD &dwDst, int iBy)
 
DWORD PlrClr2TxtClr (DWORD dwClr)
 
DWORD GetClrModulation (DWORD dwSrcClr, DWORD dwDstClr, DWORD &dwBack)
 
bool rgb2xyY (double r, double g, double b, double *px, double *py, double *pY)
 
bool xy2upvp (double x, double y, double *pu, double *pv)
 
bool RGB2rgb (int R, int G, int B, double *pr, double *pg, double *pb, double gamma=2.2)
 

Macro Definition Documentation

◆ C4RGB

#define C4RGB (   r,
  g,
  b 
)    (((DWORD)(0xff)<<24)|(((DWORD)(r)&0xff)<<16)|(((DWORD)(g)&0xff)<<8)|((b)&0xff))

Definition at line 26 of file StdColors.h.

◆ GetBlueValue

#define GetBlueValue (   rgb)    ((unsigned char)(rgb))

Definition at line 27 of file StdColors.h.

◆ GetGreenValue

#define GetGreenValue (   rgb)    ((unsigned char)(((unsigned short)(rgb)) >> 8))

Definition at line 28 of file StdColors.h.

◆ GetRedValue

#define GetRedValue (   rgb)    ((unsigned char)((rgb)>>16))

Definition at line 29 of file StdColors.h.

Function Documentation

◆ BltAlpha()

void BltAlpha ( DWORD dwDst,
DWORD  dwSrc 
)
inline

Definition at line 31 of file StdColors.h.

32 {
33  // blit one color value w/alpha on another
34  if (dwDst>>24 == 0x00) { dwDst=dwSrc; return; }
35  BYTE byAlphaSrc=BYTE(dwSrc>>24); BYTE byAlphaDst=255-byAlphaSrc;
36  dwDst = std::min<uint32_t>(((dwDst & 0xff ) * byAlphaDst + (dwSrc & 0xff ) * byAlphaSrc) >>8, 0xff) | // blue
37  std::min<uint32_t>(((dwDst & 0xff00) * byAlphaDst + (dwSrc & 0xff00 ) * byAlphaSrc) >>8 & 0xff00, 0xff00) | // green
38  std::min<uint32_t>(((dwDst & 0xff0000) * byAlphaDst + (dwSrc & 0xff0000) * byAlphaSrc) >>8 & 0xff0000, 0xff0000) | // red
39  std::min<uint32_t>( (dwDst >> 24) + byAlphaSrc, 255) << 24; // alpha
40 }
uint8_t BYTE

Referenced by CStdFont::AddRenderedChar(), C4Surface::BltPix(), and C4Surface::GetPixDw().

Here is the caller graph for this function:

◆ BltAlphaAdd()

void BltAlphaAdd ( DWORD dwDst,
DWORD  dwSrc 
)
inline

Definition at line 42 of file StdColors.h.

43 {
44  // blit one color value w/alpha on another in additive mode
45  if (dwDst>>24 == 0x00) { dwDst=dwSrc; return; }
46  BYTE byAlphaSrc=BYTE(dwSrc>>24);
47  dwDst = std::min<uint32_t>((dwDst & 0xff ) + ((int(dwSrc & 0xff ) * byAlphaSrc) >>8) , 0xff) | // blue
48  std::min<uint32_t>(((dwDst & 0xff00) + (int(dwSrc>>8 & 0xff ) * byAlphaSrc)) & 0x00ffff00, 0xff00) | // green
49  std::min<uint32_t>(((dwDst & 0xff0000) + (int(dwSrc>>8 & 0xff00) * byAlphaSrc)) & 0xffff0000, 0xff0000) | // red
50  std::min<uint32_t>( (dwDst >> 24) + byAlphaSrc, 255) << 24; // alpha
51 }

Referenced by C4Surface::BltPix().

Here is the caller graph for this function:

◆ DarkenClrBy()

DWORD DarkenClrBy ( DWORD dwDst,
int  iBy 
)
inline

Definition at line 93 of file StdColors.h.

94 {
95  // darken a color
96  // quite a desaturating method...
97  dwDst = std::max<int>(int(dwDst & 0xff) - iBy, 0) | // blue
98  std::max<int>(int(dwDst>> 8 & 0xff) - iBy, 0) << 8 | // green
99  std::max<int>(int(dwDst>>16 & 0xff) - iBy, 0) << 16 | // red
100  (dwDst & 0xff000000); // alpha
101  return dwDst;
102 }

◆ GetClrModulation()

DWORD GetClrModulation ( DWORD  dwSrcClr,
DWORD  dwDstClr,
DWORD dwBack 
)
inline

Definition at line 112 of file StdColors.h.

113 {
114  // get modulation that is necessary to transform dwSrcClr to dwDstClr
115  // does not support alpha values in dwSrcClr and dwDstClr
116  // get source color
117  BYTE sB=BYTE(dwSrcClr); dwSrcClr=dwSrcClr>>8;
118  BYTE sG=BYTE(dwSrcClr); dwSrcClr=dwSrcClr>>8;
119  BYTE sR=BYTE(dwSrcClr); dwSrcClr=dwSrcClr>>8;
120  // get dest color
121  BYTE dB=BYTE(dwDstClr); dwDstClr=dwDstClr>>8;
122  BYTE dG=BYTE(dwDstClr); dwDstClr=dwDstClr>>8;
123  BYTE dR=BYTE(dwDstClr); dwDstClr=dwDstClr>>8;
124  // get difference
125  int cR=(int) dR-sR;
126  int cG=(int) dG-sG;
127  int cB=(int) dB-sB;
128  // get max enlightment
129  int diffN=0;
130  if (cR>0) diffN=cR;
131  if (cG>0) diffN=std::max(diffN, cG);
132  if (cB>0) diffN=std::max(diffN, cB);
133  // is dest > src?
134  if (diffN)
135  {
136  // so a back mask must be used
137  int bR=sR+(cR*255)/diffN;
138  int bG=sG+(cG*255)/diffN;
139  int bB=sB+(cB*255)/diffN;
140  dwBack=RGBA(bR, bG, bB, 255);
141  }
142  if (!sR) sR=1;
143  if (!sG) sG=1;
144  if (!sB) sB=1;
145  return RGBA(std::min((int)dR*256/sR, 255), std::min((int)dG*256/sG, 255), std::min((int)dB*256/sB, 255), 255-diffN);
146 }
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:22

References RGBA().

Here is the call graph for this function:

◆ LightenClrBy()

DWORD LightenClrBy ( DWORD dwDst,
int  iBy 
)
inline

Definition at line 82 of file StdColors.h.

83 {
84  // enlight a color
85  // quite a desaturating method...
86  dwDst = std::min<int>((dwDst & 0xff) + iBy, 255) | // blue
87  std::min<int>((dwDst>> 8 & 0xff) + iBy, 255) << 8 | // green
88  std::min<int>((dwDst>>16 & 0xff) + iBy, 255) << 16 | // red
89  (dwDst & 0xff000000); // alpha
90  return dwDst;
91 }

Referenced by PlrClr2TxtClr().

Here is the caller graph for this function:

◆ ModulateClr()

void ModulateClr ( DWORD dwDst,
DWORD  dwMod 
)
inline

Definition at line 53 of file StdColors.h.

54 {
55  // modulate two color values
56  // get alpha
57  int iA1=dwDst>>24, iA2=dwMod>>24;
58  // modulate color values; mod alpha upwards
59  dwDst = ((dwDst & 0xff) * (dwMod & 0xff) / 0xff) | // blue
60  ((dwDst>> 8 & 0xff) * (dwMod>> 8 & 0xff) / 0xff) << 8 | // green
61  ((dwDst>>16 & 0xff) * (dwMod>>16 & 0xff) / 0xff) << 16| // red
62  std::min(iA1*iA2/0xff, 255) << 24; // alpha (TODO: We don't need std::min() here, do we?)
63 }

Referenced by CStdFont::DrawText(), and C4Surface::GetPixDw().

Here is the caller graph for this function:

◆ ModulateClrA()

void ModulateClrA ( DWORD dwDst,
DWORD  dwMod 
)
inline

Definition at line 65 of file StdColors.h.

66 {
67  // modulate two color values and add alpha value
68  dwDst = ((dwDst & 0xff) * (dwMod & 0xff) / 0xff) | // B
69  ((dwDst>> 8 & 0xff) * (dwMod>> 8 & 0xff) / 0xff) << 8 | // G
70  ((dwDst>>16 & 0xff) * (dwMod>>16 & 0xff) / 0xff) << 16| // R
71  (std::max<uint32_t>((dwDst>>24)+(dwMod>>24), 0xff) - 0xff)<<24;
72 }

Referenced by CStdFont::DrawText().

Here is the caller graph for this function:

◆ ModulateClrMOD2()

void ModulateClrMOD2 ( DWORD dwDst,
DWORD  dwMod 
)
inline

Definition at line 73 of file StdColors.h.

74 {
75  // signed color addition
76  dwDst = (Clamp<int>(((int)(dwDst&0xff)+(dwMod&0xff)-0x7f)<<1,0,0xff)&0xff) | // B
77  (Clamp<int>(((int)(dwDst&0xff00)+(dwMod&0xff00)-0x7f00)<<1,0,0xff00)&0xff00) | // G
78  (Clamp<int>(((int)(dwDst&0xff0000)+(dwMod&0xff0000)-0x7f0000)<<1,0,0xff0000)&0xff0000) | // R
79  (std::max<uint32_t>((dwDst>>24)+(dwMod>>24), 0xff) - 0xff)<<24;
80 }

Referenced by C4Surface::GetPixDw().

Here is the caller graph for this function:

◆ PlrClr2TxtClr()

DWORD PlrClr2TxtClr ( DWORD  dwClr)
inline

Definition at line 104 of file StdColors.h.

105 {
106  // convert player color to text color, lightening up when necessary
107  int lgt=std::max(std::max(GetRedValue(dwClr), GetGreenValue(dwClr)), GetBlueValue(dwClr));
108  if (lgt<0x8f) LightenClrBy(dwClr, 0x8f-lgt);
109  return dwClr|0xff000000;
110 }
#define GetRedValue(rgb)
Definition: StdColors.h:29
#define GetGreenValue(rgb)
Definition: StdColors.h:28
DWORD LightenClrBy(DWORD &dwDst, int iBy)
Definition: StdColors.h:82
#define GetBlueValue(rgb)
Definition: StdColors.h:27

References GetBlueValue, GetGreenValue, GetRedValue, and LightenClrBy().

Referenced by C4MessageBoard::Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RGB2rgb()

bool RGB2rgb ( int  R,
int  G,
int  B,
double *  pr,
double *  pg,
double *  pb,
double  gamma = 2.2 
)
inline

Definition at line 175 of file StdColors.h.

176 {
177  *pr = pow((double) R / 255.0, 1.0/gamma);
178  *pg = pow((double) G / 255.0, 1.0/gamma);
179  *pb = pow((double) B / 255.0, 1.0/gamma);
180  return true;
181 }

Referenced by IsColorConflict().

Here is the caller graph for this function:

◆ rgb2xyY()

bool rgb2xyY ( double  r,
double  g,
double  b,
double *  px,
double *  py,
double *  pY 
)
inline

Definition at line 148 of file StdColors.h.

149 {
150  double X = 0.412453*r + 0.357580*g + 0.180423*b;
151  double Y = 0.212671*r + 0.715160*g + 0.072169*b;
152  double Z = 0.019334*r + 0.119193*g + 0.950227*b;
153  double XYZ=X+Y+Z;
154  if (!XYZ)
155  {
156  *px=*py=0.3; // assume grey cromaticity for black
157  }
158  else
159  {
160  *px = X/XYZ; *py = Y/XYZ;
161  }
162  *pY = Y;
163  return true;
164 }
#define X(sdl, oc)
#define b

References b, and X.

Referenced by IsColorConflict().

Here is the caller graph for this function:

◆ RGBA()

uint32_t RGBA ( uint32_t  r,
uint32_t  g,
uint32_t  b,
uint32_t  a 
)
inline

Definition at line 22 of file StdColors.h.

23 {
24  return ((a & 255) << 24) | ((r & 255) << 16) | ((g & 255) << 8) | (b & 255);
25 }
#define a

References a, and b.

Referenced by CStdFont::AddRenderedChar(), ClrByOwner(), GetClrModulation(), CPNGFile::GetPix(), C4Draw::Grayscale(), and C4LandscapeRenderGL::Update().

Here is the caller graph for this function:

◆ xy2upvp()

bool xy2upvp ( double  x,
double  y,
double *  pu,
double *  pv 
)
inline

Definition at line 166 of file StdColors.h.

167 {
168  double n = -2.0*x+12.0*y+3.0;
169  if (!n) return false;
170  *pu = 4.0*x / n;
171  *pv = 9.0*y / n;
172  return true;
173 }

Referenced by IsColorConflict().

Here is the caller graph for this function: