OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Surface.cpp File Reference
Include dependency graph for C4Surface.cpp:

Go to the source code of this file.

Macros

#define RANGE   255
 
#define HLSMAX   RANGE
 
#define RGBMAX   255
 

Functions

bool ClrByOwner (DWORD &dwClr)
 
double ColorDistance (BYTE *bpRGB1, BYTE *bpRGB2)
 

Variables

C4TexMgrpTexMgr
 

Macro Definition Documentation

#define HLSMAX   RANGE

Definition at line 200 of file C4Surface.cpp.

Referenced by ClrByOwner().

#define RANGE   255

Definition at line 199 of file C4Surface.cpp.

#define RGBMAX   255

Definition at line 201 of file C4Surface.cpp.

Referenced by ClrByOwner().

Function Documentation

bool ClrByOwner ( DWORD dwClr)

Definition at line 203 of file C4Surface.cpp.

References b, GetBlueValue, GetGreenValue, GetRedValue, HLSMAX, Inside(), RGBA(), and RGBMAX.

Referenced by C4Surface::CreateColorByOwner().

204 {
205  int H,L,S;
206  WORD R,G,B;
207  BYTE cMax,cMin;
208  WORD Rdelta,Gdelta,Bdelta;
209  // get RGB
210  R = GetRedValue(dwClr);
211  G = GetGreenValue(dwClr);
212  B = GetBlueValue(dwClr);
213  // calculate lightness
214  cMax = std::max<int>(std::max<int>(R,G),B);
215  cMin = std::min<int>(std::min<int>(R,G),B);
216  L = ( ((cMax+cMin)*HLSMAX) + RGBMAX )/(2*RGBMAX);
217  // achromatic case
218  if (cMax == cMin)
219  {
220  S = 0;
221  H = (HLSMAX*2/3);
222  }
223  // chromatic case
224  else
225  {
226  // saturation
227  if (L <= (HLSMAX/2))
228  S = ( ((cMax-cMin)*HLSMAX) + ((cMax+cMin)/2) ) / (cMax+cMin);
229  else
230  S = ( ((cMax-cMin)*HLSMAX) + ((2*RGBMAX-cMax-cMin)/2) )
231  / (2*RGBMAX-cMax-cMin);
232  // hue
233  Rdelta = ( ((cMax-R)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
234  Gdelta = ( ((cMax-G)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
235  Bdelta = ( ((cMax-B)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
236  if (R == cMax)
237  H = Bdelta - Gdelta;
238  else if (G == cMax)
239  H = (HLSMAX/3) + Rdelta - Bdelta;
240  else
241  H = ((2*HLSMAX)/3) + Gdelta - Rdelta;
242  if (H < 0)
243  H += HLSMAX;
244  if (H > HLSMAX)
245  H -= HLSMAX;
246  }
247  // Not blue
248  if (!(Inside(H, 145, 175) && (S > 100))) return false;
249  // It's blue: make it gray
250  BYTE b = GetBlueValue(dwClr);
251  dwClr = RGBA(b, b, b, 0) | (dwClr & 0xff000000);
252  return true;
253 }
#define GetGreenValue(rgb)
Definition: StdColors.h:28
#define b
uint8_t BYTE
#define GetRedValue(rgb)
Definition: StdColors.h:29
#define GetBlueValue(rgb)
Definition: StdColors.h:27
#define HLSMAX
Definition: C4Surface.cpp:200
#define RGBMAX
Definition: C4Surface.cpp:201
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:22
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43
uint16_t WORD

Here is the call graph for this function:

Here is the caller graph for this function:

double ColorDistance ( BYTE bpRGB1,
BYTE bpRGB2 
)

Definition at line 439 of file C4Surface.cpp.

References Abs().

440 {
441  return (double) (Abs(bpRGB1[0]-bpRGB2[0]) + Abs(bpRGB1[1]-bpRGB2[1]) + Abs(bpRGB1[2]-bpRGB2[2])) / 6.0;
442 }
T Abs(T val)
Definition: Standard.h:42

Here is the call graph for this function:

Variable Documentation

C4TexMgr* pTexMgr

Definition at line 880 of file C4Surface.cpp.

Referenced by C4TexRef::C4TexRef(), C4TexMgr::UnregTex(), and C4TexRef::~C4TexRef().