aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs50
1 files changed, 49 insertions, 1 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
index cdcc648..742ea5b 100644
--- a/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
+++ b/OpenSim/Region/Environment/Modules/Terrain/TerrainModule.cs
@@ -27,15 +27,17 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing;
30using libsecondlife; 31using libsecondlife;
31using Nini.Config; 32using Nini.Config;
32using OpenSim.Framework; 33using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces; 34using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
35 36
37
36namespace OpenSim.Region.Environment.Modules.Terrain 38namespace OpenSim.Region.Environment.Modules.Terrain
37{ 39{
38 public class TerrainModule : IRegionModule 40 public class TerrainModule : IRegionModule , ITerrainTemp
39 { 41 {
40 public enum StandardTerrainEffects : byte 42 public enum StandardTerrainEffects : byte
41 { 43 {
@@ -139,6 +141,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
139 public void Initialise(Scene scene, IConfigSource config) 141 public void Initialise(Scene scene, IConfigSource config)
140 { 142 {
141 m_scene = scene; 143 m_scene = scene;
144 m_scene.RegisterModuleInterface<ITerrainTemp>(this);
142 m_gConfig = config; 145 m_gConfig = config;
143 146
144 // Install terrain module in the simulator 147 // Install terrain module in the simulator
@@ -312,6 +315,51 @@ namespace OpenSim.Region.Environment.Modules.Terrain
312 } 315 }
313 } 316 }
314 317
318 public byte[] WriteJpegImage(string gradientmap)
319 {
320 byte[] imageData = null;
321 try
322 {
323 Bitmap bmp = TerrainToBitmap(gradientmap);
324
325 imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true);
326
327 }
328 catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
329 {
330 Console.WriteLine("Failed generating terrain map: " + e.ToString());
331 }
332
333 return imageData;
334 }
335
336 private Bitmap TerrainToBitmap(string gradientmap)
337 {
338 Bitmap gradientmapLd = new Bitmap(gradientmap);
339
340 int pallete = gradientmapLd.Height;
341
342 Bitmap bmp = new Bitmap(m_channel.Width, m_channel.Height);
343 Color[] colours = new Color[pallete];
344
345 for (int i = 0; i < pallete; i++)
346 {
347 colours[i] = gradientmapLd.GetPixel(0, i);
348 }
349
350 TerrainChannel copy =(TerrainChannel) m_channel.MakeCopy();
351 for (int y = 0; y < copy.Height; y++)
352 {
353 for (int x = 0; x < copy.Width; x++)
354 {
355 // 512 is the largest possible height before colours clamp
356 int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1));
357 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
358 }
359 }
360 return bmp;
361 }
362
315 public void PostInitialise() 363 public void PostInitialise()
316 { 364 {
317 InstallDefaultEffects(); 365 InstallDefaultEffects();