30 using System.Drawing.Imaging;
32 using OpenSim.Region.Framework.Interfaces;
33 using OpenSim.Region.Framework.Scenes;
45 #region ITerrainLoader Members
47 public string FileExtension
49 get {
return ".gsd"; }
62 using (Bitmap b =
new Bitmap(filename))
66 public virtual ITerrainChannel LoadFile(
string filename,
int offsetX,
int offsetY,
int fileWidth,
int fileHeight,
int w,
int h)
68 using (Bitmap bitmap =
new Bitmap(filename))
72 for (
int x = 0; x < retval.Width; x++)
74 for (
int y = 0; y < retval.Height; y++)
76 retval[x, y] = bitmap.GetPixel(offsetX * retval.Width + x, (bitmap.Height - (retval.Height * (offsetY + 1))) + retval.
Height - y - 1).GetBrightness() * 128;
86 using (Bitmap b =
new Bitmap(stream))
95 for (x = 0; x < bitmap.Width; x++)
98 for (y = 0; y < bitmap.Height; y++)
100 retval[x, y] = bitmap.GetPixel(x, bitmap.Height - y - 1).GetBrightness() * 128;
114 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
116 colours.Save(filename, ImageFormat.Png);
126 Bitmap colours = CreateGrayscaleBitmapFromMap(map);
128 colours.Save(stream, ImageFormat.Png);
132 int offsetX,
int offsetY,
133 int fileWidth,
int fileHeight,
134 int regionSizeX,
int regionSizeY)
139 string tempName = Path.GetTempFileName();
141 Bitmap existingBitmap = null;
142 Bitmap thisBitmap = null;
143 Bitmap newBitmap = null;
147 if (File.Exists(filename))
149 File.Copy(filename, tempName,
true);
150 existingBitmap =
new Bitmap(tempName);
151 if (existingBitmap.Width != fileWidth * regionSizeX || existingBitmap.Height != fileHeight * regionSizeY)
154 newBitmap =
new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
158 newBitmap = existingBitmap;
163 newBitmap =
new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
168 for (
int x = 0; x < regionSizeX; x++)
169 for (
int y = 0; y < regionSizeY; y++)
170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
172 Save(newBitmap, filename);
176 if (existingBitmap != null)
177 existingBitmap.Dispose();
179 if (thisBitmap != null)
180 thisBitmap.Dispose();
182 if (newBitmap != null)
185 if (File.Exists(tempName))
186 File.Delete(tempName);
190 protected virtual void Save(Bitmap bmp,
string filename)
192 bmp.Save(filename, ImageFormat.Png);
199 return "SYS.DRAWING";
220 const int pallete = 256;
222 Color[] grays =
new Color[pallete];
223 for (
int i = 0; i < grays.Length; i++)
225 grays[i] = Color.FromArgb(i, i, i);
228 for (
int y = 0; y < map.Height; y++)
230 for (
int x = 0; x < map.Width; x++)
237 int colorindex = (int)map[x, y] * 2;
242 else if (colorindex >= pallete)
243 colorindex = pallete - 1;
244 bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]);
virtual ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int w, int h)
virtual void SaveFile(ITerrainChannel m_channel, string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int regionSizeX, int regionSizeY)
Save a number of map tiles to a single big image file.
virtual void Save(Bitmap bmp, string filename)
virtual void SaveStream(Stream stream, ITerrainChannel map)
Exports a stream using a System.Drawing exporter.
static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map)
Protected method, generates a grayscale bitmap image from a specified terrain channel.
virtual ITerrainChannel LoadStream(Stream stream)
virtual ITerrainChannel LoadBitmap(Bitmap bitmap)
virtual bool SupportsTileSave()
A new version of the old Channel class, simplified
A virtual class designed to have methods overloaded, this class provides an interface for a generic i...
override string ToString()
virtual void SaveFile(string filename, ITerrainChannel map)
Exports a file to a image on the disk using a System.Drawing exporter.
virtual ITerrainChannel LoadFile(string filename)
Loads a file from a specified filename on the disk, parses the image using the System.Drawing parsers then returns a terrain channel. Values are returned based on HSL brightness between 0m and 128m