aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/UbitMeshing/SculptMap.cs')
-rw-r--r--OpenSim/Region/Physics/UbitMeshing/SculptMap.cs95
1 files changed, 71 insertions, 24 deletions
diff --git a/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs b/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs
index b3d9cb6..1c75db6 100644
--- a/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs
+++ b/OpenSim/Region/Physics/UbitMeshing/SculptMap.cs
@@ -25,14 +25,10 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28// to build without references to System.Drawing, comment this out
29#define SYSTEM_DRAWING
30
31using System; 28using System;
32using System.Collections.Generic; 29using System.Collections.Generic;
33using System.Text; 30using System.Text;
34 31
35#if SYSTEM_DRAWING
36using System.Drawing; 32using System.Drawing;
37using System.Drawing.Imaging; 33using System.Drawing.Imaging;
38 34
@@ -60,11 +56,12 @@ namespace PrimMesher
60 56
61 int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image 57 int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
62 58
63 bool smallMap = bmW * bmH <= numLodPixels;
64 bool needsScaling = false; 59 bool needsScaling = false;
60 bool smallMap = false;
65 61
66 width = bmW; 62 width = bmW;
67 height = bmH; 63 height = bmH;
64
68 while (width * height > numLodPixels * 4) 65 while (width * height > numLodPixels * 4)
69 { 66 {
70 width >>= 1; 67 width >>= 1;
@@ -85,9 +82,12 @@ namespace PrimMesher
85 82
86 if (width * height > numLodPixels) 83 if (width * height > numLodPixels)
87 { 84 {
85 smallMap = false;
88 width >>= 1; 86 width >>= 1;
89 height >>= 1; 87 height >>= 1;
90 } 88 }
89 else
90 smallMap = true;
91 91
92 int numBytes = (width + 1) * (height + 1); 92 int numBytes = (width + 1) * (height + 1);
93 redBytes = new byte[numBytes]; 93 redBytes = new byte[numBytes];
@@ -95,21 +95,18 @@ namespace PrimMesher
95 blueBytes = new byte[numBytes]; 95 blueBytes = new byte[numBytes];
96 96
97 int byteNdx = 0; 97 int byteNdx = 0;
98 Color c;
98 99
99 try 100 try
100 { 101 {
101 for (int y = 0; y <= height; y++) 102 for (int y = 0; y <= height; y++)
102 { 103 {
103 for (int x = 0; x <= width; x++) 104 for (int x = 0; x < width; x++)
104 { 105 {
105 Color c;
106
107 if (smallMap) 106 if (smallMap)
108 c = bm.GetPixel(x < width ? x : x - 1, 107 c = bm.GetPixel(x, y < height ? y : y - 1);
109 y < height ? y : y - 1);
110 else 108 else
111 c = bm.GetPixel(x < width ? x * 2 : x * 2 - 1, 109 c = bm.GetPixel(x * 2, y < height ? y * 2 : y * 2 - 1);
112 y < height ? y * 2 : y * 2 - 1);
113 110
114 redBytes[byteNdx] = c.R; 111 redBytes[byteNdx] = c.R;
115 greenBytes[byteNdx] = c.G; 112 greenBytes[byteNdx] = c.G;
@@ -117,6 +114,17 @@ namespace PrimMesher
117 114
118 ++byteNdx; 115 ++byteNdx;
119 } 116 }
117
118 if (smallMap)
119 c = bm.GetPixel(width - 1, y < height ? y : y - 1);
120 else
121 c = bm.GetPixel(width * 2 - 1, y < height ? y * 2 : y * 2 - 1);
122
123 redBytes[byteNdx] = c.R;
124 greenBytes[byteNdx] = c.G;
125 blueBytes[byteNdx] = c.B;
126
127 ++byteNdx;
120 } 128 }
121 } 129 }
122 catch (Exception e) 130 catch (Exception e)
@@ -140,7 +148,6 @@ namespace PrimMesher
140 int rowNdx, colNdx; 148 int rowNdx, colNdx;
141 int smNdx = 0; 149 int smNdx = 0;
142 150
143
144 for (rowNdx = 0; rowNdx < numRows; rowNdx++) 151 for (rowNdx = 0; rowNdx < numRows; rowNdx++)
145 { 152 {
146 List<Coord> row = new List<Coord>(numCols); 153 List<Coord> row = new List<Coord>(numCols);
@@ -163,16 +170,27 @@ namespace PrimMesher
163 { 170 {
164 171
165 Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb); 172 Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
166 173
167 Color c; 174 Color c;
168 float xscale = srcImage.Width / destWidth;
169 float yscale = srcImage.Height / destHeight;
170 175
176
177 // will let last step to be eventually diferent, as seems to be in sl
178
179 float xscale = (float)srcImage.Width / (float)destWidth;
180 float yscale = (float)srcImage.Height / (float)destHeight;
181
182 int lastsx = srcImage.Width - 1;
183 int lastsy = srcImage.Height - 1;
184 int lastdx = destWidth - 1;
185 int lastdy = destHeight - 1;
186
171 float sy = 0.5f; 187 float sy = 0.5f;
172 for (int y = 0; y < destHeight; y++) 188 float sx;
189
190 for (int y = 0; y < lastdy; y++)
173 { 191 {
174 float sx = 0.5f; 192 sx = 0.5f;
175 for (int x = 0; x < destWidth; x++) 193 for (int x = 0; x < lastdx; x++)
176 { 194 {
177 try 195 try
178 { 196 {
@@ -182,16 +200,45 @@ namespace PrimMesher
182 catch (IndexOutOfRangeException) 200 catch (IndexOutOfRangeException)
183 { 201 {
184 } 202 }
185
186 sx += xscale; 203 sx += xscale;
187 } 204 }
205 try
206 {
207 c = srcImage.GetPixel(lastsx, (int)(sy));
208 scaledImage.SetPixel(lastdx, y, Color.FromArgb(c.R, c.G, c.B));
209 }
210 catch (IndexOutOfRangeException)
211 {
212 }
213
188 sy += yscale; 214 sy += yscale;
189 } 215 }
216
217 sx = 0.5f;
218 for (int x = 0; x < lastdx; x++)
219 {
220 try
221 {
222 c = srcImage.GetPixel((int)(sx), lastsy);
223 scaledImage.SetPixel(x, lastdy, Color.FromArgb(c.R, c.G, c.B));
224 }
225 catch (IndexOutOfRangeException)
226 {
227 }
228
229 sx += xscale;
230 }
231 try
232 {
233 c = srcImage.GetPixel(lastsx, lastsy);
234 scaledImage.SetPixel(lastdx, lastdy, Color.FromArgb(c.R, c.G, c.B));
235 }
236 catch (IndexOutOfRangeException)
237 {
238 }
239
190 srcImage.Dispose(); 240 srcImage.Dispose();
191 return scaledImage; 241 return scaledImage;
192 } 242 }
193
194 }
195
196 } 243 }
197#endif 244} \ No newline at end of file