/// <summary> /// Calculates the linear interpolation between the current color and the specified color. /// </summary> /// <param name="other">The <see cref="ColorRGB24"/> to interpolate against.</param> /// <param name="tr">The interpolation factor for the red channel, 0.0 to 1.0.</param> /// <param name="tg">The interpolation factor for the green channel, 0.0 to 1.0.</param> /// <param name="tb">The interpolation factor for the blue channel, 0.0 to 1.0.</param> /// <returns>A new <see cref="ColorRGB24"/> that is the result of the interpolation.</returns> public ColorRGB24 LinearInterpolate(ColorRGB24 other, float tr, float tg, float tb) { Contract.Requires(tr <= 1.0f); Contract.Requires(0.0f <= tr); Contract.Requires(tg <= 1.0f); Contract.Requires(0.0f <= tg); Contract.Requires(tb <= 1.0f); Contract.Requires(0.0f <= tb); return(new ColorRGB24( (byte)((this.red * tr) + (other.red * (1.0f - tr))), (byte)((this.green * tg) + (other.green * (1.0f - tg))), (byte)((this.blue * tb) + (other.blue * (1.0f - tb))))); }
private BitmapRGB24 ApplyEffectRGB24(BitmapRGB24 input) { ColorRGB24[] pix = new ColorRGB24[input.Size.Elements]; var c = this.Contrast; for (int i = 0; i < pix.Length; i++) { pix[i].Red = (byte)((pix[i].Red - 127) * c); pix[i].Green = (byte)((pix[i].Green - 127) * c); pix[i].Blue = (byte)((pix[i].Blue - 127) * c); } return new BitmapRGB24(input.Size, pix); }
private void BoxBlurRGB24(BitmapRGB24 input, BitmapRGB24 output, BitmapRGB32 mask = null) { Contract.Requires(input != null); Contract.Requires(output != null); Contract.Requires(input.Width == output.Width); Contract.Requires(input.Height == output.Height); int radius = this.Radius; int w = input.Width; int h = input.Height; var bmp = output; var pix = bmp.Pixels; float div = (float)Math.Pow((radius * 2 + 1), 2); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { var tr = 0.0; var tg = 0.0; var tb = 0.0; for (int ky = -radius; ky <= radius; ky++) { for (int kx = -radius; kx <= radius; kx++) { var px = Math.Max(Math.Min(x + kx, w - 1), 0); var py = Math.Max(Math.Min(y + ky, h - 1), 0); var p = input[px, py]; tr += p.Red; tg += p.Green; tb += p.Blue; //div += 1; } } //total.Alpha = 1.0f; bmp[x, y] = new ColorRGB24((byte)(tr / 255.0 * (255.0 / div)), (byte)(tg / 255.0 * (255.0 / div)), (byte)(tb / 255.0 * (255.0 / div))); } } }
/// <summary> /// Calculates the linear interpolation between the current color and the specified color. /// </summary> /// <param name="other">The <see cref="ColorRGB24"/> to interpolate against.</param> /// <param name="tr">The interpolation factor for the red channel, 0.0 to 1.0.</param> /// <param name="tg">The interpolation factor for the green channel, 0.0 to 1.0.</param> /// <param name="tb">The interpolation factor for the blue channel, 0.0 to 1.0.</param> /// <returns>A new <see cref="ColorRGB24"/> that is the result of the interpolation.</returns> public ColorRGB24 LinearInterpolate(ColorRGB24 other, float tr, float tg, float tb) { Contract.Requires(tr <= 1.0f); Contract.Requires(0.0f <= tr); Contract.Requires(tg <= 1.0f); Contract.Requires(0.0f <= tg); Contract.Requires(tb <= 1.0f); Contract.Requires(0.0f <= tb); return new ColorRGB24( (byte)((this.red * tr) + (other.red * (1.0f - tr))), (byte)((this.green * tg) + (other.green * (1.0f - tg))), (byte)((this.blue * tb) + (other.blue * (1.0f - tb)))); }
/// <summary> /// Calculates the linear interpolation between the current color and the specified color. /// </summary> /// <param name="other">The other <see cref="ColorRGB24"/> to interpolate against.</param> /// <param name="t">The interpolation factor, 0.0 to 1.0.</param> /// <returns>A new <see cref="ColorRGB24"/> that is the result of the interpolation.</returns> public ColorRGB24 LinearInterpolate(ColorRGB24 other, float t) { Contract.Requires(t <= 1.0f); Contract.Requires(0.0f <= t); return this.LinearInterpolate(other, t, t, t); }
/// <summary> /// Indicates whether this <see cref="ColorRGB24"/> and a specified <see cref="ColorRGB24"/> instance represent the same color value. /// </summary> /// <param name="other">A <see cref="ColorRGB24"/> instance to compare to the current instance.</param> /// <returns>true if both instances represent the same color value; otherwise false.</returns> public bool Equals(ColorRGB24 other) { return this == other; }
/// <summary> /// Calculates the linear interpolation between the current color and the specified color. /// </summary> /// <param name="other">The other <see cref="ColorRGB24"/> to interpolate against.</param> /// <param name="t">The interpolation factor, 0.0 to 1.0.</param> /// <returns>A new <see cref="ColorRGB24"/> that is the result of the interpolation.</returns> public ColorRGB24 LinearInterpolate(ColorRGB24 other, float t) { Contract.Requires(t <= 1.0f); Contract.Requires(0.0f <= t); return(this.LinearInterpolate(other, t, t, t)); }
/// <summary> /// Indicates whether this <see cref="ColorRGB24"/> and a specified <see cref="ColorRGB24"/> instance represent the same color value. /// </summary> /// <param name="other">A <see cref="ColorRGB24"/> instance to compare to the current instance.</param> /// <returns>true if both instances represent the same color value; otherwise false.</returns> public bool Equals(ColorRGB24 other) { return(this == other); }