fix terrain save greyscale mapping to 1:1 suporting standard 0-255m range and not only 0-127m. Jpeg format still using a non standard color encoded heightmap

avinationmerge
UbitUmarov 2015-09-20 15:31:38 +01:00
parent 56a4b5ba7a
commit fe5807cd09
1 changed files with 15 additions and 53 deletions

View File

@ -128,7 +128,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
colours.Save(stream, ImageFormat.Png);
}
public virtual void SaveFile(ITerrainChannel m_channel, string filename,
public virtual void SaveFile(ITerrainChannel m_channel, string filename,
int offsetX, int offsetY,
int fileWidth, int fileHeight,
int regionSizeX, int regionSizeY)
@ -162,13 +162,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
{
newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
}
thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
for (int x = 0; x < regionSizeX; x++)
for (int y = 0; y < regionSizeY; y++)
newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
Save(newBitmap, filename);
}
finally
@ -227,59 +227,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
{
for (int x = 0; x < map.Width; x++)
{
// 512 is the largest possible height before colours clamp
int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1));
int colorindex = (int)map[x, y]; // one to one conversion as seems apparent on sl docs
// or 0-511 range?
// int colorindex = (int)map[x, y]/2; // 0-511
// Handle error conditions
if (colorindex > pallete - 1 || colorindex < 0)
bmp.SetPixel(x, map.Height - y - 1, Color.Red);
else
bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
}
}
return bmp;
}
/// <summary>
/// Protected method, generates a coloured bitmap
/// image from a specified terrain channel.
/// </summary>
/// <param name="map">The terrain channel to export to bitmap</param>
/// <returns>A System.Drawing.Bitmap containing a coloured image</returns>
protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{
int pallete;
Bitmap bmp;
Color[] colours;
using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
{
pallete = gradientmapLd.Height;
bmp = new Bitmap(map.Width, map.Height);
colours = new Color[pallete];
for (int i = 0; i < pallete; i++)
{
colours[i] = gradientmapLd.GetPixel(0, i);
}
}
for (int y = 0; y < map.Height; y++)
{
for (int x = 0; x < map.Width; x++)
{
// 512 is the largest possible height before colours clamp
int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1));
// Handle error conditions
if (colorindex > pallete - 1 || colorindex < 0)
bmp.SetPixel(x, map.Height - y - 1, Color.Red);
else
bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]);
// clamp it not adding the red warning
if (colorindex < 0)
colorindex = 0;
else if (colorindex >= pallete)
colorindex = pallete - 1;
bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
}
}
return bmp;
}
}
}