aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs')
-rw-r--r--OpenSim/OpenSim.Terrain.BasicTerrain/TerrainEngine.cs44
1 files changed, 44 insertions, 0 deletions
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;
30using System.Text; 30using System.Text;
31using System.Drawing; 31using System.Drawing;
32using libTerrain; 32using libTerrain;
33using OpenJPEGNet;
33 34
34namespace OpenSim.Terrain 35namespace OpenSim.Terrain
35{ 36{
@@ -507,5 +508,48 @@ namespace OpenSim.Terrain
507 Console.WriteLine("Failed generating terrain map: " + e.ToString()); 508 Console.WriteLine("Failed generating terrain map: " + e.ToString());
508 } 509 }
509 } 510 }
511
512 /// <summary>
513 /// Exports the current heightmap in Jpeg2000 format to a byte[]
514 /// </summary>
515 /// <param name="gradientmap">A 1x*height* image which contains the colour gradient to export with. Must be at least 1x2 pixels, 1x256 or more is ideal.</param>
516 public byte[] exportJpegImage(string gradientmap)
517 {
518 byte[] imageData = null;
519 try
520 {
521 Bitmap gradientmapLd = new Bitmap(gradientmap);
522
523 int pallete = gradientmapLd.Height;
524
525 Bitmap bmp = new Bitmap(heightmap.w, heightmap.h);
526 Color[] colours = new Color[pallete];
527
528 for (int i = 0; i < pallete; i++)
529 {
530 colours[i] = gradientmapLd.GetPixel(0, i);
531 }
532
533 Channel copy = heightmap.copy();
534 for (int x = 0; x < copy.w; x++)
535 {
536 for (int y = 0; y < copy.h; y++)
537 {
538 // 512 is the largest possible height before colours clamp
539 int colorindex = (int)(Math.Max(Math.Min(1.0, copy.get(copy.w -x, copy.h - y) / 512.0), 0.0) * pallete);
540 bmp.SetPixel(x, y, colours[colorindex]);
541 }
542 }
543
544 //bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
545 imageData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bmp, "map");
546
547 }
548 catch (Exception e)
549 {
550 Console.WriteLine("Failed generating terrain map: " + e.ToString());
551 }
552 return imageData;
553 }
510 } 554 }
511} \ No newline at end of file 555} \ No newline at end of file