Esempio n. 1
0
        /// <summary>
        /// Converts ColorMine.ColorSpaces.Lch to System.Drawing.Color
        /// </summary>
        /// <param name="lchColor">The LCH colour that is to be converted to System.Drawing.Color.</param>
        /// <returns>The source RGB colour in LCH.</returns>
        public static Color LchToColor(Lch lchColor)
        {
            // First convert to ColorSpace.colorRGB
            Rgb colorRGB = new Rgb(lchColor);

            // Retrieve the RGB Components
            int R = (int)Math.Round(colorRGB.R * 255.0, MidpointRounding.AwayFromZero);
            int G = (int)Math.Round(colorRGB.G * 255.0, MidpointRounding.AwayFromZero);
            int B = (int)Math.Round(colorRGB.B * 255.0, MidpointRounding.AwayFromZero);

            // Ensure they are in permissible ranges. (In case of multithreading, concurrency issues)
            if (R > 255)
            {
                R = 255;
            }
            if (G > 255)
            {
                G = 255;
            }
            if (B > 255)
            {
                B = 255;
            }

            // Return as System.Drawing.Color
            return(Color.FromArgb(R, G, B));
        }
Esempio n. 2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="Color"></param>
            /// <returns></returns>
            public override Point PointFromColor(Color Color)
            {
                var lch = new Lch(Color, Observer, Illuminant);
                var x   = ((lch.C / Lch.MaxValue.C) * 255d).ToInt32();
                var y   = 255 - ((lch.L / Lch.MaxValue.L) * 255d).ToInt32();

                return(new Point(x, y));
            }
            public void MaroonLchToMunsell()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Munsell("10R 3/12");

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
            public void MaroonLchToHex()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Hex("7d0000");

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 5
0
        /// <summary>
        /// Converts LCH colour back to System.Windows.Media.Color.
        /// </summary>
        public static Color ToColor(this Lch lchColor)
        {
            Rgb rgbColor = lchColor.To <Rgb>();

            byte R = (byte)Math.Round(rgbColor.R, MidpointRounding.AwayFromZero);
            byte G = (byte)Math.Round(rgbColor.G, MidpointRounding.AwayFromZero);
            byte B = (byte)Math.Round(rgbColor.B, MidpointRounding.AwayFromZero);

            return(Color.FromArgb(255, R, G, B));
        }
