unsafe void generate_alpha_mask(int cx, int cy) { m_alpha_buf = new byte[cx * cy]; fixed(byte *pAlphaBuffer = m_alpha_buf) { #if USE_CLIPPING_ALPHA_MASK m_alpha_mask_rbuf.attach(pAlphaBuffer + 20 * cx + 20, (uint)cx - 40, (uint)cy - 40, cx, 1); #else m_alpha_mask_rbuf.attach(pAlphaBuffer, (uint)cx, (uint)cy, cx, 1); #endif FormatGray pixf = new FormatGray(m_alpha_mask_rbuf, new BlenderGray(), 1, 0); FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); ScanlinePacked8 sl = new ScanlinePacked8(); clippingProxy.Clear(new RGBA_Doubles(0)); VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(); System.Random randGenerator = new Random(1432); int i; int num = (int)m_num_cb.value().ToInt(); for (i = 0; i < num; i++) { if (i == num - 1) { ell.Init(width().Divide(2), height().Divide(2), M.New <T>(110), M.New <T>(110), 100); g_rasterizer.AddPath(ell); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, sl, new RGBA_Bytes(0, 0, 0, 255)); ell.Init(ell.X, ell.Y, ell.RX.Subtract(10), ell.RY.Subtract(10), 100); g_rasterizer.AddPath(ell); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, sl, new RGBA_Bytes(255, 0, 0, 255)); } else { ell.Init(randGenerator.Next() % cx, randGenerator.Next() % cy, randGenerator.Next() % 100 + 20, randGenerator.Next() % 100 + 20, 100); // set the color to draw into the alpha channel. // there is not very much reason to set the alpha as you will get the amount of // transparency based on the color you draw. (you might want some type of different edeg effect but it will be minor). g_rasterizer.AddPath(ell); Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, sl, new RGBA_Bytes((uint)((float)i / (float)num * 255), 0, 0, 255)); } } m_alpha_mask_rbuf.dettachBuffer(); } }
public override void OnDraw() { FormatRGB pf = new FormatRGB(rbuf_window(), new BlenderBGR()); FormatGray pfr = new FormatGray(rbuf_window(), new BlenderGray(), 3, 2); FormatGray pfg = new FormatGray(rbuf_window(), new BlenderGray(), 3, 1); FormatGray pfb = new FormatGray(rbuf_window(), new BlenderGray(), 3, 0); FormatClippingProxy clippingProxy = new FormatClippingProxy(pf); FormatClippingProxy clippingProxyRed = new FormatClippingProxy(pfr); FormatClippingProxy clippingProxyGreen = new FormatClippingProxy(pfg); FormatClippingProxy clippingProxyBlue = new FormatClippingProxy(pfb); RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>(); ScanlinePacked8 sl = new ScanlinePacked8(); clippingProxy.Clear(m_UseBlackBackground.status() ? new RGBA_Doubles(0, 0, 0) : new RGBA_Doubles(1, 1, 1)); RGBA_Bytes FillColor = m_UseBlackBackground.status() ? new RGBA_Bytes(255, 255, 255, (uint)(m_alpha.value().ToInt())) : new RGBA_Bytes(0, 0, 0, (uint)(m_alpha.value().ToInt())); VertexSource.Ellipse <T> er = new AGG.VertexSource.Ellipse <T>(width().Divide(2).Subtract(0.87 * 50), height().Divide(2).Subtract(0.5 * 50), M.New <T>(100), M.New <T>(100), 100); ras.AddPath(er); Renderer <T> .RenderSolid(clippingProxyRed, ras, sl, FillColor); VertexSource.Ellipse <T> eg = new AGG.VertexSource.Ellipse <T>(width().Divide(2).Add(0.87 * 50), height().Divide(2).Subtract(0.5 * 50), M.New <T>(100), M.New <T>(100), 100); ras.AddPath(eg); Renderer <T> .RenderSolid(clippingProxyGreen, ras, sl, FillColor); //renderer_scanlines.render_scanlines_aa_solid(ras, sl, rbg, new gray8(0, unsigned(m_alpha.Value()))); VertexSource.Ellipse <T> eb = new AGG.VertexSource.Ellipse <T>(width().Divide(2), height().Divide(2).Add(50), M.New <T>(100), M.New <T>(100), 100); ras.AddPath(eb); Renderer <T> .RenderSolid(clippingProxyBlue, ras, sl, FillColor); //renderer_scanlines.render_scanlines_aa_solid(ras, sl, rbb, new gray8(0, unsigned(m_alpha.Value()))); //m_alpha.Render(ras, sl, clippingProxy); //m_UseBlackBackground.Render(ras, sl, clippingProxy); base.OnDraw(); }