Example #1
0
        public void SetPixel(int x, int y, PixelData colour)
        {
            PixelData *pixel = PixelAt(x, y);

            *pixel = colour;
        }
Example #2
0
        Bitmap DrawShape(ShapeWithStyle s, Edge[] edges, Rect r)
        {
            int top  = r.YMin / TWIP;
            int left = r.XMin / TWIP;
            int w    = (r.XMax - r.XMin) / TWIP;
            int h    = (r.YMax - r.YMin) / TWIP;

            colors.Clear();
            colors.Add(new PixelData(0xFF, 0xFF, 0xFF, 0x00));
            foreach (IFillStyle fs in s.FillStyles.FillStyles)
            {
                if (fs.FillType == FillType.Solid)
                {
                    RGBA c = ((SolidFill)fs).Color;
                    colors.Add(new PixelData(c.R, c.G, c.B, c.A));
                }
                else
                {
                    colors.Add(new PixelData(0x80, 0x80, 0x80, 0xFF));
                }
            }
            //UnsafeBitmapP b = new UnsafeBitmapP(w, h);
            UnsafeBitmap b = new UnsafeBitmap(w + left, h + top);

            b.LockBitmap();

            List <Edge> activeEdges = new List <Edge>();
            int         edgeIndex   = 0;

            byte[,] bytes = new byte[w, h];

            bool orderChanged = true;

            int syTwip = 0;

            for (int sy = 0; sy < h + top; sy++)
            {
                syTwip += TWIP;

                //AdjustActiveTable
                //remove stale
                for (int i = activeEdges.Count - 1; i >= 0; i--)
                {
                    if (activeEdges[i].endY < sy * TWIP)
                    {
                        activeEdges.RemoveAt(i);
                    }
                }

                // add new elements
                while (edgeIndex < edges.Length && edges[edgeIndex].startY <= sy * TWIP)
                {
                    activeEdges.Add(edges[edgeIndex]);
                    edgeIndex++;
                    orderChanged = true;
                }

                // sort
                if (orderChanged)
                {
                    activeEdges.Sort(Edge.CurrentXComparer);
                    orderChanged = false;
                }

                if (activeEdges.Count > 0)
                {
                    int       xIndex  = 0;
                    byte      curFill = 0;
                    Edge      edge    = activeEdges[xIndex];
                    PixelData col     = colors[0];
                    PixelData nextCol = colors[0];
                    int       sxTwip  = 0;
                    float     pc      = 0;

                    for (int sx = 0; sx < w + left; sx++)
                    {
                        sxTwip += TWIP;
                        if (sxTwip >= edge.currentX)
                        {
                            pc = (edge.currentX % TWIP) / TWIP;
                            if ((int)edge.currentX != edge.startX)
                            {
                                nextCol = colors[edge.fill0];
                                col.Interpolate(pc, nextCol);
                            }

                            while (sxTwip >= edge.currentX)
                            {
                                xIndex++;
                                if (xIndex < activeEdges.Count)
                                {
                                    if (xIndex > 0 && activeEdges[xIndex - 1].currentX > activeEdges[xIndex].currentX)
                                    {
                                    }
                                    else
                                    {
                                        edge    = activeEdges[xIndex];
                                        curFill = edge.fill1;
                                    }
                                }
                                else
                                {
                                    b.SetPixel(sx, sy, col);
                                    goto ENDXLOOP;
                                }
                            }
                        }

                        if (sy == 80)
                        {
                            //col.blue = 255;
                        }

                        if (col.alpha > 0)
                        {
                            b.SetPixel(sx, sy, col);
                        }

                        col = colors[curFill];
                    }
                }
ENDXLOOP:

                for (int i = 0; i < activeEdges.Count; i++)
                {
                    activeEdges[i].IncX(syTwip);
                }
            }


            b.UnlockBitmap();
            Program.form.Bitmap = b.Bitmap;
            // b.Bitmap.Save("test.png");

            return(null);
        }
Example #3
0
        public PixelData GetPixel(int x, int y)
        {
            PixelData returnValue = *PixelAt(x, y);

            return(returnValue);
        }