Esempio n. 6
0
            public void MaroonLchToLab()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Lab {
                    L = 25.531, A = 48.055, B = 38.059,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 7
0
            public void MaroonLchToCmy()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Cmy {
                    C = .5215, M = .99993, Y = 1,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 8
0
            public void MaroonLchToHsb()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Hsb {
                    H = 0, S = 100, B = 24.5,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 9
0
            public void AliceBlueHsbToLch()
            {
                var knownColor = new Hsb {
                    H = 208, S = 100, B = 97,
                };
                var expectedColor = new Lch {
                    L = 97.179, C = 4.5683, H = 252.551,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 10
0
            public void MaroonLchToXyz()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Xyz {
                    X = 8.458, Y = 4.360, Z = .396,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 11
0
            public void DarkVioletCmykToLch()
            {
                var knownColor = new Cmyk {
                    C = .29858, M = 1, Y = 0, K = .17255,
                };
                var expectedColor = new Lch {
                    L = 39.579, C = 103.828, H = 317.325,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 12
0
            public void SteelBlueCmyToLch()
            {
                var knownColor = new Cmy {
                    C = .72549, M = .49020, Y = .29412,
                };
                var expectedColor = new Lch {
                    L = 52.467, C = 32.454, H = 262.796,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 13
0
            public void MaroonLchToYxy()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Yxy {
                    Y1 = 4.360, X = 0.64005, Y2 = .32998,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 14
0
            public void BlackRgbToLch()
            {
                var knownColor = new Rgb {
                    R = 0, G = 0, B = 0,
                };
                var expectedColor = new Lch {
                    L = 0, C = 0, H = 0,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 15
0
            public void GoldenrodRgbToLch()
            {
                var knownColor = new Rgb {
                    R = 218, G = 165, B = 32,
                };
                var expectedColor = new Lch {
                    L = 70.816, C = 69.291, H = 82.933,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 16
0
            public void SilverLuvToLch()
            {
                var knownColor = new Luv {
                    L = 77.704, U = .001, V = -.013,
                };
                var expectedColor = new Lch {
                    L = 77.704, C = .0074, H = 290.49463,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 17
0
            public void AquamarineHsvToLch()
            {
                var knownColor = new Hsv {
                    H = 160, S = .5, V = 1,
                };
                var expectedColor = new Lch {
                    L = 92.036, C = 46.545, H = 167.957,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 18
0
            public void MaroonLchToRgb()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Rgb {
                    R = 125, G = .03555, B = .00182,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 19
0
            public void RivergumXyzToLch()
            {
                var knownColor = new Xyz {
                    X = 13.123, Y = 15.372, Z = 13.174,
                };
                var expectedColor = new Lch {
                    L = 46.140, C = 12.502, H = 138.898,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 20
0
            public void WhiteRgbToLch()
            {
                var knownColor = new Rgb {
                    R = 255, G = 255, B = 255,
                };
                var expectedColor = new Lch {
                    L = 100, C = .01166, H = 296.813,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 21
0
            public void MaroonLchToLab()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Lab {
                    L = 24.829, A = 47.237, B = 37.146,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 22
0
            public void MaroonLchToCmyk()
            {
                var knownColor = new Lch {
                    L = 24.829, C = 60.093, H = 38.180,
                };
                var expectedColor = new Cmyk {
                    C = .0, M = .99972, Y = 1, K = .50980,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 23
0
            public void RedLabToLch()
            {
                var knownColor = new Lab {
                    L = 53.233, A = 80.109, B = 67.220,
                };
                var expectedColor = new Lch {
                    L = 53.33, C = 104.575, H = 40,
                };

                ExpectedValuesForKnownColor(knownColor, expectedColor);
            }
Esempio n. 24
0
        private static Lch GetInterpolatedValue(IMunsell item, Lch lowlch, Lch highlch, double rate = 0.5d)
        {
            //彩度の調整
            var diffC      = Math.Abs(highlch.C - lowlch.C);
            var newMetricC = (item.C % 2.0d) / 2.0d * diffC + Math.Min(lowlch.C, highlch.C);
            //色相の調整
            var diffH      = Math.Abs(lowlch.H - highlch.H);
            var newMetricH = Math.Min(lowlch.H, highlch.H) + diffH * rate;

            return(new Lch {
                L = lowlch.L, C = newMetricC, H = newMetricH
            });
        }
Esempio n. 25
0
        /// <summary>
        /// Calculates an intermediate colour between Colour X and Colour Y.
        /// </summary>
        /// <param name="sourceColor">Colour interpolation begins from.</param>
        /// <param name="destinationColor">Colour interpolation ends up.</param>
        /// <param name="time">A normalized time between 0-1 which dictates the interpolated colour. The formula for the returned colour is "sourceColor + ((destinationColor - sourceColor) * time)" for each of the 3 LCh components.</param>
        public static Lch CalculateIntermediateColour(Lch sourceColor, Lch destinationColor, float time)
        {
            // Calculate the differences of LCH from source to destination.
            double hDelta = destinationColor.H - sourceColor.H;
            double cDelta = destinationColor.C - sourceColor.C;
            double lDelta = destinationColor.L - sourceColor.L;

            return(new Lch
            {
                L = sourceColor.L + lDelta * time,
                C = sourceColor.C + cDelta * time,
                H = sourceColor.H + hDelta * time
            });
        }
Esempio n. 26
0
        /// <summary>
        /// Calculates all of the intermediate colours between colour X and colour Y
        /// to be used for interpolation purposes.
        /// </summary>
        /// <param name="sourceColor">Colour from which the list of interpolated colours begins from.</param>
        /// <param name="destinationColor">The target colour from which the to which the source colour gets interpolated to.</param>
        public List <Lch> CalculateIntermediateColours(Lch sourceColor, Lch destinationColor)
        {
            // Calculate the differences of LCH from source to destination.
            double hDelta = destinationColor.H - sourceColor.H;
            double cDelta = destinationColor.C - sourceColor.C;
            double lDelta = destinationColor.L - sourceColor.L;

            // Store list of colours.
            List <Lch> colours = new List <Lch>(Iterations);

            // Calculate all intermediate colours.
            // x = 1 ignores source colour.
            // Iterations + 1 ensures no traces of original colour left when e.g. fading to black.
            for (int x = 1; x < Iterations; x++)
            {
                // Defines the percentage in terms of completeness of all iterations.
                double percentageProgress = (float)x / Iterations;

                // Scale the delta values by the percentage.
                double hScaled = hDelta * percentageProgress;
                double cScaled = cDelta * percentageProgress;
                double lScaled = lDelta * percentageProgress;

                // Add a new colour which is a combination of the source value with added scaled delta
                colours.Add
                (
                    new Lch
                    (
                        sourceColor.L + lScaled,
                        sourceColor.C + cScaled,
                        sourceColor.H + hScaled
                    )
                );
            }

            // Add target colour
            colours.Add(destinationColor);

            // Return the new colours.
            return(colours);
        }
        private static async void InterpolateColor(PropertyInfo propertyInfo, AnimMessage animationMessage, AnimInterpolator interpolator, Color sourceColor, Color destinationColor)
        {
            // Safety procedure
            try
            {
                // Calculate all interpolated colours in between.
                Lch        originalColorLch = ColorspaceConverter.ColorToLch(sourceColor);
                Lch        newColorLch      = ColorspaceConverter.ColorToLch(destinationColor);
                List <Lch> lchColours       = interpolator.CalculateIntermediateColours(originalColorLch, newColorLch);

                // Converted interpolated colours to RGB.
                List <Color> interpolatedColours = ColorspaceConverter.LchListToColor(lchColours);

                // Check if object is a winform control.
                Control winFormControl   = animationMessage.Control as Control;
                bool    isWinFormControl = winFormControl != null;

                // Interpolate over the colours.
                foreach (Color newBackgroundColour in interpolatedColours)
                {
                    // Check exit condition.
                    if (animationMessage.PlayAnimation == false)
                    {
                        return;
                    }

                    // Set the BackColor
                    if (isWinFormControl)
                    {
                        winFormControl.Invoke((ChangeColorDelegate)ChangeColor, propertyInfo, winFormControl, newBackgroundColour);
                    }
                    else
                    {
                        propertyInfo.SetValue(animationMessage.Control, newBackgroundColour, null);
                    }

                    // Wait
                    await Task.Delay(interpolator.SleepTime);
                }
            } catch { }
        }
Esempio n. 28
0
        /// <summary>
        /// Your own user code starts here.
        /// If this is your first time, do consider reading the notice above.
        /// It contains some very useful information.
        /// </summary>
        public static async void Init()
        {
            /*
             *  Reloaded Mod Loader Sample: DX9 Internal Overlay Example
             *  Architectures supported: X86
             *
             *  Demonstrates an example of drawing with Reloaded's DirectX 9 hooking mechanism,
             *  the API that's used by a large majority of the games out there at the time of writing.
             *
             *  Note: Debugging this might prove troublesome for this entry function, with async methods,
             *  local variable values are not exactly known to show in all configurations.
             *
             *  The following sample has been tested with Sonic Adventure 2 and Sonic Heroes (under Crosire's D3D8To9)
             *  as well as Tales of Berseria (X64 & Denuvo).
             */

            /*
             *  AnimInterpolator: A tool for generating intermediate LCH colours between two targets.
             *  ColorspaceConverter: Converts between System.Drawing.Color and LCH in batch.
             *
             *  Both of these have been shamelessly and lazily stolen from Reloaded's
             *  Reloaded-GUI project for the Launcher WinForms GUI, please do not heed them any mind.
             */

            // Calculate triangle render colours (for animation).
            // This isn't pretty, just a reuse of code from Reloaded-GUI.
            AnimInterpolator interpolator = new AnimInterpolator(1000, 60);

            Lch redColor   = ColorspaceConverter.ColorToLch(System.Drawing.Color.Red);
            Lch blueColor  = ColorspaceConverter.ColorToLch(System.Drawing.Color.Blue);
            Lch greenColor = ColorspaceConverter.ColorToLch(System.Drawing.Color.Green);

            List <Lch> redToGreenColour  = interpolator.CalculateIntermediateColours(redColor, greenColor);
            List <Lch> greenToBlueColour = interpolator.CalculateIntermediateColours(greenColor, blueColor);
            List <Lch> blueToRedColour   = interpolator.CalculateIntermediateColours(blueColor, redColor);

            _redToGreenColours  = new List <Color>();
            _greenToBlueColours = new List <Color>();
            _blueToRedColours   = new List <Color>();

            // Convert our Lch colours to SharpDX ones.
            foreach (var colour in redToGreenColour)
            {
                System.Drawing.Color colorRGB = ColorspaceConverter.LchToColor(colour);
                _redToGreenColours.Add(new SharpDX.Color(colorRGB.R, colorRGB.G, colorRGB.B));
            }

            foreach (var colour in greenToBlueColour)
            {
                System.Drawing.Color colorRGB = ColorspaceConverter.LchToColor(colour);
                _greenToBlueColours.Add(new SharpDX.Color(colorRGB.R, colorRGB.G, colorRGB.B));
            }

            foreach (var colour in blueToRedColour)
            {
                System.Drawing.Color colorRGB = ColorspaceConverter.LchToColor(colour);
                _blueToRedColours.Add(new SharpDX.Color(colorRGB.R, colorRGB.G, colorRGB.B));
            }

            /*
             *  This one's going to be embarrasingly short, sit tight.
             *  Make sure to add using SharpDX.Direct3D9; to the top of your file.
             *
             *  RenderDelegate: EndScene hook, this is where you will render stuff to the screen.
             *  ResetDelegate: Reset hook, this is called when the resolution of the window changes, or a switch from fullscreen to window is performed.
             *  HookDelay: Some games require this due to bad programming *cough* Sonic Adventure 2 *cough*.
             */

            _directX9Overlay = await DX9Overlay.CreateDirectXOverlay(RenderDelegate, ResetDelegate, 0);

            _directX9Overlay.EndSceneHook?.Activate();
            _directX9Overlay.ResetHook?.Activate();
            _directX9Overlay.EndSceneHook64?.Activate();
            _directX9Overlay.ResetHook64?.Activate();

            /*
             *  Warning: Amateur DirectX 9 Rendering Code.
             *  I've only provided the hooks, at the time of writing this, I was not familliar with DirectX
             *  nor SharpDX myself, below is (was) a basic example of rendering some text, a line and a basic arbitrary shape.
             *
             *  Protip: If looking for a SharpDX function, search the SharpDX repository with the C++ function.
             *  I would also highly advise looking at SharpDX examples https://github.com/sharpdx/SharpDX-Samples/tree/master/Desktop/Direct3D9
             */
        }