示例#1
0
 public void ExportAltitudes(string directory, int x, int y, IUltimaMapDataProvider manager)
 {
     using (var bitmap = BitmapReader.ExportAltitude(manager, x, y, EventExtractAltitudeProgress))
     {
         bitmap.Save(Path.Combine(directory, "Altitude.BMP"), ImageFormat.Bmp);
     }
     GC.Collect();
     EventEndExtractAltitudeEnd(this, EventArgs.Empty);
 }
示例#2
0
        public static Bitmap ExportAltitude(IUltimaMapDataProvider provider, int width, int height, EventHandler eventProgress)
        {
            if (eventProgress != null)
            {
                eventProgress(null, new ProgressEventArgs()
                {
                    PayLoad = "Extracting Altitude", Progress = 0
                });
            }
            //set the number of bytes per pixel
            const int pixelsize     = 3;
            var       stride        = width * pixelsize;
            var       providerCoord = new BlockCoordinatesProvider(width, height, 0, 0);
            var       array         = new byte[height * stride];

            while (providerCoord.HasNextCoord())
            {
                int x, y;
                providerCoord.GetNext(out x, out y);

                provider.GetCoordinates(( uint )x, ( uint )y);

                var grayScale = ( byte )(provider.Atitude + 128);



                for (int i = 0; i < pixelsize; i++)
                {
                    array[(y * stride) + (x * pixelsize + i)] = grayScale;
                }

                var percent1 = ( byte )(Math.Round(( double )((100 * providerCoord.Progress) / (height))));
                if (eventProgress != null)
                {
                    eventProgress(null, new ProgressEventArgs()
                    {
                        PayLoad = "Extracting Altitude", Progress = percent1
                    });
                }
            }

            Bitmap bmp;

            unsafe
            {
                fixed(byte *ptr = array)
                {
                    bmp = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, new IntPtr(ptr));
                }
            }

            return(bmp);
        }
示例#3
0
        public void MapEditor(string directory, string bitmaplocation, string bitmapZLocation, int x, int y, int index, IUltimaMapDataProvider manager)
        {
            CollectionColorArea.InitializeSeaches();
            CollectionAreaTexture.InitializeSeaches();
            var list_errors = new List <string>();

            foreach (var VARIABLE in CollectionColorArea.List)
            {
                AreaTextures area;
                CollectionAreaTexture._fast.TryGetValue(VARIABLE.TextureIndex, out area);
                if (VARIABLE.Max < VARIABLE.Min)
                {
                    var tmp = VARIABLE.Max;
                    VARIABLE.Max = VARIABLE.Min;
                    VARIABLE.Min = tmp;
                }

                if (area != null || VARIABLE.Type == TypeColor.Cliff)
                {
                    continue;
                }

                var error = VARIABLE.Name + @" refers to a non-existent texture '" + VARIABLE.TextureIndex + @"' not found";
                list_errors.Add(error);
            }

            if (list_errors.Count > 0)
            {
                string errors = "";
                foreach (var error_in in list_errors)
                {
                    errors += error_in + '\n';
                }

                throw new Exception(errors);
            }

            var task = new Task[2];



            var taskMapBitmap =
                Task <AreaColor[]> .Factory.StartNew(() => BitmapReader.ColorsFromBitmap(CollectionColorArea,
                                                                                         bitmaplocation, x, y));

            var taskMapZ = Task <sbyte[]> .Factory.StartNew(() => BitmapReader.AltitudeFromBitmapVersion2(bitmapZLocation, x, y));

            task[0] = taskMapBitmap;
            task[1] = taskMapZ;
            try
            {
                Task.WaitAll(task);
            }
            catch (Exception e)
            {
                throw e;
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
            var mulmaker = new MapMaking.MapMaker(taskMapZ.Result, taskMapBitmap.Result, x, y, index)
            {
                CollectionAreaColor = CollectionColorArea,
                TextureAreas        = CollectionAreaTexture,
                AutomaticZMode      = AutomaticMode,
                MulDirectory        = directory,
                EditingMap          = manager,
                EditMul             = true,
            };

            mulmaker.EditingMap.MapIndex = index;
            mulmaker.ProgressText       += EventProgress;

            try
            {
                mulmaker.MapEditing();
                OnMakingMap(EventArgs.Empty);
            }
            catch (Exception e)
            {
                throw e;
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }