public override void Save(bool force) { if (!force && !Modified) { return; } string ext = parent.MosaicDesc.FileExt; // swap the z coord of the tiles to deal with our -Z = north coordinate system int loadTileZ = parent.MosaicDesc.SizeZTiles - 1 - tileZ; string tileName = string.Format("{0}_x{1}y{2}.{3}", parent.BaseName, tileX, loadTileZ, ext); string fileName; if (ResourceManager.HasCommonResourceData(tileName)) { fileName = ResourceManager.GetCommonResourceDataFilePath(tileName); } else { string saveDir = parent.MosaicDesc.DefaultTerrainSaveDirectory; fileName = Path.Combine(saveDir, tileName); if (!Directory.Exists(saveDir)) { Directory.CreateDirectory(saveDir); } ResourceManager.AddCommonSearchPath(saveDir); } TaoImage image = new TaoImage(tileSizeSamples, tileSizeSamples, tileData.BytesPerSample, tileData.IlFormat); for (int z = 0; z < tileSizeSamples; z++) { for (int x = 0; x < tileSizeSamples; x++) { uint heightData = tileData.GetData(x, z); image.SetPixel(x, z, heightData); } } if (File.Exists(fileName)) { File.Delete(fileName); } image.Save(fileName); if (Modified) { Modified = false; } }
public void Copy(TaoImage src, int sx, int sy, int dx, int dy, int w, int h) { Debug.Assert(src.bytesPerPixel == bytesPerPixel); Debug.Assert((sx + w) <= src.Width); Debug.Assert((sy + h) <= src.Height); Debug.Assert((dx + w) <= Width); Debug.Assert((dy + h) <= Height); for (int y = 0; y < h; y++) { int destoff = ((dy + y) * Width + dx) * bytesPerPixel; int srcoff = ((sy + y) * src.Width + sx) * bytesPerPixel; for (int x = 0; x < (w * bytesPerPixel); x++) { buffer[destoff + x] = src.buffer[srcoff + x]; } } }
/// <summary> /// Create an image from an area of another image /// </summary> /// <param name="src">source image</param> /// <param name="sx">x offset in source image to copy from</param> /// <param name="sy">y offset in source image to copy from</param> /// <param name="w">width of dest image and area to copy</param> /// <param name="h">width of dest image and area to copy</param> public TaoImage(TaoImage src, int sx, int sy, int w, int h) { format = src.format; bytesPerPixel = src.bytesPerPixel; depth = src.depth; Width = w; Height = h; buffer = new byte[w * h * bytesPerPixel]; int copyw = w; int copyh = h; if ((sx + w) > src.Width) { copyw = src.Width - sx; } if ((sy + h) > src.Height) { copyh = src.Height - sy; } Copy(src, sx, sy, 0, 0, copyw, copyh); }