package exnihiloadscensio.texturing;

public class Color {

	public float r;
	public float g;
	public float b;
	public float a;

	public Color(float red, float green, float blue, float alpha)
	{
		this.r = red;
		this.g = green;
		this.b = blue;
		this.a = alpha;
	}

	public Color (int color)
	{
		//stupid minecraft color is RGB not ARGB.
		//need to simulate the Alpha value.
		//this.a = (float) (color >> 24 & 255) / 255.0F;
		this(color, true);
	}

	public Color (int color, boolean ignoreAlpha)
	{
		if (ignoreAlpha)
		{
			this.a = 1.0f;
			this.r = (float) (color >> 16 & 255) / 255.0F;
			this.g = (float) (color >> 8 & 255) / 255.0F;
			this.b = (float) (color & 255) / 255.0F;
		}
		else
		{
			this.a = (float) (color >> 24 & 255) / 255.0F;
			this.r = (float) (color >> 16 & 255) / 255.0F;
			this.g = (float) (color >> 8 & 255) / 255.0F;
			this.b = (float) (color & 255) / 255.0F;
		}
	}

	public Color (String hex)
	{
		this(Integer.parseInt(hex, 16));
	}

	public int toInt()
	{
		int color = 0;
		color |= (int)(this.a * 255) << 24;
		color |= (int)(this.r * 255) << 16;
		color |= (int)(this.g * 255) << 8;
		color |= (int)(this.b * 255);
		return color;
	}

	public static Color average(Color colorA, Color colorB, float percentage)
	{
		float avgR = colorA.r + (colorB.r - colorA.r) * percentage;
		float avgG = colorA.g + (colorB.g - colorA.g) * percentage;
		float avgB = colorA.b + (colorB.b - colorA.b) * percentage;
		float avgA = colorA.a + (colorB.a - colorA.a) * percentage;

		return new Color(avgR, avgG, avgB, avgA);
	}

}

@@ -1255,30 +1255,147 @@
 %09%7B%0A%09
-%09float avgR = colorA.r
+    float opposite = 1 - percentage;%0A%09    //Gamma correction%0A%0A        float averageR = (float) Math.sqrt((colorA.r * colorA.r) * (opposite)
  + (
@@ -1407,22 +1407,23 @@
 B.r 
--
+*
  color
-A
+B
 .r) * 
+(
 perc
@@ -1432,33 +1432,89 @@
 tage
-;%0A%09%09float avgG = colorA.g
+));%0A        float averageG = (float) Math.sqrt((colorA.g * colorA.g) * (opposite)
  + (
@@ -1524,24 +1524,25 @@
 orB.
-g -
+r *
  color
-A
+B
 .g) * 
+(
 perc
@@ -1551,33 +1551,89 @@
 tage
-;%0A%09%09float avgB = colorA.b
+));%0A        float averageB = (float) Math.sqrt((colorA.b * colorA.b) * (opposite)
  + (
@@ -1643,24 +1643,25 @@
 orB.
-b -
+r *
  color
-A
+B
 .b) * 
+(
 perc
@@ -1670,20 +1670,25 @@
 tage
+))
 ;%0A%09
-%09
+    
 float av
 gA =
@@ -1683,17 +1683,21 @@
 float av
-g
+erage
 A = colo
@@ -1705,31 +1705,29 @@
 A.a 
-+ (colorB.a -
+* opposite +
  color
-A
+B
 .a
-)
  * p
@@ -1737,16 +1737,24 @@
 entage;%0A
+        
 %0A%09%09retur
@@ -1771,27 +1771,43 @@
 r(av
-gR, avgG, avgB, avg
+erageR, averageG, averageB, average
 A);%0A

Make color blending take gamma into account