aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Terrain/FileLoaders
diff options
context:
space:
mode:
authoronefang2019-05-19 21:24:15 +1000
committeronefang2019-05-19 21:24:15 +1000
commit5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch)
treea9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Region/CoreModules/World/Terrain/FileLoaders
parentAdd a build script. (diff)
downloadopensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2
opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Terrain/FileLoaders')
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs81
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs14
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs10
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs10
7 files changed, 54 insertions, 91 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs
index fb57c82..ec2d085 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs
@@ -47,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
47 /// <param name="map">The terrain channel being saved</param> 47 /// <param name="map">The terrain channel being saved</param>
48 public override void SaveFile(string filename, ITerrainChannel map) 48 public override void SaveFile(string filename, ITerrainChannel map)
49 { 49 {
50 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 50 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
51 51 colours.Save(filename,ImageFormat.Bmp);
52 colours.Save(filename, ImageFormat.Bmp);
53 } 52 }
54 53
55 /// <summary> 54 /// <summary>
@@ -59,9 +58,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
59 /// <param name="map">The terrain channel being saved</param> 58 /// <param name="map">The terrain channel being saved</param>
60 public override void SaveStream(Stream stream, ITerrainChannel map) 59 public override void SaveStream(Stream stream, ITerrainChannel map)
61 { 60 {
62 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 61 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
63 62 colours.Save(stream,ImageFormat.Bmp);
64 colours.Save(stream, ImageFormat.Png);
65 } 63 }
66 64
67 /// <summary> 65 /// <summary>
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs
index 79cc50b..3843708 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs
@@ -36,9 +36,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
36 { 36 {
37 public override void SaveFile(string filename, ITerrainChannel map) 37 public override void SaveFile(string filename, ITerrainChannel map)
38 { 38 {
39 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 39 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
40 40 colours.Save(filename,ImageFormat.Gif);
41 colours.Save(filename, ImageFormat.Gif);
42 } 41 }
43 42
44 /// <summary> 43 /// <summary>
@@ -48,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
48 /// <param name="map">The terrain channel being saved</param> 47 /// <param name="map">The terrain channel being saved</param>
49 public override void SaveStream(Stream stream, ITerrainChannel map) 48 public override void SaveStream(Stream stream, ITerrainChannel map)
50 { 49 {
51 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 50 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
52 51 colours.Save(stream,ImageFormat.Gif);
53 colours.Save(stream, ImageFormat.Gif);
54 } 52 }
55 53
56 public override string ToString() 54 public override string ToString()
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index d5c77ec..bcd9dcd 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
59 /// <returns>A terrain channel generated from the image.</returns> 59 /// <returns>A terrain channel generated from the image.</returns>
60 public virtual ITerrainChannel LoadFile(string filename) 60 public virtual ITerrainChannel LoadFile(string filename)
61 { 61 {
62 using (Bitmap b = new Bitmap(filename)) 62 using(Bitmap b = new Bitmap(filename))
63 return LoadBitmap(b); 63 return LoadBitmap(b);
64 } 64 }
65 65
@@ -111,9 +111,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
111 /// <param name="map">The terrain channel being saved</param> 111 /// <param name="map">The terrain channel being saved</param>
112 public virtual void SaveFile(string filename, ITerrainChannel map) 112 public virtual void SaveFile(string filename, ITerrainChannel map)
113 { 113 {
114 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 114 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
115 115 colours.Save(filename,ImageFormat.Png);
116 colours.Save(filename, ImageFormat.Png);
117 } 116 }
118 117
119 /// <summary> 118 /// <summary>
@@ -123,12 +122,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
123 /// <param name="map">The terrain channel being saved</param> 122 /// <param name="map">The terrain channel being saved</param>
124 public virtual void SaveStream(Stream stream, ITerrainChannel map) 123 public virtual void SaveStream(Stream stream, ITerrainChannel map)
125 { 124 {
126 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 125 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
127 126 colours.Save(stream,ImageFormat.Png);
128 colours.Save(stream, ImageFormat.Png);
129 } 127 }
130 128
131 public virtual void SaveFile(ITerrainChannel m_channel, string filename, 129 public virtual void SaveFile(ITerrainChannel m_channel, string filename,
132 int offsetX, int offsetY, 130 int offsetX, int offsetY,
133 int fileWidth, int fileHeight, 131 int fileWidth, int fileHeight,
134 int regionSizeX, int regionSizeY) 132 int regionSizeX, int regionSizeY)
@@ -162,13 +160,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
162 { 160 {
163 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); 161 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
164 } 162 }
165 163
166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); 164 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
167 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); 165 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
168 for (int x = 0; x < regionSizeX; x++) 166 for (int x = 0; x < regionSizeX; x++)
169 for (int y = 0; y < regionSizeY; y++) 167 for (int y = 0; y < regionSizeY; y++)
170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); 168 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
171 169
172 Save(newBitmap, filename); 170 Save(newBitmap, filename);
173 } 171 }
174 finally 172 finally
@@ -213,8 +211,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
213 /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> 211 /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns>
214 protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) 212 protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map)
215 { 213 {
214 // Bitmap bmp = new Bitmap(map.Width, map.Height, PixelFormat.Format24bppRgb);
216 Bitmap bmp = new Bitmap(map.Width, map.Height); 215 Bitmap bmp = new Bitmap(map.Width, map.Height);
217 216
217
218 const int pallete = 256; 218 const int pallete = 256;
219 219
220 Color[] grays = new Color[pallete]; 220 Color[] grays = new Color[pallete];
@@ -227,59 +227,24 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
227 { 227 {
228 for (int x = 0; x < map.Width; x++) 228 for (int x = 0; x < map.Width; x++)
229 { 229 {
230 // 512 is the largest possible height before colours clamp 230 // to change this, loading also needs change
231 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1));
232
233 // Handle error conditions
234 if (colorindex > pallete - 1 || colorindex < 0)
235 bmp.SetPixel(x, map.Height - y - 1, Color.Red);
236 else
237 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
238 }
239 }
240 return bmp;
241 }
242
243 /// <summary>
244 /// Protected method, generates a coloured bitmap
245 /// image from a specified terrain channel.
246 /// </summary>
247 /// <param name="map">The terrain channel to export to bitmap</param>
248 /// <returns>A System.Drawing.Bitmap containing a coloured image</returns>
249 protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
250 {
251 int pallete;
252 Bitmap bmp;
253 Color[] colours;
254 231
255 using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png")) 232 // int colorindex = (int)map[x, y]; // one to one conversion 0 - 255m range
256 { 233 // int colorindex = (int)map[x, y] / 2; // 0 - 510 range
257 pallete = gradientmapLd.Height;
258
259 bmp = new Bitmap(map.Width, map.Height);
260 colours = new Color[pallete];
261
262 for (int i = 0; i < pallete; i++)
263 {
264 colours[i] = gradientmapLd.GetPixel(0, i);
265 }
266 }
267 234
268 for (int y = 0; y < map.Height; y++) 235 int colorindex = (int)map[x, y] * 2; // the original 0 - 127.5 range
269 {
270 for (int x = 0; x < map.Width; x++)
271 {
272 // 512 is the largest possible height before colours clamp
273 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
274 236
275 // Handle error conditions 237 // clamp it not adding the red warning
276 if (colorindex > pallete - 1 || colorindex < 0) 238 if (colorindex < 0)
277 bmp.SetPixel(x, map.Height - y - 1, Color.Red); 239 colorindex = 0;
278 else 240 else if (colorindex >= pallete)
279 bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); 241 colorindex = pallete - 1;
242 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
280 } 243 }
281 } 244 }
282 return bmp; 245 return bmp;
283 } 246 }
284 } 247 }
285} 248}
249
250
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
index 9cc767a..d604dc7 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
@@ -59,9 +59,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
59 59
60 public void SaveFile(string filename, ITerrainChannel map) 60 public void SaveFile(string filename, ITerrainChannel map)
61 { 61 {
62 Bitmap colours = CreateBitmapFromMap(map); 62 using(Bitmap colours = CreateBitmapFromMap(map))
63 63 colours.Save(filename,ImageFormat.Jpeg);
64 colours.Save(filename, ImageFormat.Jpeg);
65 } 64 }
66 65
67 /// <summary> 66 /// <summary>
@@ -71,9 +70,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
71 /// <param name="map">The terrain channel being saved</param> 70 /// <param name="map">The terrain channel being saved</param>
72 public void SaveStream(Stream stream, ITerrainChannel map) 71 public void SaveStream(Stream stream, ITerrainChannel map)
73 { 72 {
74 Bitmap colours = CreateBitmapFromMap(map); 73 using(Bitmap colours = CreateBitmapFromMap(map))
75 74 colours.Save(stream,ImageFormat.Jpeg);
76 colours.Save(stream, ImageFormat.Jpeg);
77 } 75 }
78 76
79 public virtual void SaveFile(ITerrainChannel m_channel, string filename, 77 public virtual void SaveFile(ITerrainChannel m_channel, string filename,
@@ -106,10 +104,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
106 using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png")) 104 using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
107 { 105 {
108 pallete = gradientmapLd.Height; 106 pallete = gradientmapLd.Height;
109 107
110 bmp = new Bitmap(map.Width, map.Height); 108 bmp = new Bitmap(map.Width, map.Height);
111 colours = new Color[pallete]; 109 colours = new Color[pallete];
112 110
113 for (int i = 0; i < pallete; i++) 111 for (int i = 0; i < pallete; i++)
114 { 112 {
115 colours[i] = gradientmapLd.GetPixel(0, i); 113 colours[i] = gradientmapLd.GetPixel(0, i);
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
index be1fb24..68d6ed2 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
@@ -57,6 +57,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
57 57
58 public LLRAW() 58 public LLRAW()
59 { 59 {
60 }
61
62 private void BuildLookupHeightTable()
63 {
60 LookupHeightTable = new HeightmapLookupValue[256 * 256]; 64 LookupHeightTable = new HeightmapLookupValue[256 * 256];
61 65
62 for (int i = 0; i < 256; i++) 66 for (int i = 0; i < 256; i++)
@@ -186,6 +190,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
186 190
187 public void SaveStream(Stream s, ITerrainChannel map) 191 public void SaveStream(Stream s, ITerrainChannel map)
188 { 192 {
193 if (LookupHeightTable == null)
194 BuildLookupHeightTable();
195
189 using (BinaryWriter binStream = new BinaryWriter(s)) 196 using (BinaryWriter binStream = new BinaryWriter(s))
190 { 197 {
191 // Output the calculated raw 198 // Output the calculated raw
@@ -241,6 +248,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
241 } 248 }
242 } 249 }
243 } 250 }
251 LookupHeightTable = null;
244 } 252 }
245 253
246 public string FileExtension 254 public string FileExtension
@@ -267,6 +275,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
267 public bool SupportsTileSave() 275 public bool SupportsTileSave()
268 { 276 {
269 return false; 277 return false;
270 } 278 }
271 } 279 }
272} \ No newline at end of file 280} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs
index c5c12ae..8ea8e9d 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs
@@ -36,9 +36,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
36 { 36 {
37 public override void SaveFile(string filename, ITerrainChannel map) 37 public override void SaveFile(string filename, ITerrainChannel map)
38 { 38 {
39 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 39 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
40 40 colours.Save(filename,ImageFormat.Png);
41 colours.Save(filename, ImageFormat.Png);
42 } 41 }
43 42
44 /// <summary> 43 /// <summary>
@@ -48,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
48 /// <param name="map">The terrain channel being saved</param> 47 /// <param name="map">The terrain channel being saved</param>
49 public override void SaveStream(Stream stream, ITerrainChannel map) 48 public override void SaveStream(Stream stream, ITerrainChannel map)
50 { 49 {
51 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 50 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
52 51 colours.Save(stream,ImageFormat.Png);
53 colours.Save(stream, ImageFormat.Png);
54 } 52 }
55 53
56 public override string ToString() 54 public override string ToString()
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
index b416b82..d103a6f 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
@@ -36,9 +36,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
36 { 36 {
37 public override void SaveFile(string filename, ITerrainChannel map) 37 public override void SaveFile(string filename, ITerrainChannel map)
38 { 38 {
39 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 39 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
40 40 colours.Save(filename,ImageFormat.Tiff);
41 colours.Save(filename, ImageFormat.Tiff);
42 } 41 }
43 42
44 /// <summary> 43 /// <summary>
@@ -48,9 +47,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
48 /// <param name="map">The terrain channel being saved</param> 47 /// <param name="map">The terrain channel being saved</param>
49 public override void SaveStream(Stream stream, ITerrainChannel map) 48 public override void SaveStream(Stream stream, ITerrainChannel map)
50 { 49 {
51 Bitmap colours = CreateGrayscaleBitmapFromMap(map); 50 using(Bitmap colours = CreateGrayscaleBitmapFromMap(map))
52 51 colours.Save(stream,ImageFormat.Tiff);
53 colours.Save(stream, ImageFormat.Tiff);
54 } 52 }
55 53
56 public override string ToString() 54 public override string ToString()