コード例 #1
0
        private static List <Bitmap> GetDistinctBitmaps(List <List <Bitmap> > grid)
        {
            List <Bitmap> DistinctTiles = new List <Bitmap>();

            foreach (var verticalRow in grid)
            {
                foreach (var tile in verticalRow)
                {
                    var Distinct = true;
                    foreach (var validatedTile in DistinctTiles)
                    {
                        var equal = BitmapOperations.Compare(validatedTile, tile);
                        if (equal)
                        {
                            Distinct = false;
                            break;
                        }
                    }
                    if (Distinct == true)
                    {
                        DistinctTiles.Add(tile);
                    }
                }
            }
            return(DistinctTiles);
        }
コード例 #2
0
 public void SaveResult(string folderpath)
 {
     BitmapOperations.SaveBitmapToFile(
         folderpath + "Seed" + LastSeed.ToString() + "Effective" + LastEffectiveSeed.ToString() + ".bmp"
         , LastResult.TileMap
         );
 }
コード例 #3
0
        public void LoadTileset(string path, bool horizontalMirror = true, string debugFilePath = null, bool hasSpacing = false)
        {
            //Chop up tileset
            Bitmap tilesetImg = Image.FromFile(path) as Bitmap;

            if (horizontalMirror)
            {
                tilesetImg = tilesetImg.AddHorizontalMirror(hasSpacing);
            }
            _tileset = BitmapOperations.GetBitmapTiles(tilesetImg, _tileWidth, _tileHeight, hasSpacing);

            if (debugFilePath != null)
            {
                Bitmap quickcheck = BitmapOperations.CreateBitmapFromTiles(_tileset, true);
                BitmapOperations.SaveBitmapToFile(debugFilePath, quickcheck);
            }


            //setup wfcTiles (and neighbors)
            var distinctTiles = GetDistinctBitmaps(_tileset);

            //why does this mess things up
            //distinctTiles.AddRange(GetWeightedTiles(_tileWidth, _tileHeight, hasSpacing));

            //List<List<Bitmap>> distinctElements = new List<List<Bitmap>>();
            //distinctElements.Add(distinctTiles);

            _wfcTiles = ToOpinionatedList(distinctTiles);
            SetAcceptableItems(_wfcTiles, _tileset);
        }
コード例 #4
0
        private List <List <Bitmap> > ChopUpTilesWithMirror2D(Bitmap img)
        {
            List <Bitmap> result     = new List <Bitmap>();
            Bitmap        tilesetImg = img.AddHorizontalMirror(true);
            var           tiles      = BitmapOperations.GetBitmapTiles(tilesetImg, 6, 6, true);

            return(tiles);
        }
コード例 #5
0
        private List <List <Bitmap> > ChopUpTilesWithMirror2D(string tilespath)
        {
            List <Bitmap> result     = new List <Bitmap>();
            Bitmap        tilesetImg = LoadBmp(tilespath);

            tilesetImg = tilesetImg.AddHorizontalMirror(true);
            var tiles = BitmapOperations.GetBitmapTiles(tilesetImg, 6, 6, true);

            return(tiles);
        }
コード例 #6
0
        public bool OutputWfc(string outPath)
        {
            var collapsedTiles = ToTilesList(_grid);

            Bitmap tilesetRedux = BitmapOperations.CreateBitmapFromTiles(collapsedTiles);

            BitmapOperations.SaveBitmapToFile(outPath, tilesetRedux);

            return(true);
        }
コード例 #7
0
        private List <Bitmap> ChopUpTiles(Bitmap img)
        {
            List <Bitmap> result = new List <Bitmap>();
            var           tiles  = BitmapOperations.GetBitmapTiles(img, 6, 6, true);

            foreach (var row in tiles)
            {
                result.AddRange(row);
            }
            return(result);
        }
コード例 #8
0
        private List <OpinionatedItem <Bitmap> > getWcfTilesInBmp(string path, bool hasSpacing = false)
        {
            Bitmap bmp = Image.FromFile(path) as Bitmap;
            List <List <Bitmap> > tileset = BitmapOperations.GetBitmapTiles(bmp, _tileWidth, _tileHeight, hasSpacing);
            List <Bitmap>         tiles   = new List <Bitmap>();

            foreach (var list in tileset)
            {
                tiles.AddRange(list);
            }
            return(_wfcTiles.Where(element => tiles.Any(t => BitmapOperations.Compare(t, element.actualItem))).ToList());
        }
コード例 #9
0
        protected Bitmap CalculateDifference(Bitmap bmp1, Bitmap bmp2)
        {
            if (bmp1 == null || bmp2 == null || Equals(bmp1, bmp2) || !bmp1.Size.Equals(bmp2.Size) || !bmp1.PixelFormat.Equals(bmp2.PixelFormat))
            {
                throw new InvalidOperationException("Can't calculate.");
            }

            return(BitmapOperations.Create((sources, i, j) =>
            {
                return sources[0].GetPixel(i, j) - sources[1].GetPixel(i, j);
            }, bmp1.TransformToEffectiveBitmap(), bmp2.TransformToEffectiveBitmap()).ToBitmap());
        }
コード例 #10
0
        private List <Bitmap> ChopUpTiles(string tilespath)
        {
            Console.WriteLine("ChoppingUpTiles at " + tilespath);
            List <Bitmap> result     = new List <Bitmap>();
            Bitmap        tilesetImg = LoadBmp(tilespath);
            var           tiles      = BitmapOperations.GetBitmapTiles(tilesetImg, 6, 6, true);

            foreach (var row in tiles)
            {
                result.AddRange(row);
            }
            return(result);
        }
コード例 #11
0
        private EffectiveBitmap Watermark(EffectiveBitmap original, EffectiveBitmap watermark)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var originalPixel = sources[0].GetPixel(i, j);
                var watermarkPixel = sources[1].GetPixel(i, j);

                var r = (int)(originalPixel.R + (watermarkPixel.R * parameters.Ratio)) / 2;
                var g = (int)(originalPixel.G + (watermarkPixel.G * parameters.Ratio)) / 2;
                var b = (int)(originalPixel.B + (watermarkPixel.B * parameters.Ratio)) / 2;

                return new PixelInfo(r, g, b);
            }, original, watermark));
        }
コード例 #12
0
        private EffectiveBitmap CleanWatermark(EffectiveBitmap watermarked)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);

                var divider = (int)(Math.Pow(2, parameters.BitsForWatermark) + 0.5);
                // TODO better method instead of random bit on last position
                var r = (byte)(watermarkedImgPixel.R - watermarkedImgPixel.R % divider + CreateRandomNumber(divider));
                var g = (byte)(watermarkedImgPixel.G - watermarkedImgPixel.G % divider + CreateRandomNumber(divider));
                var b = (byte)(watermarkedImgPixel.B - watermarkedImgPixel.B % divider + CreateRandomNumber(divider));

                return new PixelInfo(r, g, b);
            }, watermarked));
        }
コード例 #13
0
        private EffectiveBitmap PreprocessToSimplifiedWatermark(EffectiveBitmap watermark)
        {
            var divider = (byte)(Math.Ceiling(255 / Math.Pow(2, parameters.BitsForWatermark)) + 0.5);

            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkPixel = sources[0].GetPixel(i, j);

                byte r = (byte)(watermarkPixel.R / divider);
                byte g = (byte)(watermarkPixel.G / divider);
                byte b = (byte)(watermarkPixel.B / divider);

                return new PixelInfo(r, g, b);
            }, watermark));
        }
コード例 #14
0
        private EffectiveBitmap ExtractWatermark(EffectiveBitmap watermarked)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);

                var divider = (int)Math.Pow(2, parameters.BitsForWatermark);
                var multiplier = 255 / (divider - 1);
                byte r = (byte)(watermarkedImgPixel.R % divider * multiplier);
                byte g = (byte)(watermarkedImgPixel.G % divider * multiplier);
                byte b = (byte)(watermarkedImgPixel.B % divider * multiplier);

                return new PixelInfo(r, g, b);
            }, watermarked));
        }
コード例 #15
0
 public void DrawBitmapManaged(int ObjectDesiredWidth, int ObjectDesiredHeight, bool ChangePosition, int NewLeft, int NewTop, bool ShowOverlay, int OverlayDesiredLeft, int OverlayDesiredTop, int OverlayDesiredWidth, int OverlayDesiredHeight, bool ChangeOpacity, int NewOpacity)
 {
     try
     {
         if (this.ObjectBitmap != null)
         {
             this.CurrentObjectBitmap = BitmapOperations.ScaleBySizeBestFit(ref this.ObjectBitmap, ObjectDesiredWidth, ObjectDesiredHeight);
             if (ShowOverlay && this.OverlayBitmap != null)
             {
                 using (Graphics graphics = Graphics.FromImage(this.CurrentObjectBitmap))
                 {
                     graphics.SmoothingMode      = SmoothingMode.HighSpeed;
                     graphics.PixelOffsetMode    = PixelOffsetMode.HighSpeed;
                     graphics.CompositingQuality = CompositingQuality.HighSpeed;
                     graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                     graphics.DrawImage(this.CurrentObjectBitmap, new Rectangle(OverlayDesiredLeft, OverlayDesiredTop, OverlayDesiredWidth, OverlayDesiredHeight), new Rectangle(0, 0, this.OverlayBitmap.Width, this.OverlayBitmap.Height), GraphicsUnit.Pixel);
                 }
             }
             if (this.ObjectSize.Width != ObjectDesiredWidth || this.ObjectSize.Height != ObjectDesiredHeight)
             {
                 this.ObjectSize = new Size(ObjectDesiredWidth, ObjectDesiredHeight);
             }
             if (this.OverlaySize.Width != OverlayDesiredWidth || this.OverlaySize.Height != OverlayDesiredHeight)
             {
                 this.OverlaySize = new Size(OverlayDesiredWidth, OverlayDesiredHeight);
             }
             if (ChangeOpacity)
             {
                 if (NewOpacity < 0)
                 {
                     this.ObjectOpacity = 0;
                 }
                 else if (NewOpacity > 255)
                 {
                     this.ObjectOpacity = 255;
                 }
                 else
                 {
                     this.ObjectOpacity = NewOpacity;
                 }
             }
             this.SetBitmap(ref this.CurrentObjectBitmap, (byte)this.ObjectOpacity, ChangePosition, NewLeft, NewTop);
         }
     }
     catch (Exception)
     {
     }
 }
コード例 #16
0
        public List <Bitmap> GetWeightedTiles(int _tileWidth, int _tileHeight, bool hasSpacing = false)
        {
            List <Bitmap> result     = new List <Bitmap>();
            var           weight     = 10;
            Bitmap        tilesetIMg = Image.FromFile(ConfigurationManager.AppSettings["TenXWeightedTiles"].ToString()) as Bitmap;

            _tileset = BitmapOperations.GetBitmapTiles(tilesetIMg, _tileWidth, _tileHeight, hasSpacing);
            for (var i = 0; i < weight; i++)
            {
                foreach (var verticalRow in _tileset)
                {
                    result.AddRange(verticalRow);
                }
            }
            return(result);
        }
コード例 #17
0
        private EffectiveBitmap CleanWatermark(EffectiveBitmap imgWatermarked, EffectiveBitmap watermark)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);
                var watermarkPixel = sources[1].GetPixel(i, j);

                var r = (int)(watermarkedImgPixel.R * 2 - watermarkPixel.R * parameters.Ratio);
                var g = (int)(watermarkedImgPixel.G * 2 - watermarkPixel.G * parameters.Ratio);
                var b = (int)(watermarkedImgPixel.B * 2 - watermarkPixel.B * parameters.Ratio);

                r = r < 0 ? r + 1 : r;
                g = g < 0 ? g + 1 : g;
                b = b < 0 ? b + 1 : b;

                return new PixelInfo(r, g, b);
            }, imgWatermarked, watermark));
        }
コード例 #18
0
        private List <Bitmap> ChopUpTilesWithMirror(Bitmap img)
        {
            List <Bitmap> result   = new List <Bitmap>();
            var           tilesImg = img.AddHorizontalMirror(true);
            var           tiles    = BitmapOperations.GetBitmapTiles(tilesImg, 6, 6, true);
            //bad form
            var path = TilesetDebugFolderPath;

            if (path != null)
            {
                BitmapOperations.SaveBitmapToFile(path + /*"../../TilesetsDebug/Current/" +*/ "mainTilesetDebug" + ".bmp", BitmapOperations.CreateBitmapFromTiles(tiles, true));
            }
            foreach (var row in tiles)
            {
                result.AddRange(row);
            }
            return(result);
        }
コード例 #19
0
        private EffectiveBitmap ExtractWatermark(EffectiveBitmap imgWatermarked, EffectiveBitmap original)
        {
            return(BitmapOperations.Create((sources, i, j) =>
            {
                var watermarkedImgPixel = sources[0].GetPixel(i, j);
                var originalPixel = sources[1].GetPixel(i, j);

                var r = (int)((2 * watermarkedImgPixel.R - originalPixel.R) * (1 / parameters.Ratio));
                var g = (int)((2 * watermarkedImgPixel.G - originalPixel.G) * (1 / parameters.Ratio));
                var b = (int)((2 * watermarkedImgPixel.B - originalPixel.B) * (1 / parameters.Ratio));

                r = r < 0 ? 0 : r;
                g = g < 0 ? 0 : g;
                b = b < 0 ? 0 : b;

                return new PixelInfo(r, g, b);
            }, imgWatermarked, original));
        }
