aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-06-29 19:21:43 +0000
committerJustin Clarke Casey2008-06-29 19:21:43 +0000
commit7d5a21ddbf738c51197a98bef11a52ceb85fe907 (patch)
treeb45ce6542acb9b6d17824983fb8d135560e8d3f8 /OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
parent* Fix for http://opensimulator.org/mantis/view.php?id=1512 (diff)
downloadopensim-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/Terrain/FileLoaders/GenericSystemDrawing.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/GenericSystemDrawing.cs43
1 files changed, 32 insertions, 11 deletions
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 @@
28using System; 28using System;
29using System.Drawing; 29using System.Drawing;
30using System.Drawing.Imaging; 30using System.Drawing.Imaging;
31using System.IO;
31using OpenSim.Region.Environment.Interfaces; 32using OpenSim.Region.Environment.Interfaces;
32 33
33namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders 34namespace 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