Beatmup Java package
Beatmup.Imaging.Color Class Reference

Integer RGBA color value. More...

Public Member Functions

 Color ()
 Creates a zero-valued color. More...
 
 Color (int r, int g, int b, int a)
 Creates a color by aggregating the four channels values components. More...
 
 Color (int code)
 Constructs a color from its integer code. More...
 
int getRgbaCode ()
 
Color scale (float factorRGB, float factorAlpha)
 Returns a scaled version of the current color by given factors. More...
 

Static Public Member Functions

static Color parseString (String expr) throws IllegalArgumentException
 Builds a color from a string. More...
 
static Color byHue (float hueDegrees)
 Returns a fully saturated color from its hue. More...
 

Public Attributes

int r
 red More...
 
int g
 green More...
 
int b
 blue More...
 
int a
 alpha More...
 

Static Public Attributes

static final Color TRANSPARENT_BLACK = new Color(0, 0, 0, 0)
 Predefined color constants. More...
 

Detailed Description

Integer RGBA color value.

Definition at line 24 of file Color.java.

Constructor & Destructor Documentation

◆ Color() [1/3]

Beatmup.Imaging.Color.Color ( )
inline

Creates a zero-valued color.

Definition at line 33 of file Color.java.

33  {
34  r = g = b = a = 0;
35  }

◆ Color() [2/3]

Beatmup.Imaging.Color.Color ( int  r,
int  g,
int  b,
int  a 
)
inline

Creates a color by aggregating the four channels values components.

Parameters
rthe red channel value
gthe green channel value
bthe blue channel value
athe alpha channel value

Definition at line 44 of file Color.java.

44  {
45  this.r = r;
46  this.g = g;
47  this.b = b;
48  this.a = a;
49  // This constructor is called by JNI, do not remove it.
50  }

◆ Color() [3/3]

Beatmup.Imaging.Color.Color ( int  code)
inline

Constructs a color from its integer code.

Parameters
codeThe integer code.

Definition at line 56 of file Color.java.

56  {
57  b = code % 256;
58  g = (code >> 8) % 256;
59  r = (code >> 16) % 256;
60  a = (code >> 24) % 256;
61  }

Member Function Documentation

◆ getRgbaCode()

int Beatmup.Imaging.Color.getRgbaCode ( )
inline
Returns
the integer code of the current color.

Definition at line 66 of file Color.java.

66  {
67  return r | g << 8 | b << 16 | a << 24;
68  }

◆ parseString()

static Color Beatmup.Imaging.Color.parseString ( String  expr) throws IllegalArgumentException
inlinestatic

Builds a color from a string.

Accepts hexadecimal RGB and RGBA notations like "7f7f7f", "7f7f7fFF" (case-insensitive) and a comma-separed list of 3 or 4 decimal integer values like "127,127,127,255".

Parameters
exprThe string expression
Returns
the corresponding color. If cannot parsem throws an exception.

Definition at line 76 of file Color.java.

76  {
77  // hex notation
78  if (expr.matches("(\\d|[a-fA-F]){6}")) {
79  Color c = new Color(Integer.parseInt(expr, 16));
80  c.a = 255;
81  return c;
82  }
83  if (expr.matches("(\\d|[a-fA-F]){8}"))
84  return new Color(Integer.parseInt(expr, 16));
85  // comma split notation
86  String vals[] = expr.split(",");
87  if (vals.length != 3 && vals.length != 4)
88  throw new IllegalArgumentException("Cannot parse color from expression '" +expr+ "'");
89  return new Color(
90  Integer.parseInt(vals[0]),
91  Integer.parseInt(vals[1]),
92  Integer.parseInt(vals[2]),
93  vals.length > 3 ? Integer.parseInt(vals[3]) : 255
94  );
95  }
Color()
Creates a zero-valued color.
Definition: Color.java:33

◆ scale()

Color Beatmup.Imaging.Color.scale ( float  factorRGB,
float  factorAlpha 
)
inline

Returns a scaled version of the current color by given factors.

Parameters
factorRGBThe color components scaling factor
factorAlphaThe alpha component scaling factor
Returns
the scaled color value. The current instance of Color is not changed.

Definition at line 103 of file Color.java.

103  {
104  return new Color(
105  Math.round(r * factorRGB),
106  Math.round(g * factorRGB),
107  Math.round(b * factorRGB),
108  Math.round(a * factorAlpha)
109  );
110  }

◆ byHue()

static Color Beatmup.Imaging.Color.byHue ( float  hueDegrees)
inlinestatic

Returns a fully saturated color from its hue.

Parameters
hueDegreesThe hue in degrees.
Returns
the color having the given hue.

Definition at line 117 of file Color.java.

117  {
118  final double
119  SQRT3 = 1.732050807568877,
120  hue = Math.toRadians(hueDegrees),
121  r = Math.max(0, (2 * Math.cos(hue) + 1) / 3),
122  g = Math.max(0, (SQRT3 * Math.sin(hue) - Math.cos(hue) + 1) / 3),
123  b = Math.max(0, (1 - SQRT3 * Math.sin(hue) - Math.cos(hue)) / 3),
124  norm = Math.max(r, Math.max(g, b));
125  return new Color(
126  (int) Math.floor(255 * r / norm),
127  (int) Math.floor(255 * g / norm),
128  (int) Math.floor(255 * b / norm),
129  255
130  );
131  }

Member Data Documentation

◆ r

int Beatmup.Imaging.Color.r

red

Definition at line 25 of file Color.java.

◆ g

int Beatmup.Imaging.Color.g

green

Definition at line 26 of file Color.java.

◆ b

int Beatmup.Imaging.Color.b

blue

Definition at line 27 of file Color.java.

◆ a

int Beatmup.Imaging.Color.a

alpha

Definition at line 28 of file Color.java.

◆ TRANSPARENT_BLACK

final Color Beatmup.Imaging.Color.TRANSPARENT_BLACK = new Color(0, 0, 0, 0)
static

Predefined color constants.

Definition at line 137 of file Color.java.


The documentation for this class was generated from the following file: