public ColorRecipe(HdrRGB color, params WeightedValue<HdrRGB>[] ingredients) { Contract.Requires(ingredients.Length > 0); Color = color; Ingredients = ingredients; }
public BaseColor(string name, HdrRGB color) { Contract.Requires(!String.IsNullOrEmpty(name)); Name = name; Color = color; }
public ColorComponentSearch(ColorFilteringPars filteringPars, ColorMixingPars mixingPars, HdrRGB targetColor, params BaseColor[] baseColors) { Contract.Requires(filteringPars != null); Contract.Requires(mixingPars != null); Contract.Requires(baseColors != null); Contract.Requires(baseColors.Length > 0); FilteringPars = filteringPars; MixingPars = mixingPars; BaseColors = baseColors; TargetColor = targetColor; }
private double GetMinDiff(HdrRGB color, out BaseColor bestBaseColor) { double minDiff = double.MaxValue; bestBaseColor = null; foreach (var baseColor in BaseColors) { double rDiff = Math.Abs(color.R - baseColor.Color.R); double gDiff = Math.Abs(color.G - baseColor.Color.G); double bDiff = Math.Abs(color.B - baseColor.Color.B); double d = (rDiff * rDiff + gDiff * gDiff + bDiff * bDiff) / 3.0; if (d < minDiff) { minDiff = d; bestBaseColor = baseColor; } } return minDiff / BaseColors.Length; }
public HdrRGB Filter(HdrRGB color) { double fPMR = Math.Max(MulRatio.RRatio * MulV, double.Epsilon); double fPMG = Math.Max(MulRatio.GRatio * MulV, double.Epsilon); double fPMB = Math.Max(MulRatio.BRatio * MulV, double.Epsilon); double fPIMR = Math.Max(InnerMulRatio.RRatio * MulV, double.Epsilon); double fPIMG = Math.Max(InnerMulRatio.GRatio * MulV, double.Epsilon); double fPIMB = Math.Max(InnerMulRatio.BRatio * MulV, double.Epsilon); double fPPR = PowRatio.RRatio * PowV; double fPPG = PowRatio.GRatio * PowV; double fPPB = PowRatio.BRatio * PowV; double fPCR = ConstRatio.RRatio * AddV - AddV2; double fPCG = ConstRatio.GRatio * AddV - AddV2; double fPCB = ConstRatio.BRatio * AddV - AddV2; double r = (Math.Pow(color.R * fPIMR, fPPR) * fPMR) + fPCR; double g = (Math.Pow(color.G * fPIMG, fPPG) * fPMG) + fPCG; double b = (Math.Pow(color.B * fPIMB, fPPB) * fPMB) + fPCB; return new HdrRGB(r, g, b); }
public HdrRGB UndoFilter(HdrRGB color) { double fPMR = Math.Max(MulRatio.RRatio * MulV, double.Epsilon); double fPMG = Math.Max(MulRatio.GRatio * MulV, double.Epsilon); double fPMB = Math.Max(MulRatio.BRatio * MulV, double.Epsilon); double fPIMR = Math.Max(InnerMulRatio.RRatio * MulV, double.Epsilon); double fPIMG = Math.Max(InnerMulRatio.GRatio * MulV, double.Epsilon); double fPIMB = Math.Max(InnerMulRatio.BRatio * MulV, double.Epsilon); double fPPR = PowRatio.RRatio * PowV; double fPPG = PowRatio.GRatio * PowV; double fPPB = PowRatio.BRatio * PowV; double fPCR = ConstRatio.RRatio * AddV - AddV2; double fPCG = ConstRatio.GRatio * AddV - AddV2; double fPCB = ConstRatio.BRatio * AddV - AddV2; double r = Math.Pow(Math.Max((color.R - fPCR) / fPMR, 0.0), 1.0 / fPPR) / fPIMR; double g = Math.Pow(Math.Max((color.G - fPCG) / fPMG, 0.0), 1.0 / fPPG) / fPIMG; double b = Math.Pow(Math.Max((color.B - fPCB) / fPMB, 0.0), 1.0 / fPPB) / fPIMB; return new HdrRGB(r, g, b); }