Ejemplo n.º 1
0
        /// <summary>
        /// Blends the colors based on the given weight values.
        /// </summary>
        /// <param name="c">The array of color values.</param>
        /// <param name="w">The array of weight values.</param>
        /// <returns>
        /// Each color will be blended in proportionally to its weight value respective to
        /// the total summation of the weight values.
        /// </returns>
        /// <remarks>
        /// "WAIP" stands for "weights, floating-point"</remarks>
        public static ColorBgra BlendColorsWFP(ColorBgra[] c, double[] w)
        {
            if (c.Length != w.Length)
            {
                throw new ArgumentException("c.Length != w.Length");
            }

            if (c.Length == 0)
            {
                return(ColorBgra.FromUInt32(0));
            }

            double wsum = 0;
            double asum = 0;

            for (int i = 0; i < w.Length; ++i)
            {
                wsum += w[i];
                asum += (double)c[i].A * w[i];
            }

            double a         = asum / wsum;
            double aMultWsum = a * wsum;

            double b;
            double g;
            double r;

            if (asum == 0)
            {
                b = 0;
                g = 0;
                r = 0;
            }
            else
            {
                b = 0;
                g = 0;
                r = 0;

                for (int i = 0; i < c.Length; ++i)
                {
                    b += (double)c[i].A * c[i].B * w[i];
                    g += (double)c[i].A * c[i].G * w[i];
                    r += (double)c[i].A * c[i].R * w[i];
                }

                b /= aMultWsum;
                g /= aMultWsum;
                r /= aMultWsum;
            }

            return(ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Blends the colors based on the given weight values.
        /// </summary>
        /// <param name="c">The array of color values.</param>
        /// <param name="w">The array of weight values.</param>
        /// <returns>
        /// The weights should be fixed point numbers.
        /// The total summation of the weight values will be treated as "1.0".
        /// Each color will be blended in proportionally to its weight value respective to
        /// the total summation of the weight values.
        /// </returns>
        /// <remarks>
        /// "WAIP" stands for "weights, arbitrary integer precision"</remarks>
        public static ColorBgra BlendColorsWAIP(ColorBgra[] c, uint[] w)
        {
            if (c.Length != w.Length)
            {
                throw new ArgumentException("c.Length != w.Length");
            }

            if (c.Length == 0)
            {
                return(ColorBgra.FromUInt32(0));
            }

            long wsum = 0;
            long asum = 0;

            for (int i = 0; i < w.Length; ++i)
            {
                wsum += w[i];
                asum += c[i].A * w[i];
            }

            uint a = (uint)((asum + (wsum >> 1)) / wsum);

            long b;
            long g;
            long r;

            if (a == 0)
            {
                b = 0;
                g = 0;
                r = 0;
            }
            else
            {
                b = 0;
                g = 0;
                r = 0;

                for (int i = 0; i < c.Length; ++i)
                {
                    b += (long)c[i].A * c[i].B * w[i];
                    g += (long)c[i].A * c[i].G * w[i];
                    r += (long)c[i].A * c[i].R * w[i];
                }

                b /= asum;
                g /= asum;
                r /= asum;
            }

            return(ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a MaskSurface by copying the given region-of-interest from an Image.
        /// </summary>
        /// <param name="source">The Surface to copy pixels from.</param>
        /// <param name="roi">Defines the Region from which to copy pixels from the Image.</param>
        public MaskedSurface(Surface source, PdnRegion roi)
        {
            PdnRegion roiClipped = (PdnRegion)roi.Clone();

            roiClipped.Intersect(source.Bounds);

            Rectangle boundsClipped = roiClipped.GetBoundsInt();

            this.surface = new Surface(boundsClipped.Size);
            this.surface.Clear(ColorBgra.FromUInt32(0x00ffffff));

            Rectangle rect      = boundsClipped;
            Point     dstOffset = new Point(rect.X - boundsClipped.X, rect.Y - boundsClipped.Y);

            this.surface.CopySurface(source, dstOffset, rect);

            this.region = roiClipped;
            SetPathField(PdnGraphicsPath.FromRegion(this.region));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructs a MaskSurface by copying the given region-of-interest from an Image.
        /// </summary>
        /// <param name="source">The Surface to copy pixels from.</param>
        /// <param name="roi">Defines the Region from which to copy pixels from the Image.</param>
        public MaskedSurface(Surface source, PdnRegion roi)
        {
            PdnRegion roiClipped = (PdnRegion)roi.Clone();

            roiClipped.Intersect(source.Bounds);

            Rectangle boundsClipped = roiClipped.GetBoundsInt();

            this.SurfaceReadOnly = new Surface(boundsClipped.Size);
            this.SurfaceReadOnly.Clear(ColorBgra.FromUInt32(0x00ffffff));

            Rectangle rect      = boundsClipped;
            Point     dstOffset = new Point(rect.X - boundsClipped.X, rect.Y - boundsClipped.Y);

            this.SurfaceReadOnly.CopySurface(source, dstOffset, rect);

            this.region = roiClipped;
            // TODO: FromRegion() is a VERY expensive call for what we are doing!
            PdnGraphicsPath newPath = PdnGraphicsPath.FromRegion(this.region);

            SetPathField(newPath);
        }
Ejemplo n.º 5
0
 public override ColorBgra Apply(ColorBgra color)
 {
     return(ColorBgra.FromUInt32(color.Bgra | 0xff000000));
 }
Ejemplo n.º 6
0
 public override ColorBgra Apply(ColorBgra color)
 {
     return(ColorBgra.FromUInt32((color.Bgra & 0x00ffffff) + addValue));
 }
Ejemplo n.º 7
0
        public static ColorBgra ParseHexString(string hexString)
        {
            uint value = Convert.ToUInt32(hexString, 16);

            return(ColorBgra.FromUInt32(value));
        }