diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs | 69 |
1 files changed, 18 insertions, 51 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs index d5c77ec..e8c719a 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 | |||
128 | colours.Save(stream, ImageFormat.Png); | 128 | colours.Save(stream, ImageFormat.Png); |
129 | } | 129 | } |
130 | 130 | ||
131 | public virtual void SaveFile(ITerrainChannel m_channel, string filename, | 131 | public virtual void SaveFile(ITerrainChannel m_channel, string filename, |
132 | int offsetX, int offsetY, | 132 | int offsetX, int offsetY, |
133 | int fileWidth, int fileHeight, | 133 | int fileWidth, int fileHeight, |
134 | int regionSizeX, int regionSizeY) | 134 | int regionSizeX, int regionSizeY) |
@@ -162,13 +162,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
162 | { | 162 | { |
163 | newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); | 163 | newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); |
164 | } | 164 | } |
165 | 165 | ||
166 | thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); | 166 | thisBitmap = CreateGrayscaleBitmapFromMap(m_channel); |
167 | // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); | 167 | // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY); |
168 | for (int x = 0; x < regionSizeX; x++) | 168 | for (int x = 0; x < regionSizeX; x++) |
169 | for (int y = 0; y < regionSizeY; y++) | 169 | for (int y = 0; y < regionSizeY; y++) |
170 | newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); | 170 | newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y)); |
171 | 171 | ||
172 | Save(newBitmap, filename); | 172 | Save(newBitmap, filename); |
173 | } | 173 | } |
174 | finally | 174 | finally |
@@ -213,8 +213,10 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
213 | /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> | 213 | /// <returns>A System.Drawing.Bitmap containing a grayscale image</returns> |
214 | protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) | 214 | protected static Bitmap CreateGrayscaleBitmapFromMap(ITerrainChannel map) |
215 | { | 215 | { |
216 | // Bitmap bmp = new Bitmap(map.Width, map.Height, PixelFormat.Format24bppRgb); | ||
216 | Bitmap bmp = new Bitmap(map.Width, map.Height); | 217 | Bitmap bmp = new Bitmap(map.Width, map.Height); |
217 | 218 | ||
219 | |||
218 | const int pallete = 256; | 220 | const int pallete = 256; |
219 | 221 | ||
220 | Color[] grays = new Color[pallete]; | 222 | Color[] grays = new Color[pallete]; |
@@ -227,59 +229,24 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders | |||
227 | { | 229 | { |
228 | for (int x = 0; x < map.Width; x++) | 230 | for (int x = 0; x < map.Width; x++) |
229 | { | 231 | { |
230 | // 512 is the largest possible height before colours clamp | 232 | // to change this, loading also needs change |
231 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 128.0), 0.0) * (pallete - 1)); | ||
232 | |||
233 | // Handle error conditions | ||
234 | if (colorindex > pallete - 1 || colorindex < 0) | ||
235 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | ||
236 | else | ||
237 | bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); | ||
238 | } | ||
239 | } | ||
240 | return bmp; | ||
241 | } | ||
242 | |||
243 | /// <summary> | ||
244 | /// Protected method, generates a coloured bitmap | ||
245 | /// image from a specified terrain channel. | ||
246 | /// </summary> | ||
247 | /// <param name="map">The terrain channel to export to bitmap</param> | ||
248 | /// <returns>A System.Drawing.Bitmap containing a coloured image</returns> | ||
249 | protected static Bitmap CreateBitmapFromMap(ITerrainChannel map) | ||
250 | { | ||
251 | int pallete; | ||
252 | Bitmap bmp; | ||
253 | Color[] colours; | ||
254 | 233 | ||
255 | using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png")) | 234 | // int colorindex = (int)map[x, y]; // one to one conversion 0 - 255m range |
256 | { | 235 | // int colorindex = (int)map[x, y] / 2; // 0 - 510 range |
257 | pallete = gradientmapLd.Height; | ||
258 | |||
259 | bmp = new Bitmap(map.Width, map.Height); | ||
260 | colours = new Color[pallete]; | ||
261 | |||
262 | for (int i = 0; i < pallete; i++) | ||
263 | { | ||
264 | colours[i] = gradientmapLd.GetPixel(0, i); | ||
265 | } | ||
266 | } | ||
267 | 236 | ||
268 | for (int y = 0; y < map.Height; y++) | 237 | int colorindex = (int)map[x, y] * 2; // the original 0 - 127.5 range |
269 | { | ||
270 | for (int x = 0; x < map.Width; x++) | ||
271 | { | ||
272 | // 512 is the largest possible height before colours clamp | ||
273 | int colorindex = (int) (Math.Max(Math.Min(1.0, map[x, y] / 512.0), 0.0) * (pallete - 1)); | ||
274 | 238 | ||
275 | // Handle error conditions | 239 | // clamp it not adding the red warning |
276 | if (colorindex > pallete - 1 || colorindex < 0) | 240 | if (colorindex < 0) |
277 | bmp.SetPixel(x, map.Height - y - 1, Color.Red); | 241 | colorindex = 0; |
278 | else | 242 | else if (colorindex >= pallete) |
279 | bmp.SetPixel(x, map.Height - y - 1, colours[colorindex]); | 243 | colorindex = pallete - 1; |
244 | bmp.SetPixel(x, map.Height - y - 1, grays[colorindex]); | ||
280 | } | 245 | } |
281 | } | 246 | } |
282 | return bmp; | 247 | return bmp; |
283 | } | 248 | } |
284 | } | 249 | } |
285 | } | 250 | } |
251 | |||
252 | |||