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
|
@ -227,59 +227,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
{
|
{
|
||||||
for (int x = 0; x < map.Width; x++)
|
for (int x = 0; x < map.Width; x++)
|
||||||
{
|
{
|
||||||
// 512 is the largest possible height before colours clamp
|
int colorindex = (int)map[x, y]; // one to one conversion as seems apparent on sl docs
|
||||||
int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1));
|
// or 0-511 range?
|
||||||
|
// int colorindex = (int)map[x, y]/2; // 0-511
|
||||||
|
|
||||||
// Handle error conditions
|
// clamp it not adding the red warning
|
||||||
if (colorindex > pallete - 1 || colorindex < 0)
|
if (colorindex < 0)
|
||||||
bmp.SetPixel(x, map.Height - y - 1, Color.Red);
|
colorindex = 0;
|
||||||
else
|
else if (colorindex >= pallete)
|
||||||
|
colorindex = pallete - 1;
|
||||||
bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
|
bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bmp;
|
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]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue