Beispiel #1
0
 public ColorRGB32 LinearInterpolate(ColorRGB32 other, float rn, float gn, float bn, float an)
 {
     return(new ColorRGB32(
                (byte)((this.red * rn) + (other.red * (1.0f - rn))),
                (byte)((this.green * gn) + (other.green * (1.0f - gn))),
                (byte)((this.blue * bn) + (other.blue * (1.0f - bn))),
                (byte)((this.alpha * an) + (other.alpha * (1.0f - an)))));
 }
Beispiel #2
0
        /// <summary>
        /// Pre-multiplies the Red, Green, and Blue color components against the Alpha component.
        /// </summary>
        /// <param name="color">The color value to be premultiplied.</param>
        /// <returns>A new <see cref="ColorRGB32"/> instance that contains the premultiplied color value.</returns>
        public static ColorRGB32 PremultiplyAlpha(ColorRGB32 color)
        {
            var a = color.alpha / 255f;

            return(new ColorRGB32(
                       (byte)(color.Red * a),
                       (byte)(color.Green * a),
                       (byte)(color.Blue * a),
                       255));
        }
Beispiel #3
0
        private unsafe void RefreshCachedBitmap(IBitmap frameBitmap)
        {
            this.bitmap.Lock();

            if (frameBitmap is BitmapRGB24)
            {
                var bmp24 = frameBitmap as BitmapRGB24;

                fixed (void* ptr = &bmp24.Pixels[0])
                {
                    IntPtr buffer = new IntPtr(ptr);
                    this.bitmap.WritePixels(new Int32Rect(0, 0, bmp24.Width, bmp24.Height), buffer, bmp24.Pixels.Length * 3, bmp24.Width * 3);
                }

            }
            else if (frameBitmap is BitmapRGB32)
            {
                var bmp32 = frameBitmap as BitmapRGB32;

                fixed (void* ptr = &bmp32.Pixels[0])
                {
                    IntPtr buffer = new IntPtr(ptr);
                    this.bitmap.WritePixels(new Int32Rect(0, 0, bmp32.Width, bmp32.Height), buffer, bmp32.Pixels.Length * sizeof(ColorRGB32), bmp32.Width * 4);
                }
            }
            else
            {
                var bmp = frameBitmap as BitmapRGB;
                var src = bmp.Pixels;
                var pix = new ColorRGB32[bmp.Size.Elements];

                for (int i = 0; i < pix.Length; i++)
                {
                    var p = src[i];
                    pix[i] = new ColorRGB32(p.Red, p.Green, p.Blue, p.Alpha);
                }

                fixed (void* ptr = &pix[0])
                {
                    IntPtr buffer = new IntPtr(ptr);
                    this.bitmap.WritePixels(new Int32Rect(0, 0, bmp.Width, bmp.Height), buffer, bmp.Pixels.Length * sizeof(ColorRGB32), bmp.Width * sizeof(ColorRGB32));
                }
            }

            this.bitmap.AddDirtyRect(new Int32Rect(0, 0, this.bitmap.PixelWidth, this.bitmap.PixelHeight));
            this.bitmap.Unlock();
            this.Dispatcher.Invoke(DispatcherPriority.Render, EmptyAction);
        }
Beispiel #4
0
 public ColorRGB32 LinearInterpolate(ColorRGB32 other, float n)
 {
     return(this.LinearInterpolate(other, n, n, n, n));
 }
Beispiel #5
0
 /// <summary>
 /// Pre-multiplies the Red, Green, and Blue color components against the Alpha component.
 /// </summary>
 /// <returns>A new <see cref="ColorRGB32"/> instance that contains the premultiplied color value.</returns>
 public ColorRGB32 PremultiplyAlpha()
 {
     return(ColorRGB32.PremultiplyAlpha(this));
 }
Beispiel #6
0
 /// <summary>
 /// Indicates whether this <see cref="ColorRGB32"/> and a specified <see cref="ColorRGB32"/> instance represent the same color value.
 /// </summary>
 /// <param name="other">A <see cref="ColorRGB32"/> instance to compare to the current instance.</param>
 /// <returns>true if both instances represent the same color value; otherwise false.</returns>
 public bool Equals(ColorRGB32 other)
 {
     return(this == other);
 }
Beispiel #7
0
 public ColorRGB32 LinearInterpolate(ColorRGB32 other, float rn, float gn, float bn, float an)
 {
     return new ColorRGB32(
         (byte)((this.red * rn) + (other.red * (1.0f - rn))),
         (byte)((this.green * gn) + (other.green * (1.0f - gn))),
         (byte)((this.blue * bn) + (other.blue * (1.0f - bn))),
         (byte)((this.alpha * an) + (other.alpha * (1.0f - an))));
 }
Beispiel #8
0
 public ColorRGB32 LinearInterpolate(ColorRGB32 other, float n)
 {
     return this.LinearInterpolate(other, n, n, n, n);
 }
Beispiel #9
0
 /// <summary>
 /// Indicates whether this <see cref="ColorRGB32"/> and a specified <see cref="ColorRGB32"/> instance represent the same color value.
 /// </summary>
 /// <param name="other">A <see cref="ColorRGB32"/> instance to compare to the current instance.</param>
 /// <returns>true if both instances represent the same color value; otherwise false.</returns>
 public bool Equals(ColorRGB32 other)
 {
     return this == other;
 }
Beispiel #10
0
 /// <summary>
 /// Pre-multiplies the Red, Green, and Blue color components against the Alpha component.
 /// </summary>
 /// <param name="color">The color value to be premultiplied.</param>
 /// <returns>A new <see cref="ColorRGB32"/> instance that contains the premultiplied color value.</returns>
 public static ColorRGB32 PremultiplyAlpha(ColorRGB32 color)
 {
     var a = color.alpha / 255f;
     return new ColorRGB32(
         (byte)(color.Red * a),
         (byte)(color.Green * a),
         (byte)(color.Blue * a),
         255);
 }