aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs70
1 files changed, 16 insertions, 54 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index d5c77ec..c0b276a 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -128,7 +128,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
128 colours.Save(stream, ImageFormat.Png); 128 colours.Save(stream, ImageFormat.Png);
129 } 129 }
130 130
131 public virtual void SaveFile(ITerrainChannel m_channel, string filename, 131 public virtual void SaveFile(ITerrainChannel m_channel, string filename,
132 int offsetX, int offsetY, 132 int offsetX, int offsetY,
133 int fileWidth, int fileHeight, 133 int fileWidth, int fileHeight,
134 int regionSizeX, int regionSizeY) 134 int regionSizeX, int regionSizeY)
@@ -162,13 +162,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
162 { 162 {
163 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); 163 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
164 } 164 }
165 165
166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); 166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
167 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); 167 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
168 for (int x = 0; x < regionSizeX; x++) 168 for (int x = 0; x < regionSizeX; x++)
169 for (int y = 0; y < regionSizeY; y++) 169 for (int y = 0; y < regionSizeY; y++)
170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); 170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
171 171
172 Save(newBitmap, filename); 172 Save(newBitmap, filename);
173 } 173 }
174 finally 174 finally
@@ -227,59 +227,21 @@ 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 int colorindex = (int)map[x, y]; // one to one conversion as seems apparent on sl docs
231 int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); 231 // or 0-511 range?
232 232 // int colorindex = (int)map[x, y]/2; // 0-511
233 // Handle error conditions 233
234 if (colorindex > pallete - 1 || colorindex < 0) 234 // clamp it not adding the red warning
235 bmp.SetPixel(x, map.Height - y - 1, Color.Red); 235 if (colorindex < 0)
236 else 236 colorindex = 0;
237 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); 237 else if (colorindex >= pallete)
238 } 238 colorindex = pallete - 1;
239 } 239 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
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
255 using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
256 {
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
268 for (int y = 0; y < map.Height; y++)
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
275 // Handle error conditions
276 if (colorindex > pallete - 1 || colorindex < 0)
277 bmp.SetPixel(x, map.Height - y - 1, Color.Red);
278 else
279 bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]);
280 } 240 }
281 } 241 }
282 return bmp; 242 return bmp;
283 } 243 }
284 } 244 }
285} 245}
246
247