override protected void RenderFunction(object o) { object[] P = (object[])o; //create fractal object RenderResult.RenderComplete clbk = (RenderResult.RenderComplete)P[0]; RenderResult.RenderStatus status_clbk = (RenderResult.RenderStatus)P[1]; try { //set parameters int width = (int)pars.GetValue("WIDTH"); int heigth = (int)pars.GetValue("HEIGHT"); //Create new bitmap Bitmap bmp = new Bitmap(width, heigth, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); //Use graphics from the bitmap using (Graphics g = Graphics.FromImage(bmp)) { Random r = new Random(); //Create draw box for (int i = 0; i < 10000; i++) { int x = r.Next(0, width); int y = r.Next(0, heigth); int w = r.Next(1, width - x); int h = r.Next(1, heigth - y); int col = r.Next(0, 255); using (SolidBrush br = new SolidBrush(Color.FromArgb(col, col, col))) { g.FillRectangle(br, new Rectangle(x, y, w, h)); } status_clbk(((float)i) / 100.0f); } } //Check if its completed, if yes then wait for further input res.IsCompleted = true; ((AutoResetEvent)(res.AsyncWaitHandle)).Set(); clbk(bmp, 0); } catch { clbk(null, -1); } }
override protected void RenderFunction(object o) { object[] P = (object[])o; RenderResult.RenderComplete clbk = (RenderResult.RenderComplete)P[0]; RenderResult.RenderStatus status_clbk = (RenderResult.RenderStatus)P[1]; try { Random r = new Random(); int width = (int)pars.GetValue("WIDTH"); int heigth = (int)pars.GetValue("HEIGHT"); int iterations = (int)pars.GetValue("ITERATIONS") - 1; Int32[] Palette = (Int32[])pars.GetValue("PALETTE"); int NumThreads = (int)pars.GetValue("NUM_THREADS", 2); int BilinearFilter = (int)pars.GetValue("APPLY_BILINEAR_FILTER", 0); int[] colrTable = new int[width * heigth]; WaitHandle[] handles = new WaitHandle[NumThreads]; Thread[] threads = new Thread[NumThreads]; lines_rendered = 0; // Create the line that needs to be rendered, then iterate through each pixel. //Display diag information such as cpu cores identified etc. for (int i = 0; i < NumThreads; i++) { handles[i] = new AutoResetEvent(false); threads[i] = new Thread(new ParameterizedThreadStart(PartialRender)); threads[i].Start((object)(new object[] { i *heigth / NumThreads, heigth / NumThreads, colrTable, status_clbk, handles[i] })); } while (true) { if (WaitHandle.WaitAll(handles, 100, false) == true) { break; } else if (interrupt.WaitOne(100, false) == true) { try { for (int i = 0; i < NumThreads; i++) { threads[i].Abort(); } } catch { } clbk(null, -2); return; } } //BILINEAR FILTER IS EXPERIMENTAL AND SHOULD NOT BE USED ON BASE FRACTAL SETS //Bilinear will filter any image on a 2D/3D plane to make the image look more smooth. Higher resolutions may have no effect. if (BilinearFilter == 1) { int [] filteredColorTable = new int[(width * heigth)]; int idxs11 = 0, idxs12 = 0, idxs21 = 0, idxs22 = 0; for (int y = 0; y < heigth - 1; y++) { idxs11 = y * (width); idxs12 = idxs11 + 1; idxs21 = idxs11 + width; idxs22 = idxs21 + 1; for (int x = 0; x < width - 1; x++) { int colf1 = Utils.InterpolateColors(colrTable[idxs11], colrTable[idxs12], 127); int colf2 = Utils.InterpolateColors(colrTable[idxs21], colrTable[idxs22], 127); filteredColorTable[idxs11] = Utils.InterpolateColors(colf1, colf2, 128); idxs11++; idxs12++; idxs21++; idxs22++; } } colrTable = filteredColorTable; } //Bitmap Creation, allows painting onto object window. Bitmap bmp = new Bitmap(width, heigth, PixelFormat.Format32bppPArgb); BitmapData pdate = bmp.LockBits(new Rectangle(0, 0, width, heigth), ImageLockMode.ReadWrite, PixelFormat.Format32bppPArgb); IntPtr pscan0 = pdate.Scan0; Marshal.Copy(colrTable, 0, pscan0, width * heigth); bmp.UnlockBits(pdate); res.IsCompleted = true; ((AutoResetEvent)(res.AsyncWaitHandle)).Set(); clbk(bmp, 0); } catch { clbk(null, -1); } }