diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs index 96182cdcb1..da74f30dee 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs @@ -57,6 +57,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static string LogHeader = "[MAP IMAGE SERVICE MODULE]"; private bool m_enabled = false; private IMapImageService m_MapService; @@ -192,47 +193,94 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage 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) + ); + } + } + } + } + } + /// /// /// 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 - byte[] jpgData = Utils.EmptyBytes; IMapImageGenerator tileGenerator = scene.RequestModuleInterface(); 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; } - 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 // is no static map tile. if (mapTile == null) 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); - jpgData = stream.ToArray(); + m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader, + scene.RegionInfo.RegionName, locX, locY, reason); } } - - if (jpgData == Utils.EmptyBytes) + else { - m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Tile image generation failed"); - 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); + m_log.WarnFormat("{0} Tile image generation failed for region {1}", LogHeader, scene.RegionInfo.RegionName); } } }