Exemplo n.º 1
0
    static void Main(string[] args)
    {
        FastColor c = new FastColor(127, 192, 255);

        Console.WriteLine("Please select an image.");
        OpenFileDialog ofd = new OpenFileDialog()
        {
            Filter = "BMP Files|*.bmp|JPG Files|*.jpg|PNG Files|*.png", CheckFileExists = true, CheckPathExists = true
        };
        SaveFileDialog sfd = new SaveFileDialog()
        {
            Filter = "BMP Files|*.bmp", CheckPathExists = true
        };

        if (ofd.ShowDialog() == DialogResult.OK)
        {
            FastBitmap f = FastBitmap.FromFile(ofd.FileName);

            // Edge detection, yay!
            f.Effects.EdgeDetection();

            Console.WriteLine("Please select the save path");

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                f.Save(sfd.FileName);
            }
        }
    }
Exemplo n.º 2
0
        static public void AddToBitmap(long _x, long _y)

        {
            //The Origin gets an offset
            int bitmap_x = (int)(_x / 10 + sol_offset._x);
            int bitmap_y = (int)(img_res._y) - (int)(_y / 10 + sol_offset._y);

            //we get the color-value. (since it's greyscale R = G = B)
            int systems_amount = bitmap.GetPixel(bitmap_x, bitmap_y).R;

            if (systems_amount < 253) //We count up if we dont cause a byte overflow
            {
                systems_amount = systems_amount + 3;
                FastColor c = new FastColor();
                c.R = (byte)systems_amount;
                c.G = (byte)systems_amount;
                c.B = (byte)systems_amount;
                Write("[" + counter + "]\n" + bitmap_x + " " + bitmap_y + "@ " + c.R);
                bitmap.SetPixel(bitmap_x, bitmap_y, c);
            }
            else if (systems_amount > 252 && systems_amount < 255) //if we would've caused a byte overflow we just set the value to byte.maximum (255)
            {
                systems_amount = 255;
                FastColor c = new FastColor();
                c.R = (byte)systems_amount;
                c.G = (byte)systems_amount;
                c.B = (byte)systems_amount;
                Write("[" + counter + "]\n");
                bitmap.SetPixel(bitmap_x, bitmap_y, c);
            }
        }
        public void DrawFpsHistoryGraph()
        {
            float maxtime = 0;

            foreach (var v in fpshistory)
            {
                if (v > maxtime)
                {
                    maxtime = v;
                }
            }
            float historyheight = 80;
            int   posx          = 25;
            int   posy          = d_ViewportSize.Height - (int)historyheight - 20;

            FastColor[] colors    = new[] { new FastColor(Color.Black), new FastColor(Color.Red) };
            Color       linecolor = Color.White;

            if (todraw == null)
            {
                todraw = new Draw2dData[MAX_COUNT];
            }
            for (int i = 0; i < fpshistory.Count; i++)
            {
                float time = fpshistory[i];
                time = (time * 60) * historyheight;
                FastColor c = Interpolation.InterpolateColor((float)i / fpshistory.Count, colors);
                todraw[i].x1        = posx + i;
                todraw[i].y1        = posy - time;
                todraw[i].width     = 1;
                todraw[i].height    = time;
                todraw[i].inAtlasId = null;
                todraw[i].color     = c;
            }
            d_Draw.Draw2dTextures(todraw, d_Draw.WhiteTexture());

            d_Draw.Draw2dTexture(d_Draw.WhiteTexture(), posx, posy - historyheight, fpshistory.Count, 1, null, linecolor);
            d_Draw.Draw2dTexture(d_Draw.WhiteTexture(), posx, posy - historyheight * (60f / 75), fpshistory.Count, 1, null, linecolor);
            d_Draw.Draw2dTexture(d_Draw.WhiteTexture(), posx, posy - historyheight * (60f / 30), fpshistory.Count, 1, null, linecolor);
            d_Draw.Draw2dTexture(d_Draw.WhiteTexture(), posx, posy - historyheight * (60f / 150), fpshistory.Count, 1, null, linecolor);
            d_Draw.Draw2dText("60", posx, posy - historyheight * (60f / 60), 6, null);
            d_Draw.Draw2dText("75", posx, posy - historyheight * (60f / 75), 6, null);
            d_Draw.Draw2dText("30", posx, posy - historyheight * (60f / 30), 6, null);
            d_Draw.Draw2dText("150", posx, posy - historyheight * (60f / 150), 6, null);
        }
