Ejemplo n.º 1
0
 public static void AreEqual(IMagickColor <QuantumType> expected, IMagickImage <QuantumType> image, int x, int y)
 {
     using (var pixels = image.GetPixelsUnsafe())
     {
         AreEqual(expected, pixels.GetPixel(x, y), $" at position {x}x{y}");
     }
 }
Ejemplo n.º 2
0
 public static void NotEqual(IMagickColor <QuantumType> notExpected, IMagickColor <QuantumType> actual, string messageSuffix)
 {
     if (notExpected.R == actual.R && notExpected.G == actual.G && notExpected.B == actual.B && notExpected.A == actual.A)
     {
         throw new XunitException("Colors are the same (" + actual.ToString() + ")" + messageSuffix);
     }
 }
Ejemplo n.º 3
0
 public static void AreNotEqual(IMagickColor <QuantumType> notExpected, IMagickImage <QuantumType> image, int x, int y)
 {
     using (var collection = image.GetPixelsUnsafe())
     {
         AreNotEqual(notExpected, collection.GetPixel(x, y), $" at position {x}x{y}");
     }
 }
Ejemplo n.º 4
0
 public bool FuzzyEquals(IMagickColor <QuantumType>?other, QuantumType fuzz)
 {
     using (var otherNative = MagickColor.CreateInstance(other))
     {
         bool result;
         #if PLATFORM_AnyCPU
         if (OperatingSystem.IsArm64)
         #endif
         #if PLATFORM_arm64 || PLATFORM_AnyCPU
         result = NativeMethods.ARM64.MagickColor_FuzzyEquals(Instance, otherNative.Instance, fuzz);
         #endif
         #if PLATFORM_AnyCPU
         else if (OperatingSystem.Is64Bit)
         #endif
         #if PLATFORM_x64 || PLATFORM_AnyCPU
         result = NativeMethods.X64.MagickColor_FuzzyEquals(Instance, otherNative.Instance, fuzz);
         #endif
         #if PLATFORM_AnyCPU
         else
         #endif
         #if PLATFORM_x86 || PLATFORM_AnyCPU
         result = NativeMethods.X86.MagickColor_FuzzyEquals(Instance, otherNative.Instance, fuzz);
         #endif
         return(result);
     }
 }
Ejemplo n.º 5
0
 private ColorYUV(IMagickColor <QuantumType> color)
     : base(color)
 {
     Y = (1.0 / Quantum.Max) * ((0.298839 * color.R) + (0.586811 * color.G) + (0.11435 * color.B));
     U = ((1.0 / Quantum.Max) * ((-0.147 * color.R) - (0.289 * color.G) + (0.436 * color.B))) + 0.5;
     V = ((1.0 / Quantum.Max) * ((0.615 * color.R) - (0.515 * color.G) - (0.1 * color.B))) + 0.5;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="other">The color to compare this color with.</param>
        /// <returns>A signed number indicating the relative values of this instance and value.</returns>
        public int CompareTo(IMagickColor <QuantumType>?other)
        {
            if (other is null)
            {
                return(1);
            }

            if (R < other.R)
            {
                return(-1);
            }

            if (R > other.R)
            {
                return(1);
            }

            if (G < other.G)
            {
                return(-1);
            }

            if (G > other.G)
            {
                return(1);
            }

            if (B < other.B)
            {
                return(-1);
            }

            if (B > other.B)
            {
                return(1);
            }

            if (K < other.K)
            {
                return(-1);
            }

            if (K > other.K)
            {
                return(1);
            }

            if (A < other.A)
            {
                return(-1);
            }

            if (A > other.A)
            {
                return(1);
            }

            return(0);
        }
Ejemplo n.º 7
0
 internal static INativeInstance CreateInstance(IMagickColor <QuantumType> instance)
 {
     if (instance == null)
     {
         return(NativeInstance.Zero);
     }
     return(MagickColor.CreateNativeInstance(instance));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SparseColorArg"/> class.
        /// </summary>
        /// <param name="x">The X position.</param>
        /// <param name="y">The Y position.</param>
        /// <param name="color">The color.</param>
        public SparseColorArg(double x, double y, IMagickColor <QuantumType> color)
        {
            Throw.IfNull(nameof(color), color);

            X     = x;
            Y     = y;
            Color = color;
        }
Ejemplo n.º 9
0
 private ColorGray(IMagickColor <QuantumType> color)
     : base(color)
 {
     _shade =
         (0.212656 * Quantum.ScaleToDouble(color.R)) +
         (0.715158 * Quantum.ScaleToDouble(color.G)) +
         (0.072186 * Quantum.ScaleToDouble(color.B));
 }
Ejemplo n.º 10
0
 public static void AreNotEqual(IMagickColor <QuantumType> notExpected, IMagickColor <QuantumType> actual, string messageSuffix)
 {
     if (notExpected.R == actual.R && notExpected.G == actual.G &&
         notExpected.B == actual.B && notExpected.A == actual.A)
     {
         Assert.Fail("Colors are the same (" + actual.ToString() + ")");
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Converts the specified <see cref="IMagickColor{QuantumType}"/> to an instance of this type.
        /// </summary>
        /// <param name="color">The color to use.</param>
        /// <returns>A <see cref="ColorMono"/> instance.</returns>
        public static ColorMono?FromMagickColor(IMagickColor <QuantumType> color)
        {
            if (color == null)
            {
                return(null);
            }

            return(new ColorMono(color));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Converts the specified <see cref="IMagickColor{QuantumType}"/> to an instance of this type.
        /// </summary>
        /// <param name="color">The color to use.</param>
        /// <returns>A <see cref="ColorCMYK"/> instance.</returns>
        public static ColorCMYK?FromMagickColor(IMagickColor <QuantumType> color)
        {
            if (color is null)
            {
                return(null);
            }

            return(new ColorCMYK(color));
        }
Ejemplo n.º 13
0
        private static void AreEqual(QuantumType expected, QuantumType actual, IMagickColor <QuantumType> expectedColor, IMagickColor <QuantumType> actualColor, float delta, string channel, string messageSuffix)
        {
#if Q16HDRI
            if (double.IsNaN(actual))
            {
                actual = 0;
            }
#endif

            Assert.AreEqual(expected, actual, delta, channel + " is not equal (" + expectedColor.ToString() + " != " + actualColor.ToString() + ")" + messageSuffix);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MagickColor"/> class.
        /// </summary>
        /// <param name="color">The color to use.</param>
        public MagickColor(IMagickColor <QuantumType> color)
        {
            Throw.IfNull(nameof(color), color);

            R      = color.R;
            G      = color.G;
            B      = color.B;
            A      = color.A;
            K      = color.K;
            IsCmyk = color.IsCmyk;
        }
Ejemplo n.º 15
0
 private static NativeMagickColor CreateNativeInstance(IMagickColor <QuantumType> instance)
 {
     return(new NativeMagickColor
     {
         Red = instance.R,
         Green = instance.G,
         Blue = instance.B,
         Alpha = instance.A,
         Black = instance.K,
         IsCMYK = instance.IsCmyk,
     });
 }
Ejemplo n.º 16
0
        private static void Equal(QuantumType expected, QuantumType actual, IMagickColor <QuantumType> expectedColor, IMagickColor <QuantumType> actualColor, double delta, string channel, string messageSuffix)
        {
#if Q16HDRI
            if (double.IsNaN(actual))
            {
                actual = 0;
            }
#endif

            if (actual < expected - delta || actual > expected + delta)
            {
                throw new XunitException(channel + " is not equal (" + expectedColor.ToString() + " != " + actualColor.ToString() + ") (" + expected + " != " + actual + ") " + messageSuffix);
            }
        }
Ejemplo n.º 17
0
 private ColorMono(IMagickColor <QuantumType> color)
     : base(color)
 {
     if (color.Equals(MagickColors.Black))
     {
         IsBlack = true;
     }
     else if (color.Equals(MagickColors.White))
     {
         IsBlack = false;
     }
     else
     {
         throw new ArgumentException("Invalid color specified.", nameof(color));
     }
 }
Ejemplo n.º 18
0
        public static void AreEqual(IMagickColor <QuantumType> expected, IMagickColor <QuantumType> actual, string messageSuffix)
        {
            Assert.IsNotNull(actual);

#if Q16HDRI
            /* Allow difference of 1 due to rounding issues */
            QuantumType delta = 1;
#else
            QuantumType delta = 0;
#endif

            AreEqual(expected.R, actual.R, expected, actual, delta, "R", messageSuffix);
            AreEqual(expected.G, actual.G, expected, actual, delta, "G", messageSuffix);
            AreEqual(expected.B, actual.B, expected, actual, delta, "B", messageSuffix);
            AreEqual(expected.A, actual.A, expected, actual, delta, "A", messageSuffix);
        }
Ejemplo n.º 19
0
        internal static IMagickColor <QuantumType>?Clone(IMagickColor <QuantumType>?value)
        {
            if (value == null)
            {
                return(value);
            }

            return(new MagickColor
            {
                R = value.R,
                G = value.G,
                B = value.B,
                A = value.A,
                K = value.K,
                IsCmyk = value.IsCmyk,
            });
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Determines whether the specified color is fuzzy equal to the current color.
        /// </summary>
        /// <param name="other">The color to compare this color with.</param>
        /// <param name="fuzz">The fuzz factor.</param>
        /// <returns>True when the specified color is fuzzy equal to the current instance.</returns>
        public bool FuzzyEquals(IMagickColor <QuantumType> other, Percentage fuzz)
        {
            if (other is null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            using (NativeMagickColor instance = CreateNativeInstance(this))
            {
                return(instance.FuzzyEquals(other, fuzz.ToQuantumType()));
            }
        }
Ejemplo n.º 21
0
 public void SetFillColor(IMagickColor <QuantumType>?value)
 {
     using (var valueNative = MagickColor.CreateInstance(value))
     {
         #if PLATFORM_AnyCPU
         if (OperatingSystem.Is64Bit)
         #endif
         #if PLATFORM_x64 || PLATFORM_AnyCPU
         NativeMethods.X64.MontageSettings_SetFillColor(Instance, valueNative.Instance);
         #endif
         #if PLATFORM_AnyCPU
         else
         #endif
         #if PLATFORM_x86 || PLATFORM_AnyCPU
         NativeMethods.X86.MontageSettings_SetFillColor(Instance, valueNative.Instance);
         #endif
     }
 }
Ejemplo n.º 22
0
 public void SetStrokeColor(IMagickColor <QuantumType> value)
 {
     using (INativeInstance valueNative = MagickColor.CreateInstance(value))
     {
         #if PLATFORM_AnyCPU
         if (NativeLibrary.Is64Bit)
         #endif
         #if PLATFORM_x64 || PLATFORM_AnyCPU
         NativeMethods.X64.MontageSettings_SetStrokeColor(Instance, valueNative.Instance);
         #endif
         #if PLATFORM_AnyCPU
         else
         #endif
         #if PLATFORM_x86 || PLATFORM_AnyCPU
         NativeMethods.X86.MontageSettings_SetStrokeColor(Instance, valueNative.Instance);
         #endif
     }
 }
Ejemplo n.º 23
0
 public bool FuzzyEquals(IMagickColor <QuantumType> other, QuantumType fuzz)
 {
     using (INativeInstance otherNative = MagickColor.CreateInstance(other))
     {
         #if PLATFORM_AnyCPU
         if (OperatingSystem.Is64Bit)
         #endif
         #if PLATFORM_x64 || PLATFORM_AnyCPU
         return(NativeMethods.X64.MagickColor_FuzzyEquals(Instance, otherNative.Instance, fuzz));
         #endif
         #if PLATFORM_AnyCPU
         else
         #endif
         #if PLATFORM_x86 || PLATFORM_AnyCPU
         return(NativeMethods.X86.MagickColor_FuzzyEquals(Instance, otherNative.Instance, fuzz));
         #endif
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Determines whether the specified color is equal to the current color.
        /// </summary>
        /// <param name="other">The color to compare this color with.</param>
        /// <returns>True when the specified color is equal to the current color.</returns>
        public bool Equals(IMagickColor <QuantumType>?other)
        {
            if (other is null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                (IsCmyk == other.IsCmyk &&
                 A == other.A &&
                 B == other.B &&
                 G == other.G &&
                 R == other.R &&
                 K == other.K);
        }
        public static string GetAverageHtmlColourFromImageStreamUsingScale(int frameTime, string file, VideoCollection videoCollection, SettingsWrapper settings)
        {
            SetTempDir(settings);

            using MemoryStream ms = new MemoryStream();
            new NReco.VideoConverter.FFMpegConverter().GetVideoThumbnail(videoCollection.Config.FullPath, ms, frameTime);

            if (ms.Length == 0)
            {
                return(null);
            }

            Image.FromStream(ms).Save(Path.Combine(videoCollection.Config.ImageDirectory, file), ImageFormat.Jpeg);

            ms.Seek(0, SeekOrigin.Begin);

            using MagickImage image = new MagickImage(ms, new MagickReadSettings { Format = MagickFormat.Jpeg });
            image.Crop(new MagickGeometry(new Percentage(70), new Percentage(70)), Gravity.Center);
            image.Scale(1, 1);

            IMagickColor <byte> color = image.GetPixels().First().ToColor();

            return(ColorTranslator.ToHtml(Color.FromArgb(color.A, color.R, color.G, color.B)));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DrawableTextUnderColor"/> class.
        /// </summary>
        /// <param name="color">The color to use.</param>
        public DrawableTextUnderColor(IMagickColor <QuantumType> color)
        {
            Throw.IfNull(nameof(color), color);

            Color = color;
        }
Ejemplo n.º 27
0
 private static void AreNotEqual(IMagickColor <QuantumType> expected, IPixel <QuantumType> actual, string messageSuffix)
 => AreNotEqual(expected, actual.ToColor(), messageSuffix);
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance that implements <see cref="IMagickImage{TQuantumType}"/>.
 /// </summary>
 /// <param name="color">The color to fill the image with.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <returns>A new <see cref="IMagickImage{TQuantumType}"/> instance.</returns>
 public IMagickImage <QuantumType> Create(IMagickColor <QuantumType> color, int width, int height)
 => new MagickImage(color, width, height);
Ejemplo n.º 29
0
 public static void AreNotEqual(IMagickColor <QuantumType> notExpected, IMagickColor <QuantumType> actual)
 => AreNotEqual(notExpected, actual, null);
Ejemplo n.º 30
0
 public static void AreEqual(IMagickColor <QuantumType> expected, IMagickColor <QuantumType> actual)
 => AreEqual(expected, actual, null);