private void Initialize() { if (_background == null) { byte[] pixelData = new byte[4*_size.Width*_size.Height]; for (int n = 0; n < pixelData.Length; n += 4) { byte[] pixel = BitConverter.GetBytes(Color.FromArgb(196, 85, 85, 85).ToArgb()); pixelData[n + 0] = pixel[0]; pixelData[n + 1] = pixel[1]; pixelData[n + 2] = pixel[2]; pixelData[n + 3] = pixel[3]; } base.Graphics.Add(_background = new ColorImageGraphic(_size.Height, _size.Width, pixelData)); } if (_progressBarGraphic == null) { base.Graphics.Add(_progressBarGraphic = ProgressBarGraphic.Create(_style)); var offset = Center(_size, _progressBarGraphic.Size) + new Size(0, 10); _progressBarGraphic.SpatialTransform.TranslationX = offset.X; _progressBarGraphic.SpatialTransform.TranslationY = offset.Y; } if (_progressTextGraphic == null) { base.Graphics.Add(_progressTextGraphic = new InvariantTextPrimitive()); var offset = Center(_size, new Size(1, 1)) - new Size(0, 15); _progressTextGraphic.SpatialTransform.TranslationX = offset.X; _progressTextGraphic.SpatialTransform.TranslationY = offset.Y; } }
private void OnCloneComplete() { _progressTextGraphic = (ITextGraphic) CollectionUtils.SelectFirst(base.Graphics, g => g is ITextGraphic); _progressBarGraphic = (ProgressBarGraphic) CollectionUtils.SelectFirst(base.Graphics, g => g is ProgressBarGraphic); _background = (ColorImageGraphic) CollectionUtils.SelectFirst(base.Graphics, g => g is ColorImageGraphic); Initialize(); }
/// <summary> /// Cloning constructor. /// </summary> protected ColorImageGraphic(ColorImageGraphic source, ICloningContext context) : base(source, context) { context.CloneFields(source, this); if (source.LutComposer.VoiLut != null) //clone the voi lut. { this.InstallVoiLut(source.VoiLut.Clone()); } }
/// <summary> /// Creates a test pattern of <paramref name="size"/> consisting of red, blue, green and black in the NW, NE, SW, SE corners respectively. /// </summary> public static ColorImageGraphic CreateRGBKCorners(Size size) { int width = size.Width; int height = size.Height; int halfWidth = width/2; int halfHeight = height/2; ColorImageGraphic imageGraphic = new ColorImageGraphic(height, width); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Color c; if (x < halfWidth) c = y < halfHeight ? Color.Red : Color.LimeGreen; else c = y < halfHeight ? Color.Blue : Color.Black; imageGraphic.PixelData.SetPixel(x, y, c); } } return imageGraphic; }
/// <summary> /// Cloning constructor. /// </summary> protected ColorImageGraphic(ColorImageGraphic source, ICloningContext context) : base(source, context) { context.CloneFields(source, this); if (source.LutComposer.VoiLut != null) //clone the voi lut. this.InstallVoiLut(source.VoiLut.Clone()); }
private void Initialize() { if (_background == null) { var pixelCount = _size.Width*_size.Height; var pixelData = new byte[4*pixelCount]; var fillColor = Color.FromArgb(196, 85, 85, 85).ToArgb(); unsafe { fixed (byte* pPixelBytes = pixelData) { var pPixels = (int*) pPixelBytes; for (var n = 0; n < pixelCount; ++n) pPixels[n] = fillColor; } } base.Graphics.Add(_background = new ColorImageGraphic(_size.Height, _size.Width, pixelData)); } if (_progressBarGraphic == null) { base.Graphics.Add(_progressBarGraphic = ProgressBarGraphic.Create(_style)); var offset = Center(_size, _progressBarGraphic.Size) + new Size(0, 10); _progressBarGraphic.SpatialTransform.TranslationX = offset.X; _progressBarGraphic.SpatialTransform.TranslationY = offset.Y; } if (_progressTextGraphic == null) { base.Graphics.Add(_progressTextGraphic = new InvariantTextPrimitive()); var offset = Center(_size, new Size(1, 1)) - new Size(0, 15); _progressTextGraphic.SpatialTransform.TranslationX = offset.X; _progressTextGraphic.SpatialTransform.TranslationY = offset.Y; } }
private void AddProbabilityOverlay() { _probabilityOverlay = new ColorImageGraphic(_frame.Rows, _frame.Columns); this.OverlayGraphics.Add(_probabilityOverlay); }
private static void RenderColor( ColorImageGraphic image, RectangleF srcViewableRectangle, Rectangle dstViewableRectangle, IntPtr pDstPixelData, int dstWidth, int dstBytesPerPixel) { fixed (byte* pSrcPixelData = image.PixelData.Raw) { if (image.InterpolationMode == InterpolationMode.Bilinear) { int srcBytesPerPixel = 4; if (image.VoiLutsEnabled) { int[] finalLutBuffer = ConstructFinalLut(image.OutputLut, image.Invert); fixed (int* pFinalLutData = finalLutBuffer) { ImageInterpolatorBilinear.LutData lutData; lutData.Data = pFinalLutData; lutData.FirstMappedPixelData = image.OutputLut.MinInputValue; lutData.Length = finalLutBuffer.Length; ImageInterpolatorBilinear.Interpolate( srcViewableRectangle, pSrcPixelData, image.Columns, image.Rows, srcBytesPerPixel, 32, dstViewableRectangle, (byte*) pDstPixelData, dstWidth, dstBytesPerPixel, IsRotated(image), &lutData, //ok because it's a local variable in an unsafe method, therefore it's already fixed. true, false, false); } } else { ImageInterpolatorBilinear.Interpolate( srcViewableRectangle, pSrcPixelData, image.Columns, image.Rows, srcBytesPerPixel, 32, dstViewableRectangle, (byte*) pDstPixelData, dstWidth, dstBytesPerPixel, IsRotated(image), null, true, false, false); } } } }
private void Invalidate() { if (_imageGraphic != null) { base.Graphics.Remove(_imageGraphic); _imageGraphic.Dispose(); _imageGraphic = null; //don't de-allocate and reallocate unnecessarily. if (!HasShutters) _cacheItem = null; } }
/// <summary> /// Fires the <see cref="Graphic.Drawing"/> event. Should be called by an <see cref="IRenderer"/> /// for each object just before it is drawn/rendered, hence the reason it is public. /// </summary> public override void OnDrawing() { base.OnDrawing(); if (_imageGraphic != null || !HasShutters) return; _cacheItem = GeometricShutterCache.GetCacheItem(GetAllShutters(), _imageRectangle, _fillColor); //IMPORTANT: don't just pass the value of Raw, otherwise, memory management won't work (hard reference). _imageGraphic = new ColorImageGraphic(_cacheItem.PixelData.Rows, _cacheItem.PixelData.Columns, () => _cacheItem.PixelData.Raw); base.Graphics.Add(_imageGraphic); }