/// <summary> /// Copy a source buffer into the tile. The buffer must fit within a single /// tile. /// </summary> /// <param name="destCoordIn"></param> /// <param name="src"></param> public void CopyIn(CoordXZ destCoordIn, MapBuffer src) { Debug.Assert(metersPerSample == src.MetersPerSample); // convert to tile coordinates for this layer CoordXZ destTileCoord = new CoordXZ(destCoordIn, tileSize); // compute the offset in world coordinates within the CoordXZ worldDestCoord = new CoordXZ(destCoordIn, WorldMap.oneMeter); CoordXZ worldDestTileCoord = new CoordXZ(destTileCoord, WorldMap.oneMeter); CoordXZ tileOffset = worldDestCoord - worldDestTileCoord; if (TileExists(destTileCoord)) { // load the tile if necessary if (!TileLoaded(destTileCoord)) { LoadTile(destTileCoord); } } else { // If the tile doesn't exist, then create it. CreateTile(destTileCoord); } // copy the source image into the tile tiles[destTileCoord].Copy(tileOffset.x / metersPerSample, tileOffset.z / metersPerSample, src); }
public void Flush() { foreach (KeyValuePair <CoordXZ, MapBuffer> kvp in tiles) { CoordXZ tileCoord = kvp.Key; MapBuffer buffer = kvp.Value; if ((buffer != null) && buffer.Dirty) { buffer.Save(TilePath(tileCoord)); } } }
protected MapBuffer ScaleDown(int scaleFactor) { int destSize = numSamples / scaleFactor; MapBuffer dest = NewBuffer(map, destSize, metersPerSample * scaleFactor); for (int z = 0; z < destSize; z++) { for (int x = 0; x < destSize; x++) { uint destValue = AverageValue(x * scaleFactor, z * scaleFactor, scaleFactor); dest.SetValue(x, z, destValue); } } return(dest); }
/// <summary> /// Internal method to scale up an image. /// /// XXX - should probably use some better algorithm here. /// </summary> /// <param name="scaleFactor"></param> /// <returns></returns> protected MapBuffer ScaleUp(int scaleFactor) { int destSize = scaleFactor * numSamples; MapBuffer dest = NewBuffer(map, destSize, metersPerSample / scaleFactor); for (int z = 0; z < numSamples; z++) { for (int x = 0; x < numSamples; x++) { uint destValue = GetValue(x, z); dest.Fill(destValue, x * scaleFactor, z * scaleFactor, scaleFactor); } } return(dest); }
public void UnloadTile(CoordXZ tileCoord) { if (TileLoaded(tileCoord)) { MapBuffer buffer = tiles[tileCoord]; if (buffer != null) { if (buffer.Dirty) { buffer.Save(TilePath(tileCoord)); } } tiles.Remove(tileCoord); } }
/// <summary> /// Copies one buffer into an area of another. /// Source buffer must fit within bounds of dest buffer when placed at dest offset. /// Source and dest buffers must be of the same type (MapBuffer16). /// Source and dest buffers must have the same meters per sample. /// </summary> /// <param name="destX">X offset within dest to place src</param> /// <param name="destZ">Z offset within dest to place src</param> /// <param name="src">Source map</param> public override void Copy(int destX, int destZ, MapBuffer src) { Debug.Assert(src is MapBuffer32); Debug.Assert(src.MetersPerSample == metersPerSample); Debug.Assert((destX + src.NumSamples) <= numSamples); Debug.Assert((destZ + src.NumSamples) <= numSamples); MapBuffer32 src32 = src as MapBuffer32; for (int z = 0; z < src.NumSamples; z++) { int srcoff = z * src.NumSamples; int destoff = ((destZ + z) * numSamples) + destX; for (int x = 0; x < src.NumSamples; x++) { buffer[destoff] = src32.buffer[srcoff]; srcoff++; destoff++; } } dirty = true; }
/// <summary> /// Create a thumbnail bitmap of the map area /// </summary> /// <param name="coord"></param> /// <param name="worldSize"></param> /// <param name="pixelSize"></param> /// <returns></returns> public System.Drawing.Bitmap CreateThumbnail(CoordXZ coord, int worldSize, int pixelSize) { int numSamples = worldSize / (metersPerSample * map.OneMeter); Debug.Assert(WorldMap.IsPowerOf2(numSamples)); Debug.Assert(WorldMap.IsPowerOf2(pixelSize)); CoordXZ tileCoord; CoordXZ sampleOffset; bool exact = CoordToTileOffset(coord, out tileCoord, out sampleOffset); // make sure that coordinate is an exact sample Debug.Assert(exact); if (!TileLoaded(tileCoord)) { LoadTile(tileCoord); } MapBuffer tile = tiles[tileCoord]; return(tile.CreateThumbnail(sampleOffset.x, sampleOffset.z, worldSize / (metersPerSample * map.OneMeter), pixelSize)); }
public abstract void Copy(int destX, int destZ, MapBuffer src);