OpenClonk
C4Teams.cpp File Reference
#include "C4Include.h"
#include "control/C4Teams.h"
#include "c4group/C4Components.h"
#include "control/C4GameControl.h"
#include "lib/C4Random.h"
#include "player/C4Player.h"
#include "player/C4PlayerList.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

◆ GenerateRandomPlayerColor()

DWORD GenerateRandomPlayerColor ( int32_t  iTry)

Definition at line 32 of file C4PlayerInfoConflicts.cpp.

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

Referenced by C4Team::RecheckColor().

Here is the caller graph for this function:

◆ IsColorConflict()

bool IsColorConflict ( DWORD  dwClr1,
DWORD  dwClr2 
)

Definition at line 39 of file C4PlayerInfoConflicts.cpp.

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

Referenced by C4Team::RecheckColor().

Here is the caller graph for this function: