29 using System.Collections.Generic;
33 using System.Drawing.Imaging;
37 public class SculptMap
54 if (bmW == 0 || bmH == 0)
55 throw new Exception(
"SculptMap: bitmap has no data");
57 int numLodPixels = lod * lod;
59 bool needsScaling =
false;
60 bool smallMap =
false;
80 throw new Exception(
"Exception in ScaleImage(): e: " + e.ToString());
102 for (
int y = 0; y <=
height; y++)
104 for (
int x = 0; x <
width; x++)
107 c = bm.GetPixel(x, y <
height ? y : y - 1);
109 c = bm.GetPixel(x * 2, y <
height ? y * 2 : y * 2 - 1);
119 c = bm.GetPixel(width - 1, y <
height ? y : y - 1);
121 c = bm.GetPixel(width * 2 - 1, y <
height ? y * 2 : y * 2 - 1);
132 throw new Exception(
"Caught exception processing byte arrays in SculptMap(): e: " + e.ToString());
139 public List<List<Coord>>
ToRows(
bool mirror)
144 List<List<Coord>> rows =
new List<List<Coord>>(numRows);
146 float pixScale = 1.0f / 255;
151 for (rowNdx = 0; rowNdx < numRows; rowNdx++)
153 List<Coord> row =
new List<Coord>(numCols);
154 for (colNdx = 0; colNdx < numCols; colNdx++)
169 private Bitmap ScaleImage(Bitmap srcImage,
int destWidth,
int destHeight)
172 Bitmap scaledImage =
new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
179 float xscale = (float)srcImage.Width / (
float)destWidth;
180 float yscale = (float)srcImage.Height / (
float)destHeight;
182 int lastsx = srcImage.Width - 1;
183 int lastsy = srcImage.Height - 1;
184 int lastdx = destWidth - 1;
185 int lastdy = destHeight - 1;
190 for (
int y = 0; y < lastdy; y++)
193 for (
int x = 0; x < lastdx; x++)
197 c = srcImage.GetPixel((int)(sx), (int)(sy));
198 scaledImage.SetPixel(x, y, Color.FromArgb(c.R, c.G, c.B));
200 catch (IndexOutOfRangeException)
207 c = srcImage.GetPixel(lastsx, (int)(sy));
208 scaledImage.SetPixel(lastdx, y, Color.FromArgb(c.R, c.G, c.B));
210 catch (IndexOutOfRangeException)
218 for (
int x = 0; x < lastdx; x++)
222 c = srcImage.GetPixel((int)(sx), lastsy);
223 scaledImage.SetPixel(x, lastdy, Color.FromArgb(c.R, c.G, c.B));
225 catch (IndexOutOfRangeException)
233 c = srcImage.GetPixel(lastsx, lastsy);
234 scaledImage.SetPixel(lastdx, lastdy, Color.FromArgb(c.R, c.G, c.B));
236 catch (IndexOutOfRangeException)
SculptMap(Bitmap bm, int lod)
List< List< Coord > > ToRows(bool mirror)