varregion: update MapImageServiceModule to upload multiple map tiles for large regions.

avinationmerge
Robert Adams 2015-03-29 17:21:19 -07:00
parent 6081ae3554
commit c0ad5ee81d
1 changed files with 66 additions and 18 deletions

View File

@ -57,6 +57,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
{ {
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static string LogHeader = "[MAP IMAGE SERVICE MODULE]";
private bool m_enabled = false; private bool m_enabled = false;
private IMapImageService m_MapService; private IMapImageService m_MapService;
@ -192,47 +193,94 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
m_lastrefresh = Util.EnvironmentTickCount(); m_lastrefresh = Util.EnvironmentTickCount();
} }
public void UploadMapTile(IScene scene, Bitmap mapTile)
{
m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.Name);
// mapTile.Save( // DEBUG DEBUG
// String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY),
// ImageFormat.Jpeg);
// If the region/maptile is legacy sized, just upload the one tile like it has always been done
if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
{
ConvertAndUploadMaptile(mapTile, scene,
scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY);
}
else
{
// For larger regions (varregion) we must cut the region image into legacy sized
// pieces since that is how the maptile system works.
// Note the assumption that varregions are always a multiple of legacy size.
for (uint xx = 0; xx < mapTile.Width; xx += Constants.RegionSize)
{
for (uint yy = 0; yy < mapTile.Height; yy += Constants.RegionSize)
{
// Images are addressed from the upper left corner so have to do funny
// math to pick out the sub-tile since regions are numbered from
// the lower left.
Rectangle rect = new Rectangle(
(int)xx,
mapTile.Height - (int)yy - (int)Constants.RegionSize,
(int)Constants.RegionSize, (int)Constants.RegionSize);
using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
{
ConvertAndUploadMaptile(subMapTile, scene,
scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize)
);
}
}
}
}
}
///<summary> ///<summary>
/// ///
///</summary> ///</summary>
public void UploadMapTile(IScene scene) public void UploadMapTile(IScene scene)
{ {
m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: upload maptile for {0}", scene.RegionInfo.RegionName); m_log.DebugFormat("{0}: upload maptile for {1}", LogHeader, scene.RegionInfo.RegionName);
// Create a JPG map tile and upload it to the AddMapTile API // Create a JPG map tile and upload it to the AddMapTile API
byte[] jpgData = Utils.EmptyBytes;
IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
if (tileGenerator == null) if (tileGenerator == null)
{ {
m_log.Warn("[MAP IMAGE SERVICE MODULE]: Cannot upload PNG map tile without an ImageGenerator"); m_log.WarnFormat("{0} Cannot upload map tile without an ImageGenerator", LogHeader);
return; return;
} }
using (Image mapTile = tileGenerator.CreateMapTile()) using (Bitmap mapTile = tileGenerator.CreateMapTile())
{ {
// XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there // XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there
// is no static map tile. // is no static map tile.
if (mapTile == null) if (mapTile == null)
return; return;
using (MemoryStream stream = new MemoryStream()) UploadMapTile(scene, mapTile);
}
}
private void ConvertAndUploadMaptile(Image tileImage, IScene scene, uint locX, uint locY)
{
byte[] jpgData = Utils.EmptyBytes;
using (MemoryStream stream = new MemoryStream())
{
tileImage.Save(stream, ImageFormat.Jpeg);
jpgData = stream.ToArray();
}
if (jpgData != Utils.EmptyBytes)
{
string reason = string.Empty;
if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, scene.RegionInfo.ScopeID, out reason))
{ {
mapTile.Save(stream, ImageFormat.Jpeg); m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader,
jpgData = stream.ToArray(); scene.RegionInfo.RegionName, locX, locY, reason);
} }
} }
else
if (jpgData == Utils.EmptyBytes)
{ {
m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Tile image generation failed"); m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, scene.RegionInfo.RegionName);
return;
}
string reason = string.Empty;
if (!m_MapService.AddMapTile((int)scene.RegionInfo.RegionLocX, (int)scene.RegionInfo.RegionLocY, jpgData, scene.RegionInfo.ScopeID, out reason))
{
m_log.DebugFormat("[MAP IMAGE SERVICE MODULE]: Unable to upload tile image for {0} at {1}-{2}: {3}",
scene.RegionInfo.RegionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, reason);
} }
} }
} }