diff options
author | Justin Clarke Casey | 2008-06-29 19:21:43 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-06-29 19:21:43 +0000 |
commit | 7d5a21ddbf738c51197a98bef11a52ceb85fe907 (patch) | |
tree | b45ce6542acb9b6d17824983fb8d135560e8d3f8 /OpenSim/Region/Environment/Modules/World | |
parent | * Fix for http://opensimulator.org/mantis/view.php?id=1512 (diff) | |
download | opensim-SC-7d5a21ddbf738c51197a98bef11a52ceb85fe907.zip opensim-SC-7d5a21ddbf738c51197a98bef11a52ceb85fe907.tar.gz opensim-SC-7d5a21ddbf738c51197a98bef11a52ceb85fe907.tar.bz2 opensim-SC-7d5a21ddbf738c51197a98bef11a52ceb85fe907.tar.xz |
* Allow terrains to be loaded and saved from streams as well as directly to and from files
* Should be making use of this in the next revisions
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World')
12 files changed, 264 insertions, 44 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/BMP.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/BMP.cs index 98d69a5..34bbf78 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/BMP.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/BMP.cs | |||
@@ -24,8 +24,10 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | |||
27 | using System.Drawing; | 28 | using System.Drawing; |
28 | using System.Drawing.Imaging; | 29 | using System.Drawing.Imaging; |
30 | using System.IO; | ||
29 | using OpenSim.Region.Environment.Interfaces; | 31 | using OpenSim.Region.Environment.Interfaces; |
30 | 32 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | 33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders |
@@ -49,6 +51,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
49 | 51 | ||
50 | colours.Save(filename, ImageFormat.Bmp); | 52 | colours.Save(filename, ImageFormat.Bmp); |
51 | } | 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 | } | ||
52 | 66 | ||
53 | /// <summary> | 67 | /// <summary> |
54 | /// The human readable version of the file format(s) this loader handles | 68 | /// The human readable version of the file format(s) this loader handles |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GIF.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GIF.cs index 9bfe851..0cd9000 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GIF.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GIF.cs | |||
@@ -24,8 +24,10 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | |||
27 | using System.Drawing; | 28 | using System.Drawing; |
28 | using System.Drawing.Imaging; | 29 | using System.Drawing.Imaging; |
30 | using System.IO; | ||
29 | using OpenSim.Region.Environment.Interfaces; | 31 | using OpenSim.Region.Environment.Interfaces; |
30 | 32 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | 33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders |
@@ -38,6 +40,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
38 | 40 | ||
39 | colours.Save(filename, ImageFormat.Gif); | 41 | colours.Save(filename, ImageFormat.Gif); |
40 | } | 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 | } | ||
41 | 55 | ||
42 | public override string ToString() | 56 | public override string ToString() |
43 | { | 57 | { |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs index f87d3ee..4d213e0 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Drawing; | 29 | using System.Drawing; |
30 | using System.Drawing.Imaging; | 30 | using System.Drawing.Imaging; |
31 | using System.IO; | ||
31 | using OpenSim.Region.Environment.Interfaces; | 32 | using OpenSim.Region.Environment.Interfaces; |
32 | 33 | ||
33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | 34 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders |
@@ -57,26 +58,34 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
57 | /// <returns>A terrain channel generated from the image.</returns> | 58 | /// <returns>A terrain channel generated from the image.</returns> |
58 | public virtual ITerrainChannel LoadFile(string filename) | 59 | public virtual ITerrainChannel LoadFile(string filename) |
59 | { | 60 | { |
60 | Bitmap file = new Bitmap(filename); | 61 | return LoadBitmap(new Bitmap(filename)); |
62 | } | ||
61 | 63 | ||
62 | ITerrainChannel retval = new TerrainChannel(file.Width, file.Height); | 64 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) |
65 | { | ||
66 | throw new NotImplementedException(); | ||
67 | } | ||
68 | |||
69 | public virtual ITerrainChannel LoadStream(Stream stream) | ||
70 | { | ||
71 | return LoadBitmap(new Bitmap(stream)); | ||
72 | } | ||
73 | |||
74 | protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap) | ||
75 | { | ||
76 | ITerrainChannel retval = new TerrainChannel(bitmap.Width, bitmap.Height); | ||
63 | 77 | ||
64 | int x; | 78 | int x; |
65 | for (x = 0; x < file.Width; x++) | 79 | for (x = 0; x < bitmap.Width; x++) |
66 | { | 80 | { |
67 | int y; | 81 | int y; |
68 | for (y = 0; y < file.Height; y++) | 82 | for (y = 0; y < bitmap.Height; y++) |
69 | { | 83 | { |
70 | retval[x, y] = file.GetPixel(x, file.Height - y - 1).GetBrightness() * 128; | 84 | retval[x, y] = bitmap.GetPixel(x, bitmap.Height - y - 1).GetBrightness() * 128; |
71 | } | 85 | } |
72 | } | 86 | } |
73 | 87 | ||
74 | return retval; | 88 | return retval; |
75 | } | ||
76 | |||
77 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
78 | { | ||
79 | throw new NotImplementedException(); | ||
80 | } | 89 | } |
81 | 90 | ||
82 | /// <summary> | 91 | /// <summary> |
@@ -90,6 +99,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
90 | 99 | ||
91 | colours.Save(filename, ImageFormat.Png); | 100 | colours.Save(filename, ImageFormat.Png); |
92 | } | 101 | } |
102 | |||
103 | /// <summary> | ||
104 | /// Exports a stream using a System.Drawing exporter. | ||
105 | /// </summary> | ||
106 | /// <param name="stream">The target stream</param> | ||
107 | /// <param name="map">The terrain channel being saved</param> | ||
108 | public virtual void SaveStream(Stream stream, ITerrainChannel map) | ||
109 | { | ||
110 | Bitmap colours = CreateGrayscaleBitmapFromMap(map); | ||
111 | |||
112 | colours.Save(stream, ImageFormat.Png); | ||
113 | } | ||
93 | 114 | ||
94 | #endregion | 115 | #endregion |
95 | 116 | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs index 628c201..9886b81 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/JPEG.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Drawing; | 29 | using System.Drawing; |
30 | using System.Drawing.Imaging; | 30 | using System.Drawing.Imaging; |
31 | using System.IO; | ||
31 | using OpenSim.Region.Environment.Interfaces; | 32 | using OpenSim.Region.Environment.Interfaces; |
32 | 33 | ||
33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | 34 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders |
@@ -50,6 +51,11 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
50 | { | 51 | { |
51 | throw new NotImplementedException(); | 52 | throw new NotImplementedException(); |
52 | } | 53 | } |
54 | |||
55 | public ITerrainChannel LoadStream(Stream stream) | ||
56 | { | ||
57 | throw new NotImplementedException(); | ||
58 | } | ||
53 | 59 | ||
54 | public void SaveFile(string filename, ITerrainChannel map) | 60 | public void SaveFile(string filename, ITerrainChannel map) |
55 | { | 61 | { |
@@ -57,6 +63,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
57 | 63 | ||
58 | colours.Save(filename, ImageFormat.Jpeg); | 64 | colours.Save(filename, ImageFormat.Jpeg); |
59 | } | 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 | } | ||
60 | 78 | ||
61 | #endregion | 79 | #endregion |
62 | 80 | ||
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs index 85afaf8..d8d0648 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/LLRAW.cs | |||
@@ -71,10 +71,24 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
71 | 71 | ||
72 | public ITerrainChannel LoadFile(string filename) | 72 | public ITerrainChannel LoadFile(string filename) |
73 | { | 73 | { |
74 | TerrainChannel retval = new TerrainChannel(); | ||
75 | |||
76 | FileInfo file = new FileInfo(filename); | 74 | FileInfo file = new FileInfo(filename); |
77 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | 75 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); |
76 | ITerrainChannel retval = LoadStream(s); | ||
77 | |||
78 | s.Close(); | ||
79 | |||
80 | return retval; | ||
81 | } | ||
82 | |||
83 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
84 | { | ||
85 | throw new NotImplementedException(); | ||
86 | } | ||
87 | |||
88 | public ITerrainChannel LoadStream(Stream s) | ||
89 | { | ||
90 | TerrainChannel retval = new TerrainChannel(); | ||
91 | |||
78 | BinaryReader bs = new BinaryReader(s); | 92 | BinaryReader bs = new BinaryReader(s); |
79 | int y; | 93 | int y; |
80 | for (y = 0; y < retval.Height; y++) | 94 | for (y = 0; y < retval.Height; y++) |
@@ -87,21 +101,22 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
87 | } | 101 | } |
88 | } | 102 | } |
89 | 103 | ||
90 | bs.Close(); | 104 | bs.Close(); |
91 | s.Close(); | 105 | |
92 | |||
93 | return retval; | 106 | return retval; |
94 | } | 107 | } |
95 | 108 | ||
96 | public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) | ||
97 | { | ||
98 | throw new NotImplementedException(); | ||
99 | } | ||
100 | |||
101 | public void SaveFile(string filename, ITerrainChannel map) | 109 | public void SaveFile(string filename, ITerrainChannel map) |
102 | { | 110 | { |
103 | FileInfo file = new FileInfo(filename); | 111 | FileInfo file = new FileInfo(filename); |
104 | FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); | 112 | FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write); |
113 | SaveStream(s, map); | ||
114 | |||
115 | s.Close(); | ||
116 | } | ||
117 | |||
118 | public void SaveStream(Stream s, ITerrainChannel map) | ||
119 | { | ||
105 | BinaryWriter binStream = new BinaryWriter(s); | 120 | BinaryWriter binStream = new BinaryWriter(s); |
106 | 121 | ||
107 | // Output the calculated raw | 122 | // Output the calculated raw |
@@ -150,11 +165,9 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
150 | } | 165 | } |
151 | } | 166 | } |
152 | 167 | ||
153 | binStream.Close(); | 168 | binStream.Close(); |
154 | s.Close(); | ||
155 | } | 169 | } |
156 | 170 | ||
157 | |||
158 | public string FileExtension | 171 | public string FileExtension |
159 | { | 172 | { |
160 | get { return ".raw"; } | 173 | get { return ".raw"; } |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/PNG.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/PNG.cs index b893f70..cf95486 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/PNG.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/PNG.cs | |||
@@ -24,8 +24,10 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | |||
27 | using System.Drawing; | 28 | using System.Drawing; |
28 | using System.Drawing.Imaging; | 29 | using System.Drawing.Imaging; |
30 | using System.IO; | ||
29 | using OpenSim.Region.Environment.Interfaces; | 31 | using OpenSim.Region.Environment.Interfaces; |
30 | 32 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | 33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders |
@@ -38,6 +40,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
38 | 40 | ||
39 | colours.Save(filename, ImageFormat.Png); | 41 | colours.Save(filename, ImageFormat.Png); |
40 | } | 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 | } | ||
41 | 55 | ||
42 | public override string ToString() | 56 | public override string ToString() |
43 | { | 57 | { |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs index 689abcf..bb8b0f7 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs | |||
@@ -41,22 +41,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
41 | 41 | ||
42 | public ITerrainChannel LoadFile(string filename) | 42 | public ITerrainChannel LoadFile(string filename) |
43 | { | 43 | { |
44 | TerrainChannel retval = new TerrainChannel(); | ||
45 | |||
46 | FileInfo file = new FileInfo(filename); | 44 | FileInfo file = new FileInfo(filename); |
47 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | 45 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); |
48 | BinaryReader bs = new BinaryReader(s); | 46 | ITerrainChannel retval = LoadStream(s); |
49 | int y; | ||
50 | for (y = 0; y < retval.Height; y++) | ||
51 | { | ||
52 | int x; | ||
53 | for (x = 0; x < retval.Width; x++) | ||
54 | { | ||
55 | retval[x, y] = bs.ReadSingle(); | ||
56 | } | ||
57 | } | ||
58 | 47 | ||
59 | bs.Close(); | ||
60 | s.Close(); | 48 | s.Close(); |
61 | 49 | ||
62 | return retval; | 50 | return retval; |
@@ -124,11 +112,38 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
124 | 112 | ||
125 | return retval; | 113 | return retval; |
126 | } | 114 | } |
115 | |||
116 | public ITerrainChannel LoadStream(Stream s) | ||
117 | { | ||
118 | TerrainChannel retval = new TerrainChannel(); | ||
119 | |||
120 | BinaryReader bs = new BinaryReader(s); | ||
121 | int y; | ||
122 | for (y = 0; y < retval.Height; y++) | ||
123 | { | ||
124 | int x; | ||
125 | for (x = 0; x < retval.Width; x++) | ||
126 | { | ||
127 | retval[x, y] = bs.ReadSingle(); | ||
128 | } | ||
129 | } | ||
127 | 130 | ||
131 | bs.Close(); | ||
132 | |||
133 | return retval; | ||
134 | } | ||
135 | |||
128 | public void SaveFile(string filename, ITerrainChannel map) | 136 | public void SaveFile(string filename, ITerrainChannel map) |
129 | { | 137 | { |
130 | FileInfo file = new FileInfo(filename); | 138 | FileInfo file = new FileInfo(filename); |
131 | FileStream s = file.Open(FileMode.Create, FileAccess.Write); | 139 | FileStream s = file.Open(FileMode.Create, FileAccess.Write); |
140 | SaveStream(s, map); | ||
141 | |||
142 | s.Close(); | ||
143 | } | ||
144 | |||
145 | public void SaveStream(Stream s, ITerrainChannel map) | ||
146 | { | ||
132 | BinaryWriter bs = new BinaryWriter(s); | 147 | BinaryWriter bs = new BinaryWriter(s); |
133 | 148 | ||
134 | int y; | 149 | int y; |
@@ -141,8 +156,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
141 | } | 156 | } |
142 | } | 157 | } |
143 | 158 | ||
144 | bs.Close(); | 159 | bs.Close(); |
145 | s.Close(); | ||
146 | } | 160 | } |
147 | 161 | ||
148 | #endregion | 162 | #endregion |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/TIFF.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/TIFF.cs index c081aea..3f98f40 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/TIFF.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/TIFF.cs | |||
@@ -24,8 +24,10 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | |||
27 | using System.Drawing; | 28 | using System.Drawing; |
28 | using System.Drawing.Imaging; | 29 | using System.Drawing.Imaging; |
30 | using System.IO; | ||
29 | using OpenSim.Region.Environment.Interfaces; | 31 | using OpenSim.Region.Environment.Interfaces; |
30 | 32 | ||
31 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | 33 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders |
@@ -38,6 +40,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
38 | 40 | ||
39 | colours.Save(filename, ImageFormat.Tiff); | 41 | colours.Save(filename, ImageFormat.Tiff); |
40 | } | 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 | } | ||
41 | 55 | ||
42 | public override string ToString() | 56 | public override string ToString() |
43 | { | 57 | { |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs index fe36cf7..5dc2aa5 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs | |||
@@ -43,10 +43,19 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
43 | 43 | ||
44 | public ITerrainChannel LoadFile(string filename) | 44 | public ITerrainChannel LoadFile(string filename) |
45 | { | 45 | { |
46 | TerrainChannel retval = new TerrainChannel(); | ||
47 | |||
48 | FileInfo file = new FileInfo(filename); | 46 | FileInfo file = new FileInfo(filename); |
49 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | 47 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); |
48 | ITerrainChannel retval = LoadStream(s); | ||
49 | |||
50 | s.Close(); | ||
51 | |||
52 | return retval; | ||
53 | } | ||
54 | |||
55 | public ITerrainChannel LoadStream(Stream s) | ||
56 | { | ||
57 | TerrainChannel retval = new TerrainChannel(); | ||
58 | |||
50 | BinaryReader bs = new BinaryReader(s); | 59 | BinaryReader bs = new BinaryReader(s); |
51 | 60 | ||
52 | bool eof = false; | 61 | bool eof = false; |
@@ -98,8 +107,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
98 | } | 107 | } |
99 | 108 | ||
100 | bs.Close(); | 109 | bs.Close(); |
101 | s.Close(); | 110 | |
102 | |||
103 | return retval; | 111 | return retval; |
104 | } | 112 | } |
105 | 113 | ||
@@ -107,6 +115,11 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | |||
107 | { | 115 | { |
108 | throw new NotImplementedException(); | 116 | throw new NotImplementedException(); |
109 | } | 117 | } |
118 | |||
119 | public void SaveStream(Stream stream, ITerrainChannel map) | ||
120 | { | ||
121 | throw new NotImplementedException(); | ||
122 | } | ||
110 | 123 | ||
111 | public string FileExtension | 124 | public string FileExtension |
112 | { | 125 | { |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainLoader.cs b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainLoader.cs index 4c16c1c..950b27b 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainLoader.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainLoader.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.IO; | ||
28 | using OpenSim.Region.Environment.Interfaces; | 29 | using OpenSim.Region.Environment.Interfaces; |
29 | 30 | ||
30 | namespace OpenSim.Region.Environment.Modules.World.Terrain | 31 | namespace OpenSim.Region.Environment.Modules.World.Terrain |
@@ -34,6 +35,8 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain | |||
34 | string FileExtension { get; } | 35 | string FileExtension { get; } |
35 | ITerrainChannel LoadFile(string filename); | 36 | ITerrainChannel LoadFile(string filename); |
36 | ITerrainChannel LoadFile(string filename, int fileStartX, int fileStartY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight); | 37 | ITerrainChannel LoadFile(string filename, int fileStartX, int fileStartY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight); |
38 | ITerrainChannel LoadStream(Stream stream); | ||
37 | void SaveFile(string filename, ITerrainChannel map); | 39 | void SaveFile(string filename, ITerrainChannel map); |
40 | void SaveStream(Stream stream, ITerrainChannel map); | ||
38 | } | 41 | } |
39 | } \ No newline at end of file | 42 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainModule.cs index 6ab2372..e255515 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/ITerrainModule.cs | |||
@@ -25,12 +25,33 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.IO; | ||
29 | |||
28 | namespace OpenSim.Region.Environment.Modules.World.Terrain | 30 | namespace OpenSim.Region.Environment.Modules.World.Terrain |
29 | { | 31 | { |
30 | public interface ITerrainModule | 32 | public interface ITerrainModule |
31 | { | 33 | { |
32 | void LoadFromFile(string filename); | 34 | void LoadFromFile(string filename); |
33 | void SaveToFile(string filename); | 35 | void SaveToFile(string filename); |
36 | |||
37 | /// <summary> | ||
38 | /// Load a terrain from a stream. | ||
39 | /// </summary> | ||
40 | /// <param name="filename"> | ||
41 | /// Only required here to identify the image type. Not otherwise used in the loading itself. | ||
42 | /// </param> | ||
43 | /// <param name="stream"></param> | ||
44 | void LoadFromStream(string filename, Stream stream); | ||
45 | |||
46 | /// <summary> | ||
47 | /// Save a terrain to a stream. | ||
48 | /// </summary> | ||
49 | /// <param name="filename"> | ||
50 | /// Only required here to identify the image type. Not otherwise used in the saving itself. | ||
51 | /// </param> | ||
52 | /// <param name="stream"></param> | ||
53 | void SaveToStream(string filename, Stream stream); | ||
54 | |||
34 | void InstallPlugin(string name, ITerrainEffect plug); | 55 | void InstallPlugin(string name, ITerrainEffect plug); |
35 | } | 56 | } |
36 | } | 57 | } |
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs index 1bda2a0..fb81abc 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs | |||
@@ -221,6 +221,67 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain | |||
221 | throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented")); | 221 | throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented")); |
222 | } | 222 | } |
223 | } | 223 | } |
224 | |||
225 | /// <summary> | ||
226 | /// Loads a terrain file from a stream and installs it in the scene. | ||
227 | /// </summary> | ||
228 | /// <param name="filename">Filename to terrain file. Type is determined by extension.</param> | ||
229 | /// <param name="stream"></param> | ||
230 | public void LoadFromStream(string filename, Stream stream) | ||
231 | { | ||
232 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
233 | { | ||
234 | if (filename.EndsWith(loader.Key)) | ||
235 | { | ||
236 | lock (m_scene) | ||
237 | { | ||
238 | try | ||
239 | { | ||
240 | ITerrainChannel channel = loader.Value.LoadStream(stream); | ||
241 | m_scene.Heightmap = channel; | ||
242 | m_channel = channel; | ||
243 | UpdateRevertMap(); | ||
244 | } | ||
245 | catch (NotImplementedException) | ||
246 | { | ||
247 | m_log.Error("[TERRAIN]: Unable to load heightmap, the " + loader.Value + | ||
248 | " parser does not support file loading. (May be save only)"); | ||
249 | throw new TerrainException(String.Format("unable to load heightmap: parser {0} does not support loading", loader.Value)); | ||
250 | } | ||
251 | } | ||
252 | CheckForTerrainUpdates(); | ||
253 | m_log.Info("[TERRAIN]: File (" + filename + ") loaded successfully"); | ||
254 | return; | ||
255 | } | ||
256 | } | ||
257 | m_log.Error("[TERRAIN]: Unable to load heightmap, no file loader availible for that format."); | ||
258 | throw new TerrainException(String.Format("unable to load heightmap from file {0}: no loader available for that format", filename)); | ||
259 | } | ||
260 | |||
261 | /// <summary> | ||
262 | /// Saves the current heightmap to a specified stream. | ||
263 | /// </summary> | ||
264 | /// <param name="filename">The destination filename. Used here only to identify the image type</param> | ||
265 | /// <param name="stream"></param> | ||
266 | public void SaveToStream(string filename, Stream stream) | ||
267 | { | ||
268 | try | ||
269 | { | ||
270 | foreach (KeyValuePair<string, ITerrainLoader> loader in m_loaders) | ||
271 | { | ||
272 | if (filename.EndsWith(loader.Key)) | ||
273 | { | ||
274 | loader.Value.SaveStream(stream, m_channel); | ||
275 | return; | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | catch (NotImplementedException) | ||
280 | { | ||
281 | m_log.Error("Unable to save to " + filename + ", saving of this file format has not been implemented."); | ||
282 | throw new TerrainException(String.Format("Unable to save heightmap: saving of this file format not implemented")); | ||
283 | } | ||
284 | } | ||
224 | 285 | ||
225 | #region Plugin Loading Methods | 286 | #region Plugin Loading Methods |
226 | 287 | ||