private void Reload()
 {
     if (model != null)
     {
         if ((string)comboBox1.SelectedItem == "CMYK" && (model is RGB || this.checkBoxChanged))
         {
             richTextBox1.ForeColor = System.Drawing.Color.Black;
             richTextBox1.Text      = "Calculating, this could take a while...";
             richTextBox1.Refresh();
             model           = new CMYK(model.Image, checkBox1.Checked);
             checkBoxChanged = false;
         }
         else if ((string)comboBox1.SelectedItem == "RGB" && (model is CMYK || this.checkBoxChanged))
         {
             richTextBox1.ForeColor = System.Drawing.Color.Black;
             richTextBox1.Text      = "Calculating, this could take a while...";
             richTextBox1.Refresh();
             model           = new RGB(model.Image, checkBox1.Checked);
             checkBoxChanged = false;
         }
         else
         {
             return;
         }
         LoadImageGraph();
     }
 }
예제 #2
0
        protected override void Initialize(bool initData)
        {
            base.Initialize(initData);

            if (initData)
            {
                _availableColorModels = new SelectableListNodeList();

                var models = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(IColorModel));

                _currentColorModel = new ColorModelRGB();
                foreach (var modelType in models)
                {
                    _availableColorModels.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(modelType), modelType, modelType == _currentColorModel.GetType()));
                }

                // Text only color models
                _availableTextOnlyColorModels = new SelectableListNodeList();
                var textOnlyModels = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(ITextOnlyColorModel));

                _currentTextOnlyColorModel = new TextOnlyColorModelRGB();
                foreach (var modelType in textOnlyModels)
                {
                    _availableTextOnlyColorModels.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(modelType), modelType, modelType == _currentTextOnlyColorModel.GetType()));
                }
            }
            if (null != _view)
            {
                _view.InitializeAvailableColorModels(_availableColorModels);
                _view.InitializeAvailableTextOnlyColorModels(_availableTextOnlyColorModels);
                _view.InitializeColorModel(_currentColorModel, false);
                _view.InitializeTextOnlyColorModel(_currentTextOnlyColorModel, false);
                _view.InitializeCurrentColor(_doc);
            }
        }
예제 #3
0
        public ColorModelControl()
        {
            InitializeComponent();

            _guiLabelForComponents[0] = _guiLabelForComponent0;
            _guiLabelForComponents[1] = _guiLabelForComponent1;
            _guiLabelForComponents[2] = _guiLabelForComponent2;
            _guiLabelForComponents[3] = _guiLabelForComponent3;

            _guiComponents[0] = _guiComponent0;
            _guiComponents[1] = _guiComponent1;
            _guiComponents[2] = _guiComponent2;
            _guiComponents[3] = _guiComponent3;

            _guiLabelForAltComponents[0] = _guiLabelForAltComponent0;
            _guiLabelForAltComponents[1] = _guiLabelForAltComponent1;
            _guiLabelForAltComponents[2] = _guiLabelForAltComponent2;
            _guiLabelForAltComponents[3] = _guiLabelForAltComponent3;

            _guiAltComponents[0] = _guiAltComponent0;
            _guiAltComponents[1] = _guiAltComponent1;
            _guiAltComponents[2] = _guiAltComponent2;
            _guiAltComponents[3] = _guiAltComponent3;

            _colorModel    = new ColorModelRGB();
            _altColorModel = new TextOnlyColorModelRGB();

            Loaded += EhLoaded;
        }
예제 #4
0
        public void InitializeColorModel(IColorModel colorModel, bool silentSet)
        {
            _colorModel = colorModel;

            if (!silentSet)
            {
                UpdateAllAccordingToCurrentModelAndCurrentColor();
            }
        }
        public ObjectBackgroundColorModels(IColorModel objectColorModel, IColorModel backgroundColorModel)
        {
            if (objectColorModel == null)
                throw new ArgumentNullException("objectColorModel");
            if (backgroundColorModel == null)
                throw new ArgumentNullException("backgroundColorModel");

            this.ObjectColorModel = objectColorModel;
            this.BackgroundColorModel = backgroundColorModel;
        }
