コード例 #1
0
        /// <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);
        }
コード例 #2
0
        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));
                }
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        /// <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;
        }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
 public abstract void Copy(int destX, int destZ, MapBuffer src);
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        /// <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;
        }
コード例 #11
0
 public abstract void Copy(int destX, int destZ, MapBuffer src);