コード例 #1
0
 public ColorPicker()
 {
     InitializeComponent();
     original = current = D.Color.FromArgb(255, 255, 255, 255);
     hsv      = HsvColor.FromColor(current);
     Init();
 }
コード例 #2
0
            private void RenderSelectedLineBackground(IntPtr hdc, RendererState rs)
            {
                var rect = new RECT
                {
                    left   = rs.TextRectangle.Left - this.TextView.ScrollHost.ScrollPosH,
                    right  = int.MaxValue,
                    top    = rs.TextRectangle.Top + rs.Y - rs.ViewportY,
                    bottom = rs.TextRectangle.Top + rs.Y + rs.LineHeight - rs.ViewportY
                };

                if (this.TextView.BackgroundImage == null)
                {
                    SafeNativeMethods.FillRect(hdc, ref rect, this._brushCurrentLine.DangerousGetHandle());
                }
                else
                {
                    // Paint using GDI+ if a background image is used, for the sake of using transparency.
                    using (var g = Graphics.FromHdc(hdc))
                    {
                        HsvColor c = HsvColor.FromColor(this.TextView.LineHighlightColor);

                        var alpha = (int)(255 - (255 * ((100 - c.Saturation) / 100d)));
                        c.Saturation = 100;

                        using (var currentLineBrush = new SolidBrush(Color.FromArgb(alpha, c.ToColor())))
                        {
                            g.FillRectangle(currentLineBrush, rect.left, rect.top, this.TextView.ClientSize.Width, rs.LineHeight);
                        }
                    }
                }
            }
コード例 #3
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[0] is Color color1 && int.TryParse(values[1].ToString(), out int stepCount))
            {
                Color color2;

                if (color1 == Colors.Black)
                {
                    color2 = Colors.White;
                }
                else if (color1 == Colors.White)
                {
                    color2 = Colors.Black;
                }
                else
                {
                    // MEMO : グレースケール化したときの明度が50%未満かで白に向けるか黒に向けるかを切り替える。
                    var brightness = HsvColor.FromColor(color1).GetBrightness();
                    color2 = (brightness < 0.5) ? Colors.White : Colors.Black;
                }

                var colors = new Color[stepCount + 1];
                for (int idx = 0; idx <= stepCount; idx++)
                {
                    float ratio = idx / (float)(stepCount + 1);
                    colors[idx] = Color.FromRgb(
                        (byte)(color2.R * ratio + color1.R * (1 - ratio)),
                        (byte)(color2.G * ratio + color1.G * (1 - ratio)),
                        (byte)(color2.B * ratio + color1.B * (1 - ratio)));
                }
                return(colors);
            }
            return(null);
        }
コード例 #4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            // Grab all values
            SerializedProperty hue        = property.FindPropertyRelative("hue");
            SerializedProperty saturation = property.FindPropertyRelative("saturation");
            SerializedProperty value      = property.FindPropertyRelative("value");
            SerializedProperty alpha      = property.FindPropertyRelative("alpha");

            // Convert these values into a color
            HsvColor color          = new HsvColor(hue.floatValue, saturation.floatValue, value.floatValue, alpha.floatValue);
            Color    convertedColor = color.ToColor();

            // Draw the color field
            convertedColor = EditorGUI.ColorField(position, label, convertedColor);

            // Convert the color back to the values
            color                 = HsvColor.FromColor(convertedColor);
            hue.floatValue        = color.Hue;
            saturation.floatValue = color.Saturation;
            value.floatValue      = color.Value;
            alpha.floatValue      = color.Alpha;

            // End the property
            EditorGUI.EndProperty();
        }
コード例 #5
0
ファイル: Posterize.cs プロジェクト: efredin/Comic-Mashup
        protected override unsafe void ProcessFilter(UnmanagedImage image)
        {
            //IntPtr scan0 = image.Scan0;
            //int stride = image.Stride;
            int offset = (image.Stride - image.Width * 3);

            int factor = 100 / this.Value;

            byte *ptr = (byte *)image.ImageData.ToPointer();

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++, ptr += 3)
                {
                    Color    color = Color.FromArgb(ptr[RGB.R], ptr[RGB.G], ptr[RGB.B]);
                    HsvColor hsv   = HsvColor.FromColor(color);

                    // Posterize value
                    hsv.Value -= (hsv.Value % factor);

                    // Convert back to RGB
                    color = hsv.ToColor();

                    ptr[RGB.R] = (byte)color.R;
                    ptr[RGB.G] = (byte)color.G;
                    ptr[RGB.B] = (byte)color.B;
                }

                ptr += offset;
            }
        }
コード例 #6
0
 public ColorPicker(D.Color p)
 {
     InitializeComponent();
     current  = p;
     original = p;
     hsv      = HsvColor.FromColor(p);
     Init();
 }
コード例 #7
0
        private void ASlideInput_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (isInputASlide)
            {
                isInputASlide = false;
                return;
            }

            float f = (float)ASlideInput.Value;

            alpha   = Math.Min(1, Math.Max(0, f));
            current = D.Color.FromArgb((int)(alpha * 255), current.R, current.G, current.B);
            hsv     = HsvColor.FromColor(current);
            UpdatePreview();
            UpdateSliders();
            UpdateTextFields();
        }
