Ejemplo n.º 1
0
        private unsafe void generate_alpha_mask(int cx, int cy)
        {
            alphaByteArray = new byte[cx * cy];
            {
#if USE_CLIPPING_ALPHA_MASK
                alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 20 * cx + 20, cx - 40, cy - 40, cx, 8, 1);
#else
                alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1);
#endif

                ImageBuffer image = new ImageBuffer();
                image.Attach(alphaMaskImageBuffer, new blender_gray(1), 1, 0, 8);
                ImageClippingProxy   clippingProxy = new ImageClippingProxy(image);
                ScanlineCachePacked8 sl            = new ScanlineCachePacked8();

                clippingProxy.clear(new ColorF(0));

                VertexSource.Ellipse ellipseForMask = new MatterHackers.Agg.VertexSource.Ellipse();

                System.Random randGenerator = new Random(1432);

                ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
                int i;
                int num = (int)numMasksSlider.Value;
                for (i = 0; i < num; i++)
                {
                    if (i == num - 1)
                    {
                        ellipseForMask.init(Width / 2, Height / 2, 110, 110, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color(0, 0, 0, 255));

                        ellipseForMask.init(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color(255, 0, 0, 255));
                    }
                    else
                    {
                        ellipseForMask.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).
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color((int)((float)i / (float)num * 255), 0, 0, 255));
                    }
                }

                alphaMaskImageBuffer.DettachBuffer();
            }
        }
Ejemplo n.º 2
0
        // Create
        //--------------------------------------------------------------------
        public void create(IImageByte src)
        {
            // we are going to create a dilated image for filtering
            // we add m_dilation pixels to every side of the image and then copy the image in the x
            // direction 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)agg_basics.uceil(src.Height);
            m_width           = (int)agg_basics.uceil(src.Width);
            m_width_hr        = (int)agg_basics.uround(src.Width * LineAABasics.line_subpixel_scale);
            m_half_height_hr  = (int)agg_basics.uround(src.Height * LineAABasics.line_subpixel_scale / 2);
            m_offset_y_hr     = m_dilation_hr + m_half_height_hr - LineAABasics.line_subpixel_scale / 2;
            m_half_height_hr += LineAABasics.line_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 byte[m_DataSizeInBytes];
            }

            m_buf.AttachBuffer(m_data, 0, bufferWidth, bufferHeight, bufferWidth * bytesPerPixel, src.BitDepth, bytesPerPixel);
            byte[] destBuffer   = m_buf.GetBuffer();
            byte[] sourceBuffer = src.GetBuffer();

            // 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.GetBufferOffsetXY(x, y);
                    int destOffset   = m_buf.GetBufferOffsetXY(m_dilation, y + m_dilation);
                    for (int channel = 0; channel < bytesPerPixel; channel++)
                    {
                        destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                    }
                }
            }

            // copy the first two pixels form the end into the beginning and from the beginning into the end
            for (int y = 0; y < m_height; y++)
            {
                int s1Offset = src.GetBufferOffsetXY(0, y);
                int d1Offset = m_buf.GetBufferOffsetXY(m_dilation + m_width, y);

                int s2Offset = src.GetBufferOffsetXY(m_width - m_dilation, y);
                int d2Offset = m_buf.GetBufferOffsetXY(0, y);

                for (int x = 0; x < m_dilation; x++)
                {
                    for (int channel = 0; channel < bytesPerPixel; channel++)
                    {
                        destBuffer[d1Offset++] = sourceBuffer[s1Offset++];
                        destBuffer[d2Offset++] = sourceBuffer[s2Offset++];
                    }
                }
            }
        }