internal void Initialize(int width, int height, int bitDepth) { if (width > 0 && height > 0) { switch (bitDepth) { case 24: windowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); backingImageBufferByte = new ImageBuffer(width, height, 24, new BlenderBGR()); break; case 32: windowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb); //widowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); //widowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //32bppPArgb backingImageBufferByte = new ImageBuffer(width, height); break; case 128: windowsBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppRgb); backingImageBufferByte = null; backingImageBufferFloat = new ImageBufferFloat(width, height, 128, new BlenderBGRAFloat()); break; default: throw new NotImplementedException("Don't support this bit depth yet."); } } }
public MarchingSquaresFloat(ImageBufferFloat imageToMarch, int threshold, int debugColor) { this.threshold = threshold; this.imageToMarch = imageToMarch; this.debugColor = debugColor; CreateLineSegments(); }
public static void DoMatch(ImageBufferFloat imageToSearch, ImageBufferFloat imageToFind, ImageBufferFloat result) { result = new ImageBufferFloat(imageToSearch.Width, imageToSearch.Height, 32, new BlenderBGRAFloat()); if (imageToSearch.Width >= imageToFind.Width && imageToSearch.Height >= imageToFind.Height && imageToSearch.BitDepth == imageToFind.BitDepth) { int floatsPerPixel = imageToSearch.BitDepth / 32; int searchDistanceBetweenPixels = imageToSearch.GetFloatsBetweenPixelsInclusive(); int findDistanceBetweenPixels = imageToFind.GetFloatsBetweenPixelsInclusive(); float[] searchBuffer = imageToSearch.GetBuffer(); float[] findBuffer = imageToFind.GetBuffer(); float[] resultBuffer = imageToFind.GetBuffer(); int resutsBufferOffset = 0; for (int matchY = 0; matchY <= imageToSearch.Height - imageToFind.Height; matchY++) { for (int matchX = 0; matchX <= imageToSearch.Width - imageToFind.Width; matchX++) { double currentLeastSquares = 0; for (int imageToFindY = 0; imageToFindY < imageToFind.Height; imageToFindY++) { int searchBufferOffset = imageToSearch.GetBufferOffsetXY(matchX, matchY + imageToFindY); int findBufferOffset = imageToFind.GetBufferOffsetY(imageToFindY); for (int findX = 0; findX < imageToFind.Width; findX++) { for (int byteIndex = 0; byteIndex < floatsPerPixel; byteIndex++) { float aByte = searchBuffer[searchBufferOffset + byteIndex]; float bByte = findBuffer[findBufferOffset + byteIndex]; int difference = (int)aByte - (int)bByte; currentLeastSquares += difference * difference; } searchBufferOffset += searchDistanceBetweenPixels; findBufferOffset += findDistanceBetweenPixels; } } resultBuffer[resutsBufferOffset] = (float)currentLeastSquares; resutsBufferOffset++; } } } }
public override void OnDraw(Graphics2D graphics2D) { if (graphics2D.DestImage != null) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); IImageByte backBuffer = widgetsSubImage; int distBetween = backBuffer.GetBytesBetweenPixelsInclusive(); ImageBuffer redImageBuffer = new ImageBuffer(); redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8); ImageBuffer greenImageBuffer = new ImageBuffer(); greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8); ImageBuffer blueImageBuffer = new ImageBuffer(); blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8); ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer); ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer); ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer); ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer); ScanlineRasterizer ras = new ScanlineRasterizer(); ScanlineCachePacked8 sl = new ScanlineCachePacked8(); RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255); clippingProxy.clear(clearColor); alphaSlider.View.BackgroundColor = clearColor; RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value)); VertexSource.Ellipse er = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); ras.add_path(er); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); scanlineRenderer.RenderSolid(clippingProxyRed, ras, sl, FillColor); VertexSource.Ellipse eg = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); ras.add_path(eg); scanlineRenderer.RenderSolid(clippingProxyGreen, ras, sl, FillColor); VertexSource.Ellipse eb = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100); ras.add_path(eb); scanlineRenderer.RenderSolid(clippingProxyBlue, ras, sl, FillColor); } else if (graphics2D.DestImageFloat != null) { #if false IImageFloat backBuffer = graphics2D.DestImageFloat; int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive(); ImageBufferFloat redImageBuffer = new ImageBufferFloat(); redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8); ImageBufferFloat greenImageBuffer = new ImageBufferFloat(); greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8); ImageBufferFloat blueImageBuffer = new ImageBufferFloat(); blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8); ImageClippingProxy clippingProxy = new ImageClippingProxy(backBuffer); ImageClippingProxy clippingProxyRed = new ImageClippingProxy(redImageBuffer); ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer); ImageClippingProxy clippingProxyBlue = new ImageClippingProxy(blueImageBuffer); ScanlineRasterizer ras = new ScanlineRasterizer(); ScanlineCachePacked8 sl = new ScanlineCachePacked8(); RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255); clippingProxy.clear(clearColor); alphaSlider.View.BackGroundColor = clearColor; RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value)); VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); ras.add_path(er); agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor); VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); ras.add_path(eg); agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor); VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100); ras.add_path(eb); agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor); #endif } base.OnDraw(graphics2D); }
public override void OnParentChanged(EventArgs e) { AnchorAll(); #if SourceDepthFloat ImageBufferFloat tempImageToLoadInto = new ImageBufferFloat(); #else ImageBuffer tempImageToLoadInto = new ImageBuffer(); #endif string img_name = "spheres.bmp"; if (!AggContext.ImageIO.LoadImageData(img_name, tempImageToLoadInto)) { string buf; buf = "File not found: " + img_name + ".bmp" + ". Download http://www.antigrain.com/" + img_name + "\n" + "or copy it from another directory if available."; MessageBox.ShowMessageBox(buf, "Missing Files"); } else { #if SourceDepth24 image_filters.m_TempDestImage = new ImageBuffer(tempImageToLoadInto, new BlenderBGR()); image_filters.m_RotatedImage = new ImageBuffer(image_filters.m_TempDestImage, new BlenderBGR()); image_filters.m_OriginalImage = new ImageBuffer(image_filters.m_TempDestImage, new BlenderBGR()); image_filters.m_TempDestImage.SetRecieveBlender(new BlenderPreMultBGR()); #else #if SourceDepthFloat image_filters.m_TempDestImage = new ImageBufferFloat(tempImageToLoadInto.Width, tempImageToLoadInto.Height, 128, new BlenderBGRAFloat()); image_filters.m_TempDestImage.CopyFrom(tempImageToLoadInto); image_filters.m_RotatedImage = new ImageBufferFloat(image_filters.m_TempDestImage, new BlenderBGRAFloat()); image_filters.m_OriginalImage = new ImageBufferFloat(image_filters.m_TempDestImage, new BlenderBGRAFloat()); //image_filters.m_TempDestImage.SetRecieveBlender(new BlenderBGRAFloat()); image_filters.m_TempDestImage.SetRecieveBlender(new BlenderPreMultBGRAFloat()); #else image_filters.m_TempDestImage = new ImageBuffer(tempImageToLoadInto.Width, tempImageToLoadInto.Height, 32, new BlenderBGRA()); image_filters.m_TempDestImage.CopyFrom(tempImageToLoadInto); image_filters.m_RotatedImage = new ImageBuffer(image_filters.m_TempDestImage, new BlenderBGRA()); image_filters.m_OriginalImage = new ImageBuffer(image_filters.m_TempDestImage, new BlenderBGRA()); image_filters.m_TempDestImage.SetRecieveBlender(new BlenderPreMultBGRA()); #endif #endif int w = image_filters.m_TempDestImage.Width + 220; int h = image_filters.m_TempDestImage.Height + 200; if (w < 305) { w = 305; } if (h < 325) { h = 325; } Parent.LocalBounds = new RectangleDouble(0, 0, w, h); transform_image(0.0); } base.OnParentChanged(e); }
public virtual bool LoadImageData(String filename, ImageBufferFloat destImage) { throw new Exception("You must implement this in an inherited class."); }
static public bool LoadImageData(String filename, ImageBufferFloat destImage) { return(AvailableImageIOPlugin.LoadImageData(filename, destImage)); }