OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Teams.cpp File Reference
#include "C4Include.h"
#include "control/C4Teams.h"
#include "game/C4Game.h"
#include "lib/C4Random.h"
#include "c4group/C4Components.h"
#include "player/C4Player.h"
#include "player/C4PlayerList.h"
#include "control/C4GameControl.h"
Include dependency graph for C4Teams.cpp:

Go to the source code of this file.

Functions

DWORD GenerateRandomPlayerColor (int32_t iTry)
 
bool IsColorConflict (DWORD dwClr1, DWORD dwClr2)
 

Function Documentation

DWORD GenerateRandomPlayerColor ( int32_t  iTry)

Definition at line 33 of file C4PlayerInfoConflicts.cpp.

Referenced by C4Team::RecheckColor().

34 {
35  // generate a random one biased towards max channel luminance
36  // (for greater color difference and less gray-ish colors)
37  return C4RGB(std::min<int>(UnsyncedRandom(302), 256), std::min<int>(UnsyncedRandom(302), 256), std::min<int>(UnsyncedRandom(302), 256));
38 }
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
#define C4RGB(r, g, b)
Definition: StdColors.h:28

Here is the caller graph for this function:

bool IsColorConflict ( DWORD  dwClr1,
DWORD  dwClr2 
)

Definition at line 40 of file C4PlayerInfoConflicts.cpp.

Referenced by C4Team::RecheckColor().

41 {
42  // NEW COLOR CONFLICT METHOD: u'v'-distance
43  int R1 = 0xff & (dwClr1 >> 16);
44  int G1 = 0xff & (dwClr1 >> 8);
45  int B1 = 0xff & (dwClr1 );
46  int R2 = 0xff & (dwClr2 >> 16);
47  int G2 = 0xff & (dwClr2 >> 8);
48  int B2 = 0xff & (dwClr2 );
49  double r1=0,g1=0,b1=0,r2=0,g2=0,b2=0,x1=0,y1=0,Y1=0,x2=0,y2=0,Y2=0,u1=0,v1=0,u2=0,v2=0;
50  RGB2rgb(R1, G1, B1, &r1, &g1, &b1);
51  RGB2rgb(R2, G2, B2, &r2, &g2, &b2);
52  rgb2xyY(r1, g1, b1, &x1, &y1, &Y1);
53  rgb2xyY(r2, g2, b2, &x2, &y2, &Y2);
54  xy2upvp(x1, y1, &u1, &v1);
55  xy2upvp(x2, y2, &u2, &v2);
56  double Y = (Y1+Y2)/2.0;
57  double clrdiff = sqrt((u2-u1)*(u2-u1) + (v2-v1)*(v2-v1)) * Y*Y * 150;
58  double lumdiff = (Abs<double>(Y2-Y1) / std::max<double>(Y*Y*5, 0.5)) / 0.10;
59  return clrdiff + lumdiff < 1.0;
60 }
bool xy2upvp(double x, double y, double *pu, double *pv)
Definition: StdColors.h:166
bool rgb2xyY(double r, double g, double b, double *px, double *py, double *pY)
Definition: StdColors.h:148
bool RGB2rgb(int R, int G, int B, double *pr, double *pg, double *pb, double gamma=2.2)
Definition: StdColors.h:175

Here is the caller graph for this function: