Skip to content

Commit

Permalink
Add LXColor16 class; move the LXColor.Blend enum to BlendMode.
Browse files Browse the repository at this point in the history
  • Loading branch information
zestyping committed Apr 20, 2018
1 parent 2e67b97 commit dada6db
Show file tree
Hide file tree
Showing 4 changed files with 650 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/heronarts/lx/LXLayeredComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package heronarts.lx;

import heronarts.lx.color.BlendMode;
import heronarts.lx.color.LXColor;
import heronarts.lx.color.LXPalette;
import heronarts.lx.model.LXFixture;
Expand Down Expand Up @@ -177,12 +178,12 @@ protected final LXLayeredComponent setColor(int i, int c) {
*
* @return this
*/
protected final LXLayeredComponent blendColor(int i, int c, LXColor.Blend blendMode) {
protected final LXLayeredComponent blendColor(int i, int c, BlendMode blendMode) {
this.colors[i] = LXColor.blend(this.colors[i], c, blendMode);
return this;
}

protected final LXLayeredComponent blendColor(LXFixture f, int c, LXColor.Blend blendMode) {
protected final LXLayeredComponent blendColor(LXFixture f, int c, BlendMode blendMode) {
for (LXPoint p : f.getPoints()) {
this.colors[p.index] = LXColor.blend(this.colors[p.index], c, blendMode);
}
Expand Down
14 changes: 14 additions & 0 deletions src/heronarts/lx/color/BlendMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package heronarts.lx.color;

/**
* Color blending modes
*/
public enum BlendMode {
LERP,
ADD,
SUBTRACT,
MULTIPLY,
SCREEN,
LIGHTEST,
DARKEST
}
33 changes: 16 additions & 17 deletions src/heronarts/lx/color/LXColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,9 @@

import java.awt.Color;

/**
* Various utilities that operate on color values
*/
/** Various utilities that operate on 32-bit integers representing RGBA colors */
public class LXColor {

/**
* Color blending modes
*/
public enum Blend {
LERP,
ADD,
SUBTRACT,
MULTIPLY,
SCREEN,
LIGHTEST,
DARKEST
}

public static final int BLACK = 0xff000000;
public static final int WHITE = 0xffffffff;
public static final int RED = 0xffff0000;
Expand Down Expand Up @@ -71,6 +56,20 @@ public static byte blue(int argb) {
return (byte) (argb & BLUE_MASK);
}

public static long toLong(int argb) {
// If we were to shift left by 8, then 0xff would become 0xff00.
// Instead, we multiply by 0x0101, so that 0xff becomes 0xffff.
return LXColor16.rgba(
(int) red(argb) * 0x0101,
(int) green(argb) * 0x0101,
(int) blue(argb) * 0x0101,
(int) alpha(argb) * 0x0101);
}

public static void intsToLongs(int[] ints, long[] longs) {
for (int i = 0; i < ints.length; i++) longs[i] = toLong(ints[i]);
}

/**
* Hue of a color from 0-360
*
Expand Down Expand Up @@ -390,7 +389,7 @@ public static float[] RGBtoHSB(int rgb, float[] hsb) {
* @param blendMode Type of blending
* @return Blended color
*/
public static int blend(int c1, int c2, Blend blendMode) {
public static int blend(int c1, int c2, BlendMode blendMode) {
switch (blendMode) {
case ADD:
return add(c1, c2);
Expand Down
Loading

0 comments on commit dada6db

Please sign in to comment.