First commit

Former-commit-id: 9340873f9cfb15264004c32d6e4b8f8bd6828d94
Former-commit-id: 1916747c109876aa064412e01204c3aeda9bbbc0
This commit is contained in:
Song Minjae
2016-02-05 13:36:35 +09:00
commit d5c99aad5e
1340 changed files with 298157 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package com.Torvald.ColourUtil;
import org.newdawn.slick.Color;
/**
* Created by minjaesong on 16-01-23.
*/
public class Col12 {
private short data;
/**
* Create new Col12 format
* @param data 0x000-0xFFF, in RGB
*/
public Col12(int data) {
this.data = (short) data;
}
public Color create(int i) {
if (i > 0xFFF || i < 0) {
throw new IllegalArgumentException("Colour range: #000 - #FFF");
}
int r = (i & 0xF00) >> 8;
int g = (i & 0x0F0) >> 4;
int b = i & 0x00F;
return new Color(
(r << 4) | r
, (g << 4) | g
, (b << 4) | b
);
}
public byte[] toByteArray() {
byte[] ret = new byte[3];
int r = (data & 0xF00) >> 8;
int g = (data & 0x0F0) >> 4;
int b = data & 0x00F;
ret[0] = (byte) ((r << 4) | r);
ret[1] = (byte) ((g << 4) | g);
ret[2] = (byte) ((b << 4) | b);
return ret;
}
}

View File

@@ -0,0 +1,76 @@
package com.Torvald.ColourUtil;
import com.jme3.math.FastMath;
import org.newdawn.slick.Color;
/**
* Created by minjaesong on 16-01-16.
*/
public class HSV {
/**
* Convert HSV parameters to RGB color.
* @param h 0-359 Hue
* @param s 0-255 Saturation
* @param v 0-255 Value
* @return org.newdawn.slick.Color
* @link http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
*/
public static Color toRGB(int h, int s, int v) {
int H = h;
if (H < 0 || H >= 360) {
H %= 360;
}
float S = s / 255f;
float V = v / 255f;
float C = V * S;
float X = C * (1 - FastMath.abs(
(H / 60f) % 2 - 1
));
float m = V - C;
float R_prime = Float.NaN;
float G_prime = Float.NaN;
float B_prime = Float.NaN;
if (H < 60) {
R_prime = C;
G_prime = X;
B_prime = 0;
}
else if (H < 120) {
R_prime = X;
G_prime = C;
B_prime = 0;
}
else if (H < 180) {
R_prime = 0;
G_prime = C;
B_prime = X;
}
else if (H < 240) {
R_prime = 0;
G_prime = X;
B_prime = C;
}
else if (H < 300) {
R_prime = X;
G_prime = 0;
B_prime = C;
}
else if (H < 360) {
R_prime = C;
G_prime = 0;
B_prime = X;
}
return new Color(
(int) ((R_prime + m) * 255)
, (int) ((G_prime + m) * 255)
, (int) ((B_prime + m) * 255)
);
}
}