public DrawingLayer CalculateHistogram(DrawingLayer originalLayer) { DrawingLayer ping = originalLayer.Factory.CreateDrawingLayer(originalLayer.Width, originalLayer.Height); DrawingLayer pong = originalLayer.Factory.CreateDrawingLayer(originalLayer.Width, originalLayer.Height); float kernelHeight = 2; Rectangle rect = new Rectangle(0, 0, originalLayer.Width, (int)Math.Ceiling(originalLayer.Height / kernelHeight)); DrawingLayer source = ping; DrawingLayer target = pong; SourceHeight = rect.Height; originalLayer.ApplyEffect(this, source, rect, false); rect.Height = (int)Math.Ceiling(rect.Height / kernelHeight); while (rect.Height > 1) { SourceHeight = rect.Height; source.ApplyEffect(this, target, rect, false); //Swap layers for next round DrawingLayer temp = source; source = target; target = temp; rect.Height = (int)Math.Ceiling(rect.Height / kernelHeight); } //Target was switched with source, so source points to last result return source; }
internal void CopyToDrawingLayer(DrawingLayer drawingLayer, Rectangle destRect) { IntPtr pBuffer; int bufferSize; int stride = 0; int hr = 0; var rect = new WICRect { X = 0, Y = 0, Width = Width, Height = Height }; IWICBitmapLock imageLock; hr = m_internalBitmap.Lock(ref rect, WICBitmapLockFlags.WICBitmapLockRead, out imageLock); if(hr != 0) throw new Exception("Could not lock the image"); hr = imageLock.GetDataPointer(out bufferSize, out pBuffer); imageLock.GetStride(out stride); if(destRect.IsEmpty) drawingLayer.D2DRenderTarget.InternalBitmap.FromMemory(pBuffer, stride); else drawingLayer.D2DRenderTarget.InternalBitmap.FromMemory(pBuffer, stride, destRect.GetInternalRect()); Marshal.ReleaseComObject(imageLock); }
public ImageData Lock(Rectangle lockRectangle, ImageLock lockType) { IWICBitmapLock imageLock; WICBitmapLockFlags flags; var rect = new WICRect { X = lockRectangle.X, Y = lockRectangle.Y, Width = lockRectangle.Width, Height = lockRectangle.Height }; switch(lockType) { case ImageLock.Read: flags = WICBitmapLockFlags.WICBitmapLockRead; break; case ImageLock.Write: flags = WICBitmapLockFlags.WICBitmapLockWrite; break; case ImageLock.ReadWrite: flags = WICBitmapLockFlags.WICBitmapLockRead | WICBitmapLockFlags.WICBitmapLockWrite; break; default: throw new ArgumentOutOfRangeException("lockType"); } int hr = m_internalBitmap.Lock(ref rect, flags, out imageLock); if (hr != 0) throw new Exception("Could not lock the image"); return new ImageData(imageLock); }
static Rectangle() { m_empty = new Rectangle(); }
public bool Equals(Rectangle other) { return other.X == X && other.Y == Y && other.Width == Width && other.Height == Height; }
public void CopyFromImage(Image sourceImage, Rectangle destRect) { sourceImage.CopyToDrawingLayer(this, destRect); }
public void ApplyEffect(ShaderEffect effect, DrawingLayer output, Rectangle targetRect, bool clearOutput = true) { m_directCanvasFactory.ApplyEffect(effect, this, output, targetRect, clearOutput); }
protected override void DrawLayer(DrawingLayer outputLayer) { base.DrawLayer(outputLayer); DepthFrame.MinThreshold = (ushort)this.MinThreshold; DepthFrame.MaxThreshold = (ushort)this.MaxThreshold; ushort minValue; ushort maxValue; var img = DepthFrame.ToDirectCanvasImage(Factory, out minValue, out maxValue); effectLayer.CopyFromImage(img); Rect crop = DepthFrame.Crop; Rectangle rect = new Rectangle((int)crop.X, (int)crop.Y, (int)crop.Width, (int)crop.Height); RectangleF rectf = new RectangleF((float)crop.X, (float)crop.Y, (float)crop.Width, (float)crop.Height); colorMapEffect.MinThreshold = (float)MinThreshold; colorMapEffect.MaxThreshold = (float)MaxThreshold; colorMapEffect.MinValue = minValue; colorMapEffect.MaxValue = maxValue; unpackEffect.TexSize = new DirectCanvas.Misc.Size(effectLayer.Width, effectLayer.Height); effectLayer.ApplyEffect(unpackEffect, effectLayer2, true); effectLayer2.ApplyEffect(colorMapEffect, outputLayer, true); outputLayer.BeginDraw(); outputLayer.DrawRectangle(rectBrushBackground, rectf, 3f); outputLayer.DrawRectangle(rectBrushForeground, rectf, 1f); outputLayer.EndDraw(); }
internal void ApplyEffect(ShaderEffect effect, DrawingLayer input, DrawingLayer output, Rectangle targetRect, bool clearOutput = true) { m_shaderRenderer.Apply(effect, input.RenderTargetTexture, output.RenderTargetTexture, targetRect, clearOutput); }
/// <summary> /// Applys a shader effect /// </summary> /// <param name="effect">The shader effect to apply</param> /// <param name="inTexture">The DrawingLayer to be used as input</param> /// <param name="outTexture">The DrawingLayer to be used as output</param> /// <param name="targetRect"></param> /// <param name="clearOutput">Clear the output before writing</param> public void Apply(ShaderEffect effect, RenderTargetTexture inTexture, RenderTargetTexture outTexture, Rectangle targetRect, bool clearOutput) { var device = m_directCanvasFactory.DeviceContext.Device; if (clearOutput) outTexture.Clear(new Color4(0, 0, 0, 0)); outTexture.SetRenderTarget(new Viewport(targetRect.X, targetRect.Y, targetRect.Width, targetRect.Height, 0, 1)); device.PixelShader.SetShaderResource(inTexture.InternalShaderResourceView, 0); if (effect.Filter == ShaderEffectFilter.Linear) device.PixelShader.SetSampler(m_linearSamplerState, 0); else if (effect.Filter == ShaderEffectFilter.Point) device.PixelShader.SetSampler(m_pointSamplerState, 0); effect.Draw(); }