aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:16:36 +0000
committerAdam Frisby2008-04-30 21:16:36 +0000
commitf5c312bc3c2567449c7268a54a08a54119f58d53 (patch)
tree424668a4bbec6873ebc5b8256f3671db102f5e9c /OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
parent* Adds the AuthbuyerID field to sqlite and makes use of it. (diff)
downloadopensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.zip
opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz
opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2
opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.xz
* Refactored Environment/Modules directory - modules now reside in their own directory with any associated module-specific classes.
* Each module directory is currently inside one of the following category folders: Agent (Anything relating to do with Client<->Server communications.), Avatar (Anything to do with the avatar or presence inworld), Framework (Classes modules can use), Grid (Grid traffic, new OGS2 grid comms), Scripting (Scripting functions, etc), World (The enrivonment/scene, IE Sun/Tree modules.) * This should be moved into a seperate project file.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs168
1 files changed, 0 insertions, 168 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
deleted file mode 100644
index 763735f..0000000
--- a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs
+++ /dev/null
@@ -1,168 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Drawing;
30using Nini.Config;
31using OpenJPEGNet;
32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Scenes;
34
35namespace OpenSim.Region.Environment.Modules.Terrain
36{
37 internal class MapImageModule : IMapImageGenerator, IRegionModule
38 {
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
63 #region IRegionModule Members
64
65 public void Initialise(Scene scene, IConfigSource source)
66 {
67 m_scene = scene;
68 m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
69 }
70
71 public void PostInitialise()
72 {
73 }
74
75 public void Close()
76 {
77 }
78
79 public string Name
80 {
81 get { return "MapImageModule"; }
82 }
83
84 public bool IsSharedModule
85 {
86 get { return false; }
87 }
88
89 #endregion
90
91 private void ShadeBuildings(ref Bitmap map)
92 {
93 lock (map)
94 {
95 lock (m_scene.Entities)
96 {
97 foreach (EntityBase entity in m_scene.Entities.Values)
98 {
99 if (entity is SceneObjectGroup)
100 {
101 SceneObjectGroup sog = (SceneObjectGroup) entity;
102
103 foreach (SceneObjectPart primitive in sog.Children.Values)
104 {
105 int x, y, w, h;
106 x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
107 y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
108 w = (int) primitive.Scale.X;
109 h = (int) primitive.Scale.Y;
110
111 int dx;
112 for (dx = x; dx < x + w; dx++)
113 {
114 int dy;
115 for (dy = y; dy < y + h; dy++)
116 {
117 if (x < 0 || y < 0)
118 continue;
119 if (x >= map.Width || y >= map.Height)
120 continue;
121
122 map.SetPixel(dx, dy, Color.DarkGray);
123 }
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131
132 private Bitmap TerrainToBitmap(string gradientmap)
133 {
134 Bitmap gradientmapLd = new Bitmap(gradientmap);
135
136 int pallete = gradientmapLd.Height;
137
138 Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height);
139 Color[] colours = new Color[pallete];
140
141 for (int i = 0; i < pallete; i++)
142 {
143 colours[i] = gradientmapLd.GetPixel(0, i);
144 }
145
146 lock (m_scene.Heightmap)
147 {
148 ITerrainChannel copy = m_scene.Heightmap;
149 for (int y = 0; y < copy.Height; y++)
150 {
151 for (int x = 0; x < copy.Width; x++)
152 {
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));
155
156 // Handle error conditions
157 if (colorindex > pallete - 1 || colorindex < 0)
158 bmp.SetPixel(x, copy.Height - y - 1, Color.Red);
159 else
160 bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]);
161 }
162 }
163 ShadeBuildings(ref bmp);
164 return bmp;
165 }
166 }
167 }
168} \ No newline at end of file