diff options
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs index ebcb440..1dc0d0b 100644 --- a/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/Environment/Modules/World/WorldMap/WorldMapModule.cs | |||
@@ -28,8 +28,12 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Drawing; | ||
32 | using System.Drawing.Imaging; | ||
33 | using System.IO; | ||
31 | using System.Reflection; | 34 | using System.Reflection; |
32 | using libsecondlife; | 35 | using libsecondlife; |
36 | using OpenJPEGNet; | ||
33 | using log4net; | 37 | using log4net; |
34 | using Nini.Config; | 38 | using Nini.Config; |
35 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
@@ -55,6 +59,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
55 | private Scene m_scene; | 59 | private Scene m_scene; |
56 | private List<MapBlockData> cachedMapBlocks = new List<MapBlockData>(); | 60 | private List<MapBlockData> cachedMapBlocks = new List<MapBlockData>(); |
57 | private int cachedTime = 0; | 61 | private int cachedTime = 0; |
62 | private byte[] myMapImageJPEG; | ||
58 | 63 | ||
59 | //private int CacheRegionsDistance = 256; | 64 | //private int CacheRegionsDistance = 256; |
60 | 65 | ||
@@ -62,8 +67,15 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
62 | 67 | ||
63 | public void Initialise(Scene scene, IConfigSource config) | 68 | public void Initialise(Scene scene, IConfigSource config) |
64 | { | 69 | { |
70 | myMapImageJPEG = new byte[0]; | ||
71 | |||
65 | m_scene = scene; | 72 | m_scene = scene; |
66 | 73 | string regionimage = "regionImage" + scene.RegionInfo.RegionID.ToString(); | |
74 | regionimage = regionimage.Replace("-", ""); | ||
75 | m_log.Warn("[WEBMAP]: JPEG Map location: http://" + m_scene.RegionInfo.ExternalEndPoint.Address.ToString() + ":" + m_scene.RegionInfo.HttpPort.ToString() + "/index.php?method=" + regionimage); | ||
76 | |||
77 | |||
78 | m_scene.AddHTTPHandler(regionimage, OnHTTPGetMapImage); | ||
67 | //QuadTree.Subdivide(); | 79 | //QuadTree.Subdivide(); |
68 | //QuadTree.Subdivide(); | 80 | //QuadTree.Subdivide(); |
69 | 81 | ||
@@ -235,5 +247,72 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap | |||
235 | mapBlocks = m_scene.CommsManager.GridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4); | 247 | mapBlocks = m_scene.CommsManager.GridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4); |
236 | remoteClient.SendMapBlock(mapBlocks); | 248 | remoteClient.SendMapBlock(mapBlocks); |
237 | } | 249 | } |
250 | public Hashtable OnHTTPGetMapImage(Hashtable keysvals) | ||
251 | { | ||
252 | m_log.Info("[WEBMAP]: Sending map image jpeg"); | ||
253 | Hashtable reply = new Hashtable(); | ||
254 | int statuscode = 200; | ||
255 | |||
256 | byte[] jpeg; | ||
257 | |||
258 | |||
259 | if (myMapImageJPEG.Length == 0) | ||
260 | { | ||
261 | MemoryStream imgstream = new MemoryStream(); | ||
262 | Bitmap mapTexture = new Bitmap(1,1); | ||
263 | System.Drawing.Image image = (System.Drawing.Image)mapTexture; | ||
264 | |||
265 | |||
266 | try | ||
267 | { | ||
268 | // Taking our jpeg2000 data, decoding it, then saving it to a byte array with regular jpeg data | ||
269 | |||
270 | |||
271 | imgstream = new MemoryStream(); | ||
272 | |||
273 | // non-async because we know we have the asset immediately. | ||
274 | AssetBase mapasset = m_scene.AssetCache.GetAsset(m_scene.RegionInfo.lastMapUUID, true); | ||
275 | |||
276 | // Decode image to System.Drawing.Image | ||
277 | image = OpenJPEG.DecodeToImage(mapasset.Data); | ||
278 | |||
279 | // Save to bitmap | ||
280 | mapTexture = new Bitmap(image); | ||
281 | |||
282 | // Save bitmap to stream | ||
283 | mapTexture.Save(imgstream, ImageFormat.Jpeg); | ||
284 | |||
285 | // Write the stream to a byte array for output | ||
286 | jpeg = imgstream.ToArray(); | ||
287 | myMapImageJPEG = jpeg; | ||
288 | } | ||
289 | catch (Exception) | ||
290 | { | ||
291 | // Dummy! | ||
292 | jpeg = new byte[0]; | ||
293 | m_log.Warn("[WEBMAP]: Unable to generate Map image"); | ||
294 | } | ||
295 | finally | ||
296 | { | ||
297 | // Reclaim memory, these are unmanaged resources | ||
298 | mapTexture.Dispose(); | ||
299 | image.Dispose(); | ||
300 | imgstream.Close(); | ||
301 | imgstream.Dispose(); | ||
302 | } | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | // Use cached version so we don't have to loose our mind | ||
307 | jpeg = myMapImageJPEG; | ||
308 | } | ||
309 | //jpeg = new byte[0]; | ||
310 | |||
311 | reply["str_response_string"] = Convert.ToBase64String(jpeg); | ||
312 | reply["int_response_code"] = statuscode; | ||
313 | reply["content_type"] = "image/jpeg"; | ||
314 | |||
315 | return reply; | ||
316 | } | ||
238 | } | 317 | } |
239 | } | 318 | } |