public IsoCat(Map map, IsoCatMode mode, int rot) { Rot = rot; Mode = mode; Map = map; dimX = Map.Width; dimY = Map.Length; offsetY = Math.Max(0, Map.Width - Map.Length); offsetX = Math.Max(0, Map.Length - Map.Width); dimX2 = dimX / 2 - 1; dimY2 = dimY / 2 - 1; dimX1 = dimX - 1; dimY1 = dimY - 1; blendDivisor = 255 * Map.Height; imageWidth = TileX * Math.Max(dimX, dimY) + TileY / 2 * Map.Height + TileX * 2; imageHeight = TileY / 2 * Map.Height + MaxTileDim / 2 * Math.Max(Math.Max(dimX, dimY), Map.Height) + TileY * 2; imageBmp = new Bitmap(imageWidth, imageHeight, PixelFormat.Format32bppArgb); imageData = imageBmp.LockBits(new Rectangle(0, 0, imageBmp.Width, imageBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); image = (byte *)imageData.Scan0; imageStride = imageData.Stride; isoOffset = (Map.Height * TileY / 2 * imageStride + imageStride / 2 + TileX * 2); isoX = (TileX / 4 * imageStride + TileX * 2); isoY = (TileY / 4 * imageStride - TileY * 2); isoH = (-TileY / 2 * imageStride); mh34 = Map.Height * 3 / 4; }
public IsoCat(Level level, IsoCatMode mode, int rot) { Rot = rot; Mode = mode; Level = level; dimX = Level.width; dimY = Level.height; offsetY = Math.Max(0, Level.width - Level.height); offsetX = Math.Max(0, Level.height - Level.width); dimX2 = dimX / 2 - 1; dimY2 = dimY / 2 - 1; dimX1 = dimX - 1; dimY1 = dimY - 1; blendDivisor = 255 * Level.depth; imageWidth = TileX * Math.Max(dimX, dimY) + TileY / 2 * Level.depth + TileX * 2; imageHeight = TileY / 2 * Level.depth + MaxTileDim / 2 * Math.Max(Math.Max(dimX, dimY), Level.depth) + TileY * 2; imageBmp = new Bitmap(imageWidth, imageHeight, PixelFormat.Format32bppArgb); imageData = imageBmp.LockBits(new Rectangle(0, 0, imageBmp.Width, imageBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); image = (byte *)imageData.Scan0; imageStride = imageData.Stride; isoOffset = (Level.depth * TileY / 2 * imageStride + imageStride / 2 + TileX * 2); isoX = (TileX / 4 * imageStride + TileX * 2); isoY = (TileY / 4 * imageStride - TileY * 2); isoH = (-TileY / 2 * imageStride); mh34 = Level.depth * 3 / 4; }
public IsoCat( Map map, IsoCatMode mode, int rot ) { Rot = rot; Mode = mode; Map = map; dimX = Map.Width; dimY = Map.Length; offsetY = Math.Max( 0, Map.Width - Map.Length ); offsetX = Math.Max( 0, Map.Length - Map.Width ); dimX2 = dimX / 2 - 1; dimY2 = dimY / 2 - 1; dimX1 = dimX - 1; dimY1 = dimY - 1; blendDivisor = 255 * Map.Height; imageWidth = TileX * Math.Max( dimX, dimY ) + TileY / 2 * Map.Height + TileX * 2; imageHeight = TileY / 2 * Map.Height + MaxTileDim / 2 * Math.Max( Math.Max( dimX, dimY ), Map.Height ) + TileY * 2; imageBmp = new Bitmap( imageWidth, imageHeight, PixelFormat.Format32bppArgb ); imageData = imageBmp.LockBits( new Rectangle( 0, 0, imageBmp.Width, imageBmp.Height ), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb ); image = (byte*)imageData.Scan0; imageStride = imageData.Stride; isoOffset = (Map.Height * TileY / 2 * imageStride + imageStride / 2 + TileX * 2); isoX = (TileX / 4 * imageStride + TileX * 2); isoY = (TileY / 4 * imageStride - TileY * 2); isoH = (-TileY / 2 * imageStride); mh34 = Map.Height * 3 / 4; }
public IsoCat(Level level, IsoCatMode mode, int rot) { Rot = rot; Mode = mode; Level = level; dimX = Level.width; dimY = Level.height; offsetY = Math.Max(0, Level.width - Level.height); offsetX = Math.Max(0, Level.height - Level.width); dimX2 = dimX / 2 - 1; dimY2 = dimY / 2 - 1; dimX1 = dimX - 1; dimY1 = dimY - 1; blendDivisor = 255 * Level.depth; imageWidth = TileX * Math.Max(dimX, dimY) + TileY / 2 * Level.depth + TileX * 2; imageHeight = TileY / 2 * Level.depth + MaxTileDim / 2 * Math.Max(Math.Max(dimX, dimY), Level.depth) + TileY * 2; imageBmp = new Bitmap(imageWidth, imageHeight, PixelFormat.Format32bppArgb); imageData = imageBmp.LockBits(new Rectangle(0, 0, imageBmp.Width, imageBmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); image = (byte*)imageData.Scan0; imageStride = imageData.Stride; isoOffset = (Level.depth * TileY / 2 * imageStride + imageStride / 2 + TileX * 2); isoX = (TileX / 4 * imageStride + TileX * 2); isoY = (TileY / 4 * imageStride - TileY * 2); isoH = (-TileY / 2 * imageStride); mh34 = Level.depth * 3 / 4; }
static ReturnCode ParseOptions([NotNull] string[] args) { if (args == null) { throw new ArgumentNullException("args"); } string jpegQualityString = null, imageFormatName = null, angleString = null, isoCatModeName = null, regionString = null, threadCountString = null; string importerList = MapUtility.GetImporters().JoinToString(c => c.Format.ToString()); bool printHelp = false; opts = new OptionSet() .Add("a=|angle=", "Angle (orientation) from which the map is drawn. May be -90, 0, 90, 180, or 270. Default is 0.", o => angleString = o) .Add("d|tryhard", "Try ALL the map converters on map files that cannot be loaded normally.", o => p.TryHard = (o != null)) .Add("e=|export=", "Image format to use for exporting. " + "Supported formats: PNG (default), BMP, GIF, JPEG, TIFF.", o => imageFormatName = o) .Add("f=|filter=", "Pattern to filter input filenames, e.g. \"*.dat\" or \"builder*\". " + "Applicable only when a directory name is given as input.", o => p.InputFilter = o) .Add("g|nogradient", "Disables altitude-based gradient/shading on terrain.", o => p.NoGradient = (o != null)) .Add("i=|importer=", "Optional: Converter used for importing/loading maps. " + "Available importers: Auto (default), " + importerList, o => importerName = o) .Add("l|seethroughlava", "Makes all lava partially see-through, instead of opaque.", o => p.SeeThroughLava = (o != null)) .Add("m=|mode=", "Rendering mode. May be \"normal\" (default), \"cut\" (cuts out a quarter of the map, revealing inside), " + "\"peeled\" (strips the outer-most layer of blocks), \"chunk\" (renders only a specified region of the map).", o => isoCatModeName = o) .Add("o=|output=", "Path to save images to. " + "If not specified, images will be saved to the maps' directories.", o => p.OutputDirName = o) .Add("q=|quality=", "Sets JPEG compression quality. Between 0 and 100. Default is 80. " + "Applicable only when exporting images to .jpg or .jpeg.", o => jpegQualityString = o) .Add("r|recursive", "Look through all subdirectories for map files. " + "Applicable only when a directory name is given as input.", o => p.Recursive = (o != null)) .Add("t=|threads=", "Number of threads to use, to render multiple files in parallel. Default is CPU count.", o => threadCountString = o) .Add("region=", "Region of the map to render. Should be given in following format: \"region=x1,y1,z1,x2,y2,z2\" " + "Applicable only when rendering mode is set to \"chunk\".", o => regionString = o) .Add("s|noshadows", "Disables rendering of shadows.", o => p.NoShadows = (o != null)) .Add("u|uncropped", "Does not crop the finished map image, leaving some empty space around the edges.", o => p.Uncropped = (o != null)) .Add("w|seethroughwater", "Makes all water see-through, instead of mostly opaque.", o => p.SeeThroughWater = (o != null)) .Add("x|regex", "Enable regular expressions in \"filter\".", o => p.UseRegex = (o != null)) .Add("y|overwrite", "Do not ask for confirmation to overwrite existing files.", o => p.AlwaysOverwrite = (o != null)) .Add("?|h|help", "Prints out the options.", o => printHelp = (o != null)); List <string> pathList; try { pathList = opts.Parse(args); } catch (OptionException ex) { Console.Error.Write("MapRenderer: "); Console.Error.WriteLine(ex.Message); PrintHelp(); return(ReturnCode.ArgumentError); } if (printHelp) { PrintHelp(); Environment.Exit((int)ReturnCode.Success); } if (pathList.Count == 0) { Console.Error.WriteLine("MapRenderer: At least one file or directory name required."); PrintUsage(); return(ReturnCode.ArgumentError); } p.InputPathList = pathList.ToArray(); // Parse angle int angle = 0; if (angleString != null && (!Int32.TryParse(angleString, out angle) || angle != -90 && angle != 0 && angle != 180 && angle != 270)) { Console.Error.WriteLine("MapRenderer: Angle must be a number: -90, 0, 90, 180, or 270"); return(ReturnCode.ArgumentError); } p.Angle = angle; // Parse mode IsoCatMode mode = IsoCatMode.Normal; if (isoCatModeName != null && !EnumUtil.TryParse(isoCatModeName, out mode, true)) { Console.Error.WriteLine( "MapRenderer: Rendering mode should be: \"normal\", \"cut\", \"peeled\", or \"chunk\"."); return(ReturnCode.ArgumentError); } p.Mode = mode; // Parse region (if in chunk mode) if (mode == IsoCatMode.Chunk) { if (regionString == null) { Console.Error.WriteLine("MapRenderer: Region parameter is required when mode is set to \"chunk\""); return(ReturnCode.ArgumentError); } try { string[] regionParts = regionString.Split(','); p.Region = new BoundingBox(Int32.Parse(regionParts[0]), Int32.Parse(regionParts[1]), Int32.Parse(regionParts[2]), Int32.Parse(regionParts[3]), Int32.Parse(regionParts[4]), Int32.Parse(regionParts[5])); } catch { Console.Error.WriteLine( "MapRenderer: Region should be specified in the following format: \"--region=x1,y1,z1,x2,y2,z2\""); } } else if (regionString != null) { Console.Error.WriteLine( "MapRenderer: Region parameter is given, but rendering mode was not set to \"chunk\""); } // Parse given image format if (imageFormatName != null) { if (imageFormatName.Equals("BMP", StringComparison.OrdinalIgnoreCase)) { p.ExportFormat = ImageFormat.Bmp; p.ImageFileExtension = ".bmp"; } else if (imageFormatName.Equals("GIF", StringComparison.OrdinalIgnoreCase)) { p.ExportFormat = ImageFormat.Gif; p.ImageFileExtension = ".gif"; } else if (imageFormatName.Equals("JPEG", StringComparison.OrdinalIgnoreCase) || imageFormatName.Equals("JPG", StringComparison.OrdinalIgnoreCase)) { p.ExportFormat = ImageFormat.Jpeg; p.ImageFileExtension = ".jpg"; } else if (imageFormatName.Equals("PNG", StringComparison.OrdinalIgnoreCase)) { p.ExportFormat = ImageFormat.Png; p.ImageFileExtension = ".png"; } else if (imageFormatName.Equals("TIFF", StringComparison.OrdinalIgnoreCase) || imageFormatName.Equals("TIF", StringComparison.OrdinalIgnoreCase)) { p.ExportFormat = ImageFormat.Tiff; p.ImageFileExtension = ".tif"; } else { Console.Error.WriteLine( "MapRenderer: Image file format should be: BMP, GIF, JPEG, PNG, or TIFF"); return(ReturnCode.ArgumentError); } } // Parse JPEG quality if (jpegQualityString != null) { if (p.ExportFormat.Guid == ImageFormat.Jpeg.Guid) { int jpegQuality; if (!Int32.TryParse(jpegQualityString, out jpegQuality) || jpegQuality < 0 || jpegQuality > 100) { Console.Error.WriteLine( "MapRenderer: JpegQuality parameter should be a number between 0 and 100"); return(ReturnCode.ArgumentError); } p.JpegQuality = jpegQuality; } else { Console.Error.WriteLine( "MapRenderer: JpegQuality parameter given, but image export format was not set to \"JPEG\"."); } } if (p.MapImporter != null && p.TryHard) { Console.Error.WriteLine("MapRenderer: --tryhard flag can only be used when importer is \"auto\"."); return(ReturnCode.ArgumentError); } if (p.InputFilter == null && p.UseRegex) { Console.Error.WriteLine("MapRenderer: --regex flag can only be used when --filter is specified."); return(ReturnCode.ArgumentError); } byte tempThreadCount = 2; if (threadCountString != null && (!Byte.TryParse(threadCountString, out tempThreadCount) || tempThreadCount < 1)) { Console.Error.WriteLine("MapRenderer: --threads flag must be a number between 1 and 255"); return(ReturnCode.ArgumentError); } p.ThreadCount = tempThreadCount; p.OutputDirGiven = (p.OutputDirName != null); return(ReturnCode.Success); }