OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Surface.cpp File Reference
#include "C4Include.h"
#include "C4ForbidLibraryCompilation.h"
#include "graphics/C4Surface.h"
#include "platform/StdFile.h"
#include "c4group/CStdFile.h"
#include "platform/C4App.h"
#include "graphics/C4DrawGL.h"
#include "platform/C4Window.h"
#include "platform/StdRegistry.h"
#include "graphics/C4Draw.h"
#include "graphics/Bitmap256.h"
#include "graphics/StdPNG.h"
#include "config/C4Config.h"
#include "lib/StdColors.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <list>
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 210 of file C4Surface.cpp.

Referenced by ClrByOwner().

#define RANGE   255

Definition at line 209 of file C4Surface.cpp.

#define RGBMAX   255

Definition at line 211 of file C4Surface.cpp.

Referenced by ClrByOwner().

Function Documentation

bool ClrByOwner ( DWORD dwClr)

Definition at line 213 of file C4Surface.cpp.

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

Referenced by C4Surface::CreateColorByOwner().

214 {
215  int H,L,S;
216  WORD R,G,B;
217  BYTE cMax,cMin;
218  WORD Rdelta,Gdelta,Bdelta;
219  // get RGB
220  R = GetRedValue(dwClr);
221  G = GetGreenValue(dwClr);
222  B = GetBlueValue(dwClr);
223  // calculate lightness
224  cMax = std::max<int>(std::max<int>(R,G),B);
225  cMin = std::min<int>(std::min<int>(R,G),B);
226  L = ( ((cMax+cMin)*HLSMAX) + RGBMAX )/(2*RGBMAX);
227  // achromatic case
228  if (cMax == cMin)
229  {
230  S = 0;
231  H = (HLSMAX*2/3);
232  }
233  // chromatic case
234  else
235  {
236  // saturation
237  if (L <= (HLSMAX/2))
238  S = ( ((cMax-cMin)*HLSMAX) + ((cMax+cMin)/2) ) / (cMax+cMin);
239  else
240  S = ( ((cMax-cMin)*HLSMAX) + ((2*RGBMAX-cMax-cMin)/2) )
241  / (2*RGBMAX-cMax-cMin);
242  // hue
243  Rdelta = ( ((cMax-R)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
244  Gdelta = ( ((cMax-G)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
245  Bdelta = ( ((cMax-B)*(HLSMAX/6)) + ((cMax-cMin)/2) ) / (cMax-cMin);
246  if (R == cMax)
247  H = Bdelta - Gdelta;
248  else if (G == cMax)
249  H = (HLSMAX/3) + Rdelta - Bdelta;
250  else
251  H = ((2*HLSMAX)/3) + Gdelta - Rdelta;
252  if (H < 0)
253  H += HLSMAX;
254  if (H > HLSMAX)
255  H -= HLSMAX;
256  }
257  // Not blue
258  if (!(Inside(H, 145, 175) && (S > 100))) return false;
259  // It's blue: make it gray
260  BYTE b = GetBlueValue(dwClr);
261  dwClr = RGBA(b, b, b, 0) | (dwClr & 0xff000000);
262  return true;
263 }
#define GetGreenValue(rgb)
Definition: StdColors.h:30
#define b
uint8_t BYTE
#define GetRedValue(rgb)
Definition: StdColors.h:31
#define GetBlueValue(rgb)
Definition: StdColors.h:29
#define HLSMAX
Definition: C4Surface.cpp:210
#define RGBMAX
Definition: C4Surface.cpp:211
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:24
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:45
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 449 of file C4Surface.cpp.

References Abs().

450 {
451  return (double) (Abs(bpRGB1[0]-bpRGB2[0]) + Abs(bpRGB1[1]-bpRGB2[1]) + Abs(bpRGB1[2]-bpRGB2[2])) / 6.0;
452 }
T Abs(T val)
Definition: Standard.h:44

Here is the call graph for this function:

Variable Documentation

C4TexMgr* pTexMgr

Definition at line 890 of file C4Surface.cpp.

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