예제 #1
0
        public IMaterial SetTintType(TintType type, Color color)
        {
            TintType  = type;
            TintColor = color;

            return(this);
        }
예제 #2
0
 public Glass(double width, double height, TintType tint, double quantity)
 {
     this.width      = width;
     this.height     = height;
     this.tint       = tint;
     this.woodLength = 2 * (width + height) * 3.25;
     this.glassArea  = 2 * (width * height);
     dateOrdered     = DateTime.Now;
     this.quantity   = quantity;
 }
        /// <summary>
        /// Color tints an image.
        /// </summary>
        /// <param name="image">
        /// The image to color tint.
        /// </param>
        /// <param name="color">
        /// The color to use as the tint.
        /// </param>
        /// <param name="type">
        /// The type to tint to perform.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Unsupported type specified.
        /// </exception>
        public static void Tint(this GenericImage <Color> image, Color color, TintType type)
        {
            for (var indexX = 0; indexX < image.Width; indexX++)
            {
                for (var indexY = 0; indexY < image.Height; indexY++)
                {
                    var sourceColor = image[indexX, indexY];

                    var r = sourceColor.R;
                    var g = sourceColor.G;
                    var b = sourceColor.B;
                    var a = sourceColor.A;

                    switch (type)
                    {
                    case TintType.Alpha:

                        ////////////////////// ALPHA ////////////////////////
                        sourceColor.R = (byte)((r * color.R) / 255);
                        sourceColor.G = (byte)((g * color.G) / 255);
                        sourceColor.B = (byte)((b * color.B) / 255);
                        sourceColor.A = (byte)((a * color.A) / 255);
                        break;

                    case TintType.Multiply:

                        /////////////////////// MULTIPLY //////////////////////////////
                        // Faster than a division like (s * d) / 255 are 2 shifts and 2 adds
                        var ta = (a * color.A) + 128;
                        var tr = (r * color.R) + 128;
                        var tg = (g * color.G) + 128;
                        var tb = (b * color.B) + 128;

                        var ba = ((ta >> 8) + ta) >> 8;
                        var br = ((tr >> 8) + tr) >> 8;
                        var bg = ((tg >> 8) + tg) >> 8;
                        var bb = ((tb >> 8) + tb) >> 8;

                        sourceColor.R = (byte)ba;
                        sourceColor.G = (byte)(ba <= br ? ba : br);
                        sourceColor.B = (byte)(ba <= bg ? ba : bg);
                        sourceColor.A = (byte)(ba <= bb ? ba : bb);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("type");
                    }
                }
            }
        }
예제 #4
0
 public IMaterial SetTintType(TintType type)
 {
     return(this.SetTintType(type, TintColor));
 }
예제 #5
0
 public void setTint(TintType tint)
 {
     this.tint = tint;
 }