private void ThreadedProcess() { t_workflow.AllowInvalidate = true; Engine.Color.Cell c = Engine.Application.UISelectedValues.SelectedColor; t_colorVariance.SetColor(c); for (int x = 0; x < t_imageProcessed.Width; x++) { t_colorVariance.Step(); for (int y = 0; y < t_imageProcessed.Height; y++) { int offset = t_imageProcessed.GetOffset(x, y); if (y < t_imageProcessed.Height * t_percent / 100) { Engine.Color.Cell variance = t_colorVariance.ColorVariation; variance.WriteBytes(t_imageProcessed.Array, offset); } else { c.WriteBytes(t_imageProcessed.Array, offset); } } } base.PostProcess(); }
private int Threaded_Process(int start, int end, Engine.Threading.ParamList paramList) { Engine.Effects.Noise.IModule module = (Engine.Effects.Noise.IModule)paramList.Get(paramName_module).Value; double value = 0; // loop block : source and info at : https://libnoisedotnet.codeplex.com/downloads/get/720936 // and http://libnoise.sourceforge.net/tutorials/tutorial8.html for (int y = start; y < end; y++) { for (int x = 0; x < t_imageProcessed.Width - 1; x++) { value = (module.GetValue(x, y, 10) + 1) / 2.0; if (value < 0) { value = 0; } if (value > 1.0) { value = 1.0; } byte intensity = (byte)(value * 255.0); Engine.Color.Cell c = Engine.Color.Cell.ShadeOfGray(intensity); t_imageProcessed.SetPixel(c, x, y, PixelSetOptions.Ignore); } } return(0); }
private int Threaded_Loop(int start, int end, Threading.ParamList paramList) { int counter = (int)paramList.Get("counter").Value; Engine.Threading.ThreadedLoop loop = new Threading.ThreadedLoop(); for (int ii = start; ii < end; ii++) { // collect pixels in each grid cell Engine.Color.Cell[] cells = new Engine.Color.Cell[t_cellSize * t_cellSize]; AutonomousParticle p = t_particles[ii]; Engine.Threading.ParamList paramList2 = new Threading.ParamList(); paramList2.Add("particle", typeof(AutonomousParticle), p); paramList2.Add("cells", typeof(Engine.Color.Cell[]), cells); paramList2.Add("counter", typeof(int), counter); loop.Loop(t_cellSize, Threaded_Loop_Cell_Part_1, paramList2); p.Move(); loop.Loop(t_cellSize, Threaded_Loop_Cell_Part_2, paramList2); } loop.Dispose(); return(0); }
/// <summary> /// /// </summary> /// <param name="startColor"></param> /// <param name="endColor"></param> /// <param name="steps">The number of color cell to generate a gradient starting with the startColor and ending with the endColor.</param> /// <remarks>The returned buffer will have a length of steps 8 * 4 (argb). /// Also the alpha channel is affected by the calculations.</remarks> /// <returns></returns> public static int[] GenerateLinearGradient(Engine.Color.Cell startColor, Engine.Color.Cell endColor, int steps) { int[] stride = new int[steps]; int deltaRed = 0, deltaGreen = 0, deltaBlue = 0, deltaAlpha = 0; byte newRed = 0, newGreen = 0, newBlue = 0, newAlpha = 0; for (int i = 0; i < steps; i++) { deltaBlue = (endColor.Blue - startColor.Blue) * i / steps; deltaGreen = (endColor.Green - startColor.Green) * i / steps; deltaRed = (endColor.Red - startColor.Red) * i / steps; deltaAlpha = (endColor.Alpha - startColor.Alpha) * i / steps; newBlue = (byte)(deltaBlue + startColor.Blue % 256); newGreen = (byte)(deltaGreen + startColor.Green % 256); newRed = (byte)(deltaRed + startColor.Red % 256); newAlpha = (byte)(deltaAlpha + startColor.Alpha % 256); Engine.Color.Cell c = new Engine.Color.Cell(newBlue, newGreen, newRed, newAlpha); c.WriteInt(stride, i); } return(stride); }
public ImageData(int width, int height, Engine.Color.Cell c) { t_width = width; t_height = height; t_imageData = new byte[width * height * Engine.BytesPerPixel.BGRA]; Engine.Surface.Ops.FillWithColor(t_imageData, c); }
public static Engine.Color.Cell FastAlphaBlend(Engine.Color.Cell fg, Engine.Color.Cell bg) { byte iBlue = (byte)((fg.Alpha * (fg.Blue - bg.Blue)) / 256 + bg.Blue); byte iGreen = (byte)((fg.Alpha * (fg.Green - bg.Green)) / 256 + bg.Green); byte iRed = (byte)((fg.Alpha * (fg.Red - bg.Red)) / 256 + bg.Red); return(new Engine.Color.Cell(iBlue, iGreen, iRed, Engine.ColorOpacity.Opaque)); }
private Engine.Color.Cell GetColorFromPosition() { int i = CalculateFaderIndex(); Engine.Color.Cell c = new Engine.Color.Cell(t_faderImage.Array, t_faderImage.GetOffset(0, i)); return(c); }
private void RaisingColorChanged() { // get color from plane Engine.Color.Cell c = t_colorPlane.GetPixel((int)t_cursorLocation.X, (int)t_cursorLocation.Y, Engine.Surface.PixelRetrievalOptions.ReturnEdgePixel); ColorChangedEventArgs ce = new ColorChangedEventArgs(c); OnColorChanged(ce); }
protected override void OnMouseUp(MouseButtonEventArgs e) { t_cursorIsMovable = false; base.OnMouseUp(e); ConstraintMousePosition(); Engine.Color.Cell c = GetColorFromPosition(); OnColorChanged(new ColorChangedEventArgs(c)); }
void IAttribute.SetValue(object val) { if (val.GetType() == typeof(Engine.Color.Cell)) { t_color = (Engine.Color.Cell)val; } else { throw new InvalidCastException(); } }
internal override void Draw(MousePoint p) { if (!t_skipper.Skip()) { return; } Engine.Color.Cell c = Engine.Application.UISelectedValues.SelectedColor; //Engine.Surface.Ops.GetPixel(t_imageSource, p.X, p.Y); CreateParticles(c, p.X, p.Y, t_alpha); Flow(p.X, p.Y); }
private void CreateParticles(Engine.Color.Cell c, int x, int y, byte alpha) { c.Alpha = alpha; t_particles = new Engine.Effects.Particles.Obsolete.LivingPixelParticle_O[30]; for (int i = 0; i < t_particles.Length; i++) { // particles are at pen location Engine.Effects.Particles.Obsolete.LivingPixelParticle_O p = new Engine.Effects.Particles.Obsolete.LivingPixelParticle_O(c, x, y, t_particleLife, t_expansion); t_particles[i] = p; } }
protected override void OnMouseDown(MouseButtonEventArgs e) { t_cursorIsMovable = true; t_mousePoint = new Engine.Point((int)e.GetPosition(this).X, (int)e.GetPosition(this).Y); this.InvalidateVisual(); ConstraintMousePosition(); Engine.Color.Cell c = GetColorFromPosition(); OnColorChanged(new ColorChangedEventArgs(c)); base.OnMouseDown(e); }
public void FillFluid(Engine.Surface.Canvas c) { for (int y = 0; y < c.Height; y++) { for (int x = 0; x < c.Width; x++) { Engine.Color.Cell pix = c.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel); double lum = (double)Engine.Calc.Color.Luminance(pix); int offset = CellOffset(x, y, c.Width); mp_p0[offset] = lum; // lum /255; mp_xv0[offset] = lum; mp_yv0[offset] = lum; } } }
public unsafe static void FillWithColor(byte[] array, Engine.Color.Cell c) { fixed(byte *pCanvas = array) { byte *pc = pCanvas; for (int i = 0; i < array.Length; i += Engine.BytesPerPixel.BGRA) { *pc = c.Blue; pc++; *pc = c.Green; pc++; *pc = c.Red; pc++; *pc = c.Alpha; pc++; } } }
private void CreateParticles(byte alpha) { //Engine.Color.Cell color = new Engine.Color.Cell(200, 220, 230, alpha); beige Engine.Color.Cell color = Engine.Application.UISelectedValues.SelectedColor; color.Alpha = alpha; t_particles = new Particles.Obsolete.LivingPixelParticle_O[t_particleCount]; for (int i = 0; i < t_particles.Length; i++) { // particles are centered on screen Particles.Obsolete.LivingPixelParticle_O p = new Particles.Obsolete.LivingPixelParticle_O(color, t_imageSource.Width / 2, t_imageSource.Height / 2, t_particleLife, t_expansion); t_particles[i] = p; } }
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e) { t_mousePoint = new Engine.Point((int)e.GetPosition(this).X, (int)e.GetPosition(this).Y); if (t_cursorIsMovable) { this.InvalidateVisual(); ConstraintMousePosition(); Engine.Color.Cell c = GetColorFromPosition(); OnColorChanged(new ColorChangedEventArgs(c)); } base.OnMouseMove(e); }
/// <summary> /// / /// </summary> /// <param name="upperLeft"></param> /// <param name="upperRight"></param> /// <param name="lowerLeft"></param> /// <param name="lowerRight"></param> /// <param name="width">The width of the resulting grid including the provided corners.</param> /// <param name="height">The height of the resulting grid including the provided corners.</param> /// <returns></returns> public static int[,] GenerateQuadGradient(Engine.Color.Cell upperLeft, Engine.Color.Cell upperRight, Engine.Color.Cell lowerLeft, Engine.Color.Cell lowerRight, int width, int height) { int[,] grid = new int[width, height]; // first row int[] firstRow = GenerateLinearGradient(upperLeft, upperRight, width); for (int i = 0; i < width; i++) { Engine.Color.Cell c = new Engine.Color.Cell(firstRow, i); grid[i, 0] = c.Int; } // last row int[] lastRow = GenerateLinearGradient(lowerLeft, lowerRight, width); for (int i = 0; i < width; i++) { Engine.Color.Cell c = new Engine.Color.Cell(lastRow, i); grid[i, height - 1] = c.Int; } // rows in between : first column int[] firstColumn = GenerateLinearGradient(upperLeft, lowerLeft, height); // rows in between : last column int[] lastColumn = GenerateLinearGradient(upperRight, lowerRight, height); // rows in between : fill byte[,] middle = new byte[width, (height - 2)]; for (int y = 1; y < height - 1; y++) { int[] middleRow = GenerateLinearGradient(new Engine.Color.Cell(firstColumn, y), new Engine.Color.Cell(lastColumn, y), width); for (int x = 0; x < width; x++) { Engine.Color.Cell c = new Engine.Color.Cell(middleRow, x); grid[x, y] = c.Int; } } return(grid); }
internal override void Draw(MousePoint p) { for (int y = p.Y - 10; y < p.Y + 10; y++) { for (int x = p.X - 10; x < p.X + 10; x++) { if (t_mask.GetPixel(x, y, PixelRetrievalOptions.ReturnEdgePixel) == MaskValue.BlackReveal) { continue; } Engine.Color.Cell c = t_imageSource.GetPixel(x, y, PixelRetrievalOptions.ReturnEdgePixel); c.ChangeBrightness(t_brightnessAmount); t_imageSource.SetPixel(c, x, y, PixelSetOptions.Ignore); t_mask.SetPixel(MaskValue.BlackReveal, x, y, PixelSetOptions.Ignore); } } }
private void CreateFaderImage() { t_faderImage = new Engine.Surface.Canvas((int)this.Width - 10, (int)this.Height - 10); //, new Engine.Color.Cell(100, 100, 100, 255)); t_range = Engine.Calc.Color.GenerateLinearGradient(new Engine.Color.Models.HSV(0, 1.0, 1.0), new Engine.Color.Models.HSV(1.0, 1.0, 1.0), t_faderImage.Height); int offset = 0; for (int y = 0; y < t_faderImage.Height; y++) { System.Drawing.Color c = t_range[y].ToRGB().ToArgb(); Engine.Color.Cell cell = new Engine.Color.Cell(c); for (int x = 0; x < t_faderImage.Width; x++) { cell.WriteBytes(t_faderImage.Array, offset); offset += Engine.BytesPerPixel.BGRA; } } }
private int Threaded_CreateFlowField(int start, int end, Engine.Threading.ParamList paramList) { for (int y = start; y < end; y++) { for (int x = 0; x < t_imageSource.Width; x++) { // initialize vectors with basic to-the-right direction t_flowField[x, y] = new Engine.Calc.Vector(1, 0); Engine.Color.Cell c = t_imagePerlin.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel); double lum = (double)Engine.Calc.Color.Luminance(c); double angle = (lum * 360 / 255); double rad = angle * Engine.Calc.Math.DEG_TO_RAD; t_flowField[x, y].X = (float)System.Math.Cos(rad); t_flowField[x, y].Y = (float)System.Math.Sin(rad); } } return(0); }
private int Threaded_ParticleFlow(int start, int end, Engine.Threading.ParamList paramList) { int x = (int)paramList.Get(paramName_X).Value; double divSpread255 = (double)paramList.Get(paramName_divSpread255).Value; double divSpread2f = (double)paramList.Get(paramName_divSpread2f).Value; for (int y = start; y < end; y++) { Engine.Color.Cell c = t_imagePerlin.GetPixel(x, y, Surface.PixelRetrievalOptions.ReturnEdgePixel); double lum = (double)Engine.Calc.Color.Luminance(c); double angle = (lum * divSpread255) - divSpread2f; // reduce to range from 0 to 90 (degrees) then shift to get -45 to 45 (degrees) double rad = angle * Engine.Calc.Math.DEG_TO_RAD; t_flowField[x, y].X = (float)System.Math.Cos(rad); t_flowField[x, y].Y = (float)System.Math.Sin(rad); t_particles[y].Move(t_flowField[x, y]); } return(0); }