* Added a new method to IMapImageGenerator for getting the map tile before it is JPEG2000 compressed

* Aesthetically improved map tile water
* SimianGrid connector now uploads a PNG tile to the AddMapTile API
soprefactor
John Hurliman 2010-06-11 15:37:25 -07:00
parent 3525195bc9
commit d1a324888b
5 changed files with 116 additions and 33 deletions

View File

@ -70,10 +70,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
#region IMapImageGenerator Members
public byte[] WriteJpeg2000Image(string gradientmap)
public Bitmap CreateMapTile(string gradientmap)
{
byte[] imageData = null;
bool drawPrimVolume = true;
bool textureTerrain = false;
@ -98,32 +96,36 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
}
terrainRenderer.Initialise(m_scene, m_config);
using (Bitmap mapbmp = new Bitmap((int)Constants.RegionSize, (int)Constants.RegionSize))
Bitmap mapbmp = new Bitmap((int)Constants.RegionSize, (int)Constants.RegionSize, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
//long t = System.Environment.TickCount;
//for (int i = 0; i < 10; ++i) {
terrainRenderer.TerrainToBitmap(mapbmp);
//}
//t = System.Environment.TickCount - t;
//m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t);
if (drawPrimVolume)
{
//long t = System.Environment.TickCount;
//for (int i = 0; i < 10; ++i) {
terrainRenderer.TerrainToBitmap(mapbmp);
//}
//t = System.Environment.TickCount - t;
//m_log.InfoFormat("[MAPTILE] generation of 10 maptiles needed {0} ms", t);
if (drawPrimVolume)
{
DrawObjectVolume(m_scene, mapbmp);
}
try
{
imageData = OpenJPEG.EncodeFromImage(mapbmp, true);
}
catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
{
m_log.Error("Failed generating terrain map: " + e);
}
DrawObjectVolume(m_scene, mapbmp);
}
return imageData;
return mapbmp;
}
public byte[] WriteJpeg2000Image(string gradientmap)
{
try
{
using (Bitmap mapbmp = CreateMapTile(gradientmap))
return OpenJPEG.EncodeFromImage(mapbmp, true);
}
catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke
{
m_log.Error("Failed generating terrain map: " + e);
}
return null;
}
#endregion

View File

@ -37,6 +37,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
{
public class ShadedMapTileRenderer : IMapTileTerrainRenderer
{
private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95);
private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -221,8 +223,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
try
{
Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255);
mapbmp.SetPixel(x, yr, water);
mapbmp.SetPixel(x, yr, WATER_COLOR);
}
catch (ArgumentException)
{

View File

@ -136,6 +136,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
private static readonly UUID defaultTerrainTexture4 = new UUID("53a2f406-4895-1d13-d541-d2e3b86bc19c");
private static readonly Color defaultColor4 = Color.FromArgb(200, 200, 200);
private static readonly Color WATER_COLOR = Color.FromArgb(29, 71, 95);
#endregion
@ -406,8 +408,7 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
heightvalue = 100f - (heightvalue * 100f) / 19f; // 0 - 19 => 100 - 0
Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255);
mapbmp.SetPixel(x, yr, water);
mapbmp.SetPixel(x, yr, WATER_COLOR);
}
}
}

View File

@ -73,6 +73,7 @@ namespace OpenSim.Region.Framework.Interfaces
public interface IMapImageGenerator
{
System.Drawing.Bitmap CreateMapTile(string gradientmap);
byte[] WriteJpeg2000Image(string gradientmap);
}
}

View File

@ -28,17 +28,18 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Reflection;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Framework.Servers.HttpServer;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Interfaces;
using OpenSim.Server.Base;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
@ -62,7 +63,7 @@ namespace OpenSim.Services.Connectors.SimianGrid
#region ISharedRegionModule
public Type ReplaceableInterface { get { return null; } }
public void RegionLoaded(Scene scene) { }
public void RegionLoaded(Scene scene) { UploadMapTile(scene); }
public void PostInitialise() { }
public void Close() { }
@ -356,6 +357,83 @@ namespace OpenSim.Services.Connectors.SimianGrid
#endregion IGridService
private void UploadMapTile(IScene scene)
{
string errorMessage = null;
// Create a PNG map tile and upload it to the AddMapTile API
byte[] pngData = Utils.EmptyBytes;
IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
if (tileGenerator == null)
{
m_log.Warn("[SIMIAN GRID CONNECTOR]: Cannot upload PNG map tile without an IMapImageGenerator");
return;
}
using (Image mapTile = tileGenerator.CreateMapTile("defaultstripe.png"))
{
using (MemoryStream stream = new MemoryStream())
{
mapTile.Save(stream, ImageFormat.Png);
pngData = stream.ToArray();
}
}
List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>()
{
new MultipartForm.Parameter("X", scene.RegionInfo.RegionLocX.ToString()),
new MultipartForm.Parameter("Y", scene.RegionInfo.RegionLocY.ToString()),
new MultipartForm.File("Tile", "tile.png", "image/png", pngData)
};
// Make the remote storage request
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_serverUrl);
HttpWebResponse response = MultipartForm.Post(request, postParameters);
using (Stream responseStream = response.GetResponseStream())
{
string responseStr = null;
try
{
responseStr = responseStream.GetStreamString();
OSD responseOSD = OSDParser.Deserialize(responseStr);
if (responseOSD.Type == OSDType.Map)
{
OSDMap responseMap = (OSDMap)responseOSD;
if (responseMap["Success"].AsBoolean())
m_log.Info("[SIMIAN GRID CONNECTOR]: Uploaded " + pngData.Length + " byte PNG map tile to AddMapTile");
else
errorMessage = "Upload failed: " + responseMap["Message"].AsString();
}
else
{
errorMessage = "Response format was invalid:\n" + responseStr;
}
}
catch (Exception ex)
{
if (!String.IsNullOrEmpty(responseStr))
errorMessage = "Failed to parse the response:\n" + responseStr;
else
errorMessage = "Failed to retrieve the response: " + ex.Message;
}
}
}
catch (WebException ex)
{
errorMessage = ex.Message;
}
if (!String.IsNullOrEmpty(errorMessage))
{
m_log.WarnFormat("[SIMIAN GRID CONNECTOR]: Failed to store {0} byte PNG map tile for {1}: {2}",
pngData.Length, scene.RegionInfo.RegionName, errorMessage);
}
}
private GridRegion GetNearestRegion(Vector3d position, bool onlyEnabled)
{
NameValueCollection requestArgs = new NameValueCollection