コード例 #8
0
        private void RSlideInput_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (isInputRSlide)
            {
                isInputRSlide = false;
                return;
            }

            float f = (float)RSlideInput.Value;
            byte  v = (byte)Math.Min(255, Math.Max(0, f * 255));

            current = D.Color.FromArgb((int)(alpha * 255), v, current.G, current.B);
            hsv     = HsvColor.FromColor(current);
            UpdatePreview();
            UpdateTextFields();
            RedrawSatVal();
        }
コード例 #9
0
        /// <summary>
        /// Whenever a color is changed via RGB methods, call this and the HSV
        /// counterparts will be sync'd up.
        /// </summary>
        /// <param name="newColor">The RGB color that should be converted to HSV.</param>
        private void SyncHsvFromRgb(Color newColor)
        {
            if (ignore == 0)
            {
                ignore++;
                HsvColor hsvColor = HsvColor.FromColor(newColor);

                Utility.SetNumericUpDownValue(hueUpDown, hsvColor.Hue);
                Utility.SetNumericUpDownValue(saturationUpDown, hsvColor.Saturation);
                Utility.SetNumericUpDownValue(valueUpDown, hsvColor.Value);

                SetColorGradientValuesHsv(hsvColor.Hue, hsvColor.Saturation, hsvColor.Value);
                SetColorGradientMinMaxColorsHsv(hsvColor.Hue, hsvColor.Saturation, hsvColor.Value);

                colorWheel.HsvColor = hsvColor;
                ignore--;
            }
        }
コード例 #10
0
ファイル: ColorControl.cs プロジェクト: feeleen/pdn-gridwarp
        void hex_TextChanged(object sender, EventArgs e)
        {
            if (!eventssuspended)
            {
                SuspendEvents();

                try
                {
                    ColorBgra c = ColorBgra.FromOpaqueInt32(int.Parse(hex.Text, System.Globalization.NumberStyles.HexNumber));
                    HsvColor  h = HsvColor.FromColor(c);
                    wheel.Color = c;
                    SetRgbSliders(c);
                    SetHsvSliders(h);
                }
                catch
                {
                    hex.Text = "";
                }

                ResumeEvents();
            }
        }
コード例 #11
0
        private void BInput_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (isInputBText)
            {
                isInputBText = false;
                return;
            }

            float f;

            if (float.TryParse(BInput.Text, out f))
            {
                byte sf = (byte)Math.Min(255, Math.Max(0, f * 255));

                current = D.Color.FromArgb((int)(alpha * 255), current.R, current.G, sf);
                hsv     = HsvColor.FromColor(current);

                UpdateSliders();
                UpdateTextFields();
                UpdatePreview();
                RedrawSatVal();
            }
        }
コード例 #12
0
        private void MsHook_MouseClickEvent(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (globalPicking)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    D.Color c = GetColorAt((int)e.X, (int)e.Y);
                    current = c;
                    hsv     = HsvColor.FromColor(c);

                    UpdatePreview();
                    UpdateSliders();
                    UpdateTextFields();
                    RedrawSatVal();

                    globalPicking = false;

                    mag.Hide();

                    msHook.UnHook();
                    tColor.Stop();
                }
            }
        }
コード例 #13
0
ファイル: MediaExtensions.cs プロジェクト: forki/Ccr
 /// <summary>
 ///   Converts the equivelent <see cref="HsvColor"/> Hsv color
 ///   model.
 /// </summary>
 /// <param name="this">
 ///   The color to convert.
 /// </param>
 /// <returns>
 ///   The equivelent <see cref="HsvColor"/> Hsv color model.
 /// </returns>
 public static HsvColor ToHsvColor(
     this Color @this)
 {
     return(HsvColor.FromColor(
                @this));
 }
コード例 #14
0
        private void RgbGradientControl_ValueChanged(object sender, IndexEventArgs ce)
        {
            if (IgnoreChangedEvents)
            {
                return;
            }

            int red;

            if (sender == redGradientControl)
            {
                red = redGradientControl.Value;
            }
            else
            {
                red = (int)redUpDown.Value;
            }

            int green;

            if (sender == greenGradientControl)
            {
                green = greenGradientControl.Value;
            }
            else
            {
                green = (int)greenUpDown.Value;
            }

            int blue;

            if (sender == blueGradientControl)
            {
                blue = blueGradientControl.Value;
            }
            else
            {
                blue = (int)blueUpDown.Value;
            }

            Color    rgbColor = Color.FromArgb(255, red, green, blue);
            HsvColor hsvColor = HsvColor.FromColor(rgbColor);

            PushIgnoreChangedEvents();
            Utility.SetNumericUpDownValue(hueUpDown, hsvColor.Hue);
            Utility.SetNumericUpDownValue(saturationUpDown, hsvColor.Saturation);
            Utility.SetNumericUpDownValue(valueUpDown, hsvColor.Value);

            Utility.SetNumericUpDownValue(redUpDown, rgbColor.R);
            Utility.SetNumericUpDownValue(greenUpDown, rgbColor.G);
            Utility.SetNumericUpDownValue(blueUpDown, rgbColor.B);
            PopIgnoreChangedEvents();

            string hexText = GetHexNumericUpDownValue(rgbColor.R, rgbColor.G, rgbColor.B);

            hexBox.Text = hexText;

            Color = rgbColor;

            Update();
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: Comparer.cs プロジェクト: InfFelixNaumann/ppsn
 public int Compare(Color x, Color y)
 => HsvColor.FromColor(x).CompareTo(HsvColor.FromColor(y));