diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs | 188 |
1 files changed, 94 insertions, 94 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs index 01695de..c4334e0 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs | |||
@@ -1,94 +1,94 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Drawing; | 3 | using System.Drawing; |
4 | using libsecondlife; | 4 | using libsecondlife; |
5 | using Nini.Config; | 5 | using Nini.Config; |
6 | using OpenSim.Framework; | 6 | using OpenSim.Framework; |
7 | using OpenSim.Region.Environment.Interfaces; | 7 | using OpenSim.Region.Environment.Interfaces; |
8 | using OpenSim.Region.Environment.Scenes; | 8 | using OpenSim.Region.Environment.Scenes; |
9 | using OpenSim.Region.Environment.Modules.ModuleFramework; | 9 | using OpenSim.Region.Environment.Modules.ModuleFramework; |
10 | 10 | ||
11 | namespace OpenSim.Region.Environment.Modules.Terrain | 11 | namespace OpenSim.Region.Environment.Modules.Terrain |
12 | { | 12 | { |
13 | class MapImageModule : ITerrainTemp, IRegionModule | 13 | class MapImageModule : ITerrainTemp, IRegionModule |
14 | { | 14 | { |
15 | private Scene m_scene; | 15 | private Scene m_scene; |
16 | #region IRegionModule Members | 16 | #region IRegionModule Members |
17 | 17 | ||
18 | public void Initialise(Scene scene, IConfigSource source) | 18 | public void Initialise(Scene scene, IConfigSource source) |
19 | { | 19 | { |
20 | m_scene = scene; | 20 | m_scene = scene; |
21 | m_scene.RegisterModuleInterface<ITerrainTemp>(this); | 21 | m_scene.RegisterModuleInterface<ITerrainTemp>(this); |
22 | } | 22 | } |
23 | 23 | ||
24 | public void PostInitialise() | 24 | public void PostInitialise() |
25 | { | 25 | { |
26 | } | 26 | } |
27 | 27 | ||
28 | public void Close() | 28 | public void Close() |
29 | { | 29 | { |
30 | } | 30 | } |
31 | 31 | ||
32 | public string Name | 32 | public string Name |
33 | { | 33 | { |
34 | get { return "MapImageModule"; } | 34 | get { return "MapImageModule"; } |
35 | } | 35 | } |
36 | 36 | ||
37 | public bool IsSharedModule | 37 | public bool IsSharedModule |
38 | { | 38 | { |
39 | get { return false; } | 39 | get { return false; } |
40 | } | 40 | } |
41 | 41 | ||
42 | 42 | ||
43 | public byte[] WriteJpegImage(string gradientmap) | 43 | public byte[] WriteJpegImage(string gradientmap) |
44 | { | 44 | { |
45 | byte[] imageData = null; | 45 | byte[] imageData = null; |
46 | try | 46 | try |
47 | { | 47 | { |
48 | Bitmap bmp = TerrainToBitmap(gradientmap); | 48 | Bitmap bmp = TerrainToBitmap(gradientmap); |
49 | 49 | ||
50 | imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true); | 50 | imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true); |
51 | 51 | ||
52 | } | 52 | } |
53 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke | 53 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke |
54 | { | 54 | { |
55 | Console.WriteLine("Failed generating terrain map: " + e.ToString()); | 55 | Console.WriteLine("Failed generating terrain map: " + e.ToString()); |
56 | } | 56 | } |
57 | 57 | ||
58 | return imageData; | 58 | return imageData; |
59 | } | 59 | } |
60 | 60 | ||
61 | private Bitmap TerrainToBitmap(string gradientmap) | 61 | private Bitmap TerrainToBitmap(string gradientmap) |
62 | { | 62 | { |
63 | Bitmap gradientmapLd = new Bitmap(gradientmap); | 63 | Bitmap gradientmapLd = new Bitmap(gradientmap); |
64 | 64 | ||
65 | int pallete = gradientmapLd.Height; | 65 | int pallete = gradientmapLd.Height; |
66 | 66 | ||
67 | Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); | 67 | Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); |
68 | Color[] colours = new Color[pallete]; | 68 | Color[] colours = new Color[pallete]; |
69 | 69 | ||
70 | for (int i = 0; i < pallete; i++) | 70 | for (int i = 0; i < pallete; i++) |
71 | { | 71 | { |
72 | colours[i] = gradientmapLd.GetPixel(0, i); | 72 | colours[i] = gradientmapLd.GetPixel(0, i); |
73 | } | 73 | } |
74 | 74 | ||
75 | lock (m_scene.Heightmap) | 75 | lock (m_scene.Heightmap) |
76 | { | 76 | { |
77 | ITerrainChannel copy = m_scene.Heightmap; | 77 | ITerrainChannel copy = m_scene.Heightmap; |
78 | for (int y = 0; y < copy.Height; y++) | 78 | for (int y = 0; y < copy.Height; y++) |
79 | { | 79 | { |
80 | for (int x = 0; x < copy.Width; x++) | 80 | for (int x = 0; x < copy.Width; x++) |
81 | { | 81 | { |
82 | // 512 is the largest possible height before colours clamp | 82 | // 512 is the largest possible height before colours clamp |
83 | int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); | 83 | int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); |
84 | bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); | 84 | bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); |
85 | } | 85 | } |
86 | } | 86 | } |
87 | } | 87 | } |
88 | return bmp; | 88 | return bmp; |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | #endregion | 92 | #endregion |
93 | } | 93 | } |
94 | } | 94 | } |