コード例 #20
0
        private static void printLists(List <List <OpinionatedItem <Bitmap> > > ElementsList, string debugFolderPath)
        {
            List <Bitmap> Bitmaps = new List <Bitmap>();
            var           path    = debugFolderPath;

            foreach (var Elements in ElementsList)
            {
                var list = new List <List <Bitmap> >();
                list.Add(new List <Bitmap>());
                list[0].AddRange(Elements.Select(x => x.actualItem).ToList());
                var bmp = BitmapOperations.CreateBitmapFromTiles(list);
                Bitmaps.Add(bmp);
            }

            for (var i = 0; i < Bitmaps.Count; i++)
            {
                BitmapOperations.SaveBitmapToFile(path + "/" + /*"../../TilesetsDebug/Current/" +*/ i.ToString() + ".bmp", Bitmaps[i]);
            }
        }
コード例 #21
0
ファイル: Toolset.cs プロジェクト: marcAKAmarc/ProcGenTools
        public void LoadTileset(string path, bool horizontalMirror = true)
        {
            //Chop up tileset
            Bitmap tilesetImg = Image.FromFile(path) as Bitmap;

            if (horizontalMirror)
            {
                tilesetImg = tilesetImg.AddHorizontalMirror();
            }
            _tileset = BitmapOperations.GetBitmapTiles(tilesetImg, _tileWidth, _tileHeight);


            //setup wfcTiles (and neighbors)
            var distinctTiles = GetDistinctBitmaps(_tileset);

            //List<List<Bitmap>> distinctElements = new List<List<Bitmap>>();
            //distinctElements.Add(distinctTiles);
            _wfcTiles = ToOpinionatedList(distinctTiles);
            SetAcceptableItems(_wfcTiles, _tileset);
        }
