* Enables binary data in BaseHttpServer with 'image' in content type.

* Enables regular jpeg map images to be served directly from the region.
* EX: http://192.168.1.127:9000/index.php?method=regionImagecc4583cd269b41bfa525dd198e19a5c5
* This is actually HTTP server address + port + index.php?method=regionImage<REGIONUUID, no dashes>
* The Webmap image location gets printed on the console when the simulator starts up.
* JPEG data is cached so we only create the webjpeg once.
0.6.0-stable
Teravus Ovares 2008-06-16 22:06:55 +00:00
parent 1898674254
commit 53c9ce46b3
2 changed files with 90 additions and 2 deletions

View File

@ -641,8 +641,17 @@ namespace OpenSim.Framework.Servers
}
response.AddHeader("Content-type", contentType);
byte[] buffer;
byte[] buffer = Encoding.UTF8.GetBytes(responseString);
if (!contentType.Contains("image"))
{
buffer = Encoding.UTF8.GetBytes(responseString);
}
else
{
buffer = Convert.FromBase64String(responseString);
}
response.SendChunked = false;
response.ContentLength64 = buffer.Length;

View File

@ -28,8 +28,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using libsecondlife;
using OpenJPEGNet;
using log4net;
using Nini.Config;
using OpenSim.Framework;
@ -55,6 +59,7 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
private Scene m_scene;
private List<MapBlockData> cachedMapBlocks = new List<MapBlockData>();
private int cachedTime = 0;
private byte[] myMapImageJPEG;
//private int CacheRegionsDistance = 256;
@ -62,8 +67,15 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
public void Initialise(Scene scene, IConfigSource config)
{
myMapImageJPEG = new byte[0];
m_scene = scene;
string regionimage = "regionImage" + scene.RegionInfo.RegionID.ToString();
regionimage = regionimage.Replace("-", "");
m_log.Warn("[WEBMAP]: JPEG Map location: http://" + m_scene.RegionInfo.ExternalEndPoint.Address.ToString() + ":" + m_scene.RegionInfo.HttpPort.ToString() + "/index.php?method=" + regionimage);
m_scene.AddHTTPHandler(regionimage, OnHTTPGetMapImage);
//QuadTree.Subdivide();
//QuadTree.Subdivide();
@ -235,5 +247,72 @@ namespace OpenSim.Region.Environment.Modules.World.WorldMap
mapBlocks = m_scene.CommsManager.GridService.RequestNeighbourMapBlocks(minX - 4, minY - 4, minX + 4, minY + 4);
remoteClient.SendMapBlock(mapBlocks);
}
public Hashtable OnHTTPGetMapImage(Hashtable keysvals)
{
m_log.Info("[WEBMAP]: Sending map image jpeg");
Hashtable reply = new Hashtable();
int statuscode = 200;
byte[] jpeg;
if (myMapImageJPEG.Length == 0)
{
MemoryStream imgstream = new MemoryStream();
Bitmap mapTexture = new Bitmap(1,1);
System.Drawing.Image image = (System.Drawing.Image)mapTexture;
try
{
// Taking our jpeg2000 data, decoding it, then saving it to a byte array with regular jpeg data
imgstream = new MemoryStream();
// non-async because we know we have the asset immediately.
AssetBase mapasset = m_scene.AssetCache.GetAsset(m_scene.RegionInfo.lastMapUUID, true);
// Decode image to System.Drawing.Image
image = OpenJPEG.DecodeToImage(mapasset.Data);
// Save to bitmap
mapTexture = new Bitmap(image);
// Save bitmap to stream
mapTexture.Save(imgstream, ImageFormat.Jpeg);
// Write the stream to a byte array for output
jpeg = imgstream.ToArray();
myMapImageJPEG = jpeg;
}
catch (Exception)
{
// Dummy!
jpeg = new byte[0];
m_log.Warn("[WEBMAP]: Unable to generate Map image");
}
finally
{
// Reclaim memory, these are unmanaged resources
mapTexture.Dispose();
image.Dispose();
imgstream.Close();
imgstream.Dispose();
}
}
else
{
// Use cached version so we don't have to loose our mind
jpeg = myMapImageJPEG;
}
//jpeg = new byte[0];
reply["str_response_string"] = Convert.ToBase64String(jpeg);
reply["int_response_code"] = statuscode;
reply["content_type"] = "image/jpeg";
return reply;
}
}
}