From 17507404b5de340eab5e3c368dd2600ee7b1467c Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 13 Apr 2008 01:36:03 +0000 Subject: * Added some comments to terrain module. * Fixed a range issue in the GenericSystemDrawing saving mechanism. --- .../Environment/Modules/Terrain/FileLoaders/BMP.cs | 15 ++++++++ .../Terrain/FileLoaders/GenericSystemDrawing.cs | 45 ++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/Terrain/FileLoaders') diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs index 56c511e..cad0edf 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs @@ -30,8 +30,19 @@ using OpenSim.Region.Environment.Interfaces; namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders { + /// + /// A generic windows bitmap loader. + /// Should be capable of handling 24-bit RGB images. + /// + /// Uses the System.Drawing filesystem loader. + /// class BMP : GenericSystemDrawing { + /// + /// Exports a file to a image on the disk using a System.Drawing exporter. + /// + /// The target filename + /// The terrain channel being saved public override void SaveFile(string filename, ITerrainChannel map) { Bitmap colours = CreateGrayscaleBitmapFromMap(map); @@ -39,6 +50,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders colours.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp); } + /// + /// The human readable version of the file format(s) this loader handles + /// + /// public override string ToString() { return "BMP"; diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs index e24d3e5..9bcf94d 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs @@ -31,10 +31,24 @@ using OpenSim.Region.Environment.Interfaces; namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders { + /// + /// A virtual class designed to have methods overloaded, + /// this class provides an interface for a generic image + /// saving and loading mechanism, but does not specify the + /// format. It should not be insubstantiated directly. + /// public class GenericSystemDrawing : ITerrainLoader { #region ITerrainLoader Members + /// + /// Loads a file from a specified filename on the disk, + /// parses the image using the System.Drawing parsers + /// then returns a terrain channel. Values are + /// returned based on HSL brightness between 0m and 128m + /// + /// The target image to load + /// A terrain channel generated from the image. public virtual ITerrainChannel LoadFile(string filename) { Bitmap file = new Bitmap(filename); @@ -63,6 +77,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders return "SYS.DRAWING"; } + /// + /// Protected method, generates a grayscale bitmap + /// image from a specified terrain channel. + /// + /// The terrain channel to export to bitmap + /// A System.Drawing.Bitmap containing a grayscale image protected Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) { Bitmap bmp = new Bitmap(map.Width, map.Height); @@ -82,13 +102,22 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders // 512 is the largest possible height before colours clamp int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); - bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); + // Handle error conditions + if (colorindex > pallete - 1 || colorindex < 0) + bmp.SetPixel(x, map.Height - y - 1, Color.Red); + else + bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); } } return bmp; } - + /// + /// Protected method, generates a coloured bitmap + /// image from a specified terrain channel. + /// + /// The terrain channel to export to bitmap + /// A System.Drawing.Bitmap containing a coloured image protected Bitmap CreateBitmapFromMap(ITerrainChannel map) { Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); @@ -109,12 +138,22 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders { // 512 is the largest possible height before colours clamp int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); - bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); + + // Handle error conditions + if (colorindex > pallete - 1 || colorindex < 0) + bmp.SetPixel(x, map.Height - y - 1, Color.Red); + else + bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); } } return bmp; } + /// + /// Exports a file to a image on the disk using a System.Drawing exporter. + /// + /// The target filename + /// The terrain channel being saved public virtual void SaveFile(string filename, ITerrainChannel map) { Bitmap colours = CreateGrayscaleBitmapFromMap(map); -- cgit v1.1