From fe5807cd0972e015182a5e64d9ed8e7c77c4f271 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 20 Sep 2015 15:31:38 +0100 Subject: 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 --- .../Terrain/FileLoaders/GenericSystemDrawing.cs | 70 +++++----------------- 1 file changed, 16 insertions(+), 54 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs index d5c77ec..c0b276a 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs @@ -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)); - - // 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; - } - - /// - /// Protected method, generates a coloured bitmap - /// image from a specified terrain channel. - /// - /// The terrain channel to export to bitmap - /// A System.Drawing.Bitmap containing a coloured image - 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]); + 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 + + // 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; } } } + + -- cgit v1.1