* Quick patch before I start on a bigger project

* Renamed ITerrainTemp to IMapImageGenerator
* Renamed WriteJpegImage to WriteJpeg2000Image to better reflect it's function.
0.6.0-stable
Adam Frisby 2008-04-15 03:07:31 +00:00
parent b7ae8701ce
commit 0b4a8191a1
3 changed files with 59 additions and 53 deletions

View File

@ -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);
}
}

View File

@ -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<ITerrainTemp>(this);
m_scene.RegisterModuleInterface<IMapImageGenerator>(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);

View File

@ -984,19 +984,21 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary>
public void CreateTerrainTexture(bool temporary)
{
//TODOADAM: Move this to TerrainModule
//create a texture asset of the terrain
ITerrainTemp terrain = RequestModuleInterface<ITerrainTemp>();
IMapImageGenerator terrain = RequestModuleInterface<IMapImageGenerator>();
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 ((float)heightvalue > m_regInfo.EstateSettings.waterHeight)
{
// scale height value
heightvalue = low + mid * (heightvalue - low) / mid;
if (heightvalue > 255)
heightvalue = 255;
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 (heightvalue < 0)
heightvalue = 0;
heightvalue = 100 - (heightvalue * 100) / 19;
if (heightvalue > 255)
heightvalue = 255;
Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue);
if (heightvalue < 0)
heightvalue = 0;
// 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;
Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255);
mapbmp.SetPixel(x, (256 - y) - 1, water);
}
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();