Beispiel #1
0
        ///==========================================================================================
        ///<summary>
        /// Initializes a new instance of the MagickColor class using the specified RGBA hex string or
        /// name of the color (http://www.imagemagick.org/script/color.php).
        /// For example: #F00, #F00C, #FF0000, #FF0000CC
        ///</summary>
        ///<param name="color">The RGBA/CMYK hex string or name of the color.</param>
#elif Q16 || Q16HDRI
        ///<summary>
        /// Initializes a new instance of the MagickColor class using the specified RGBA hex string or
        /// name of the color (http://www.imagemagick.org/script/color.php).
        /// For example: #F00, #F00C, #FF0000, #FF0000CC, #FFFF00000000, #FFFF00000000CCCC
        ///</summary>
        ///<param name="color">The RGBA/CMYK hex string or name of the color.</param>
#else
#error Not implemented!
#endif
        public MagickColor(string color)
        {
            Throw.IfNullOrEmpty("color", color);

            if (color.Equals("transparent", StringComparison.OrdinalIgnoreCase))
            {
                Initialize(Quantum.Max, Quantum.Max, Quantum.Max, 0);
                return;
            }

            if (color[0] == '#')
            {
#if Q8
                ParseQ8HexColor(color);
#elif Q16 || Q16HDRI
                ParseQ16HexColor(color);
#else
#error Not implemented!
#endif
                return;
            }

            using (NativeMagickColor instance = new NativeMagickColor())
            {
                Throw.IfFalse("color", instance.Initialize(color), "Invalid color specified");
                Initialize(instance);
            }
        }
Beispiel #2
0
        private void Initialize(NativeMagickColor instance)
        {
            R = instance.Red;
            G = instance.Green;
            B = instance.Blue;
            A = instance.Alpha;
            K = instance.Black;

            Count = (int)instance.Count;
        }
Beispiel #3
0
        private void Initialize(NativeMagickColor instance)
        {
            R = instance.Red;
            G = instance.Green;
            B = instance.Blue;
            A = instance.Alpha;
            K = instance.Black;

            IsCmyk = instance.IsCMYK;
        }
Beispiel #4
0
 internal static MagickColor CreateInstance(IntPtr instance)
 {
     if (instance == IntPtr.Zero)
     {
         return(null);
     }
     using (NativeMagickColor nativeInstance = new NativeMagickColor(instance))
     {
         return(new MagickColor(nativeInstance));
     }
 }
Beispiel #5
0
        ///<summary>
        /// Determines whether the specified geometry 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>
        public bool FuzzyEquals(MagickColor other, Percentage fuzz)
        {
            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            using (NativeMagickColor instance = CreateNativeInstance())
            {
                return(instance.FuzzyEquals(other, fuzz.ToQuantum()));
            }
        }
Beispiel #6
0
        private NativeMagickColor CreateNativeInstance()
        {
            NativeMagickColor instance = new NativeMagickColor();

            instance.Red   = R;
            instance.Green = G;
            instance.Blue  = B;
            instance.Alpha = A;
            instance.Black = K;

            return(instance);
        }
Beispiel #7
0
        private NativeMagickColor CreateNativeInstance()
        {
            NativeMagickColor instance = new NativeMagickColor()
            {
                Red   = R,
                Green = G,
                Blue  = B,
                Alpha = A,
                Black = K,
            };

            return(instance);
        }
Beispiel #8
0
        internal static IMagickColor <QuantumType>?CreateInstance(IntPtr instance, out int count)
        {
            count = 0;
            if (instance == IntPtr.Zero)
            {
                return(null);
            }

            using (NativeMagickColor nativeInstance = new NativeMagickColor(instance))
            {
                count = (int)nativeInstance.Count;
                return(new MagickColor(nativeInstance));
            }
        }
Beispiel #9
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()));
            }
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MagickColor"/> class.
        /// </summary>
        /// <param name="color">The RGBA/CMYK hex string or name of the color (http://www.imagemagick.org/script/color.php).
        /// For example: #F000, #FF000000</param>
#elif Q16 || Q16HDRI
        /// <summary>
        /// Initializes a new instance of the <see cref="MagickColor"/> class.
        /// </summary>
        /// <param name="color">The RGBA/CMYK hex string or name of the color (http://www.imagemagick.org/script/color.php).
        /// For example: #F000, #FF000000, #FFFF000000000000</param>
#else
#error Not implemented!
#endif
        public MagickColor(string color)
        {
            Throw.IfNullOrEmpty(nameof(color), color);

            if (color.Equals("transparent", StringComparison.OrdinalIgnoreCase))
            {
                Initialize(Quantum.Max, Quantum.Max, Quantum.Max, 0);
                return;
            }

            if (color[0] == '#')
            {
                ParseHexColor(color);
                return;
            }

            using (NativeMagickColor instance = new NativeMagickColor())
            {
                Throw.IfFalse(nameof(color), instance.Initialize(color), "Invalid color specified");
                Initialize(instance);
            }
        }
Beispiel #11
0
 private MagickColor(NativeMagickColor instance) => Initialize(instance);
Beispiel #12
0
 internal static MagickColor CreateInstance(IntPtr instance)
 {
   if (instance == IntPtr.Zero)
     return null;
   using (NativeMagickColor nativeInstance = new NativeMagickColor(instance))
   {
     return new MagickColor(nativeInstance);
   }
 }