public override void Apply(Image <Rgba32> bitmap) { // Temporary buffer so we don't mess up blending. using (var buffer = new Image <Rgba32>(Configuration.Default, bitmap.Width, bitmap.Height, new Rgba32(0, 0, 0, 0))) { if (Masked) { GenPointsMasked(buffer); } else { GenPoints(buffer); } var srcSpan = buffer.GetPixelSpan(); var dstSpan = bitmap.GetPixelSpan(); var width = bitmap.Width; var height = bitmap.Height; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var i = y * width + x; var dstColor = dstSpan[i].ConvertImgSharp(); var srcColor = srcSpan[i].ConvertImgSharp(); dstSpan[i] = Color.Blend(dstColor, srcColor, DstFactor, SrcFactor).ConvertImgSharp(); } } } }
public override void Apply(Image <Rgba32> bitmap) { var noise = new NoiseGenerator(NoiseType); noise.SetSeed(Seed); noise.SetFrequency(Frequency); noise.SetPersistence(Persistence); noise.SetLacunarity(Lacunarity); noise.SetOctaves(Octaves); noise.SetPeriodX(bitmap.Width); noise.SetPeriodY(bitmap.Height); var threshVal = 1 / (1 - Threshold); var powFactor = 1 / Power; var span = bitmap.GetPixelSpan(); for (var y = 0; y < bitmap.Height; y++) { for (var x = 0; x < bitmap.Width; x++) { // Do noise calculations. var noiseVal = MathF.Min(1, MathF.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2)); // Threshold noiseVal = MathF.Max(0, noiseVal - Threshold); noiseVal *= threshVal; noiseVal = (float)MathF.Pow(noiseVal, powFactor); // Get colors based on noise values. var srcColor = Color.InterpolateBetween(OuterColor, InnerColor, noiseVal) .WithAlpha(noiseVal); // Apply blending factors & write back. var i = y * bitmap.Width + x; var dstColor = span[i].ConvertImgSharp(); span[i] = Color.Blend(dstColor, srcColor, DstFactor, SrcFactor).ConvertImgSharp(); } } }