aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Terrain/FileLoaders
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Terrain/FileLoaders')
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs76
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs61
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs195
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs112
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs250
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs61
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs170
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs61
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs142
9 files changed, 1128 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs
new file mode 100644
index 0000000..4f395b5
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/BMP.cs
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Drawing;
29using System.Drawing.Imaging;
30using System.IO;
31using OpenSim.Region.Framework.Interfaces;
32
33namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
34{
35 /// <summary>
36 /// A generic windows bitmap loader.
37 /// Should be capable of handling 24-bit RGB images.
38 ///
39 /// Uses the System.Drawing filesystem loader.
40 /// </summary>
41 internal class BMP : GenericSystemDrawing
42 {
43 /// <summary>
44 /// Exports a file to a image on the disk using a System.Drawing exporter.
45 /// </summary>
46 /// <param name="filename">The target filename</param>
47 /// <param name="map">The terrain channel being saved</param>
48 public override void SaveFile(string filename, ITerrainChannel map)
49 {
50 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
51
52 colours.Save(filename, ImageFormat.Bmp);
53 }
54
55 /// <summary>
56 /// Exports a stream using a System.Drawing exporter.
57 /// </summary>
58 /// <param name="stream">The target stream</param>
59 /// <param name="map">The terrain channel being saved</param>
60 public override void SaveStream(Stream stream, ITerrainChannel map)
61 {
62 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
63
64 colours.Save(stream, ImageFormat.Png);
65 }
66
67 /// <summary>
68 /// The human readable version of the file format(s) this loader handles
69 /// </summary>
70 /// <returns></returns>
71 public override string ToString()
72 {
73 return "BMP";
74 }
75 }
76}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs
new file mode 100644
index 0000000..cff82d1
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GIF.cs
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Drawing;
29using System.Drawing.Imaging;
30using System.IO;
31using OpenSim.Region.Framework.Interfaces;
32
33namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
34{
35 internal class GIF : GenericSystemDrawing
36 {
37 public override void SaveFile(string filename, ITerrainChannel map)
38 {
39 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
40
41 colours.Save(filename, ImageFormat.Gif);
42 }
43
44 /// <summary>
45 /// Exports a stream using a System.Drawing exporter.
46 /// </summary>
47 /// <param name="stream">The target stream</param>
48 /// <param name="map">The terrain channel being saved</param>
49 public override void SaveStream(Stream stream, ITerrainChannel map)
50 {
51 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
52
53 colours.Save(stream, ImageFormat.Gif);
54 }
55
56 public override string ToString()
57 {
58 return "GIF";
59 }
60 }
61}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
new file mode 100644
index 0000000..477c73c
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -0,0 +1,195 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Drawing;
30using System.Drawing.Imaging;
31using System.IO;
32using OpenSim.Region.Framework.Interfaces;
33using OpenSim.Region.Framework.Scenes;
34
35namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
36{
37 /// <summary>
38 /// A virtual class designed to have methods overloaded,
39 /// this class provides an interface for a generic image
40 /// saving and loading mechanism, but does not specify the
41 /// format. It should not be insubstantiated directly.
42 /// </summary>
43 public class GenericSystemDrawing : ITerrainLoader
44 {
45 #region ITerrainLoader Members
46
47 public string FileExtension
48 {
49 get { return ".gsd"; }
50 }
51
52 /// <summary>
53 /// Loads a file from a specified filename on the disk,
54 /// parses the image using the System.Drawing parsers
55 /// then returns a terrain channel. Values are
56 /// returned based on HSL brightness between 0m and 128m
57 /// </summary>
58 /// <param name="filename">The target image to load</param>
59 /// <returns>A terrain channel generated from the image.</returns>
60 public virtual ITerrainChannel LoadFile(string filename)
61 {
62 return LoadBitmap(new Bitmap(filename));
63 }
64
65 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h)
66 {
67 throw new NotImplementedException();
68 }
69
70 public virtual ITerrainChannel LoadStream(Stream stream)
71 {
72 return LoadBitmap(new Bitmap(stream));
73 }
74
75 protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap)
76 {
77 ITerrainChannel retval = new TerrainChannel(bitmap.Width, bitmap.Height);
78
79 int x;
80 for (x = 0; x < bitmap.Width; x++)
81 {
82 int y;
83 for (y = 0; y < bitmap.Height; y++)
84 {
85 retval[x, y] = bitmap.GetPixel(x, bitmap.Height - y - 1).GetBrightness() * 128;
86 }
87 }
88
89 return retval;
90 }
91
92 /// <summary>
93 /// Exports a file to a image on the disk using a System.Drawing exporter.
94 /// </summary>
95 /// <param name="filename">The target filename</param>
96 /// <param name="map">The terrain channel being saved</param>
97 public virtual void SaveFile(string filename, ITerrainChannel map)
98 {
99 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
100
101 colours.Save(filename, ImageFormat.Png);
102 }
103
104 /// <summary>
105 /// Exports a stream using a System.Drawing exporter.
106 /// </summary>
107 /// <param name="stream">The target stream</param>
108 /// <param name="map">The terrain channel being saved</param>
109 public virtual void SaveStream(Stream stream, ITerrainChannel map)
110 {
111 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
112
113 colours.Save(stream, ImageFormat.Png);
114 }
115
116 #endregion
117
118 public override string ToString()
119 {
120 return "SYS.DRAWING";
121 }
122
123 /// <summary>
124 /// Protected method, generates a grayscale bitmap
125 /// image from a specified terrain channel.
126 /// </summary>
127 /// <param name="map">The terrain channel to export to bitmap</param>
128 /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns>
129 protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map)
130 {
131 Bitmap bmp = new Bitmap(map.Width, map.Height);
132
133 const int pallete = 256;
134
135 Color[] grays = new Color[pallete];
136 for (int i = 0; i < grays.Length; i++)
137 {
138 grays[i] = Color.FromArgb(i, i, i);
139 }
140
141 for (int y = 0; y < map.Height; y++)
142 {
143 for (int x = 0; x < map.Width; x++)
144 {
145 // 512 is the largest possible height before colours clamp
146 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1));
147
148 // Handle error conditions
149 if (colorindex > pallete - 1 || colorindex < 0)
150 bmp.SetPixel(x, map.Height - y - 1, Color.Red);
151 else
152 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
153 }
154 }
155 return bmp;
156 }
157
158 /// <summary>
159 /// Protected method, generates a coloured bitmap
160 /// image from a specified terrain channel.
161 /// </summary>
162 /// <param name="map">The terrain channel to export to bitmap</param>
163 /// <returns>A System.Drawing.Bitmap containing a coloured image</returns>
164 protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
165 {
166 Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
167
168 int pallete = gradientmapLd.Height;
169
170 Bitmap bmp = new Bitmap(map.Width, map.Height);
171 Color[] colours = new Color[pallete];
172
173 for (int i = 0; i < pallete; i++)
174 {
175 colours[i] = gradientmapLd.GetPixel(0, i);
176 }
177
178 for (int y = 0; y < map.Height; y++)
179 {
180 for (int x = 0; x < map.Width; x++)
181 {
182 // 512 is the largest possible height before colours clamp
183 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
184
185 // Handle error conditions
186 if (colorindex > pallete - 1 || colorindex < 0)
187 bmp.SetPixel(x, map.Height - y - 1, Color.Red);
188 else
189 bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]);
190 }
191 }
192 return bmp;
193 }
194 }
195}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
new file mode 100644
index 0000000..f8e31f8
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/JPEG.cs
@@ -0,0 +1,112 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Drawing;
30using System.Drawing.Imaging;
31using System.IO;
32using OpenSim.Region.Framework.Interfaces;
33
34namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
35{
36 public class JPEG : ITerrainLoader
37 {
38 #region ITerrainLoader Members
39
40 public string FileExtension
41 {
42 get { return ".jpg"; }
43 }
44
45 public ITerrainChannel LoadFile(string filename)
46 {
47 throw new NotImplementedException();
48 }
49
50 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h)
51 {
52 throw new NotImplementedException();
53 }
54
55 public ITerrainChannel LoadStream(Stream stream)
56 {
57 throw new NotImplementedException();
58 }
59
60 public void SaveFile(string filename, ITerrainChannel map)
61 {
62 Bitmap colours = CreateBitmapFromMap(map);
63
64 colours.Save(filename, ImageFormat.Jpeg);
65 }
66
67 /// <summary>
68 /// Exports a stream using a System.Drawing exporter.
69 /// </summary>
70 /// <param name="stream">The target stream</param>
71 /// <param name="map">The terrain channel being saved</param>
72 public void SaveStream(Stream stream, ITerrainChannel map)
73 {
74 Bitmap colours = CreateBitmapFromMap(map);
75
76 colours.Save(stream, ImageFormat.Jpeg);
77 }
78
79 #endregion
80
81 public override string ToString()
82 {
83 return "JPEG";
84 }
85
86 private static Bitmap CreateBitmapFromMap(ITerrainChannel map)
87 {
88 Bitmap gradientmapLd = new Bitmap("defaultstripe.png");
89
90 int pallete = gradientmapLd.Height;
91
92 Bitmap bmp = new Bitmap(map.Width, map.Height);
93 Color[] colours = new Color[pallete];
94
95 for (int i = 0; i < pallete; i++)
96 {
97 colours[i] = gradientmapLd.GetPixel(0, i);
98 }
99
100 for (int y = 0; y < map.Height; y++)
101 {
102 for (int x = 0; x < map.Width; x++)
103 {
104 // 512 is the largest possible height before colours clamp
105 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
106 bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]);
107 }
108 }
109 return bmp;
110 }
111 }
112}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
new file mode 100644
index 0000000..a86ae00
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/LLRAW.cs
@@ -0,0 +1,250 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using OpenSim.Region.Framework.Interfaces;
31using OpenSim.Region.Framework.Scenes;
32
33namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
34{
35 public class LLRAW : ITerrainLoader
36 {
37 public struct HeightmapLookupValue : IComparable<HeightmapLookupValue>
38 {
39 public int Index;
40 public double Value;
41
42 public HeightmapLookupValue(int index, double value)
43 {
44 Index = index;
45 Value = value;
46 }
47
48 public int CompareTo(HeightmapLookupValue val)
49 {
50 return Value.CompareTo(val.Value);
51 }
52 }
53
54 /// <summary>Lookup table to speed up terrain exports</summary>
55 HeightmapLookupValue[] LookupHeightTable;
56
57 public LLRAW()
58 {
59 LookupHeightTable = new HeightmapLookupValue[256 * 256];
60
61 for (int i = 0; i < 256; i++)
62 {
63 for (int j = 0; j < 256; j++)
64 {
65 LookupHeightTable[i + (j * 256)] = new HeightmapLookupValue(i + (j * 256), ((double)i * ((double)j / 128.0d)));
66 }
67 }
68 Array.Sort<HeightmapLookupValue>(LookupHeightTable);
69 }
70
71 #region ITerrainLoader Members
72
73 public ITerrainChannel LoadFile(string filename)
74 {
75 FileInfo file = new FileInfo(filename);
76 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
77 ITerrainChannel retval = LoadStream(s);
78
79 s.Close();
80
81 return retval;
82 }
83
84 public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
85 {
86 TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);
87
88 FileInfo file = new FileInfo(filename);
89 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
90 BinaryReader bs = new BinaryReader(s);
91
92 int currFileYOffset = fileHeight - 1;
93
94 // if our region isn't on the first Y section of the areas to be landscaped, then
95 // advance to our section of the file
96 while (currFileYOffset > offsetY)
97 {
98 // read a whole strip of regions
99 int heightsToRead = sectionHeight * (fileWidth * sectionWidth);
100 bs.ReadBytes(heightsToRead * 13); // because there are 13 fun channels
101 currFileYOffset--;
102 }
103
104 // got to the Y start offset within the file of our region
105 // so read the file bits associated with our region
106 int y;
107 // for each Y within our Y offset
108 for (y = sectionHeight - 1; y >= 0; y--)
109 {
110 int currFileXOffset = 0;
111
112 // if our region isn't the first X section of the areas to be landscaped, then
113 // advance the stream to the X start pos of our section in the file
114 // i.e. eat X upto where we start
115 while (currFileXOffset < offsetX)
116 {
117 bs.ReadBytes(sectionWidth * 13);
118 currFileXOffset++;
119 }
120
121 // got to our X offset, so write our regions X line
122 int x;
123 for (x = 0; x < sectionWidth; x++)
124 {
125 // Read a strip and continue
126 retval[x, y] = bs.ReadByte() * (bs.ReadByte() / 128.0);
127 bs.ReadBytes(11);
128 }
129 // record that we wrote it
130 currFileXOffset++;
131
132 // if our region isn't the last X section of the areas to be landscaped, then
133 // advance the stream to the end of this Y column
134 while (currFileXOffset < fileWidth)
135 {
136 // eat the next regions x line
137 bs.ReadBytes(sectionWidth * 13); //The 13 channels again
138 currFileXOffset++;
139 }
140 }
141
142 bs.Close();
143 s.Close();
144
145 return retval;
146 }
147
148 public ITerrainChannel LoadStream(Stream s)
149 {
150 TerrainChannel retval = new TerrainChannel();
151
152 BinaryReader bs = new BinaryReader(s);
153 int y;
154 for (y = 0; y < retval.Height; y++)
155 {
156 int x;
157 for (x = 0; x < retval.Width; x++)
158 {
159 retval[x, (retval.Height - 1) - y] = bs.ReadByte() * (bs.ReadByte() / 128.0);
160 bs.ReadBytes(11); // Advance the stream to next bytes.
161 }
162 }
163
164 bs.Close();
165
166 return retval;
167 }
168
169 public void SaveFile(string filename, ITerrainChannel map)
170 {
171 FileInfo file = new FileInfo(filename);
172 FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write);
173 SaveStream(s, map);
174
175 s.Close();
176 }
177
178 public void SaveStream(Stream s, ITerrainChannel map)
179 {
180 BinaryWriter binStream = new BinaryWriter(s);
181
182 // Output the calculated raw
183 for (int y = 0; y < map.Height; y++)
184 {
185 for (int x = 0; x < map.Width; x++)
186 {
187 double t = map[x, (map.Height - 1) - y];
188 //if height is less than 0, set it to 0 as
189 //can't save -ve values in a LLRAW file
190 if (t < 0d)
191 {
192 t = 0d;
193 }
194
195 int index = 0;
196
197 // The lookup table is pre-sorted, so we either find an exact match or
198 // the next closest (smaller) match with a binary search
199 index = Array.BinarySearch<HeightmapLookupValue>(LookupHeightTable, new HeightmapLookupValue(0, t));
200 if (index < 0)
201 index = ~index - 1;
202
203 index = LookupHeightTable[index].Index;
204
205 byte red = (byte) (index & 0xFF);
206 byte green = (byte) ((index >> 8) & 0xFF);
207 const byte blue = 20;
208 const byte alpha1 = 0;
209 const byte alpha2 = 0;
210 const byte alpha3 = 0;
211 const byte alpha4 = 0;
212 const byte alpha5 = 255;
213 const byte alpha6 = 255;
214 const byte alpha7 = 255;
215 const byte alpha8 = 255;
216 byte alpha9 = red;
217 byte alpha10 = green;
218
219 binStream.Write(red);
220 binStream.Write(green);
221 binStream.Write(blue);
222 binStream.Write(alpha1);
223 binStream.Write(alpha2);
224 binStream.Write(alpha3);
225 binStream.Write(alpha4);
226 binStream.Write(alpha5);
227 binStream.Write(alpha6);
228 binStream.Write(alpha7);
229 binStream.Write(alpha8);
230 binStream.Write(alpha9);
231 binStream.Write(alpha10);
232 }
233 }
234
235 binStream.Close();
236 }
237
238 public string FileExtension
239 {
240 get { return ".raw"; }
241 }
242
243 #endregion
244
245 public override string ToString()
246 {
247 return "LL/SL RAW";
248 }
249 }
250}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs
new file mode 100644
index 0000000..0dea282
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/PNG.cs
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Drawing;
29using System.Drawing.Imaging;
30using System.IO;
31using OpenSim.Region.Framework.Interfaces;
32
33namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
34{
35 internal class PNG : GenericSystemDrawing
36 {
37 public override void SaveFile(string filename, ITerrainChannel map)
38 {
39 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
40
41 colours.Save(filename, ImageFormat.Png);
42 }
43
44 /// <summary>
45 /// Exports a stream using a System.Drawing exporter.
46 /// </summary>
47 /// <param name="stream">The target stream</param>
48 /// <param name="map">The terrain channel being saved</param>
49 public override void SaveStream(Stream stream, ITerrainChannel map)
50 {
51 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
52
53 colours.Save(stream, ImageFormat.Png);
54 }
55
56 public override string ToString()
57 {
58 return "PNG";
59 }
60 }
61}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs
new file mode 100644
index 0000000..178104f
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/RAW32.cs
@@ -0,0 +1,170 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.IO;
29using OpenSim.Region.Framework.Interfaces;
30using OpenSim.Region.Framework.Scenes;
31
32namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
33{
34 public class RAW32 : ITerrainLoader
35 {
36 #region ITerrainLoader Members
37
38 public string FileExtension
39 {
40 get { return ".r32"; }
41 }
42
43 public ITerrainChannel LoadFile(string filename)
44 {
45 FileInfo file = new FileInfo(filename);
46 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
47 ITerrainChannel retval = LoadStream(s);
48
49 s.Close();
50
51 return retval;
52 }
53
54 public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
55 {
56 TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);
57
58 FileInfo file = new FileInfo(filename);
59 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
60 BinaryReader bs = new BinaryReader(s);
61
62 int currFileYOffset = 0;
63
64 // if our region isn't on the first Y section of the areas to be landscaped, then
65 // advance to our section of the file
66 while (currFileYOffset < offsetY)
67 {
68 // read a whole strip of regions
69 int heightsToRead = sectionHeight * (fileWidth * sectionWidth);
70 bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file
71 currFileYOffset++;
72 }
73
74 // got to the Y start offset within the file of our region
75 // so read the file bits associated with our region
76 int y;
77 // for each Y within our Y offset
78 for (y = 0; y < sectionHeight; y++)
79 {
80 int currFileXOffset = 0;
81
82 // if our region isn't the first X section of the areas to be landscaped, then
83 // advance the stream to the X start pos of our section in the file
84 // i.e. eat X upto where we start
85 while (currFileXOffset < offsetX)
86 {
87 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
88 currFileXOffset++;
89 }
90
91 // got to our X offset, so write our regions X line
92 int x;
93 for (x = 0; x < sectionWidth; x++)
94 {
95 // Read a strip and continue
96 retval[x, y] = bs.ReadSingle();
97 }
98 // record that we wrote it
99 currFileXOffset++;
100
101 // if our region isn't the last X section of the areas to be landscaped, then
102 // advance the stream to the end of this Y column
103 while (currFileXOffset < fileWidth)
104 {
105 // eat the next regions x line
106 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
107 currFileXOffset++;
108 }
109 }
110
111 bs.Close();
112 s.Close();
113
114 return retval;
115 }
116
117 public ITerrainChannel LoadStream(Stream s)
118 {
119 TerrainChannel retval = new TerrainChannel();
120
121 BinaryReader bs = new BinaryReader(s);
122 int y;
123 for (y = 0; y < retval.Height; y++)
124 {
125 int x;
126 for (x = 0; x < retval.Width; x++)
127 {
128 retval[x, y] = bs.ReadSingle();
129 }
130 }
131
132 bs.Close();
133
134 return retval;
135 }
136
137 public void SaveFile(string filename, ITerrainChannel map)
138 {
139 FileInfo file = new FileInfo(filename);
140 FileStream s = file.Open(FileMode.Create, FileAccess.Write);
141 SaveStream(s, map);
142
143 s.Close();
144 }
145
146 public void SaveStream(Stream s, ITerrainChannel map)
147 {
148 BinaryWriter bs = new BinaryWriter(s);
149
150 int y;
151 for (y = 0; y < map.Height; y++)
152 {
153 int x;
154 for (x = 0; x < map.Width; x++)
155 {
156 bs.Write((float) map[x, y]);
157 }
158 }
159
160 bs.Close();
161 }
162
163 #endregion
164
165 public override string ToString()
166 {
167 return "RAW32";
168 }
169 }
170}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
new file mode 100644
index 0000000..220431f
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/TIFF.cs
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Drawing;
29using System.Drawing.Imaging;
30using System.IO;
31using OpenSim.Region.Framework.Interfaces;
32
33namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
34{
35 internal class TIFF : GenericSystemDrawing
36 {
37 public override void SaveFile(string filename, ITerrainChannel map)
38 {
39 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
40
41 colours.Save(filename, ImageFormat.Tiff);
42 }
43
44 /// <summary>
45 /// Exports a stream using a System.Drawing exporter.
46 /// </summary>
47 /// <param name="stream">The target stream</param>
48 /// <param name="map">The terrain channel being saved</param>
49 public override void SaveStream(Stream stream, ITerrainChannel map)
50 {
51 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
52
53 colours.Save(stream, ImageFormat.Tiff);
54 }
55
56 public override string ToString()
57 {
58 return "TIFF";
59 }
60 }
61}
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs
new file mode 100644
index 0000000..426708d
--- /dev/null
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/Terragen.cs
@@ -0,0 +1,142 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using System.Text;
31using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes;
33
34namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
35{
36 /// <summary>
37 /// Terragen File Format Loader
38 /// Built from specification at
39 /// http://www.planetside.co.uk/terragen/dev/tgterrain.html
40 /// </summary>
41 internal class Terragen : ITerrainLoader
42 {
43 #region ITerrainLoader Members
44
45 public ITerrainChannel LoadFile(string filename)
46 {
47 FileInfo file = new FileInfo(filename);
48 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
49 ITerrainChannel retval = LoadStream(s);
50
51 s.Close();
52
53 return retval;
54 }
55
56 public ITerrainChannel LoadStream(Stream s)
57 {
58 TerrainChannel retval = new TerrainChannel();
59
60 BinaryReader bs = new BinaryReader(s);
61
62 bool eof = false;
63 if (Encoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ")
64 {
65 int w = 256;
66 int h = 256;
67
68 // Terragen file
69 while (eof == false)
70 {
71 string tmp = Encoding.ASCII.GetString(bs.ReadBytes(4));
72 switch (tmp)
73 {
74 case "SIZE":
75 int sztmp = bs.ReadInt16() + 1;
76 w = sztmp;
77 h = sztmp;
78 bs.ReadInt16();
79 break;
80 case "XPTS":
81 w = bs.ReadInt16();
82 bs.ReadInt16();
83 break;
84 case "YPTS":
85 h = bs.ReadInt16();
86 bs.ReadInt16();
87 break;
88 case "ALTW":
89 eof = true;
90 Int16 heightScale = bs.ReadInt16();
91 Int16 baseHeight = bs.ReadInt16();
92 retval = new TerrainChannel(w, h);
93 int x;
94 for (x = 0; x < w; x++)
95 {
96 int y;
97 for (y = 0; y < h; y++)
98 {
99 retval[x, y] = baseHeight + bs.ReadInt16() * (double) heightScale / 65536.0;
100 }
101 }
102 break;
103 default:
104 bs.ReadInt32();
105 break;
106 }
107 }
108 }
109
110 bs.Close();
111
112 return retval;
113 }
114
115 public void SaveFile(string filename, ITerrainChannel map)
116 {
117 throw new NotImplementedException();
118 }
119
120 public void SaveStream(Stream stream, ITerrainChannel map)
121 {
122 throw new NotImplementedException();
123 }
124
125 public string FileExtension
126 {
127 get { return ".ter"; }
128 }
129
130 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h)
131 {
132 throw new NotImplementedException();
133 }
134
135 #endregion
136
137 public override string ToString()
138 {
139 return "Terragen";
140 }
141 }
142}