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
parent
56a4b5ba7a
commit
fe5807cd09
|
@ -164,7 +164,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
|||
}
|
||||
|
||||
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));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue