private void btnUpdatexyY_Click(object sender, RoutedEventArgs e) { SetOutOfGamut(false); double x = double.Parse(txtxyY_x.Text); double y = double.Parse(txtxyY_y.Text); double Y = double.Parse(txtxyY_Y.Text); xyYColour xyYCol = xyYColour.FromxyY(x, y, Y); XYZColour xyzColour = xyYCol.ToXYZColour(); RGBColour rgbColour = ColourUtil.XYZTosRGB(xyzColour); txtR.Text = rgbColour.R.ToString(); txtG.Text = rgbColour.G.ToString(); txtB.Text = rgbColour.B.ToString(); txtXYZ_X.Text = xyzColour.X.ToString(); txtXYZ_Y.Text = xyzColour.Y.ToString(); txtXYZ_Z.Text = xyzColour.Z.ToString(); Color newColourForRectangle = Color.FromRgb((byte)rgbColour.R, (byte)rgbColour.G, (byte)rgbColour.B); SolidColorBrush brush = new SolidColorBrush(newColourForRectangle); rectColour.Fill = brush; SetOutOfGamut(rgbColour.OutOfGamut); }
public static void GetInfluence(xyYColour pK, xyYColour pA, xyYColour pB, xyYColour pC, out double influenceA, out double influenceB, out double influenceC) { //1. Get the 3 delta's (Euclidian distance) A, B, C from point K to point pA, pB, pC double deltaA = ColourUtil.Delta3D(pK.x, pK.y, pK.Y, pA.x, pA.y, pA.Y, 8); double deltaB = ColourUtil.Delta3D(pK.x, pK.y, pK.Y, pB.x, pB.y, pB.Y, 8); double deltaC = ColourUtil.Delta3D(pK.x, pK.y, pK.Y, pC.x, pC.y, pC.Y, 8); //2. Inverse each distance and call invA, invB, invC double inverseA = 1 / deltaA; double inverseB = 1 / deltaB; double inverseC = 1 / deltaC; //3. Let t = invA + invB + invC double total = inverseA + inverseB + inverseC; //4. divide each invA invB and invC by t. This yields the resulting influence ia, ib, ic influenceA = inverseA / total; influenceB = inverseB / total; influenceC = inverseC / total; }
private void btnUpdateRGB_Click(object sender, RoutedEventArgs e) { SetOutOfGamut(false); double r = double.Parse(txtR.Text); double g = double.Parse(txtG.Text); double b = double.Parse(txtB.Text); RGBColour rgb = RGBColour.FromRGB(r, g, b); XYZColour xyzcColour = ColourUtil.RGBtoXYZ(rgb); xyYColour xyYCol = xyYColour.FromXYZ(xyzcColour); txtXYZ_X.Text = xyzcColour.X.ToString(); txtXYZ_Y.Text = xyzcColour.Y.ToString(); txtXYZ_Z.Text = xyzcColour.Z.ToString(); txtxyY_x.Text = xyYCol.x.ToString(); txtxyY_y.Text = xyYCol.y.ToString(); txtxyY_Y.Text = xyYCol.Y.ToString(); Color newColourForRectangle = Color.FromRgb((byte)r, (byte)g, (byte)b); SolidColorBrush brush = new SolidColorBrush(newColourForRectangle); rectColour.Fill = brush; }
private Color GetColorFromXYY(xyYColour xyy) { XYZColour xyz = xyy.ToXYZColour(); RGBColour rgb = ColourUtil.XYZTosRGB(xyz); Color color = Color.FromRgb((byte)rgb.R, (byte)rgb.G, (byte)rgb.B); return(color); }
private bool IsOutOfGamut(xyYColour xyy) { double x = Math.Round(xyy.x, 5, MidpointRounding.ToEven); double y = Math.Round(xyy.y, 5, MidpointRounding.ToEven); xyYColour temp = xyYColour.FromxyY(x, y, xyy.Y); XYZColour xyz = temp.ToXYZColour(); RGBColour rgb = ColourUtil.XYZTosRGB(xyz); return(rgb.OutOfGamut); }
private Color GetColorFromXYY(xyYColour xyy) { double x = Math.Round(xyy.x, 5, MidpointRounding.ToEven); double y = Math.Round(xyy.y, 5, MidpointRounding.ToEven); xyYColour temp = xyYColour.FromxyY(x, y, xyy.Y); XYZColour xyz = temp.ToXYZColour(); RGBColour rgb = ColourUtil.XYZTosRGB(xyz); Color color = Color.FromArgb(0, (byte)rgb.R, (byte)rgb.G, (byte)rgb.B); return(color); }
public static double GetAvgDistanceForPerceptualLikeness(xyYColour xyYControlCol, IDictionary <double, xyYColour> averagedColours) { double distAvg = 0; foreach (var avgColour in averagedColours) { distAvg += ColourUtil.Delta3D(avgColour.Value.x, avgColour.Value.y, 0, xyYControlCol.x, xyYControlCol.y, 0, 4); } return(distAvg / 8); }
public static xyYColour GetClosestAngleColour(ColourAngleSet angleSet, double angle) { xyYColour closestAngleColour = null; //TODO: Increase accuracy only if this whole colour system seems to be working foreach (var colourAtAngle in angleSet) { if (ColourUtil.Delta(angle, colourAtAngle.Key) <= 45) { closestAngleColour = colourAtAngle.Value; } } return(closestAngleColour); }
public static IEnumerable <xyYColour> GetThreeClosestColours(xyYColour refColour, ObserverData observer) { var closest = new List <xyYColour>(); var orderedByDistance = observer.ColourData.Select(kvp => new { Colour = kvp.Key, Distance = ColourUtil.Delta3D(refColour.x, refColour.y, refColour.Y, kvp.Key.x, kvp.Key.y, kvp.Key.Y, 8) }); orderedByDistance = orderedByDistance.OrderBy(item => item.Distance); return(orderedByDistance.Take(3).Select(item => item.Colour)); }
public static xyYColour GetClosestXy(xyYColour xyYcolour, ObserverData observerData) { var meta = new LinqMetaData(); xyYColour closestColour = null; double closestDistance = double.MaxValue; foreach (xyYColour colour in observerData.ColourData.Keys) { double distance = ColourUtil.Delta3D(colour.x, colour.y, 0, xyYcolour.x, xyYcolour.y, 0, 8); if (distance < closestDistance) { closestDistance = distance; closestColour = xyYColour.FromxyY(colour.x, colour.y, colour.Y); } } return(closestColour); }
public static double GetWeight(RGBColour rgbColourSource, RGBColour rgbColourCompare, ObserverData observerData) { XYZColour xyzColSource = ColourUtil.RGBtoXYZ(rgbColourSource); xyYColour colAsxyYSource = xyYColour.FromXYZ(xyzColSource); XYZColour xyzColCompare = ColourUtil.RGBtoXYZ(rgbColourCompare); xyYColour colAsxyYCompare = xyYColour.FromXYZ(xyzColCompare); //****Do calc**** double angle = ColourUtil.CalcAngle(colAsxyYSource.x, colAsxyYSource.y, colAsxyYCompare.x, colAsxyYCompare.y); xyYColour closestObserverSample = GetClosestXy(colAsxyYSource, observerData); //NEW BRANCH: Get 3 closest xy colours ColourAngleSet angleSet = observerData.ColourData[closestObserverSample]; return(GetWeightingFactor(closestObserverSample, angle, angleSet, observerData)); }
public static double GetWeightingFactor(xyYColour xyYControlCol, double angle, ColourAngleSet angleSet, ObserverData observerData) { //Get the closest angle xyYColour closestAngleColour = null; //TODO: Increase accuracy only if this whole colour system seems to be working foreach (var colourAtAngle in angleSet) { if (ColourUtil.Delta(angle, colourAtAngle.Key) < 45) { closestAngleColour = colourAtAngle.Value; } } double realDeltaDIff = ColourUtil.Delta3D(closestAngleColour.x, closestAngleColour.y, 0, xyYControlCol.x, xyYControlCol.y, 0, 4); return(1 / (realDeltaDIff / observerData.AverageRange)); }
private void button1_Click(object sender, EventArgs e) { try { PointF point1 = GetPoint1(); PointF point2 = GetPoint2(); if (chkRecalcPoint1.Checked) { point2.X -= point1.X; point2.Y -= point1.Y; point1.X = 0; point1.Y = 0; } double angle = ColourUtil.CalcAngle(point1.X, point1.Y, point2.X, point2.Y); txtAngle.Text = angle.ToString(); } catch (Exception) { MessageBox.Show("Incorrect input"); } }
public static double GetWeight2(RGBColour rgbColourSource, RGBColour rgbColourCompare, ObserverData observerData) { XYZColour xyzColSource = ColourUtil.RGBtoXYZ(rgbColourSource); xyYColour colAsxyYSource = xyYColour.FromXYZ(xyzColSource); XYZColour xyzColCompare = ColourUtil.RGBtoXYZ(rgbColourCompare); xyYColour colAsxyYCompare = xyYColour.FromXYZ(xyzColCompare); //****Do calc**** double angle = ColourUtil.CalcAngle(colAsxyYSource.x, colAsxyYSource.y, colAsxyYCompare.x, colAsxyYCompare.y); //NEW BRANCH: Get 3 closest xy colours IEnumerable <xyYColour> closest3 = Interpolation.GetThreeClosestColours(colAsxyYSource, observerData); double influenceA, influenceB, influenceC; xyYColour pA = closest3.ElementAt(0); xyYColour pB = closest3.ElementAt(1); xyYColour pC = closest3.ElementAt(2); Interpolation.GetInfluence(colAsxyYSource, pA, pB, pC, out influenceA, out influenceB, out influenceC); xyYColour colourAtAngleA = GetClosestAngleColour(observerData.ColourData[pA], angle); xyYColour colourAtAngleB = GetClosestAngleColour(observerData.ColourData[pB], angle); xyYColour colourAtAngleC = GetClosestAngleColour(observerData.ColourData[pC], angle); double distanceA = ColourUtil.Delta3D(pA.x, pA.y, 0, colourAtAngleA.x, colourAtAngleA.y, 0, 8); double distanceB = ColourUtil.Delta3D(pB.x, pB.y, 0, colourAtAngleB.x, colourAtAngleB.y, 0, 8); double distanceC = ColourUtil.Delta3D(pC.x, pC.y, 0, colourAtAngleC.x, colourAtAngleC.y, 0, 8); double interpolatedDistance = Interpolation.GetInterpolatedDistance(distanceA, distanceB, distanceC, influenceA, influenceB, influenceC); return(GetWeightingFactor2(interpolatedDistance, observerData)); }
private void btnCalcDelta_Click(object sender, EventArgs e) { double drgb = ColourUtil.Delta3D(rgb1.R, rgb1.G, rgb1.B, rgb2.R, rgb2.G, rgb2.B, 2); double scaler = double.Parse(txtScaler.Text); //Apply weighting for new RGB weighting system double weight = 1; if (rdoUseWeighting.Checked) { weight = RgbDiff.GetWeight(rgb1, rgb2, observerData); } else if (rdoUseWeighting2.Checked) { weight = RgbDiff.GetWeight2(rgb1, rgb2, observerData); } drgb = drgb * weight * scaler; txtDeltaRGBDiff.Text = drgb.ToString(); txtWeight.Text = weight.ToString(); }
private void CalculateMinMaxRange() { double max = double.MinValue; double min = double.MaxValue; double avg = 0; int count = 0; foreach (KeyValuePair <xyYColour, ColourAngleSet> dataItem in ColourData) { foreach (KeyValuePair <double, xyYColour> colourAngleSetItem in dataItem.Value) { double distance = ColourUtil.Delta3D(dataItem.Key.x, dataItem.Key.y, 0, colourAngleSetItem.Value.x, colourAngleSetItem.Value.y, 0, 4); if (distance > max) { max = distance; } if (distance < min) { min = distance; } count++; avg += distance; } } _minRange = min; _maxRange = max; _avgRange = avg / count; _minMaxHalfway = _minRange + ((_maxRange - _minRange) / 2); }
static public LinearGradientBrush GetLinearGradient(string c1, string c2) { return(GetLinearGradient(_def0, _def1, ColourUtil.HexStr2Clr(c1), ColourUtil.HexStr2Clr(c2))); }
static public LinearGradientBrush GetLinearGradient(FPoint p1, FPoint p2, string c1, string c2) { return(GetLinearGradient(p1, p2, ColourUtil.HexStr2Clr(c1), ColourUtil.HexStr2Clr(c2))); }