コード例 #22
0
ファイル: Dwt.cs プロジェクト: 238379/watermark_analyzer
        public override async IAsyncEnumerable <AlgorithmResultElement> AddWatermark([EnumeratorCancellation] CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();
            var haared = ProcessHaar(parameters.Original, false, parameters.Layers);

            yield return(new AlgorithmResultElement("DWT", haared, new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();

            var watermark = parameters.Watermark;

            watermark = parameters.Watermark.Resize(watermark.Width / (2 * parameters.Layers), watermark.Height / (2 * parameters.Layers));

            var haaredWatermarked = BitmapOperations.Create((sources, i, j) =>
            {
                var layers         = parameters.Layers;
                var originalPixel  = sources[0].GetPixel(i, j);
                var watermarkPixel = sources[1].GetPixel(i % watermark.Width, j % watermark.Height);

                if (i >= sources[0].Height * (2 * layers - 1) / (2 * layers) && j <= sources[0].Width / (2 * layers))
                {
                    var alpha = parameters.Alpha;

                    var r = (int)(originalPixel.R + (watermarkPixel.R * alpha)) % 255;
                    var g = (int)(originalPixel.G + (watermarkPixel.G * alpha)) % 255;
                    var b = (int)(originalPixel.B + (watermarkPixel.B * alpha)) % 255;

                    return(new PixelInfo(r, g, b));
                }

                return(originalPixel);
            }, haared, watermark);

            yield return(new AlgorithmResultElement("DWT + watermark", haaredWatermarked, new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();

            var watermarked = ProcessHaar(haaredWatermarked, true, parameters.Layers);

            yield return(new AlgorithmResultElement("Watermarked", watermarked, new ResultDescription(ToString())));
        }
コード例 #23
0
ファイル: Models.cs プロジェクト: marcAKAmarc/ProcGenTools
 private void GetTypeGrid()
 {
     for (var x = 0; x < TileGrid.Count; x++)
     {
         for (var y = 0; y < TileGrid[x].Count; y++)
         {
             var tileType = GetTileType(TileGrid[x][y]);
             try
             {
                 TypeGrid[x, y] = tileType.Value;
             }
             catch (Exception ex)
             {
                 if (Config.DebugTypeGridFolder != null)
                 {
                     Console.WriteLine("Could Not Determine tile type.  Logged to file system.");
                     BitmapOperations.SaveBitmapToFile(Config.DebugTypeGridFolder + "//unknownTile-" + x.ToString() + "-" + y.ToString() + ".bmp", TileGrid[x][y]);
                 }
             }
         }
     }
 }
コード例 #24
0
ファイル: Dwt.cs プロジェクト: 238379/watermark_analyzer
        public override async IAsyncEnumerable <AlgorithmResultElement> RemoveWatermark([EnumeratorCancellation] CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();
            var haaredWatermarked = ProcessHaar(parameters.Watermarked, false, parameters.Layers);

            ct.ThrowIfCancellationRequested();
            var haaredOriginal = ProcessHaar(parameters.Original, false, parameters.Layers);

            ct.ThrowIfCancellationRequested();
            var extractedWatermark = BitmapOperations.Create((sources, i, j) =>
            {
                var layers = parameters.Layers;
                var haaredWatermarkedPixel = sources[0].GetPixel(i, j);
                var haaredPixel            = sources[1].GetPixel(i, j);

                var alpha = parameters.Alpha;

                var r = (int)((haaredWatermarkedPixel.R - haaredPixel.R) / alpha) % 255;
                var g = (int)((haaredWatermarkedPixel.G - haaredPixel.G) / alpha) % 255;
                var b = (int)((haaredWatermarkedPixel.B - haaredPixel.B) / alpha) % 255;

                return(new PixelInfo(r, g, b));
            }, haaredWatermarked, haaredOriginal);

            EffectiveBitmap croppedRemovedWatermark = null;

            if (parameters.Layers == 1)
            {
                croppedRemovedWatermark = extractedWatermark.Crop(extractedWatermark.Width / 2, 0, extractedWatermark.Width, extractedWatermark.Height / 2);
            }
            else if (parameters.Layers == 2)
            {
                croppedRemovedWatermark = extractedWatermark.Crop(extractedWatermark.Width * 3 / 4, 0, extractedWatermark.Width, extractedWatermark.Height / 4);
            }

            ct.ThrowIfCancellationRequested();

            var haaredRemovedWatermark = BitmapOperations.Create((sources, i, j) =>
            {
                var layers         = parameters.Layers;
                var originalPixel  = sources[0].GetPixel(i, j);
                var watermarkPixel = sources[1].GetPixel(i, j);

                if (i > sources[0].Height * (2 * layers - 1) / (2 * layers) && j < sources[0].Width / (2 * layers))
                {
                    var alpha = parameters.Alpha;

                    var r = (int)(originalPixel.R - (watermarkPixel.R * alpha)) % 255;
                    var g = (int)(originalPixel.G - (watermarkPixel.G * alpha)) % 255;
                    var b = (int)(originalPixel.B - (watermarkPixel.B * alpha)) % 255;

                    return(new PixelInfo(r, g, b));
                }

                return(originalPixel);
            }, haaredWatermarked, extractedWatermark);

            var removedWatermark = ProcessHaar(haaredRemovedWatermark, true, parameters.Layers);

            ct.ThrowIfCancellationRequested();
            yield return(new AlgorithmResultElement("Cleaned", removedWatermark, new ResultDescription(ToString())));

            ct.ThrowIfCancellationRequested();
            yield return(new AlgorithmResultElement("Extracted watermark", croppedRemovedWatermark, new ResultDescription(ToString())));
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: dmarkachev/CSE803Project
        private static void Main(string[] args)
        {
            bool   success  = false;
            string fileName = "";

            if (args.Length >= 1)
            {
                directory = Path.GetDirectoryName(args[0]);
                fileName  = Path.GetFileNameWithoutExtension(args[0]);

                success = !string.IsNullOrEmpty(fileName);
            }

            if (!success)
            {
                Console.WriteLine("Could not parse arguments: FoodClassifier.exe <filepath>");
                Console.ReadKey();
                return;
            }
            if (string.IsNullOrEmpty(directory))
            {
                directory = "";
            }

            var bitmap = new BitmapImage(new Uri(args[0], string.IsNullOrEmpty(directory) ? UriKind.Relative : UriKind.Absolute));

            // give this directory to the bitmap operations class
            BitmapOperations.saveDirectory = directory;

            // Scale the image up if it is too small or down if it is too big
            double scale = 1.0;

            if (bitmap.PixelHeight < 400 && bitmap.PixelWidth < 400)
            {
                scale = Math.Min(400.0 / bitmap.PixelWidth, 400.0 / bitmap.PixelHeight);
            }
            else if (bitmap.PixelHeight > 1000 && bitmap.PixelWidth > 1000)
            {
                scale = Math.Min(1000.0 / bitmap.PixelWidth, 1000.0 / bitmap.PixelHeight);
            }
            var resizedBitmap = new BitmapImage();

            resizedBitmap.BeginInit();
            resizedBitmap.UriSource         = bitmap.UriSource;
            resizedBitmap.DecodePixelHeight = (int)(scale * bitmap.PixelHeight);
            resizedBitmap.DecodePixelWidth  = (int)(scale * bitmap.PixelWidth);
            resizedBitmap.EndInit();

            // Reformat to BGR
            var properFormatBitmap = new FormatConvertedBitmap();

            properFormatBitmap.BeginInit();
            properFormatBitmap.Source            = resizedBitmap;
            properFormatBitmap.DestinationFormat = PixelFormats.Bgr32;
            properFormatBitmap.EndInit();

            var writeableBitmap = new WriteableBitmap(properFormatBitmap); // The ready to go bitmap
            var cvImage         = new Image <Gray, byte>(new Bitmap(args[0]));

            cvImage = cvImage.Resize(scale, INTER.CV_INTER_CUBIC);

            // var classifications = ClassifyBitmap( writeableBitmap, cvImage );

            BitmapOperations.analyzeBitmapGradient(bitmap);
        }
コード例 #26
0
        private static void SetAcceptableItems(List <OpinionatedItem <Bitmap> > Elements, List <List <Bitmap> > Tilemap)
        {
            foreach (var element in Elements)
            {
                for (var x = 0; x < Tilemap.Count; x++)
                {
                    for (var y = 0; y < Tilemap[0].Count; y++)
                    {
                        if (BitmapOperations.Compare(Tilemap[x][y], element.actualItem))
                        {
                            List <Point> neighborpoints = new List <Point>()
                            {
                                // new Point(x - 1, y - 1),
                                new Point(x, y - 1),
                                //new Point(x + 1, y - 1),
                                new Point(x + 1, y),
                                //new Point(x + 1, y + 1),
                                new Point(x, y + 1),
                                //new Point(x - 1, y + 1),
                                new Point(x - 1, y)
                            };
                            neighborpoints = neighborpoints.Where(point =>
                                                                  point.X >= 0 && point.X < Tilemap.Count &&
                                                                  point.Y >= 0 && point.Y < Tilemap[0].Count
                                                                  ).ToList();

                            List <Bitmap> neighborBmps = new List <Bitmap>();
                            foreach (var neighborpoint in neighborpoints)
                            {
                                neighborBmps.Add(Tilemap[neighborpoint.X][neighborpoint.Y]);
                            }

                            for (var n = 0; n < neighborBmps.Count; n++)
                            {
                                var neighborBmp   = neighborBmps[n];
                                var neighborPoint = neighborpoints[n];
                                var elementPoint  = new Point(x, y);
                                var relativePoint = new Point(neighborPoint.X - elementPoint.X, neighborPoint.Y - elementPoint.Y);


                                OpinionatedItem <Bitmap> neighborElement = null;
                                foreach (var elementN in Elements)
                                {
                                    if (BitmapOperations.Compare(elementN.actualItem, neighborBmp))
                                    {
                                        neighborElement = elementN;
                                        break;
                                    }
                                }

                                //if neighbor in element has neighbor at pos, bail (make distinct - makes faster in long run.. no natural weight though

                                /*if (element.GetAcceptableInDirection(relativePoint.X, relativePoint.Y, 0).Any(acc => acc.Id == neighborElement.Id))
                                 *  continue;*/

                                if (neighborElement == null)
                                {
                                    throw new Exception("Couldn't find neighbor in distinct elements!");
                                }
                                element.SetAcceptableInDirection(neighborElement, relativePoint.X, relativePoint.Y, 0);
                            }
                        }
                    }
                }
            }
        }
コード例 #27
0
        public Bitmap GetBitmap()
        {
            var collapsedTiles = ToTilesList(_grid);

            return(BitmapOperations.CreateBitmapFromTiles(collapsedTiles));
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: marcAKAmarc/ProcGenTools
        static void Main(string[] args)
        {
            //setup hierarchical map
            var Random = new Random(0);

            HierarchicalMap.RelativeScales = new double[] { 4 };
            var map = new HierarchicalMap(12, 12, Random, 4, 3);

            map.DefaultSetup();
            //map.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"]);
            //for (var i = 0; i < map.flatZones.Count(); i++)
            //{
            //    var submap = map.flatZones[i].SubMap;
            //    submap.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", i.ToString() + ".bmp"));

            //}
            var mastermap     = map.GetMasterMap();
            var masterPortals = map.GetMasterPortal();


            map.PrintMasterOrderingToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "main_map.bmp"));
            map.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "main__map.bmp"));

            var tileSize = 5;

            var editor = new LevelEditor(tileSize, tileSize, 12, 12, ConfigurationManager.AppSettings["errorTile"], ConfigurationManager.AppSettings["cautionTile"]);

            editor.LoadTileset(ConfigurationManager.AppSettings["TilesetInput"], true, "..//..//Output//mainTileset.bmp", true);
            editor.SetupBorderTiles(ConfigurationManager.AppSettings["borderInput"]);
            editor.SetupHEntranceTiles(ConfigurationManager.AppSettings["hEntranceInput"]);
            editor.SetupVEntranceTiles(ConfigurationManager.AppSettings["vEntranceInput"]);
            editor.SetupCornersAndIntersectionTiles(ConfigurationManager.AppSettings["cornerTraverseInput"], true);
            editor.SetupTraversableTiles(
                ConfigurationManager.AppSettings["hTraverseInput"],
                ConfigurationManager.AppSettings["vTraverseInput"],
                true
                );


            //must be divisible by 3 for paths?!
            var scale = 12;

            var finalBitmap = new Bitmap(mastermap.GetLength(0) * scale * tileSize, mastermap.GetLength(1) * scale * tileSize);

            int bmpIndex = 0;

            for (var y = 0; y < mastermap.GetLength(1); y++)
            {
                for (var x = 0; x < mastermap.GetLength(0); x++)
                {
                    var roomLevelMap = mastermap[x, y].FirstOrDefault(mm => mm.flatZones.Count == 0 && mm.contents == null);
                    if (roomLevelMap != null)
                    {
                        bmpIndex += 1;
                        for (var attempt = 0; attempt < 8; attempt++)
                        {
                            var room = roomLevelMap.ToRoom(scale);

                            editor.SetDimensions(room.Width, room.Height);
                            editor.InitWcfGrid(Random.Next());

                            var result = true;
                            result = result && editor.AddBorder(room);
                            if (!result)
                            {
                                Console.WriteLine("Failed Add Border");
                                //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                continue;
                            }

                            result = result && editor.AddPaths(room);
                            if (!result)
                            {
                                Console.WriteLine("Failed Add Paths");
                                //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                continue;
                            }

                            if (Random.NextDouble() < .25)
                            {
                                result = result && editor.MakeSpacesIntraversable();
                                if (!result)
                                {
                                    Console.WriteLine("Failed Intraversable");
                                    //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                    Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                    continue;
                                }
                            }

                            result = result && editor.CollapseWcf();
                            if (!result)
                            {
                                Console.WriteLine("Failed Collapse");
                                //BitmapOperations.SaveBitmapToFile("../../Output/MostRecentError.bmp", editor.GetBitmap());
                                Console.WriteLine("Failed Manual Changes: " + attempt.ToString());
                                continue;
                            }

                            //if we made it here, we have succeeded
                            break;
                        }

                        roomLevelMap.contents = editor.GetBitmap();

                        //draw to larger bitmap
                        Graphics g = Graphics.FromImage(finalBitmap);
                        g.DrawImage(roomLevelMap.contents, new Point(x * scale * tileSize, y * scale * tileSize));

                        //draw portals
                        var portals = roomLevelMap._Portals;//.Where(p=>/*p.DestinationPortal!= null &&*/ p.id.CompareTo(((HierarchicalMapPortal)p.DestinationPortal).id) == -1).ToList();
                        foreach (var portal in portals)
                        {
                            if (portal.direction == new Point())
                            {
                                var breaka = "here";
                            }
                            var startPos = new Point(
                                (x * scale * tileSize) + (portal.portalOffsetFromRoom.X * tileSize),
                                (y * scale * tileSize) + (portal.portalOffsetFromRoom.Y * tileSize)
                                );
                            var endPos = new Point(
                                startPos.X + portal.direction.X * tileSize / 2,
                                startPos.Y + portal.direction.Y * tileSize / 2
                                );
                            var xDir    = Math.Sign(endPos.X - startPos.X);
                            var yDir    = Math.Sign(endPos.Y - startPos.Y);
                            var drawPos = startPos;
                            if (drawPos == endPos)
                            {
                                var breka = "here";
                            }
                            while (true)
                            {
                                var color = finalBitmap.GetPixel(drawPos.X, drawPos.Y);
                                color = Color.FromArgb(255 - (int)color.R, 255 - (int)color.G, 255 - (int)color.B);

                                if (portal.directionOfPassage == ZonePortalDirection.In)
                                {
                                    color = Color.Red;
                                }
                                else if (portal.directionOfPassage == ZonePortalDirection.Out)
                                {
                                    color = Color.Green;
                                }

                                finalBitmap.SetPixel(drawPos.X, drawPos.Y, color);

                                if (drawPos == endPos)
                                {
                                    break;
                                }



                                //getNewPos
                                drawPos.X += xDir;
                                drawPos.Y += yDir;
                            }
                        }

                        //BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "_wcf_" + bmpIndex.ToString() + ".bmp"), roomLevelMap.contents);
                    }
                }
            }

            //draw portals
            //for (var y = 0; y < masterPortals.GetLength(1); y++)
            //{
            //    for (var x = 0; x < masterPortals.GetLength(0); x++)
            //    {
            //        var portals = masterPortals[x, y].Where(p => p.SubPortal == null && p.DestinationPortal != null && ((HierarchicalMapPortal)p.DestinationPortal).id.CompareTo(p.id) == -1);
            //        foreach(var portal in portals)
            //        {
            //            var startPos = new Point(
            //                    (x * scale * tileSize) + (tileSize*2),
            //                    (y * scale * tileSize) + (tileSize*2)
            //                );
            //            var endPos = new Point(
            //                    startPos.X + portal.direction.X * tileSize,
            //                    startPos.Y + portal.direction.Y * tileSize
            //                );
            //            var xDir = Math.Sign(endPos.X - startPos.X);
            //            var yDir = Math.Sign(endPos.Y - startPos.Y);
            //            var drawPos = startPos;
            //            while (true)
            //            {
            //                var color = finalBitmap.GetPixel(drawPos.X, drawPos.Y);
            //                color = Color.FromArgb(255 - (int)color.R, 255 - (int)color.G, 255 - (int)color.B);
            //                finalBitmap.SetPixel(drawPos.X, drawPos.Y, color);

            //                if (drawPos == endPos)
            //                    break;

            //                //getNewPos
            //                drawPos.X += xDir;
            //                drawPos.Y += yDir;
            //            }
            //        }
            //    }
            //}

            BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["BitmapOutput"], finalBitmap);


            //map.PrintMasterOrderingToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", "main_map.bmp"));
            //for (var i = 0; i < map.flatZones.Count(); i++)
            //{
            //    var submap = map.flatZones[i].SubMap;
            //    submap.PrintMasterToBitmap(ConfigurationManager.AppSettings["BitmapOutput"].Replace(".bmp", i.ToString() + ".bmp"));

            //}
        }
コード例 #29
0
ファイル: Helpers.cs プロジェクト: marcAKAmarc/ProcGenTools
 public static Bitmap ToBitmap(WcfGrid grid, TilesetConfiguration TilesConfig)
 {
     return(BitmapOperations.CreateBitmapFromTiles(ToTilesList(grid, TilesConfig)));
 }
コード例 #30
0
ファイル: Helpers.cs プロジェクト: marcAKAmarc/ProcGenTools
        public static void DebugWfcPrint(List <OpinionatedItem <Bitmap> > Attempted, WcfGrid WcfGrid, int x, int y, string folderPath)
        {
            if (folderPath == null)
            {
                return;
            }


            Console.WriteLine("Collapse To Specific Item failed.");
            List <Bitmap> topBmps    = new List <Bitmap>();
            List <Bitmap> bottomBmps = new List <Bitmap>();
            List <Bitmap> leftBmps   = new List <Bitmap>();
            List <Bitmap> rightBmps  = new List <Bitmap>();

            if (y - 1 >= 0)
            {
                topBmps = WcfGrid.SuperPositions[x, y - 1, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }
            if (y + 1 < WcfGrid.Height)
            {
                bottomBmps = WcfGrid.SuperPositions[x, y + 1, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }
            if (x - 1 >= 0)
            {
                leftBmps = WcfGrid.SuperPositions[x - 1, y, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }
            if (x + 1 < WcfGrid.Width)
            {
                rightBmps = WcfGrid.SuperPositions[x + 1, y, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            }

            List <Bitmap> currentBmps  = Attempted.Select(s => (Bitmap)s.GetItem()).ToList();
            List <Bitmap> existingBmps = WcfGrid.SuperPositions[x, y, 0].slots.Where(s => !s.Collapsed).Select(s => (Bitmap)s.item.GetItem()).ToList();
            //string folderPath = ConfigurationManager.AppSettings["WfcDebugFolder"].ToString();//../../WfcDebug/Current/";
            var subPath  = "Top/";
            var FileInfo = new FileInfo(folderPath + subPath);

            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < topBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, topBmps[i]);
            }
            subPath  = "Bottom/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < bottomBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, bottomBmps[i]);
            }
            subPath  = "Left/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < leftBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, leftBmps[i]);
            }
            subPath  = "Right/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < rightBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, rightBmps[i]);
            }
            subPath  = "CurrentOptions/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < currentBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, currentBmps[i]);
            }

            subPath  = "Existing/";
            FileInfo = new FileInfo(folderPath + subPath);
            if (!FileInfo.Directory.Exists)
            {
                FileInfo.Directory.Create();
            }
            Helpers.clearFolder(folderPath + subPath);
            for (var i = 0; i < existingBmps.Count(); i++)
            {
                var filename = "bmp_" + i.ToString() + ".bmp";
                BitmapOperations.SaveBitmapToFile(folderPath + subPath + filename, existingBmps[i]);
            }
        }