Exemplo n.º 4
0
 public List<TextPart> DecodeColors(String s, FastColor defaultcolor)
 {
     List<TextPart> parts = new List<TextPart>();
     int i = 0;
     FastColor currentcolor = defaultcolor;
     String currenttext = null;
     for (; ; )
     {
         if (i >= s.Length)
         {
             if (currenttext != null)
             {
                 parts.Add(new TextPart() { text = currenttext, color = currentcolor });
             }
             currenttext = "";
             break;
         }
         if (s[i] == '&')
         {
             if (i + 1 < s.Length)
             {
                 int? color = HexToInt(s[i + 1]);
                 if (color != null)
                 {
                     if (currenttext != null)
                     {
                         parts.Add(new TextPart() { text = currenttext, color = currentcolor });
                     }
                     currenttext = "";
                     currentcolor = GetColor(color.Value);
                     i++;
                     goto next;
                 }
             }
             else
             {
             }
         }
             currenttext += s[i];
     next:
         i++;
     }
     return parts;
 }
Exemplo n.º 5
0
        public void TestMethod1()
        {
            //var image = new CandidateImage(new[] { new ColoredRectangle(1, 1, 1, 1, new FastColor(128, 10, 20, 30)) });
            Expect(FastColor.Black.Blend(new FastColor(128, 255, 255, 255)), Is.EqualTo(FastColor.Black));

            var c = FastColor.Black;
            c = new FastColor(128, 255, 255, 255).Blend(c);
            Expect(c, Is.EqualTo(new FastColor(128, 128, 128)));

            c = new FastColor(128, 255, 255, 255).Blend(c);
            Expect(c, Is.EqualTo(new FastColor(191, 191, 191)));

            c = new FastColor(128, 255, 255, 255).Blend(c);
            Expect(c, Is.EqualTo(new FastColor(223, 223, 223)));

            c = FastColor.Black;
            c = new FastColor(67, 255, 255, 255).Blend(c);
            c = new FastColor(67, 255, 255, 255).Blend(c);
            c = new FastColor(67, 255, 255, 255).Blend(c);
            Expect(c, Is.EqualTo(new FastColor(152, 152, 152)));
        }
        private void BlockPolygons(int x, int y, int z, byte[, ,] currentChunk)
        {
            int xx = x % chunksize + 1;
            int yy = y % chunksize + 1;
            int zz = z % chunksize + 1;
            var tt = currentChunk[xx, yy, zz];
            if (!data.IsValidTileType(tt))
            {
                return;
            }
            bool drawtop = IsTileEmptyForDrawingOrTransparent(xx, yy, zz + 1, tt, currentChunk) && (!currentChunkIgnore[xx - 1, yy - 1, zz - 1, (int)TileSide.Top]);
            bool drawbottom = IsTileEmptyForDrawingOrTransparent(xx, yy, zz - 1, tt, currentChunk) && (!currentChunkIgnore[xx - 1, yy - 1, zz - 1, (int)TileSide.Bottom]);
            bool drawfront = IsTileEmptyForDrawingOrTransparent(xx - 1, yy, zz, tt, currentChunk) && (!currentChunkIgnore[xx - 1, yy - 1, zz - 1, (int)TileSide.Front]);
            bool drawback = IsTileEmptyForDrawingOrTransparent(xx + 1, yy, zz, tt, currentChunk) && (!currentChunkIgnore[xx - 1, yy - 1, zz - 1, (int)TileSide.Back]);
            bool drawleft = IsTileEmptyForDrawingOrTransparent(xx, yy - 1, zz, tt, currentChunk) && (!currentChunkIgnore[xx - 1, yy - 1, zz - 1, (int)TileSide.Left]);
            bool drawright = IsTileEmptyForDrawingOrTransparent(xx, yy + 1, zz, tt, currentChunk) && (!currentChunkIgnore[xx - 1, yy - 1, zz - 1, (int)TileSide.Right]);
            int tiletype = tt;
            if (!(drawtop || drawbottom || drawfront || drawback || drawleft || drawright))
            {
                return;
            }
            FastColor color = mapstorage.GetTerrainBlockColor(x, y, z);
            FastColor colorShadowSide = new FastColor(color.A,
                (int)(color.R * BlockShadow),
                (int)(color.G * BlockShadow),
                (int)(color.B * BlockShadow));
            if (DONOTDRAWEDGES)
            {
                //if the game is fillrate limited, then this makes it much faster.
                //(39fps vs vsync 75fps)
                //bbb.
                if (z == 0) { drawbottom = false; }
                if (x == 0) { drawfront = false; }
                if (x == 256 - 1) { drawback = false; }
                if (y == 0) { drawleft = false; }
                if (y == 256 - 1) { drawright = false; }
            }
            float flowerfix = 0;
            if (data.IsBlockFlower(tiletype))
            {
                drawtop = false;
                drawbottom = false;
                flowerfix = 0.5f;
            }
            float blockheight = 1;
            if (tt == data.TileIdSingleStairs)
            {
                blockheight = 0.5f;
            }

            FastColor curcolor = color;
            float blockheight00 = blockheight;
            float blockheight01 = blockheight;
            float blockheight10 = blockheight;
            float blockheight11 = blockheight;
            //top
            if (drawtop)
            {
                curcolor = color;
                float shadowratio = GetShadowRatio(xx, yy, zz + 1, x, y, z + 1);
                if (shadowratio != 1)
                {
                    curcolor = new FastColor(color.A,
                        (int)(color.R * shadowratio),
                        (int)(color.G * shadowratio),
                        (int)(color.B * shadowratio));
                }
                int sidetexture = data.GetTileTextureId(tiletype, TileSide.Top);
                int tilecount = GetTilingCount(currentChunk, xx, yy, zz, tt, x, y, z, shadowratio, TileSide.Top);
                VerticesIndices toreturn = GetToReturn(tt, sidetexture);
                RectangleF texrec = TextureAtlas.TextureCoords1d(sidetexture, terrainrenderer.terrainTexturesPerAtlas, tilecount);
                short lastelement = (short)toreturn.vertices.Count;
                toreturn.vertices.Add(new VertexPositionTexture(x + 0.0f, z + blockheight00, y + 0.0f, texrec.Left, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 0.0f, z + blockheight01, y + 1.0f, texrec.Left, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1.0f * tilecount, z + blockheight10, y + 0.0f, texrec.Right, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1.0f * tilecount, z + blockheight11, y + 1.0f, texrec.Right, texrec.Bottom, curcolor));
                toreturn.indices.Add((ushort)(lastelement + 0));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 2));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 3));
                toreturn.indices.Add((ushort)(lastelement + 2));
            }
            //bottom - same as top, but z is 1 less.
            if (drawbottom)
            {
                curcolor = colorShadowSide;
                float shadowratio = GetShadowRatio(xx, yy, zz - 1, x, y, z - 1);
                if (shadowratio != 1)
                {
                    curcolor = new FastColor(color.A,
                        (int)(Math.Min(curcolor.R, color.R * shadowratio)),
                        (int)(Math.Min(curcolor.G, color.G * shadowratio)),
                        (int)(Math.Min(curcolor.B, color.B * shadowratio)));
                }
                int sidetexture = data.GetTileTextureId(tiletype, TileSide.Bottom);
                int tilecount = GetTilingCount(currentChunk, xx, yy, zz, tt, x, y, z, shadowratio, TileSide.Bottom);
                VerticesIndices toreturn = GetToReturn(tt, sidetexture);
                RectangleF texrec = TextureAtlas.TextureCoords1d(sidetexture, terrainrenderer.terrainTexturesPerAtlas, tilecount);
                short lastelement = (short)toreturn.vertices.Count;
                toreturn.vertices.Add(new VertexPositionTexture(x + 0.0f, z, y + 0.0f, texrec.Left, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 0.0f, z, y + 1.0f, texrec.Left, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1.0f * tilecount, z, y + 0.0f, texrec.Right, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1.0f * tilecount, z, y + 1.0f, texrec.Right, texrec.Bottom, curcolor));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 0));
                toreturn.indices.Add((ushort)(lastelement + 2));
                toreturn.indices.Add((ushort)(lastelement + 3));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 2));
            }
            //front
            if (drawfront)
            {
                curcolor = color;
                float shadowratio = GetShadowRatio(xx - 1, yy, zz, x - 1, y, z);
                if (shadowratio != 1)
                {
                    curcolor = new FastColor(color.A,
                        (int)(color.R * shadowratio),
                        (int)(color.G * shadowratio),
                        (int)(color.B * shadowratio));
                }
                int sidetexture = data.GetTileTextureId(tiletype, TileSide.Front);
                int tilecount = GetTilingCount(currentChunk, xx, yy, zz, tt, x, y, z, shadowratio, TileSide.Front);
                VerticesIndices toreturn = GetToReturn(tt, sidetexture);
                RectangleF texrec = TextureAtlas.TextureCoords1d(sidetexture, terrainrenderer.terrainTexturesPerAtlas, tilecount);
                short lastelement = (short)toreturn.vertices.Count;
                toreturn.vertices.Add(new VertexPositionTexture(x + 0 + flowerfix, z + 0, y + 0, texrec.Left, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 0 + flowerfix, z + 0, y + 1 * tilecount, texrec.Right, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 0 + flowerfix, z + blockheight00, y + 0, texrec.Left, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 0 + flowerfix, z + blockheight01, y + 1 * tilecount, texrec.Right, texrec.Top, curcolor));
                toreturn.indices.Add((ushort)(lastelement + 0));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 2));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 3));
                toreturn.indices.Add((ushort)(lastelement + 2));
            }
            //back - same as front, but x is 1 greater.
            if (drawback)
            {
                curcolor = color;
                float shadowratio = GetShadowRatio(xx + 1, yy, zz, x + 1, y, z);
                if (shadowratio != 1)
                {
                    curcolor = new FastColor(color.A,
                        (int)(color.R * shadowratio),
                        (int)(color.G * shadowratio),
                        (int)(color.B * shadowratio));
                }
                int sidetexture = data.GetTileTextureId(tiletype, TileSide.Back);
                int tilecount = GetTilingCount(currentChunk, xx, yy, zz, tt, x, y, z, shadowratio, TileSide.Back);
                VerticesIndices toreturn = GetToReturn(tt, sidetexture);
                RectangleF texrec = TextureAtlas.TextureCoords1d(sidetexture, terrainrenderer.terrainTexturesPerAtlas, tilecount);
                short lastelement = (short)toreturn.vertices.Count;
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 - flowerfix, z + 0, y + 0, texrec.Right, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 - flowerfix, z + 0, y + 1 * tilecount, texrec.Left, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 - flowerfix, z + blockheight10, y + 0, texrec.Right, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 - flowerfix, z + blockheight11, y + 1 * tilecount, texrec.Left, texrec.Top, curcolor));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 0));
                toreturn.indices.Add((ushort)(lastelement + 2));
                toreturn.indices.Add((ushort)(lastelement + 3));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 2));
            }
            if (drawleft)
            {
                curcolor = colorShadowSide;
                float shadowratio = GetShadowRatio(xx, yy - 1, zz, x, y - 1, z);
                if (shadowratio != 1)
                {
                    curcolor = new FastColor(color.A,
                        (int)(Math.Min(curcolor.R, color.R * shadowratio)),
                        (int)(Math.Min(curcolor.G, color.G * shadowratio)),
                        (int)(Math.Min(curcolor.B, color.B * shadowratio)));
                }

                int sidetexture = data.GetTileTextureId(tiletype, TileSide.Left);
                int tilecount = GetTilingCount(currentChunk, xx, yy, zz, tt, x, y, z, shadowratio, TileSide.Left);
                VerticesIndices toreturn = GetToReturn(tt, sidetexture);
                RectangleF texrec = TextureAtlas.TextureCoords1d(sidetexture, terrainrenderer.terrainTexturesPerAtlas, tilecount);
                short lastelement = (short)toreturn.vertices.Count;
                toreturn.vertices.Add(new VertexPositionTexture(x + 0, z + 0, y + 0 + flowerfix, texrec.Right, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 0, z + blockheight00, y + 0 + flowerfix, texrec.Right, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 * tilecount, z + 0, y + 0 + flowerfix, texrec.Left, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 * tilecount, z + blockheight10, y + 0 + flowerfix, texrec.Left, texrec.Top, curcolor));
                toreturn.indices.Add((ushort)(lastelement + 0));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 2));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 3));
                toreturn.indices.Add((ushort)(lastelement + 2));
            }
            //right - same as left, but y is 1 greater.
            if (drawright)
            {
                curcolor = colorShadowSide;
                float shadowratio = GetShadowRatio(xx, yy + 1, zz, x, y + 1, z);
                if (shadowratio != 1)
                {
                    curcolor = new FastColor(color.A,
                        (int)(Math.Min(curcolor.R, color.R * shadowratio)),
                        (int)(Math.Min(curcolor.G, color.G * shadowratio)),
                        (int)(Math.Min(curcolor.B, color.B * shadowratio)));
                }

                int sidetexture = data.GetTileTextureId(tiletype, TileSide.Right);
                int tilecount = GetTilingCount(currentChunk, xx, yy, zz, tt, x, y, z, shadowratio, TileSide.Right);
                VerticesIndices toreturn = GetToReturn(tt, sidetexture);
                RectangleF texrec = TextureAtlas.TextureCoords1d(sidetexture, terrainrenderer.terrainTexturesPerAtlas, tilecount);
                short lastelement = (short)toreturn.vertices.Count;
                toreturn.vertices.Add(new VertexPositionTexture(x + 0, z + 0, y + 1 - flowerfix, texrec.Left, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 0, z + blockheight01, y + 1 - flowerfix, texrec.Left, texrec.Top, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 * tilecount, z + 0, y + 1 - flowerfix, texrec.Right, texrec.Bottom, curcolor));
                toreturn.vertices.Add(new VertexPositionTexture(x + 1 * tilecount, z + blockheight11, y + 1 - flowerfix, texrec.Right, texrec.Top, curcolor));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 0));
                toreturn.indices.Add((ushort)(lastelement + 2));
                toreturn.indices.Add((ushort)(lastelement + 3));
                toreturn.indices.Add((ushort)(lastelement + 1));
                toreturn.indices.Add((ushort)(lastelement + 2));
            }
        }
