diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs index 96b5d52..763735f 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs | |||
@@ -26,20 +26,40 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
30 | using System.Drawing; | 29 | using System.Drawing; |
31 | using libsecondlife; | ||
32 | using Nini.Config; | 30 | using Nini.Config; |
33 | using OpenSim.Framework; | 31 | using OpenJPEGNet; |
34 | using OpenSim.Region.Environment.Interfaces; | 32 | using OpenSim.Region.Environment.Interfaces; |
35 | using OpenSim.Region.Environment.Scenes; | 33 | using OpenSim.Region.Environment.Scenes; |
36 | using OpenSim.Region.Environment.Modules.ModuleFramework; | ||
37 | 34 | ||
38 | namespace OpenSim.Region.Environment.Modules.Terrain | 35 | namespace OpenSim.Region.Environment.Modules.Terrain |
39 | { | 36 | { |
40 | class MapImageModule : IMapImageGenerator, IRegionModule | 37 | internal class MapImageModule : IMapImageGenerator, IRegionModule |
41 | { | 38 | { |
42 | private Scene m_scene; | 39 | private Scene m_scene; |
40 | |||
41 | #region IMapImageGenerator Members | ||
42 | |||
43 | public byte[] WriteJpeg2000Image(string gradientmap) | ||
44 | { | ||
45 | byte[] imageData = null; | ||
46 | |||
47 | Bitmap bmp = TerrainToBitmap(gradientmap); | ||
48 | |||
49 | try | ||
50 | { | ||
51 | imageData = OpenJPEG.EncodeFromImage(bmp, true); | ||
52 | } | ||
53 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
54 | { | ||
55 | Console.WriteLine("Failed generating terrain map: " + e); | ||
56 | } | ||
57 | |||
58 | return imageData; | ||
59 | } | ||
60 | |||
61 | #endregion | ||
62 | |||
43 | #region IRegionModule Members | 63 | #region IRegionModule Members |
44 | 64 | ||
45 | public void Initialise(Scene scene, IConfigSource source) | 65 | public void Initialise(Scene scene, IConfigSource source) |
@@ -66,24 +86,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
66 | get { return false; } | 86 | get { return false; } |
67 | } | 87 | } |
68 | 88 | ||
69 | 89 | #endregion | |
70 | public byte[] WriteJpeg2000Image(string gradientmap) | ||
71 | { | ||
72 | byte[] imageData = null; | ||
73 | |||
74 | Bitmap bmp = TerrainToBitmap(gradientmap); | ||
75 | |||
76 | try | ||
77 | { | ||
78 | imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true); | ||
79 | } | ||
80 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
81 | { | ||
82 | Console.WriteLine("Failed generating terrain map: " + e.ToString()); | ||
83 | } | ||
84 | |||
85 | return imageData; | ||
86 | } | ||
87 | 90 | ||
88 | private void ShadeBuildings(ref Bitmap map) | 91 | private void ShadeBuildings(ref Bitmap map) |
89 | { | 92 | { |
@@ -95,18 +98,20 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
95 | { | 98 | { |
96 | if (entity is SceneObjectGroup) | 99 | if (entity is SceneObjectGroup) |
97 | { | 100 | { |
98 | SceneObjectGroup sog = (SceneObjectGroup)entity; | 101 | SceneObjectGroup sog = (SceneObjectGroup) entity; |
99 | 102 | ||
100 | foreach (SceneObjectPart primitive in sog.Children.Values) | 103 | foreach (SceneObjectPart primitive in sog.Children.Values) |
101 | { | 104 | { |
102 | int x, y, w, h, dx, dy; | 105 | int x, y, w, h; |
103 | x = (int)(primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); | 106 | x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); |
104 | y = (int)(primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); | 107 | y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); |
105 | w = (int)primitive.Scale.X; | 108 | w = (int) primitive.Scale.X; |
106 | h = (int)primitive.Scale.Y; | 109 | h = (int) primitive.Scale.Y; |
107 | 110 | ||
111 | int dx; | ||
108 | for (dx = x; dx < x + w; dx++) | 112 | for (dx = x; dx < x + w; dx++) |
109 | { | 113 | { |
114 | int dy; | ||
110 | for (dy = y; dy < y + h; dy++) | 115 | for (dy = y; dy < y + h; dy++) |
111 | { | 116 | { |
112 | if (x < 0 || y < 0) | 117 | if (x < 0 || y < 0) |
@@ -117,8 +122,6 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
117 | map.SetPixel(dx, dy, Color.DarkGray); | 122 | map.SetPixel(dx, dy, Color.DarkGray); |
118 | } | 123 | } |
119 | } | 124 | } |
120 | |||
121 | |||
122 | } | 125 | } |
123 | } | 126 | } |
124 | } | 127 | } |
@@ -148,7 +151,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
148 | for (int x = 0; x < copy.Width; x++) | 151 | for (int x = 0; x < copy.Width; x++) |
149 | { | 152 | { |
150 | // 512 is the largest possible height before colours clamp | 153 | // 512 is the largest possible height before colours clamp |
151 | int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); | 154 | int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); |
152 | 155 | ||
153 | // Handle error conditions | 156 | // Handle error conditions |
154 | if (colorindex > pallete - 1 || colorindex < 0) | 157 | if (colorindex > pallete - 1 || colorindex < 0) |
@@ -161,7 +164,5 @@ namespace OpenSim.Region.Environment.Modules.Terrain | |||
161 | return bmp; | 164 | return bmp; |
162 | } | 165 | } |
163 | } | 166 | } |
164 | |||
165 | #endregion | ||
166 | } | 167 | } |
167 | } | 168 | } \ No newline at end of file |