From 0b4a8191a1d69294fa95381bfe7f2fa2aa400cfb Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Tue, 15 Apr 2008 03:07:31 +0000 Subject: * Quick patch before I start on a bigger project * Renamed ITerrainTemp to IMapImageGenerator * Renamed WriteJpegImage to WriteJpeg2000Image to better reflect it's function. --- OpenSim/Region/Environment/Interfaces/ITerrain.cs | 4 +- .../Environment/Modules/Terrain/MapImageModule.cs | 19 +++-- OpenSim/Region/Environment/Scenes/Scene.cs | 93 +++++++++++----------- 3 files changed, 61 insertions(+), 55 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Interfaces/ITerrain.cs b/OpenSim/Region/Environment/Interfaces/ITerrain.cs index 2cef17e..d5e1540 100644 --- a/OpenSim/Region/Environment/Interfaces/ITerrain.cs +++ b/OpenSim/Region/Environment/Interfaces/ITerrain.cs @@ -71,8 +71,8 @@ namespace OpenSim.Region.Environment.Interfaces byte[] ExportJpegImage(string gradientmap); } - public interface ITerrainTemp + public interface IMapImageGenerator { - byte[] WriteJpegImage(string gradientmap); + byte[] WriteJpeg2000Image(string gradientmap); } } diff --git a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs index c791ac3..458d781 100644 --- a/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs +++ b/OpenSim/Region/Environment/Modules/Terrain/MapImageModule.cs @@ -10,7 +10,7 @@ using OpenSim.Region.Environment.Modules.ModuleFramework; namespace OpenSim.Region.Environment.Modules.Terrain { - class MapImageModule : ITerrainTemp, IRegionModule + class MapImageModule : IMapImageGenerator, IRegionModule { private Scene m_scene; #region IRegionModule Members @@ -18,7 +18,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain public void Initialise(Scene scene, IConfigSource source) { m_scene = scene; - m_scene.RegisterModuleInterface(this); + m_scene.RegisterModuleInterface(this); } public void PostInitialise() @@ -40,15 +40,15 @@ namespace OpenSim.Region.Environment.Modules.Terrain } - public byte[] WriteJpegImage(string gradientmap) + public byte[] WriteJpeg2000Image(string gradientmap) { byte[] imageData = null; + + Bitmap bmp = TerrainToBitmap(gradientmap); + try { - Bitmap bmp = TerrainToBitmap(gradientmap); - imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true); - } catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke { @@ -122,7 +122,12 @@ namespace OpenSim.Region.Environment.Modules.Terrain { // 512 is the largest possible height before colours clamp int colorindex = (int)(Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); - bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); + + // Handle error conditions + if (colorindex > pallete - 1 || colorindex < 0) + bmp.SetPixel(x, copy.Height - y - 1, Color.Red); + else + bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); } } ShadeBuildings(ref bmp); diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index b93367c..ba8a356 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -984,19 +984,21 @@ namespace OpenSim.Region.Environment.Scenes /// public void CreateTerrainTexture(bool temporary) { - //TODOADAM: Move this to TerrainModule - //create a texture asset of the terrain - ITerrainTemp terrain = RequestModuleInterface(); + IMapImageGenerator terrain = RequestModuleInterface(); - if (Heightmap != null) + // Cannot create a map for a nonexistant heightmap yet. + if (Heightmap == null) + return; + + if (terrain == null) { Bitmap mapbmp = new Bitmap(256, 256); double[,] hm = Heightmap.GetDoubles(); float heightvalue = 0; - + Color prim = Color.FromArgb(120, 120, 120); LLVector3 RayEnd = new LLVector3(0, 0, 0); LLVector3 RayStart = new LLVector3(0, 0, 0); @@ -1038,50 +1040,50 @@ namespace OpenSim.Region.Environment.Scenes //if (rt.HitTF) //{ - //mapbmp.SetPixel(x, y, prim); + //mapbmp.SetPixel(x, y, prim); //} //else //{ - float tmpval = (float)hm[x, y]; - heightvalue = (float)hm[x, y]; + float tmpval = (float)hm[x, y]; + heightvalue = (float)hm[x, y]; - if ((float)heightvalue > m_regInfo.EstateSettings.waterHeight) - { - // scale height value - heightvalue = low + mid * (heightvalue - low) / mid; - - if (heightvalue > 255) - heightvalue = 255; - - if (heightvalue < 0) - heightvalue = 0; - - - Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue); - - // Y flip the cordinates - mapbmp.SetPixel(x, (256 - y) - 1, green); - } - else - { - // Y flip the cordinates - heightvalue = m_regInfo.EstateSettings.waterHeight - heightvalue; - if (heightvalue > 19) - heightvalue = 19; - if (heightvalue < 0) - heightvalue = 0; + if ((float)heightvalue > m_regInfo.EstateSettings.waterHeight) + { + // scale height value + heightvalue = low + mid * (heightvalue - low) / mid; - heightvalue = 100 - (heightvalue * 100) / 19; + if (heightvalue > 255) + heightvalue = 255; - if (heightvalue > 255) - heightvalue = 255; + if (heightvalue < 0) + heightvalue = 0; - if (heightvalue < 0) - heightvalue = 0; - Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255); - mapbmp.SetPixel(x, (256 - y) - 1, water); - } + Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue); + + // Y flip the cordinates + mapbmp.SetPixel(x, (256 - y) - 1, green); + } + else + { + // Y flip the cordinates + heightvalue = m_regInfo.EstateSettings.waterHeight - heightvalue; + if (heightvalue > 19) + heightvalue = 19; + if (heightvalue < 0) + heightvalue = 0; + + heightvalue = 100 - (heightvalue * 100) / 19; + + if (heightvalue > 255) + heightvalue = 255; + + if (heightvalue < 0) + heightvalue = 0; + + Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255); + mapbmp.SetPixel(x, (256 - y) - 1, water); + } //} @@ -1098,7 +1100,7 @@ namespace OpenSim.Region.Environment.Scenes { return; } - + m_regInfo.EstateSettings.terrainImageID = LLUUID.Random(); AssetBase asset = new AssetBase(); asset.FullID = m_regInfo.EstateSettings.terrainImageID; @@ -1108,12 +1110,11 @@ namespace OpenSim.Region.Environment.Scenes asset.Type = 0; asset.Temporary = temporary; AssetCache.AddAsset(asset); - - } - if (terrain != null) + } + else { - byte[] data = terrain.WriteJpegImage("defaultstripe.png"); + byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png"); if (data != null) { m_regInfo.EstateSettings.terrainImageID = LLUUID.Random(); -- cgit v1.1