private Pair <int, int> GetHues(HueDirection hueDirection) { int val1 = this._color.Hue; int val2 = this._color2.Hue; if (hueDirection == HueDirection.Clockwise) { if (val1 > val2) { val1 -= 360; } return(new Pair <int, int>(val1, val2)); } if (hueDirection == HueDirection.CounterClockwise) { if (val2 > val1) { val2 -= 360; } return(new Pair <int, int>(val1, val2)); } Pair <int, int> clk = this.GetHues(HueDirection.Clockwise); int dClk = Math.Abs(clk.Second - clk.First); Pair <int, int> cclk = this.GetHues(HueDirection.CounterClockwise); int dCclk = Math.Abs(cclk.Second - cclk.First); if (hueDirection == HueDirection.Shortest) { if (dClk < dCclk) { return(clk); } return(cclk); } else //if (hueDirection == HueDirection.Longest) { if (dClk > dCclk) { return(clk); } return(cclk); } }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { this.Initialize(); if (this._form == null) { this._form = Form.ActiveForm; if (this._form != null) { if (this._form.Text != StaticName) { this._form = null; } else { this._form.FormClosed += (sender, e) => { if (((Form)sender).DialogResult != DialogResult.OK) { this._cancelToken.SignalCancelRequest(); } }; if (this._form.CancelButton is Control c) { c.Click += (sender, e) => { this._cancelToken.SignalCancelRequest(); }; } } } } this._mode = (Modes)newToken.GetProperty <StaticListChoiceProperty>(PropertyNames.Mode).Value; this._lowerThres = (float)newToken.GetProperty <DoubleProperty>(PropertyNames.LowerThreshold).Value; this._upperThres = (float)newToken.GetProperty <DoubleProperty>(PropertyNames.UpperThreshold).Value; this._color = HsvColor.FromColor(ColorBgra.FromOpaqueInt32(newToken.GetProperty <Int32Property>(PropertyNames.Color).Value).ToColor()); this._color2 = HsvColor.FromColor(ColorBgra.FromOpaqueInt32(newToken.GetProperty <Int32Property>(PropertyNames.Color2).Value).ToColor()); this._hueDirection = (HueDirection)newToken.GetProperty <StaticListChoiceProperty>(PropertyNames.HueDirection).Value; this._radius = newToken.GetProperty <Int32Property>(PropertyNames.SmoothingRadius).Value; this._angle = MathUtil.DegreesToRadians(newToken.GetProperty <DoubleProperty>(PropertyNames.Angle).Value); string diffStr = newToken.GetProperty <StringProperty>(PropertyNames.DifferenceFilter).Value; Matrix diff; if (Matrix.TryParse(diffStr, out diff)) { if (diff.GetNormalized() != this._diffX.GetNormalized()) { this._diffX = diff; this._cancelToken.SignalCancelRequest(); this._taskSTField = null; this.Initialize(); } } int length = 2 * this._radius + 1; if (length < 3) { this._weight = null; } else if (this._weight == null || length != this._weight.RowCount) { this._weight = Utils.GetGaussianKernelY(length) * Utils.GetGaussianKernelX(length); this._cachedCharacteristics.Invalidate(); } base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }