aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/GenericSystemDrawing.cs45
1 files changed, 42 insertions, 3 deletions
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
32namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders 32namespace 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);