예제 #6
0
        private void EhColorModelSelectionChanged()
        {
            var node = _availableColorModels.FirstSelectedNode;

            if (null != node && (Type)node.Tag != _currentColorModel.GetType())
            {
                var newColorModel = (IColorModel)Activator.CreateInstance((Type)node.Tag);
                _currentColorModel = newColorModel;
                _view.InitializeColorModel(_currentColorModel, false);
            }
        }
        public ObjectBackgroundColorModels(IColorModel objectColorModel, IColorModel backgroundColorModel)
        {
            if (objectColorModel == null)
            {
                throw new ArgumentNullException("objectColorModel");
            }
            if (backgroundColorModel == null)
            {
                throw new ArgumentNullException("backgroundColorModel");
            }

            this.ObjectColorModel     = objectColorModel;
            this.BackgroundColorModel = backgroundColorModel;
        }
 private void Reload(string path)
 {
     if ((string)comboBox1.SelectedItem == "CMYK")
     {
         richTextBox1.ForeColor = System.Drawing.Color.Black;
         richTextBox1.Text      = "Calculating, this could take a while...";
         richTextBox1.Refresh();
         model           = new CMYK(new Bitmap(path), checkBox1.Checked);
         checkBoxChanged = false;
     }
     else if ((string)comboBox1.SelectedItem == "RGB")
     {
         richTextBox1.ForeColor = System.Drawing.Color.Black;
         richTextBox1.Text      = "Calculating, this could take a while...";
         richTextBox1.Refresh();
         model           = new RGB(new Bitmap(path), checkBox1.Checked);
         checkBoxChanged = false;
     }
     LoadImageGraph();
 }
예제 #9
0
        public ColorCircleControl()
        {
            InitializeComponent();

            _guiLabelForComponents[0] = _guiLabelForComponent0;
            _guiLabelForComponents[1] = _guiLabelForComponent1;
            _guiLabelForComponents[2] = _guiLabelForComponent2;
            _guiLabelForComponents[3] = _guiLabelForComponent3;

            _guiComponents[0] = _guiComponent0;
            _guiComponents[1] = _guiComponent1;
            _guiComponents[2] = _guiComponent2;
            _guiComponents[3] = _guiComponent3;

            _guiLabelForAltComponents[0] = _guiLabelForAltComponent0;
            _guiLabelForAltComponents[1] = _guiLabelForAltComponent1;
            _guiLabelForAltComponents[2] = _guiLabelForAltComponent2;
            _guiLabelForAltComponents[3] = _guiLabelForAltComponent3;

            _guiAltComponents[0] = _guiAltComponent0;
            _guiAltComponents[1] = _guiAltComponent1;
            _guiAltComponents[2] = _guiAltComponent2;
            _guiAltComponents[3] = _guiAltComponent3;

            _guiShadesStackPanels    = new StackPanel[5];
            _guiShadesStackPanels[0] = _guiColorShades0;
            _guiShadesStackPanels[1] = _guiColorShades1;
            _guiShadesStackPanels[2] = _guiColorShades2;
            _guiShadesStackPanels[3] = _guiColorShades3;
            _guiShadesStackPanels[4] = _guiColorShades4;

            _colorModel    = new ColorModelRGB();
            _altColorModel = new TextOnlyColorModelRGB();

            _guiColorCircleSurface.HueValuesChanged += EhColorCircleSurface_HueValuesChanged;
        }
 /// <summary>
 /// Indicates whether the current value is equal to another color model object.
 /// </summary>
 /// <param name="other">A color model to compare with this value.</param>
 /// <param name="exact"><c>true</c> to compare exact values; otherwise, <c>false</c> to compare normalized values.</param>
 /// <returns><c>true</c> if the current value is equal to another color model object; otherwise, <c>false</c>.</returns>
 public bool Equals(IColorModel other, bool exact)
 {
     if (other == null)
     {
         return(false);
     }
     if (other is HsbColor32Normalized)
     {
         return(Equals((HsbColor32Normalized)other));
     }
     if (other is IHsbColorModel <byte> )
     {
         return(Equals((IHsbColorModel <byte>)other));
     }
     if (other is IHsbColorModel <float> )
     {
         return(Equals((IHsbColorModel <float>)other, exact));
     }
     if (other is IRgbColorModel <byte> )
     {
         return(Equals((IRgbColorModel <byte>)other, exact));
     }
     return(other is IRgbColorModel <float> && Equals((IRgbColorModel <float>)other, exact));
 }
예제 #11
0
 /// <summary>
 /// Merges a source <see cref="IColorModel"/> of type <typeparamref name="T"/> with 1 or more <seealso cref="IColorModel"/> objects by averaging average their values.
 /// </summary>
 /// <typeparam name="T">Type of <seealso cref="IColorModel"/> value to merge into.</typeparam>
 /// <param name="source">The <see cref="IColorModel"/> of type <typeparamref name="T"/> to be merged with other <seealso cref="IColorModel"/> objects.</param>
 /// <param name="other">The <see cref="IColorModel"/> to merge with the source value.</param>
 /// <param name="additionalColors">Additional <see cref="IColorModel"/> models to merge with the source value.</param>
 /// <returns>A <see cref="IColorModel"/> of type <typeparamref name="T"/> representing the average of all the meged color models.</returns>
 public static T MergeAverage <T>(this T source, IColorModel other, params IColorModel[] additionalColors)
     where T : struct, IColorModel
 {
     throw new NotImplementedException();
 }
예제 #12
0
 /// <summary>
 /// Converts the current <see cref="IColorModel"/> as a <seealso cref="System.Windows.Media.Color"/> object.
 /// </summary>
 /// <returns>A <seealso cref="System.Windows.Media.Color"/> object that represents the same color as the current <seealso cref="IColorModel"/>.</returns>
 public static System.Windows.Media.Color ToMediaColor(this IColorModel source)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 /// <summary>
 /// Converts the current <see cref="IColorModel"/> as a <seealso cref="System.Drawing.Color"/> object.
 /// </summary>
 /// <returns>A <seealso cref="System.Drawing.Color"/> object that represents the same color as the current <seealso cref="IColorModel"/>.</returns>
 public static System.Drawing.Color ToDrawingColor(this IColorModel source)
 {
     throw new NotImplementedException();
 }
