public void ThreeThousandGetBuffers() { //PLAN: //Just like HundredGetBuffers but with 3000 threads /* * System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(@"c:\test\myerrors.txt")); * System.Diagnostics.Trace.AutoFlush = true; */ try { System.Runtime.MemoryFailPoint memCheck = new System.Runtime.MemoryFailPoint(3000 + 1500); //Thread memory + pool memory } catch (InsufficientMemoryException) { Assert.Inconclusive("There is not enough memory on the system to run this test"); } BufferPool pool = new BufferPool(10 * 1024 * 1024, 1, 1); List <IBuffer> bufferList = new List <IBuffer>(); int threadNumber = 3000; int sizeOdd = 524288; int sizeEven = 524288; AquireBuffersConcurrently(pool, bufferList, threadNumber, sizeOdd, sizeEven); AssertIsContiguous(bufferList); //TODO:Also Assert that all buffers, both Size and GetSegments().Count are equal to the requested size. Assert.IsTrue(pool.SlabCount == 150, "SlabCount is " + pool.SlabCount + ". Was expecting 150"); }
public override Bitmap LoadPage(int pageNumber) { if (!File.Exists(fileName)) { throw new Exception("File does not exist."); } if (bmp != null) { bmp.Dispose(); } var pdf = new MuPDF(fileName, ""); pdf.Page = pageNumber; pdf.AntiAlias = true; int width = (int)(pdf.Width * resolution / 72.0F); int height = (int)(pdf.Height * resolution / 72.0F); int estMemUsageMB = (int)Math.Ceiling(width * height * 3.0 / 1024 / 1024); Debug.WriteLine("Estimated memory {0} MB", estMemUsageMB); System.Runtime.MemoryFailPoint mfp = null; try { mfp = new System.Runtime.MemoryFailPoint(estMemUsageMB); bmp = pdf.GetBitmap(width, height, 72, 72, 0, RenderType.RGB, false, false, 0); } catch (InsufficientMemoryException) { throw new Exception("Not enough memory."); } finally { mfp.Dispose(); pdf.Dispose(); } return(bmp); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.InterpolationMode = InterpolationMode.NearestNeighbor; g.SmoothingMode = SmoothingMode.None; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; if (this.image != null) { bool isSelectiveLayerViewEnabled = Options.Get.IsEnabled(Constants.RenderedZIndexFilter, false); bool isSide = Options.Get.IsSideView; double origW = this.image.Width; double origH = this.image.Height; int w = (int)(origW * MainForm.PanZoomSettings.zoomLevel); int h = (int)(origH * MainForm.PanZoomSettings.zoomLevel); int zoom = (int)(MainForm.PanZoomSettings.zoomLevel); if (MainForm.PanZoomSettings.zoomLevel < 1.0D) { g.InterpolationMode = InterpolationMode.Bicubic; g.CompositingQuality = CompositingQuality.Default; g.SmoothingMode = SmoothingMode.HighSpeed; } else { g.InterpolationMode = InterpolationMode.NearestNeighbor; g.CompositingQuality = CompositingQuality.HighSpeed; g.SmoothingMode = SmoothingMode.AntiAlias; } SolidBrush brush = new SolidBrush(Color.Black); Pen pen = new Pen(brush); if (this.renderedImage != null) { Point pStart = getPointOnImage(new Point(0, 0), EstimateProp.Floor); Point fStart = getPointOnPanel(pStart); pStart.X *= CalculatedTextureSize; pStart.Y *= CalculatedTextureSize; Point pEnd = getPointOnImage(new Point(this.Width, this.Height), EstimateProp.Ceil); Point fEnd = getPointOnPanel(pEnd); pEnd.X *= CalculatedTextureSize; pEnd.Y *= CalculatedTextureSize; Rectangle rectSRC = new Rectangle(pStart, pStart.CalculateSize(pEnd)); Rectangle rectDST = new Rectangle(fStart, fStart.CalculateSize(fEnd)); try { int numMegaBytes = 32 / 8 * CalculatedTextureSize * CalculatedTextureSize * image.Height * image.Width / 1024 / 1024; if (numMegaBytes > 0) { using (var memoryCheck = new System.Runtime.MemoryFailPoint(numMegaBytes)) { g.DrawImage(image: this.renderedImage, srcRect: rectSRC, destRect: rectDST, srcUnit: GraphicsUnit.Pixel); } } else if ((image.Height * image.Width) < 2000) { g.DrawImage(image: this.renderedImage, srcRect: rectSRC, destRect: rectDST, srcUnit: GraphicsUnit.Pixel); } } catch (InsufficientMemoryException) { MainForm.Self.PreRenderedImage.DisposeSafely(); MainForm.Self.PreRenderedImage = null; CalculatedTextureSize = Math.Max(1, CalculatedTextureSize - 2); if (CalculatedTextureSize <= 2) { MessageBox.Show("Not enough memory. Please try again or reduce image size if problem continues."); } else { bool dummyBool = ForceReRender().Result; } return; } catch (System.InvalidOperationException) { MainForm.Self.PreRenderedImage.DisposeSafely(); MainForm.Self.PreRenderedImage = null; return; } } if (Options.Get.Rendered_IsShowBorder) { Point pp2 = getPointOnPanel(new Point(0, 0)); using (Pen penWE = new Pen(Color.FromArgb(127, 0, 0, 0), zoom)) { penWE.Alignment = PenAlignment.Inset; g.DrawRectangle(penWE, pp2.X, pp2.Y, (int)(this.image.Width * MainForm.PanZoomSettings.zoomLevel), (int)(this.image.Height * MainForm.PanZoomSettings.zoomLevel)); } } if (Constants.IsFullVersion) { brush.Color = Color.Red; Point wePoint = getPointOnPanel(image.WorldEditOrigin); g.FillRectangle(brush, wePoint.X, wePoint.Y, zoom + 1, zoom + 1); } // TODO: Fix what I broke with solid colors if ((Options.Get.Rendered_IsShowGrid) && (MainForm.PanZoomSettings.zoomLevel >= 0.5D)) { drawGridMask(g, Options.Get.GridSize, Options.Get.GridColor); drawGrid(g, Options.Get.GridSize, Options.Get.GridColor); if (MainForm.PanZoomSettings.zoomLevel > 5) { drawGrid(g, 1, Color.FromArgb(40, Options.Get.GridColor)); } } } }
private static int?CalculateTextureSize(BlueprintPA image) { int CalculatedTextureSize = Constants.TextureSize; // Calculate texture size so we can handle large images. if (image == null) { return(CalculatedTextureSize); } int mbSize = (image.Width * image.Height * 32 / 8); // Still need to multiply by texture size int maxSize = 400 * 1024 * 1024; // max size in bytes we'll want to allow. int tSize = 16; if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; // 16 } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; // 14 } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; // 10 } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; // 6 } else if (mbSize * tSize * tSize-- <= maxSize) { CalculatedTextureSize = tSize + 1; } else { CalculatedTextureSize = 4; } while (CalculatedTextureSize * image.Width > 22000 || CalculatedTextureSize * image.Height > 22000) { if (CalculatedTextureSize <= 1) { MessageBox.Show(Constants.ERR_DownsizeYourImage); MainForm.Self.PreRenderedImage.DisposeSafely(); MainForm.Self.PreRenderedImage = null; return(null); } CalculatedTextureSize -= 2; } bool isSuccess = false; do { try { int numMegaBytes = 32 / 8 * CalculatedTextureSize * CalculatedTextureSize * image.Height * image.Width / 1024 / 1024; if (numMegaBytes > 0) { using (var memoryCheck = new System.Runtime.MemoryFailPoint(numMegaBytes)) { } } isSuccess = true; } catch (InsufficientMemoryException) { CalculatedTextureSize = Math.Max(1, CalculatedTextureSize - 2); } } while (isSuccess == false && CalculatedTextureSize > 1); if (isSuccess == false) { MessageBox.Show(Constants.ERR_DownsizeYourImage); MainForm.Self.PreRenderedImage.DisposeSafely(); MainForm.Self.PreRenderedImage = null; return(null); } return(CalculatedTextureSize); }