diff options
author | Justin Clark-Casey (justincc) | 2012-06-06 04:11:16 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-06-06 04:11:16 +0100 |
commit | 2b0de66216ca57cf2eac52e777bb362023f8f30a (patch) | |
tree | 04d7765db2e2b455b5144e4fa6bdc58bade81a74 /OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs | |
parent | enabling all corners of a sim to be set in one call (diff) | |
download | opensim-SC_OLD-2b0de66216ca57cf2eac52e777bb362023f8f30a.zip opensim-SC_OLD-2b0de66216ca57cf2eac52e777bb362023f8f30a.tar.gz opensim-SC_OLD-2b0de66216ca57cf2eac52e777bb362023f8f30a.tar.bz2 opensim-SC_OLD-2b0de66216ca57cf2eac52e777bb362023f8f30a.tar.xz |
Actively dispose of Bitmaps in Warp3D image module and world map module once we've finished with them.
This might help with memory leakage issues though I suspect it won't.
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs index 4f4e296..3538b46 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/MapImageModule.cs | |||
@@ -204,7 +204,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
204 | Bitmap bitmap = renderer.Scene.getImage(); | 204 | Bitmap bitmap = renderer.Scene.getImage(); |
205 | 205 | ||
206 | if (m_useAntiAliasing) | 206 | if (m_useAntiAliasing) |
207 | bitmap = ImageUtils.ResizeImage(bitmap, viewport.Width, viewport.Height); | 207 | { |
208 | using (Bitmap origBitmap = bitmap) | ||
209 | bitmap = ImageUtils.ResizeImage(origBitmap, viewport.Width, viewport.Height); | ||
210 | } | ||
208 | 211 | ||
209 | return bitmap; | 212 | return bitmap; |
210 | } | 213 | } |
@@ -318,8 +321,17 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
318 | uint globalX, globalY; | 321 | uint globalX, globalY; |
319 | Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); | 322 | Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); |
320 | 323 | ||
321 | Bitmap image = TerrainSplat.Splat(heightmap, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain); | 324 | warp_Texture texture; |
322 | warp_Texture texture = new warp_Texture(image); | 325 | |
326 | using ( | ||
327 | Bitmap image | ||
328 | = TerrainSplat.Splat( | ||
329 | heightmap, textureIDs, startHeights, heightRanges, | ||
330 | new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) | ||
331 | { | ||
332 | texture = new warp_Texture(image); | ||
333 | } | ||
334 | |||
323 | warp_Material material = new warp_Material(texture); | 335 | warp_Material material = new warp_Material(texture); |
324 | material.setReflectivity(50); | 336 | material.setReflectivity(50); |
325 | renderer.Scene.addMaterial("TerrainColor", material); | 337 | renderer.Scene.addMaterial("TerrainColor", material); |
@@ -546,42 +558,46 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
546 | { | 558 | { |
547 | try | 559 | try |
548 | { | 560 | { |
549 | Bitmap bitmap = (Bitmap)J2kImage.FromStream(stream); | 561 | int pixelBytes; |
550 | width = bitmap.Width; | ||
551 | height = bitmap.Height; | ||
552 | 562 | ||
553 | BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat); | 563 | using (Bitmap bitmap = (Bitmap)J2kImage.FromStream(stream)) |
554 | int pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4; | ||
555 | |||
556 | // Sum up the individual channels | ||
557 | unsafe | ||
558 | { | 564 | { |
559 | if (pixelBytes == 4) | 565 | width = bitmap.Width; |
566 | height = bitmap.Height; | ||
567 | |||
568 | BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat); | ||
569 | pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4; | ||
570 | |||
571 | // Sum up the individual channels | ||
572 | unsafe | ||
560 | { | 573 | { |
561 | for (int y = 0; y < height; y++) | 574 | if (pixelBytes == 4) |
562 | { | 575 | { |
563 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); | 576 | for (int y = 0; y < height; y++) |
564 | |||
565 | for (int x = 0; x < width; x++) | ||
566 | { | 577 | { |
567 | b += row[x * pixelBytes + 0]; | 578 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); |
568 | g += row[x * pixelBytes + 1]; | 579 | |
569 | r += row[x * pixelBytes + 2]; | 580 | for (int x = 0; x < width; x++) |
570 | a += row[x * pixelBytes + 3]; | 581 | { |
582 | b += row[x * pixelBytes + 0]; | ||
583 | g += row[x * pixelBytes + 1]; | ||
584 | r += row[x * pixelBytes + 2]; | ||
585 | a += row[x * pixelBytes + 3]; | ||
586 | } | ||
571 | } | 587 | } |
572 | } | 588 | } |
573 | } | 589 | else |
574 | else | ||
575 | { | ||
576 | for (int y = 0; y < height; y++) | ||
577 | { | 590 | { |
578 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); | 591 | for (int y = 0; y < height; y++) |
579 | |||
580 | for (int x = 0; x < width; x++) | ||
581 | { | 592 | { |
582 | b += row[x * pixelBytes + 0]; | 593 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); |
583 | g += row[x * pixelBytes + 1]; | 594 | |
584 | r += row[x * pixelBytes + 2]; | 595 | for (int x = 0; x < width; x++) |
596 | { | ||
597 | b += row[x * pixelBytes + 0]; | ||
598 | g += row[x * pixelBytes + 1]; | ||
599 | r += row[x * pixelBytes + 2]; | ||
600 | } | ||
585 | } | 601 | } |
586 | } | 602 | } |
587 | } | 603 | } |