/// <summary> /// draw a ViewRange to this.matrix /// </summary> /// <param name="vr">ViewRange</param> /// <param name="matrix">The matrix to render in.</param> /// <returns></returns> private bool[,] drawViewRange(BrailleIOViewRange vr, bool[,] matrix) { try { if (vr == null || vr.ViewBox == null || !vr.IsVisible()) { return(matrix); } ////FIXME: for debugging //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //sw.Start(); bool[,] viewBoxMatrix = new bool[vr.ViewBox.Height, vr.ViewBox.Width]; // View Range bounds int srcOffsetX = vr.GetLeft(); int scrOffsetY = vr.GetTop(); bool handlePanning = true; bool[,] contentMatrix = new bool[1, 1]; // Matrix rendering if (vr.IsMatrix()) { if (vr.GetMatrix() != null) { contentMatrix = vr.GetMatrix(); //set content size in vr vr.ContentHeight = contentMatrix.GetLength(0); vr.ContentWidth = contentMatrix.GetLength(1); } } // Image rendering else if (vr.IsImage()) { int th = (vr is IContrastThreshold) ? ((IContrastThreshold)vr).GetContrastThreshold() : -1; using (System.Drawing.Bitmap img = vr.GetImage()) { if (vr.ContentRender is BrailleIOImageToMatrixRenderer) { handlePanning = false; if (th >= 0) { contentMatrix = ((BrailleIOImageToMatrixRenderer)vr.ContentRender).RenderImage(img, vr, vr as IPannable, vr.InvertImage, vr.GetZoom(), th); } else { contentMatrix = ((BrailleIOImageToMatrixRenderer)vr.ContentRender).RenderImage(img, vr, vr as IPannable, vr.InvertImage, vr.GetZoom(), true, handlePanning); } } else { contentMatrix = vr.ContentRender.RenderMatrix(vr, img); } } } // Text rendering else if (vr.IsText()) { if (!string.IsNullOrEmpty(vr.GetText())) { contentMatrix = vr.ContentRender.RenderMatrix(vr, vr.GetText()); } } // Generic renderer else if (vr.IsOther()) { if (vr.GetOtherContent() != null && vr.ContentRender != null) { contentMatrix = vr.ContentRender.RenderMatrix(vr, vr.GetOtherContent()); } else { return(matrix); } } else { return(matrix); } //place the content matrix (contentMatrix) in the view range matrix with aware of the box model if (vr.ContentRender is IBrailleIOPanningRendererInterfaces) { handlePanning = !((IBrailleIOPanningRendererInterfaces)vr.ContentRender).DoesPanning; } viewBoxMatrix = vmr.RenderMatrix(vr, contentMatrix, handlePanning); // Border rendering viewBoxMatrix = BrailleIO.Renderer.BrailleIOBorderRenderer.RenderMatrix(vr, viewBoxMatrix); bool pl = pins_locked; pins_locked = true; // draw content and borders to main matrix System.Threading.Tasks.Parallel.For(srcOffsetX, srcOffsetX + viewBoxMatrix.GetLength(1), x => { if (x >= 0 && x < matrix.GetLength(1)) { int _x = x - srcOffsetX; for (int y = scrOffsetY; y < scrOffsetY + viewBoxMatrix.GetLength(0); y++) { if (y >= 0 && y < matrix.GetLength(0)) { matrix[y, x] = viewBoxMatrix[y - scrOffsetY, _x]; } } } }); ////FIXME: for debugging //sw.Stop(); //System.Diagnostics.Debug.WriteLine("[" + DateTime.UtcNow.ToString("HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture) + "] (VR'"+vr.Name+"') *+~ Rendering Time Elapsed={0} ~+*", sw.Elapsed); vr.Render = false; pins_locked = pl; } catch { } finally { _renderingCount++; if (_renderingCount > 20) { GC.Collect(); _renderingCount = 0; } } return(matrix); }
/// <summary> /// draw a ViewRange to this.matrix /// </summary> /// <param name="vr">ViewRange</param> private bool drawViewRange(BrailleIOViewRange vr) { try { if (vr == null || vr.ViewBox == null || !vr.IsVisible()) { return(false); } //Stopwatch sw = new Stopwatch(); //sw.Start(); bool[,] viewBoxMatrix = new bool[vr.ViewBox.Height, vr.ViewBox.Width]; // View Range bounds int srcOffsetX = vr.GetLeft(); int scrOffsetY = vr.GetTop(); bool handlePanning = true; bool[,] contentMatrix = new bool[1, 1]; // Matrix rendering if (vr.IsMatrix()) { if (vr.GetMatrix() != null) { contentMatrix = vr.GetMatrix(); //set content size in vr vr.ContentHeight = contentMatrix.GetLength(0); vr.ContentWidth = contentMatrix.GetLength(1); } } // Image rendering else if (vr.IsImage()) { int th = (vr is IContrastThreshold) ? ((IContrastThreshold)vr).GetContrastThreshold() : -1; using (System.Drawing.Bitmap img = vr.GetImage()) { if (vr.ContentRender is BrailleIOImageToMatrixRenderer) { if (th >= 0) { contentMatrix = ((BrailleIOImageToMatrixRenderer)vr.ContentRender).RenderImage(img, vr, vr as IPannable, vr.InvertImage, vr.GetZoom(), th); } else { contentMatrix = ((BrailleIOImageToMatrixRenderer)vr.ContentRender).RenderImage(img, vr, vr as IPannable, vr.InvertImage, vr.GetZoom(), true); } } else { contentMatrix = vr.ContentRender.RenderMatrix(vr, img); } } handlePanning = false; } // Text rendering else if (vr.IsText()) { if (!string.IsNullOrEmpty(vr.GetText())) { contentMatrix = vr.ContentRender.RenderMatrix(vr, vr.GetText()); } } // Generic renderer else if (vr.IsOther()) { if (vr.GetOtherContent() != null && vr.ContentRender != null) { contentMatrix = vr.ContentRender.RenderMatrix(vr, vr.GetOtherContent()); } else { return(false); } } else { return(false); } //place the content matrix (contentMatrix) in the view range matrix with aware of the box model viewBoxMatrix = (new BrailleIO.Renderer.BrailleIOViewMatixRenderer()).RenderMatrix(vr, contentMatrix, handlePanning); // Border rendering viewBoxMatrix = BrailleIO.Renderer.BrailleIOBorderRenderer.renderMatrix(vr, viewBoxMatrix); bool pl = pins_locked; pins_locked = true; // draw content and borders to main matrix System.Threading.Tasks.Parallel.For(srcOffsetX, srcOffsetX + viewBoxMatrix.GetLength(1), x => { if (x >= 0 && x < Matrix.GetLength(1)) { System.Threading.Tasks.Parallel.For(scrOffsetY, scrOffsetY + viewBoxMatrix.GetLength(0), y => { if (y >= 0 && y < Matrix.GetLength(0)) { Matrix[y, x] = viewBoxMatrix[y - scrOffsetY, x - srcOffsetX]; } }); } }); //sw.Stop(); //Console.WriteLine("Elapsed={0}", sw.Elapsed); pins_locked = pl; return(true); } catch { return(false); } finally { GC.Collect(); } }