aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
diff options
context:
space:
mode:
authorJeff Ames2008-05-01 14:31:30 +0000
committerJeff Ames2008-05-01 14:31:30 +0000
commitd51ce47b2d7635b17f3dd429158e8f59b78b83aa (patch)
treed3595bd5194199184059aa398b91a51dc6c799cf /OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
parent* Looks like I had the bamboo build right in the first place - it was just th... (diff)
downloadopensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip
opensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz
opensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2
opensim-SC_OLD-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs334
1 files changed, 167 insertions, 167 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
index dbaec0f..fe26902 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/MapImageModule.cs
@@ -1,168 +1,168 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Drawing; 29using System.Drawing;
30using Nini.Config; 30using Nini.Config;
31using OpenJPEGNet; 31using OpenJPEGNet;
32using OpenSim.Region.Environment.Interfaces; 32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Scenes; 33using OpenSim.Region.Environment.Scenes;
34 34
35namespace OpenSim.Region.Environment.Modules.World.Terrain 35namespace OpenSim.Region.Environment.Modules.World.Terrain
36{ 36{
37 internal class MapImageModule : IMapImageGenerator, IRegionModule 37 internal class MapImageModule : IMapImageGenerator, IRegionModule
38 { 38 {
39 private Scene m_scene; 39 private Scene m_scene;
40 40
41 #region IMapImageGenerator Members 41 #region IMapImageGenerator Members
42 42
43 public byte[] WriteJpeg2000Image(string gradientmap) 43 public byte[] WriteJpeg2000Image(string gradientmap)
44 { 44 {
45 byte[] imageData = null; 45 byte[] imageData = null;
46 46
47 Bitmap bmp = TerrainToBitmap(gradientmap); 47 Bitmap bmp = TerrainToBitmap(gradientmap);
48 48
49 try 49 try
50 { 50 {
51 imageData = OpenJPEG.EncodeFromImage(bmp, true); 51 imageData = OpenJPEG.EncodeFromImage(bmp, true);
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); 55 Console.WriteLine("Failed generating terrain map: " + e);
56 } 56 }
57 57
58 return imageData; 58 return imageData;
59 } 59 }
60 60
61 #endregion 61 #endregion
62 62
63 #region IRegionModule Members 63 #region IRegionModule Members
64 64
65 public void Initialise(Scene scene, IConfigSource source) 65 public void Initialise(Scene scene, IConfigSource source)
66 { 66 {
67 m_scene = scene; 67 m_scene = scene;
68 m_scene.RegisterModuleInterface<IMapImageGenerator>(this); 68 m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
69 } 69 }
70 70
71 public void PostInitialise() 71 public void PostInitialise()
72 { 72 {
73 } 73 }
74 74
75 public void Close() 75 public void Close()
76 { 76 {
77 } 77 }
78 78
79 public string Name 79 public string Name
80 { 80 {
81 get { return "MapImageModule"; } 81 get { return "MapImageModule"; }
82 } 82 }
83 83
84 public bool IsSharedModule 84 public bool IsSharedModule
85 { 85 {
86 get { return false; } 86 get { return false; }
87 } 87 }
88 88
89 #endregion 89 #endregion
90 90
91 private void ShadeBuildings(ref Bitmap map) 91 private void ShadeBuildings(ref Bitmap map)
92 { 92 {
93 lock (map) 93 lock (map)
94 { 94 {
95 lock (m_scene.Entities) 95 lock (m_scene.Entities)
96 { 96 {
97 foreach (EntityBase entity in m_scene.Entities.Values) 97 foreach (EntityBase entity in m_scene.Entities.Values)
98 { 98 {
99 if (entity is SceneObjectGroup) 99 if (entity is SceneObjectGroup)
100 { 100 {
101 SceneObjectGroup sog = (SceneObjectGroup) entity; 101 SceneObjectGroup sog = (SceneObjectGroup) entity;
102 102
103 foreach (SceneObjectPart primitive in sog.Children.Values) 103 foreach (SceneObjectPart primitive in sog.Children.Values)
104 { 104 {
105 int x, y, w, h; 105 int x, y, w, h;
106 x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); 106 x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
107 y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); 107 y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
108 w = (int) primitive.Scale.X; 108 w = (int) primitive.Scale.X;
109 h = (int) primitive.Scale.Y; 109 h = (int) primitive.Scale.Y;
110 110
111 int dx; 111 int dx;
112 for (dx = x; dx < x + w; dx++) 112 for (dx = x; dx < x + w; dx++)
113 { 113 {
114 int dy; 114 int dy;
115 for (dy = y; dy < y + h; dy++) 115 for (dy = y; dy < y + h; dy++)
116 { 116 {
117 if (x < 0 || y < 0) 117 if (x < 0 || y < 0)
118 continue; 118 continue;
119 if (x >= map.Width || y >= map.Height) 119 if (x >= map.Width || y >= map.Height)
120 continue; 120 continue;
121 121
122 map.SetPixel(dx, dy, Color.DarkGray); 122 map.SetPixel(dx, dy, Color.DarkGray);
123 } 123 }
124 } 124 }
125 } 125 }
126 } 126 }
127 } 127 }
128 } 128 }
129 } 129 }
130 } 130 }
131 131
132 private Bitmap TerrainToBitmap(string gradientmap) 132 private Bitmap TerrainToBitmap(string gradientmap)
133 { 133 {
134 Bitmap gradientmapLd = new Bitmap(gradientmap); 134 Bitmap gradientmapLd = new Bitmap(gradientmap);
135 135
136 int pallete = gradientmapLd.Height; 136 int pallete = gradientmapLd.Height;
137 137
138 Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); 138 Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height);
139 Color[] colours = new Color[pallete]; 139 Color[] colours = new Color[pallete];
140 140
141 for (int i = 0; i < pallete; i++) 141 for (int i = 0; i < pallete; i++)
142 { 142 {
143 colours[i] = gradientmapLd.GetPixel(0, i); 143 colours[i] = gradientmapLd.GetPixel(0, i);
144 } 144 }
145 145
146 lock (m_scene.Heightmap) 146 lock (m_scene.Heightmap)
147 { 147 {
148 ITerrainChannel copy = m_scene.Heightmap; 148 ITerrainChannel copy = m_scene.Heightmap;
149 for (int y = 0; y < copy.Height; y++) 149 for (int y = 0; y < copy.Height; y++)
150 { 150 {
151 for (int x = 0; x < copy.Width; x++) 151 for (int x = 0; x < copy.Width; x++)
152 { 152 {
153 // 512 is the largest possible height before colours clamp 153 // 512 is the largest possible height before colours clamp
154 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));
155 155
156 // Handle error conditions 156 // Handle error conditions
157 if (colorindex > pallete - 1 || colorindex < 0) 157 if (colorindex > pallete - 1 || colorindex < 0)
158 bmp.SetPixel(x, copy.Height - y - 1, Color.Red); 158 bmp.SetPixel(x, copy.Height - y - 1, Color.Red);
159 else 159 else
160 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); 160 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
161 } 161 }
162 } 162 }
163 ShadeBuildings(ref bmp); 163 ShadeBuildings(ref bmp);
164 return bmp; 164 return bmp;
165 } 165 }
166 } 166 }
167 } 167 }
168} \ No newline at end of file 168} \ No newline at end of file