diff options
author | Adam Frisby | 2008-04-13 01:36:03 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-13 01:36:03 +0000 |
commit | 17507404b5de340eab5e3c368dd2600ee7b1467c (patch) | |
tree | 47a0e394785a1ca242620157c50b142fcea5c077 /OpenSim/Region/Environment/Modules/Terrain | |
parent | first drop of user storage implementation for nhibernate. (diff) | |
download | opensim-SC_OLD-17507404b5de340eab5e3c368dd2600ee7b1467c.zip opensim-SC_OLD-17507404b5de340eab5e3c368dd2600ee7b1467c.tar.gz opensim-SC_OLD-17507404b5de340eab5e3c368dd2600ee7b1467c.tar.bz2 opensim-SC_OLD-17507404b5de340eab5e3c368dd2600ee7b1467c.tar.xz |
* Added some comments to terrain module.
* Fixed a range issue in the GenericSystemDrawing saving mechanism.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Terrain/FileLoaders/BMP.cs | 15 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs | 45 |
2 files changed, 57 insertions, 3 deletions
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; | |||
30 | 30 | ||
31 | namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders | 31 | namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders |
32 | { | 32 | { |
33 | /// <summary> | ||
34 | /// A generic windows bitmap loader. | ||
35 | /// Should be capable of handling 24-bit RGB images. | ||
36 | /// | ||
37 | /// Uses the System.Drawing filesystem loader. | ||
38 | /// </summary> | ||
33 | class BMP : GenericSystemDrawing | 39 | class BMP : GenericSystemDrawing |
34 | { | 40 | { |
41 | /// <summary> | ||
42 | /// Exports a file to a image on the disk using a System.Drawing exporter. | ||
43 | /// </summary> | ||
44 | /// <param name="filename">The target filename</param> | ||
45 | /// <param name="map">The terrain channel being saved</param> | ||
35 | public override void SaveFile(string filename, ITerrainChannel map) | 46 | public override void SaveFile(string filename, ITerrainChannel map) |
36 | { | 47 | { |
37 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | 48 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); |
@@ -39,6 +50,10 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders | |||
39 | colours.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp); | 50 | colours.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp); |
40 | } | 51 | } |
41 | 52 | ||
53 | /// <summary> | ||
54 | /// The human readable version of the file format(s) this loader handles | ||
55 | /// </summary> | ||
56 | /// <returns></returns> | ||
42 | public override string ToString() | 57 | public override string ToString() |
43 | { | 58 | { |
44 | return "BMP"; | 59 | 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; | |||
31 | 31 | ||
32 | namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders | 32 | namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders |
33 | { | 33 | { |
34 | /// <summary> | ||
35 | /// A virtual class designed to have methods overloaded, | ||
36 | /// this class provides an interface for a generic image | ||
37 | /// saving and loading mechanism, but does not specify the | ||
38 | /// format. It should not be insubstantiated directly. | ||
39 | /// </summary> | ||
34 | public class GenericSystemDrawing : ITerrainLoader | 40 | public class GenericSystemDrawing : ITerrainLoader |
35 | { | 41 | { |
36 | #region ITerrainLoader Members | 42 | #region ITerrainLoader Members |
37 | 43 | ||
44 | /// <summary> | ||
45 | /// Loads a file from a specified filename on the disk, | ||
46 | /// parses the image using the System.Drawing parsers | ||
47 | /// then returns a terrain channel. Values are | ||
48 | /// returned based on HSL brightness between 0m and 128m | ||
49 | /// </summary> | ||
50 | /// <param name="filename">The target image to load</param> | ||
51 | /// <returns>A terrain channel generated from the image.</returns> | ||
38 | public virtual ITerrainChannel LoadFile(string filename) | 52 | public virtual ITerrainChannel LoadFile(string filename) |
39 | { | 53 | { |
40 | Bitmap file = new Bitmap(filename); | 54 | Bitmap file = new Bitmap(filename); |
@@ -63,6 +77,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders | |||
63 | return "SYS.DRAWING"; | 77 | return "SYS.DRAWING"; |
64 | } | 78 | } |
65 | 79 | ||
80 | /// <summary> | ||
81 | /// Protected method, generates a grayscale bitmap | ||
82 | /// image from a specified terrain channel. | ||
83 | /// </summary> | ||
84 | /// <param name="map">The terrain channel to export to bitmap</param> | ||
85 | /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> | ||
66 | protected Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) | 86 | protected Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) |
67 | { | 87 | { |
68 | Bitmap bmp = new Bitmap(map.Width, map.Height); | 88 | Bitmap bmp = new Bitmap(map.Width, map.Height); |
@@ -82,13 +102,22 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders | |||
82 | // 512 is the largest possible height before colours clamp | 102 | // 512 is the largest possible height before colours clamp |
83 | int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); | 103 | int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); |
84 | 104 | ||
85 | bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); | 105 | // Handle error conditions |
106 | if (colorindex > pallete - 1 || colorindex < 0) | ||
107 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | ||
108 | else | ||
109 | bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); | ||
86 | } | 110 | } |
87 | } | 111 | } |
88 | return bmp; | 112 | return bmp; |
89 | } | 113 | } |
90 | 114 | ||
91 | 115 | /// <summary> | |
116 | /// Protected method, generates a coloured bitmap | ||
117 | /// image from a specified terrain channel. | ||
118 | /// </summary> | ||
119 | /// <param name="map">The terrain channel to export to bitmap</param> | ||
120 | /// <returns>A System.Drawing.Bitmap containing a coloured image</returns> | ||
92 | protected Bitmap CreateBitmapFromMap(ITerrainChannel map) | 121 | protected Bitmap CreateBitmapFromMap(ITerrainChannel map) |
93 | { | 122 | { |
94 | Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); | 123 | Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); |
@@ -109,12 +138,22 @@ namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders | |||
109 | { | 138 | { |
110 | // 512 is the largest possible height before colours clamp | 139 | // 512 is the largest possible height before colours clamp |
111 | int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); | 140 | int colorindex = (int)(Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); |
112 | bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); | 141 | |
142 | // Handle error conditions | ||
143 | if (colorindex > pallete - 1 || colorindex < 0) | ||
144 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | ||
145 | else | ||
146 | bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); | ||
113 | } | 147 | } |
114 | } | 148 | } |
115 | return bmp; | 149 | return bmp; |
116 | } | 150 | } |
117 | 151 | ||
152 | /// <summary> | ||
153 | /// Exports a file to a image on the disk using a System.Drawing exporter. | ||
154 | /// </summary> | ||
155 | /// <param name="filename">The target filename</param> | ||
156 | /// <param name="map">The terrain channel being saved</param> | ||
118 | public virtual void SaveFile(string filename, ITerrainChannel map) | 157 | public virtual void SaveFile(string filename, ITerrainChannel map) |
119 | { | 158 | { |
120 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | 159 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); |