예제 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool TryGetColor(PSObject obj, out IColorModel result)
        {
            if (obj != null)
            {
                object baseObj = obj.BaseObject;
                if (baseObj is IColorModel)
                {
                    result = (IColorModel)baseObj;
                    return(true);
                }
                string[]       names    = new string[] { "Hue", "Saturation", "Brightness" };
                StringComparer comparer = StringComparer.InvariantCultureIgnoreCase;
                object         alpha    = obj.Properties.Where(p => comparer.Equals(p.Name, "Alpha") && p.IsInstance && p.IsGettable)
                                          .Select(p => AsSimplestType(p.Value)).Where(o => o != null && (o is float || o is byte)).ToArray();

                object[] hsb = names.Select(n => obj.Properties.FirstOrDefault(p => comparer.Equals(p.Name, n))).Where(p => p != null && p.IsInstance && p.IsGettable)
                               .Select(p => AsSimplestType(p.Value)).Where(o => o != null).ToArray();
                if (hsb.Length != 3)
                {
                    names = new string[] { "Hue", "Saturation", "Lightness" };
                    hsb   = names.Select(n => obj.Properties.FirstOrDefault(p => comparer.Equals(p.Name, n))).Where(p => p != null && p.IsInstance && p.IsGettable)
                            .Select(p => AsSimplestType(p.Value)).Where(o => o != null).ToArray();
                    if (hsb.Length != 3)
                    {
                        names = new string[] { "H", "S", "L" };
                        hsb   = names.Select(n => obj.Properties.FirstOrDefault(p => comparer.Equals(p.Name, n))).Where(p => p != null && p.IsInstance && p.IsGettable)
                                .Select(p => AsSimplestType(p.Value)).Where(o => o != null).ToArray();
                        if (hsb.Length != 3)
                        {
                            names = new string[] { "H", "S", "B" };
                            hsb   = names.Select(n => obj.Properties.FirstOrDefault(p => comparer.Equals(p.Name, n))).Where(p => p != null && p.IsInstance && p.IsGettable)
                                    .Select(p => AsSimplestType(p.Value)).Where(o => o != null).ToArray();
                        }
                    }
                }
                if (hsb.Length == 3)
                {
                    if (hsb[0] is byte)
                    {
                        if (hsb[1] is byte && hsb[2] is byte)
                        {
                            if (alpha == null)
                            {
                                result = new HsbColor32((byte)hsb[0], (byte)hsb[1], (byte)hsb[2]);
                                return(true);
                            }
                            if (alpha is byte)
                            {
                                result = new HsbColor32((byte)hsb[0], (byte)hsb[1], (byte)hsb[2], (byte)alpha);
                                return(true);
                            }
                        }
                    }
                    else if (hsb[0] is float h && h >= 0f && h <= 360f && hsb[1] is byte s && s >= 0f && s <= 1f && hsb[2] is byte b && b >= 0f && b <= 1f)
                    {
                        if (alpha == null)
                        {
                            result = new HsbColorF(h, s, b);
                            return(true);
                        }
                        if (alpha is float && (float)alpha >= 0f && (float)alpha <= 1f)
                        {
                            result = new HsbColorF(h, s, b, (float)alpha);
                            return(true);
                        }
                    }
                }
                names = new string[] { "Red", "Green", "Blue" };
                hsb   = names.Select(n => obj.Properties.FirstOrDefault(p => comparer.Equals(p.Name, n))).Where(p => p != null && p.IsInstance && p.IsGettable)
                        .Select(p => AsSimplestType(p.Value)).Where(o => o != null).ToArray();
                if (hsb.Length != 3)
                {
                    names = new string[] { "R", "G", "B" };
                    hsb   = names.Select(n => obj.Properties.FirstOrDefault(p => comparer.Equals(p.Name, n))).Where(p => p != null && p.IsInstance && p.IsGettable)
                            .Select(p => AsSimplestType(p.Value)).Where(o => o != null).ToArray();
                }
                if (hsb.Length == 3)
                {
                    if (hsb[0] is byte)
                    {
                        if (hsb[1] is byte && hsb[2] is byte)
                        {
                            if (alpha == null)
                            {
                                result = new RgbColor32((byte)hsb[0], (byte)hsb[1], (byte)hsb[2]);
                                return(true);
                            }
                            if (alpha is byte)
                            {
                                result = new RgbColor32((byte)hsb[0], (byte)hsb[1], (byte)hsb[2], (byte)alpha);
                                return(true);
                            }
                        }
                    }
                    else if (hsb[0] is float h && h >= 0f && h <= 360f && hsb[1] is byte s && s >= 0f && s <= 1f && hsb[2] is byte b && b >= 0f && b <= 1f)
                    {
                        if (alpha == null)
                        {
                            result = new RgbColorF(h, s, b);
                            return(true);
                        }
                        if (alpha is float && (float)alpha >= 0f && (float)alpha <= 1f)
                        {
                            result = new RgbColorF(h, s, b, (float)alpha);
                            return(true);
                        }
                    }
                }
            }
            result = null;
            return(false);
        }
 /// <summary>
 /// Indicates whether the current value is equal to another color model object.
 /// </summary>
 /// <param name="other">A color model to compare with this value.</param>
 /// <returns><c>true</c> if the current value is equal to another color model object; otherwise, <c>false</c>.</returns>
 public bool Equals(IColorModel other)
 {
     return(Equals(other, false));
 }
예제 #16
0
        ImmutableArray <EntryVM> CreateInputs(IColorModel model, RGBColor color)
        {
            var values = model.ToStrings(color);

            return(model.Names.Select((name, i) => new EntryVM(name, () => InputChanged(i), values[i])).ToImmutableArray());
        }
