示例#1
0
        public static void PaintCoast()
        {
            Bitmap img = LoadImage("terrain.bmp");
            var    p   = img.Palette;

            p.Entries[10] = Color.FromArgb(255, 247, 0);
            img.Palette   = p;
            LockBitmap lockImg = new LockBitmap(img);

            lockImg.LockBits();
            int pixelsPainted = 0;

            bool[] matchData = new bool[lockImg.Width * lockImg.Height];

            for (int y = 0; y < lockImg.Height; y++)
            {
                for (int x = 0; x < lockImg.Width; x++)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("Checking pixel (" + x + ", " + y + ")");
                    if (IsCoastPixel(x, y, lockImg, matchData))
                    {
                        lockImg.SetPixel(x, y, Color.FromArgb(255, 247, 0));
                        pixelsPainted++;
                        Console.WriteLine("Pixels Painted: " + pixelsPainted);
                    }
                }
            }

            lockImg.UnlockBits();
            SaveImage(img, "terrain_coast.bmp");
        }
示例#2
0
        public static bool IsEqual(int x, int y, LockBitmap bmp, bool[] matchData, Color color)
        {
            if (matchData[bmp.Width * y + x])
            {
                return(true);
            }
            bool b = bmp.GetPixel(x, y).Equals(color);

            if (b)
            {
                matchData[bmp.Width * y + x] = true;
            }
            return(b);
        }
示例#3
0
        public static void ConvertToEU4Terrain()
        {
            Bitmap img          = LoadImage("terrain_eu3.bmp");
            Bitmap img2         = LoadImage("terrain_eu4.bmp");
            Bitmap table        = LoadImage("terrain_eu3_colortable.bmp");
            var    p            = table.Palette;
            var    tablePalette = new Dictionary <Color, int>();

            for (int i = 0; i < p.Entries.Length; i++)
            {
                if (!tablePalette.ContainsKey(p.Entries[i]))
                {
                    tablePalette.Add(p.Entries[i], i);
                }
            }
            var p2 = img2.Palette;
            //p.Entries[10] = Color.FromArgb(255, 247, 0);
            //img.Palette = p;
            LockBitmap lockImg  = new LockBitmap(img);
            LockBitmap lockImg2 = new LockBitmap(img2);

            lockImg.LockBits();
            lockImg2.LockBits();

            for (int y = 0; y < lockImg.Height; y++)
            {
                for (int x = 0; x < lockImg.Width; x++)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("At pixel (" + x + ", " + y + ")");
                    var c        = lockImg.GetPixel(x, y);
                    int indexIn  = tablePalette.ContainsKey(c) ? tablePalette[lockImg.GetPixel(x, y)] : 0;
                    int indexOut = (int)GetTerrainCategories(GetTerrainType((TerrainCategoriesEU3)indexIn));
                    //var color = p2.Entries[indexOut];
                    lockImg2.SetPixelIndex(x, y, indexOut);
                }
            }

            lockImg.UnlockBits();
            lockImg2.UnlockBits();
            SaveImage(img2, "terrain_converted.bmp");
        }
示例#4
0
        public static void PaintHeightmap()
        {
            Bitmap     terrain   = LoadImage("terrain_eu3.bmp");
            Bitmap     heightmap = LoadImage("heightmap.bmp");
            LockBitmap lockT     = new LockBitmap(terrain);
            LockBitmap lockH     = new LockBitmap(heightmap);

            lockT.LockBits();
            lockH.LockBits();

            var tablePalette = new Dictionary <Color, int>();

            for (int i = 0; i < terrain.Palette.Entries.Length; i++)
            {
                if (!tablePalette.ContainsKey(terrain.Palette.Entries[i]))
                {
                    tablePalette.Add(terrain.Palette.Entries[i], i);
                }
            }

            for (int y = 0; y < lockT.Height; y++)
            {
                for (int x = 0; x < lockT.Width; x++)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.WriteLine("At pixel (" + x + ", " + y + ")");
                    var c       = lockT.GetPixel(x, y);
                    int indexIn = tablePalette.ContainsKey(c) ? tablePalette[lockT.GetPixel(x, y)] : 0;
                    int height  = GetHeight((TerrainCategoriesEU3)indexIn);
                    lockH.SetPixel(x, y, Color.FromArgb(height, height, height));
                }
            }

            lockT.UnlockBits();
            lockH.UnlockBits();
            SaveImage(heightmap, "heightmap_new.bmp");
        }
示例#5
0
        public static bool IsCoastPixel(int x, int y, LockBitmap bmp, bool[] matchData)
        {
            //Color to look out for.
            Color sea = Color.FromArgb(0, 32, 128);

            if (IsEqual(x, y, bmp, matchData, sea) || x == 0 || y == 0 || x == bmp.Width - 1 || y == bmp.Height - 1)
            {
                return(false);
            }

            bool nw = IsEqual(x - 1, y - 1, bmp, matchData, sea);

            if (nw)
            {
                return(true);
            }
            bool n = IsEqual(x, y - 1, bmp, matchData, sea);

            if (n)
            {
                return(true);
            }
            bool ne = IsEqual(x + 1, y - 1, bmp, matchData, sea);

            if (ne)
            {
                return(true);
            }
            bool e = IsEqual(x + 1, y, bmp, matchData, sea);

            if (e)
            {
                return(true);
            }
            bool se = IsEqual(x + 1, y + 1, bmp, matchData, sea);

            if (se)
            {
                return(true);
            }
            bool s = IsEqual(x, y + 1, bmp, matchData, sea);

            if (s)
            {
                return(true);
            }
            bool sw = IsEqual(x - 1, y + 1, bmp, matchData, sea);

            if (sw)
            {
                return(true);
            }
            bool w = IsEqual(x - 1, y, bmp, matchData, sea);

            if (w)
            {
                return(true);
            }

            return(false);
        }