Exemplo n.º 7
0
 public VertexPositionTexture(float x, float y, float z, float u, float v, FastColor c)
 {
     Position = new Vector3(x, y, z);
     this.u = u;
     this.v = v;
     r = c.R;
     g = c.G;
     b = c.B;
     a = c.A;
 }
Exemplo n.º 8
0
        private void DrawFpsHistoryGraph()
        {
            float maxtime = 0;
            foreach (var v in fpshistory)
            {
                if (v > maxtime)
                {
                    maxtime = v;
                }
            }
            float historyheight = 80;
            int posx = 25;
            int posy = Height - (int)historyheight - 20;
            Color[] colors = new[] { Color.Black, Color.Red };
            Color linecolor = Color.White;

            List<Draw2dData> todraw = new List<Draw2dData>();
            for (int i = 0; i < fpshistory.Count; i++)
            {
                float time = fpshistory[i];
                time = (time * 60) * historyheight;
                FastColor c = new FastColor(InterpolateColor((float)i / fpshistory.Count, colors));
                todraw.Add(new Draw2dData() { x1 = posx + i, y1 = posy - time, width = 1, height = time, inAtlasId = null, color = c });
            }
            Draw2dTextures(todraw, WhiteTexture());

            Draw2dTexture(WhiteTexture(), posx, posy - historyheight, fpshistory.Count, 1, null, linecolor);
            Draw2dTexture(WhiteTexture(), posx, posy - historyheight * (60f / 75), fpshistory.Count, 1, null, linecolor);
            Draw2dTexture(WhiteTexture(), posx, posy - historyheight * (60f / 30), fpshistory.Count, 1, null, linecolor);
            Draw2dTexture(WhiteTexture(), posx, posy - historyheight * (60f / 150), fpshistory.Count, 1, null, linecolor);
            Draw2dText("60", posx, posy - historyheight * (60f / 60), 6, null);
            Draw2dText("75", posx, posy - historyheight * (60f / 75), 6, null);
            Draw2dText("30", posx, posy - historyheight * (60f / 30), 6, null);
            Draw2dText("150", posx, posy - historyheight * (60f / 150), 6, null);
        }