public override void Draw(Painter p) { //this specific for agg #if DEBUG //low-level scanline rasterizer example if (p is AggPainter) { AggPainter p2 = (AggPainter)p; AggRenderSurface aggsx = p2.RenderSurface; PixelProcessing.SubBitmapBlender subImg = PixelProcessing.BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect()); //TODO: review here again PixelBlenderBGRA blenderWithGamma = new PixelProcessing.PixelBlenderBGRA(); SubBitmapBlender rasterGamma = new SubBitmapBlender(subImg, blenderWithGamma); ClipProxyImage clippingProxyNormal = new ClipProxyImage(subImg); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer; var sl = new ScanlineUnpacked8(); int size_mul = this.PixelSize; var sclineToBmpEn2 = new CustomRas_EnlargeV2(size_mul, aggsx.DestBitmap); rasterizer.Reset(); rasterizer.dbugDevMoveTo(_x[0] / size_mul, _y[0] / size_mul); rasterizer.dbugDevLineTo(_x[1] / size_mul, _y[1] / size_mul); rasterizer.dbugDevLineTo(_x[2] / size_mul, _y[2] / size_mul); sclineToBmpEn2.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); DestBitmapRasterizer bmpRas = aggsx.BitmapRasterizer; bmpRas.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //----------------------------------------------------------------------------------------------------------- rasterizer.ResetGamma(new GammaNone()); using (Tools.BorrowVxs(out var v1, out var v2)) using (Tools.BorrowPathWriter(v1, out PathWriter ps)) { ps.Clear(); ps.MoveTo(_x[0], _y[0]); ps.LineTo(_x[1], _y[1]); ps.LineTo(_x[2], _y[2]); ps.LineTo(_x[0], _y[0]); rasterizer.AddPath((new Stroke(2)).MakeVxs(v1, v2)); bmpRas.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); } } #endif }
public override void Draw(Painter p) { //specific for agg #if DEBUG //low-level scanline rasterizer example if (p is PixelFarm.CpuBlit.AggPainter p2) { AggRenderSurface aggsx = p2.RenderSurface; ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer; var widgetsSubImage = PixelProcessing.BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect()); aggsx.UseSubPixelLcdEffect = false; PixelProcessing.PixelBlenderBGRA normalBlender = new PixelProcessing.PixelBlenderBGRA(); PixelProcessing.PixelBlenderBGRA gammaBlender = new PixelProcessing.PixelBlenderBGRA(); //TODO: revisit, and fix this again gammaBlender.GammaValue = this.GammaValue; gammaBlender.EnableGamma = true; var rasterGamma = new PixelProcessing.SubBitmapBlender(widgetsSubImage, gammaBlender); ClipProxyImage clippingProxyNormal = new ClipProxyImage(widgetsSubImage); ClipProxyImage clippingProxyGamma = new ClipProxyImage(rasterGamma); clippingProxyNormal.Clear(Color.White); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); int size_mul = (int)this.PixelSize; CustomScanlineRasToBmp_EnlargedSubPixelRendering ren_en = new CustomScanlineRasToBmp_EnlargedSubPixelRendering(size_mul, aggsx.DestBitmap); rasterizer.Reset(); rasterizer.dbugDevMoveTo(_x[0] / size_mul, _y[0] / size_mul); rasterizer.dbugDevLineTo(_x[1] / size_mul, _y[1] / size_mul); rasterizer.dbugDevLineTo(_x[2] / size_mul, _y[2] / size_mul); ren_en.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); //---------------------------------------- DestBitmapRasterizer sclineRasToBmp = aggsx.BitmapRasterizer; aggsx.UseSubPixelLcdEffect = false; sclineRasToBmp.RenderWithColor(clippingProxyGamma, rasterizer, sl, Color.Black); rasterizer.ResetGamma(new GammaNone()); aggsx.UseSubPixelLcdEffect = false; //---------------------------------------- using (Tools.BorrowVxs(out var v1, out var v2)) using (Tools.BorrowPathWriter(v1, out PathWriter ps)) { ps.Clear(); ps.MoveTo(_x[0], _y[0]); ps.LineTo(_x[1], _y[1]); ps.LineTo(_x[2], _y[2]); ps.LineTo(_x[0], _y[0]); rasterizer.AddPath(_stroke.MakeVxs(v1, v2)); } //---------------------------------------- //Stroke stroke = new Stroke(ps); //stroke.Width = 2; //rasterizer.AddPath(stroke.MakeVxs(ps.MakeVxs())); //---------------------------------------- sclineRasToBmp.RenderWithColor(clippingProxyNormal, rasterizer, sl, new Color(200, 0, 150, 160)); } #endif }
// Create //-------------------------------------------------------------------- public void Create(IBitmapSrc src) { // we are going to create a dialated image for filtering // we add m_dilation pixels to every side of the image and then copy the image in the x // dirrection into each end so that we can sample into this image to get filtering on x repeating // if the original image look like this // // 123456 // // the new image would look like this // // 0000000000 // 0000000000 // 5612345612 // 0000000000 // 0000000000 m_height = (int)AggMath.uceil(src.Height); m_width = (int)AggMath.uceil(src.Width); m_width_hr = (int)AggMath.uround(src.Width * LineAA.SUBPIXEL_SCALE); m_half_height_hr = (int)AggMath.uround(src.Height * LineAA.SUBPIXEL_SCALE / 2); m_offset_y_hr = m_dilation_hr + m_half_height_hr - LineAA.SUBPIXEL_SCALE / 2; m_half_height_hr += LineAA.SUBPIXEL_SCALE / 2; int bufferWidth = m_width + m_dilation * 2; int bufferHeight = m_height + m_dilation * 2; int bytesPerPixel = src.BitDepth / 8; int newSizeInBytes = bufferWidth * bufferHeight * bytesPerPixel; if (m_DataSizeInBytes < newSizeInBytes) { m_DataSizeInBytes = newSizeInBytes; m_data = new int[m_DataSizeInBytes / 4]; } m_buf = new PixelProcessing.SubBitmapBlender(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel); unsafe { CpuBlit.Imaging.TempMemPtr destMemPtr = m_buf.GetBufferPtr(); CpuBlit.Imaging.TempMemPtr srcMemPtr = src.GetBufferPtr(); int *destBuffer = (int *)destMemPtr.Ptr; int *srcBuffer = (int *)srcMemPtr.Ptr; // copy the image into the middle of the dest for (int y = 0; y < m_height; y++) { for (int x = 0; x < m_width; x++) { int sourceOffset = src.GetBufferOffsetXY32(x, y); int destOffset = m_buf.GetBufferOffsetXY32(m_dilation, y + m_dilation); destBuffer[destOffset] = srcBuffer[sourceOffset]; } } // copy the first two pixels form the end into the begining and from the begining into the end for (int y = 0; y < m_height; y++) { int s1Offset = src.GetBufferOffsetXY32(0, y); int d1Offset = m_buf.GetBufferOffsetXY32(m_dilation + m_width, y); int s2Offset = src.GetBufferOffsetXY32(m_width - m_dilation, y); int d2Offset = m_buf.GetBufferOffsetXY32(0, y); for (int x = 0; x < m_dilation; x++) { destBuffer[d1Offset++] = srcBuffer[s1Offset++]; destBuffer[d2Offset++] = srcBuffer[s2Offset++]; } } srcMemPtr.Release(); destMemPtr.Release(); } }