* 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); 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 namespace OpenSim.Region.Environment.Modules.Terrain
{ {
class MapImageModule : ITerrainTemp, IRegionModule class MapImageModule : IMapImageGenerator, IRegionModule
{ {
private Scene m_scene; private Scene m_scene;
#region IRegionModule Members #region IRegionModule Members
@ -18,7 +18,7 @@ namespace OpenSim.Region.Environment.Modules.Terrain
public void Initialise(Scene scene, IConfigSource source) public void Initialise(Scene scene, IConfigSource source)
{ {
m_scene = scene; m_scene = scene;
m_scene.RegisterModuleInterface<ITerrainTemp>(this); m_scene.RegisterModuleInterface<IMapImageGenerator>(this);
} }
public void PostInitialise() 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; byte[] imageData = null;
Bitmap bmp = TerrainToBitmap(gradientmap);
try try
{ {
Bitmap bmp = TerrainToBitmap(gradientmap);
imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true); imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, true);
} }
catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke 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 // 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)); 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); ShadeBuildings(ref bmp);

View File

@ -984,12 +984,14 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary> /// </summary>
public void CreateTerrainTexture(bool temporary) public void CreateTerrainTexture(bool temporary)
{ {
//TODOADAM: Move this to TerrainModule
//create a texture asset of the terrain //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); Bitmap mapbmp = new Bitmap(256, 256);
double[,] hm = Heightmap.GetDoubles(); double[,] hm = Heightmap.GetDoubles();
@ -1038,50 +1040,50 @@ namespace OpenSim.Region.Environment.Scenes
//if (rt.HitTF) //if (rt.HitTF)
//{ //{
//mapbmp.SetPixel(x, y, prim); //mapbmp.SetPixel(x, y, prim);
//} //}
//else //else
//{ //{
float tmpval = (float)hm[x, y]; float tmpval = (float)hm[x, y];
heightvalue = (float)hm[x, y]; heightvalue = (float)hm[x, y];
if ((float)heightvalue > m_regInfo.EstateSettings.waterHeight) if ((float)heightvalue > m_regInfo.EstateSettings.waterHeight)
{ {
// scale height value // scale height value
heightvalue = low + mid * (heightvalue - low) / mid; heightvalue = low + mid * (heightvalue - low) / mid;
if (heightvalue > 255) if (heightvalue > 255)
heightvalue = 255; heightvalue = 255;
if (heightvalue < 0) if (heightvalue < 0)
heightvalue = 0; heightvalue = 0;
Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue); Color green = Color.FromArgb((int)heightvalue, 100, (int)heightvalue);
// Y flip the cordinates // Y flip the cordinates
mapbmp.SetPixel(x, (256 - y) - 1, green); mapbmp.SetPixel(x, (256 - y) - 1, green);
} }
else else
{ {
// Y flip the cordinates // Y flip the cordinates
heightvalue = m_regInfo.EstateSettings.waterHeight - heightvalue; heightvalue = m_regInfo.EstateSettings.waterHeight - heightvalue;
if (heightvalue > 19) if (heightvalue > 19)
heightvalue = 19; heightvalue = 19;
if (heightvalue < 0) if (heightvalue < 0)
heightvalue = 0; heightvalue = 0;
heightvalue = 100 - (heightvalue * 100) / 19; heightvalue = 100 - (heightvalue * 100) / 19;
if (heightvalue > 255) if (heightvalue > 255)
heightvalue = 255; heightvalue = 255;
if (heightvalue < 0) if (heightvalue < 0)
heightvalue = 0; heightvalue = 0;
Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255); Color water = Color.FromArgb((int)heightvalue, (int)heightvalue, 255);
mapbmp.SetPixel(x, (256 - y) - 1, water); mapbmp.SetPixel(x, (256 - y) - 1, water);
} }
//} //}
@ -1110,10 +1112,9 @@ namespace OpenSim.Region.Environment.Scenes
AssetCache.AddAsset(asset); AssetCache.AddAsset(asset);
} }
else
if (terrain != null)
{ {
byte[] data = terrain.WriteJpegImage("defaultstripe.png"); byte[] data = terrain.WriteJpeg2000Image("defaultstripe.png");
if (data != null) if (data != null)
{ {
m_regInfo.EstateSettings.terrainImageID = LLUUID.Random(); m_regInfo.EstateSettings.terrainImageID = LLUUID.Random();