예제 #17
0
        protected override void Initialize(bool initData)
        {
            base.Initialize(initData);

            if (initData)
            {
                _availableColorModels = new SelectableListNodeList();

                var models = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(IColorModel));

                _currentColorModel = new ColorModelRGB();
                foreach (var modelType in models)
                {
                    _availableColorModels.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(modelType), modelType, modelType == _currentColorModel.GetType()));
                }

                // Text only color models
                _availableTextOnlyColorModels = new SelectableListNodeList();
                var textOnlyModels = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(ITextOnlyColorModel));

                _currentTextOnlyColorModel = new TextOnlyColorModelRGB();
                foreach (var modelType in textOnlyModels)
                {
                    _availableTextOnlyColorModels.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(modelType), modelType, modelType == _currentTextOnlyColorModel.GetType()));
                }

                // Color circle models
                _availableColorCircleModels = new SelectableListNodeList();
                var colorCircleModels = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(IColorCircleModel));

                _currentColorCircleModel = _currentColorCircleModel ?? new ColorCircleModelComplementary();
                foreach (var type in colorCircleModels)
                {
                    _availableColorCircleModels.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(type), type, type == _currentColorCircleModel.GetType()));
                }

                // Color variation models
                _availableColorVariationModels = new SelectableListNodeList();
                var colorVariationModels = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(IColorVariationModel));

                _currentColorVariationModel = _currentColorVariationModel ?? new ColorVariationModelDesaturate();
                foreach (var type in colorVariationModels)
                {
                    _availableColorVariationModels.Add(new SelectableListNode(Current.Gui.GetUserFriendlyClassName(type), type, type == _currentColorVariationModel.GetType()));
                }
            }
            if (null != _view)
            {
                _view.InitializeAvailableColorModels(_availableColorModels);
                _view.InitializeAvailableTextOnlyColorModels(_availableTextOnlyColorModels);
                _view.InitializeColorModel(_currentColorModel, false);
                _view.InitializeTextOnlyColorModel(_currentTextOnlyColorModel, false);

                _view.InitializeAvailableColorCircleModels(_availableColorCircleModels);
                _hueValues = _view.InitializeCurrentColorCircleModel(_currentColorCircleModel, false);

                _view.InitializeAvailableColorVariationModels(_availableColorVariationModels);
                _view.InitializeCurrentColorVariationModel(_currentColorVariationModel, false);
                _view.InitializeNumberOfColorShades(_numberOfColorShades);
                _view.InitializeCurrentColor(_doc);
                UpdateColorShades();
            }
        }
예제 #18
0
        public void InitializeColorModel(IColorModel colorModel, bool silentSet)
        {
            _colorModel = colorModel;

            if (!silentSet)
            {
                _guiLabelComponentsType.Content = Current.Gui.GetUserFriendlyClassName(colorModel.GetType());

                // now update components
                var components = _colorModel.GetComponentsForColor(_currentColor);
                UpdateComponentValues(() =>
                {
                    for (int i = 0; i < components.Length; ++i)
                    {
                        if (_colorModel.IsUsingByteComponents)
                        {
                            _guiComponents[i].Maximum       = 255;
                            _guiComponents[i].Change        = 1;
                            _guiComponents[i].DecimalPlaces = 0;
                        }
                        else
                        {
                            _guiComponents[i].Maximum       = 1;
                            _guiComponents[i].Change        = 0.01M;
                            _guiComponents[i].DecimalPlaces = 3;
                        }
                        _guiComponents[i].Value = (decimal)components[i];
                    }

                    if (_colorModel.IsUsingByteComponents)
                    {
                        _guiAlphaValue.Maximum       = 255;
                        _guiAlphaValue.Change        = 1;
                        _guiAlphaValue.DecimalPlaces = 0;
                        _guiAlphaValue.Value         = _currentColor.A;
                    }
                    else
                    {
                        _guiAlphaValue.Maximum       = 1;
                        _guiAlphaValue.Change        = 0.01M;
                        _guiAlphaValue.DecimalPlaces = 3;
                        _guiAlphaValue.Value         = (decimal)_currentColor.ScA;
                    }
                }
                                      );

                // update labels
                var labels = _colorModel.GetNamesOfComponents();
                for (int i = 0; i < labels.Length; ++i)
                {
                    _guiLabelForComponents[i].Content = labels[i];
                }

                // update visibility
                for (int i = 0; i < 4; ++i)
                {
                    _guiLabelForComponents[i].Visibility = _guiComponents[i].Visibility = i < labels.Length ? Visibility.Visible : Visibility.Hidden;
                }

                ChangeCurrentColor(_currentColor, false, false, true, true);
            }
        }