protected override void CustomRenderSingleScanLine(IBitmapBlender destImage, Scanline scanline, Color color) { int y = scanline.Y; int num_spans = scanline.SpanCount; byte[] covers = scanline.GetCovers(); int spanCount = scanline.SpanCount; var ras = _gfx.ScanlineRasterizer; var rasToBmp = _gfx.BitmapRasterizer; for (int i = 1; i <= num_spans; ++i) { var span2 = scanline.GetSpan(i); int x = span2.x; int num_pix = span2.len; int coverIndex = span2.cover_index; do { int a = (covers[coverIndex++] * color.Alpha0To255) >> 8; _square.Draw(rasToBmp, ras, _sl, destImage, Color.FromArgb(a, color), x, y); ++x; }while (--num_pix > 0); } }
public SubBitmapBlender(IBitmapBlender image, int arrayOffset32, int width, int height) { this.OutputPixelBlender = image.OutputPixelBlender; AttachBuffer(image.GetBufferPtr(), arrayOffset32, width, height, image.Stride, image.BitDepth, image.BytesBetweenPixelsInclusive); }
/// <summary> /// This will create a new ImageBuffer that references the same memory as the image that you took the sub image from. /// It will modify the original main image when you draw to it. /// </summary> /// <param name="parentImage"></param> /// <param name="subImgBounds"></param> /// <returns></returns> public static SubBitmapBlender CreateSubBitmapBlender(IBitmapBlender parentImage, RectInt subImgBounds) { if (subImgBounds.Left < 0 || subImgBounds.Bottom < 0 || subImgBounds.Right > parentImage.Width || subImgBounds.Top > parentImage.Height || subImgBounds.Left >= subImgBounds.Right || subImgBounds.Bottom >= subImgBounds.Top) { throw new ArgumentException("The subImageBounds must be on the image and valid."); } int left = Math.Max(0, subImgBounds.Left); int bottom = Math.Max(0, subImgBounds.Bottom); int width = Math.Min(parentImage.Width - left, subImgBounds.Width); int height = Math.Min(parentImage.Height - bottom, subImgBounds.Height); return(new SubBitmapBlender(parentImage, parentImage.GetBufferOffsetXY32(left, bottom), width, height)); }
public override void Draw(PixelFarm.Drawing.Painter p) { //specific for agg if (!(p is AggPainter)) { return; } AggPainter p2 = (AggPainter)p; AggRenderSurface asx = p2.RenderSurface; if (asx.DestBitmapBlender != null) { IBitmapBlender backBuffer = asx.DestBitmapBlender; //use different pixel blender var redImageBuffer = new SubBitmapBlender(backBuffer, new PixelBlenderGrey()); var greenImageBuffer = new SubBitmapBlender(backBuffer, new PixelBlenderGrey()); var blueImageBuffer = new SubBitmapBlender(backBuffer, new PixelBlenderGrey()); ClipProxyImage clippingProxy = new ClipProxyImage(backBuffer); ClipProxyImage clippingProxyRed = new ClipProxyImage(redImageBuffer); ClipProxyImage clippingProxyGreen = new ClipProxyImage(greenImageBuffer); ClipProxyImage clippingProxyBlue = new ClipProxyImage(blueImageBuffer); // ScanlineRasterizer sclineRas = asx.ScanlineRasterizer; ScanlinePacked8 scline = asx.ScanlinePacked8; Drawing.Color clearColor = this.UseBlackBlackground ? Drawing.Color.FromArgb(0, 0, 0) : Drawing.Color.FromArgb(255, 255, 255); clippingProxy.Clear(clearColor); Drawing.Color fillColor = this.UseBlackBlackground ? new Drawing.Color((byte)(this.AlphaValue), 255, 255, 255) : new Drawing.Color((byte)(this.AlphaValue), 0, 0, 0); DestBitmapRasterizer bmpRas = asx.BitmapRasterizer; using (VectorToolBox.Borrow(out Ellipse ellipse)) using (VxsTemp.Borrow(out var v1)) { ellipse.Set(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); sclineRas.AddPath(ellipse.MakeVxs(v1)); v1.Clear();//** bmpRas.RenderWithColor(clippingProxyRed, sclineRas, scline, fillColor); //// ellipse.Set(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100); sclineRas.AddPath(ellipse.MakeVxs(v1)); v1.Clear();//*** bmpRas.RenderWithColor(clippingProxyGreen, sclineRas, scline, fillColor); // ellipse.Set(Width / 2, Height / 2 + 50, 100, 100, 100); sclineRas.AddPath(ellipse.MakeVxs(v1)); v1.Clear(); //*** bmpRas.RenderWithColor(clippingProxyBlue, sclineRas, scline, 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 // } }
public ProxyImage(IBitmapBlender linkedImage) { _linkedImage = linkedImage; }
public void Blur(IBitmapBlender img, double radius) { BlurX(img, radius); BlurY(img, radius); }
public void BlurY(IBitmapBlender img, double radius) { FormatTransposer img2 = new FormatTransposer(img); BlurX(img2, radius); }
public void BlurX(IBitmapBlender img, double radius) { if (radius < 0.62) { return; } if (img.Width < 3) { return; } double s = (double)(radius * 0.5); double q = (double)((s < 2.5) ? 3.97156 - 4.14554 * Math.Sqrt(1 - 0.26891 * s) : 0.98711 * s - 0.96330); double q2 = (double)(q * q); double q3 = (double)(q2 * q); double b0 = (double)(1.0 / (1.578250 + 2.444130 * q + 1.428100 * q2 + 0.422205 * q3)); double b1 = (double)(2.44413 * q + 2.85619 * q2 + 1.26661 * q3); double b2 = (double)(-1.42810 * q2 + -1.26661 * q3); double b3 = (double)(0.422205 * q3); double b = (double)(1 - (b1 + b2 + b3) * b0); b1 *= b0; b2 *= b0; b3 *= b0; int w = img.Width; int h = img.Height; int wm = (int)w - 1; int x, y; int startCreatingAt = (int)m_sum1.Count; m_sum1.AdjustSize(w); m_sum2.AdjustSize(w); m_buf.Allocate(w); RecursizeBlurCalculator[] Sum1Array = m_sum1.UnsafeInternalArray; RecursizeBlurCalculator[] Sum2Array = m_sum2.UnsafeInternalArray; Color[] BufferArray = m_buf.UnsafeInternalArray; for (int i = startCreatingAt; i < w; i++) { Sum1Array[i] = m_RecursizeBlurCalculatorFactory.CreateNew(); Sum2Array[i] = m_RecursizeBlurCalculatorFactory.CreateNew(); } for (y = 0; y < h; y++) { //TODO: review get pixel here... RecursizeBlurCalculator c = m_RecursizeBlurCalculatorFactory; c.FromPix(img.GetPixel(0, y)); Sum1Array[0].Calc(b, b1, b2, b3, c, c, c, c); c.FromPix(img.GetPixel(1, y)); Sum1Array[1].Calc(b, b1, b2, b3, c, Sum1Array[0], Sum1Array[0], Sum1Array[0]); c.FromPix(img.GetPixel(2, y)); Sum1Array[2].Calc(b, b1, b2, b3, c, Sum1Array[1], Sum1Array[0], Sum1Array[0]); for (x = 3; x < w; ++x) { c.FromPix(img.GetPixel(x, y)); Sum1Array[x].Calc(b, b1, b2, b3, c, Sum1Array[x - 1], Sum1Array[x - 2], Sum1Array[x - 3]); } Sum2Array[wm].Calc(b, b1, b2, b3, Sum1Array[wm], Sum1Array[wm], Sum1Array[wm], Sum1Array[wm]); Sum2Array[wm - 1].Calc(b, b1, b2, b3, Sum1Array[wm - 1], Sum2Array[wm], Sum2Array[wm], Sum2Array[wm]); Sum2Array[wm - 2].Calc(b, b1, b2, b3, Sum1Array[wm - 2], Sum2Array[wm - 1], Sum2Array[wm], Sum2Array[wm]); Sum2Array[wm].ToPix(ref BufferArray[wm]); Sum2Array[wm - 1].ToPix(ref BufferArray[wm - 1]); Sum2Array[wm - 2].ToPix(ref BufferArray[wm - 2]); for (x = wm - 3; x >= 0; --x) { Sum2Array[x].Calc(b, b1, b2, b3, Sum1Array[x], Sum2Array[x + 1], Sum2Array[x + 2], Sum2Array[x + 3]); Sum2Array[x].ToPix(ref BufferArray[x]); } img.CopyColorHSpan(0, y, w, BufferArray, 0); } }