From ef494fdf9c24387c2d98ffde5400f93fa276aa9e Mon Sep 17 00:00:00 2001
From: MW
Date: Sun, 17 Jun 2007 18:04:35 +0000
Subject: Each Region will now generate a texture image of their terrain and
this will be used by the map. Note: Currently each region generates a new
image every time they start; even if the terrain is read from the database.
And also they don't update it when the terrain changes.
---
.../OpenSim.Terrain.BasicTerrain/TerrainEngine.cs | 44 ++++++++++++++++++++++
1 file changed, 44 insertions(+)
(limited to 'OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs')
diff --git a/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
index ecbd078..e5831a0 100644
--- a/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
+++ b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
@@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Text;
using System.Drawing;
using libTerrain;
+using OpenJPEGNet;
namespace OpenSim.Terrain
{
@@ -507,5 +508,48 @@ namespace OpenSim.Terrain
Console.WriteLine("Failed generating terrain map: " + e.ToString());
}
}
+
+ ///
+ /// Exports the current heightmap in Jpeg2000 format to a byte[]
+ ///
+ /// A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal.
+ public byte[] exportJpegImage(string gradientmap)
+ {
+ byte[] imageData = null;
+ try
+ {
+ Bitmap gradientmapLd = new Bitmap(gradientmap);
+
+ int pallete = gradientmapLd.Height;
+
+ Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
+ Color[] colours = new Color[pallete];
+
+ for (int i = 0; i < pallete; i++)
+ {
+ colours[i] = gradientmapLd.GetPixel(0, i);
+ }
+
+ Channel copy = heightmap.copy();
+ for (int x = 0; x < copy.w; x++)
+ {
+ for (int y = 0; y < copy.h; y++)
+ {
+ // 512 is the largest possible height before colours clamp
+ int colorindex = (int)(Math.Max(Math.Min(1.0, copy.get(copy.w -x, copy.h - y) / 512.0), 0.0) * pallete);
+ bmp.SetPixel(x, y, colours[colorindex]);
+ }
+ }
+
+ //bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
+ imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, "map");
+
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Failed generating terrain map: " + e.ToString());
+ }
+ return imageData;
+ }
}
}
\ No newline at end of file
--
cgit v1.1