GetTileBitmap() 공개 메소드

public GetTileBitmap ( SymbolID symbolID, int size ) : System.Windows.Media.Imaging.BitmapSource
symbolID SymbolID
size int
리턴 System.Windows.Media.Imaging.BitmapSource
예제 #1
0
        static void CreatePng(TileSetLoader loader, string dstPath)
        {
            int numSymbols = EnumHelpers.GetEnumMax <SymbolID>() + 1;

            int[] tileSizes = new int[] {
                8, 10, 12,
                16, 20, 24,
                32, 40, 48,
                64, 80, 96
            };

            int maxTileSize = tileSizes.Max();

            WriteableBitmap target = new WriteableBitmap(tileSizes.Sum(), maxTileSize * numSymbols, 96, 96,
                                                         PixelFormats.Bgra32, null);

            target.Lock();

            // leave the first one (Undefined) empty
            for (int i = 1; i < numSymbols; ++i)
            {
                int xOffset = 0;

                foreach (int tileSize in tileSizes)
                {
                    var source = loader.GetTileBitmap((SymbolID)i, tileSize);

                    int    stride = source.PixelWidth * (source.Format.BitsPerPixel / 8);
                    byte[] data   = new byte[stride * source.PixelHeight];

                    source.CopyPixels(data, stride, 0);

                    target.WritePixels(new Int32Rect(xOffset, i * maxTileSize, tileSize, tileSize), data, stride, 0);

                    xOffset += tileSize;
                }
            }

            target.Unlock();

            string tileSizesStr = string.Join(",", tileSizes.Select(i => i.ToString()));
            var    pngEncoder   = new PngBitmapEncoder();
            var    metadata     = new BitmapMetadata("png");

            metadata.SetQuery("/tEXt/Software", "Dwarrowdelf");
            metadata.SetQuery("/tEXt/tilesizes", tileSizesStr);
            var frame = BitmapFrame.Create(target, null, metadata, null);

            pngEncoder.Frames = new BitmapFrame[] { frame };

            string path = Path.Combine(dstPath, "TileSet.png");

            using (var stream = File.OpenWrite(path))
                pngEncoder.Save(stream);

            Console.WriteLine("Generated TileSet to {0}", path);
        }
예제 #2
0
        static void CreateDds(GraphicsDevice device, TileSetLoader loader, string dstPath)
        {
            int numDistinctBitmaps = EnumHelpers.GetEnumMax<SymbolID>() + 1;

            const int bytesPerPixel = 4;
            int maxTileSize = 64;
            int mipLevels = 6; // 64, 32, 16, 8, 4, 2

            var atlasTexture = Texture2D.New(device, maxTileSize, maxTileSize, mipLevels,
                SharpDX.Toolkit.Graphics.PixelFormat.B8G8R8A8.UNorm, TextureFlags.None, numDistinctBitmaps,
                D3D11.ResourceUsage.Default);

            //int autoGenMipLevel = 0;

            for (int mipLevel = 0; mipLevel < mipLevels; ++mipLevel)
            {
                int tileSize = maxTileSize >> mipLevel;

                /*
                if (tileSet.HasTileSize(tileSize) == false)
                {
                    autoGenMipLevel = mipLevel - 1;
                    break;
                }
                */

                // leave the first one (Undefined) empty
                for (int i = 1; i < numDistinctBitmaps; ++i)
                {
                    var bmp = loader.GetTileBitmap((SymbolID)i, tileSize);

                    int pitch = tileSize * bytesPerPixel;

                    var arr = new uint[tileSize * tileSize];

                    bmp.CopyPixels(arr, pitch, 0);

                    using (var txt = Texture2D.New(device, tileSize, tileSize, SharpDX.Toolkit.Graphics.PixelFormat.B8G8R8A8.UNorm, arr))
                        device.Copy(txt, 0, atlasTexture, atlasTexture.GetSubResourceIndex(i, mipLevel));
                }
            }

            // Generate mipmaps for the smallest tiles
            //atlasTexture.FilterTexture(device.ImmediateContext, autoGenMipLevel, FilterFlags.Triangle);

            string path = Path.Combine(dstPath, "TileSet.dds");

            atlasTexture.Save(path, ImageFileType.Dds);

            Console.WriteLine("Generated TileSet to {0}", path);
        }
예제 #3
0
        static void CreateDds(GraphicsDevice device, TileSetLoader loader, string dstPath)
        {
            int numDistinctBitmaps = EnumHelpers.GetEnumMax <SymbolID>() + 1;

            const int bytesPerPixel = 4;
            int       maxTileSize   = 64;
            int       mipLevels     = 6;   // 64, 32, 16, 8, 4, 2

            var atlasTexture = Texture2D.New(device, maxTileSize, maxTileSize, mipLevels,
                                             SharpDX.Toolkit.Graphics.PixelFormat.B8G8R8A8.UNorm, TextureFlags.None, numDistinctBitmaps,
                                             D3D11.ResourceUsage.Default);

            //int autoGenMipLevel = 0;

            for (int mipLevel = 0; mipLevel < mipLevels; ++mipLevel)
            {
                int tileSize = maxTileSize >> mipLevel;

                /*
                 * if (tileSet.HasTileSize(tileSize) == false)
                 * {
                 *      autoGenMipLevel = mipLevel - 1;
                 *      break;
                 * }
                 */

                // leave the first one (Undefined) empty
                for (int i = 1; i < numDistinctBitmaps; ++i)
                {
                    var bmp = loader.GetTileBitmap((SymbolID)i, tileSize);

                    int pitch = tileSize * bytesPerPixel;

                    var arr = new uint[tileSize * tileSize];

                    bmp.CopyPixels(arr, pitch, 0);

                    using (var txt = Texture2D.New(device, tileSize, tileSize, SharpDX.Toolkit.Graphics.PixelFormat.B8G8R8A8.UNorm, arr))
                        device.Copy(txt, 0, atlasTexture, atlasTexture.GetSubResourceIndex(i, mipLevel));
                }
            }

            // Generate mipmaps for the smallest tiles
            //atlasTexture.FilterTexture(device.ImmediateContext, autoGenMipLevel, FilterFlags.Triangle);

            string path = Path.Combine(dstPath, "TileSet.dds");

            atlasTexture.Save(path, ImageFileType.Dds);

            Console.WriteLine("Generated TileSet to {0}", path);
        }
예제 #4
0
        static void CreatePng(TileSetLoader loader, string dstPath)
        {
            int numSymbols = EnumHelpers.GetEnumMax<SymbolID>() + 1;

            int[] tileSizes = new int[] {
                8, 10, 12,
                16, 20, 24,
                32, 40, 48,
                64, 80, 96
            };

            int maxTileSize = tileSizes.Max();

            WriteableBitmap target = new WriteableBitmap(tileSizes.Sum(), maxTileSize * numSymbols, 96, 96,
                PixelFormats.Bgra32, null);

            target.Lock();

            // leave the first one (Undefined) empty
            for (int i = 1; i < numSymbols; ++i)
            {
                int xOffset = 0;

                foreach (int tileSize in tileSizes)
                {
                    var source = loader.GetTileBitmap((SymbolID)i, tileSize);

                    int stride = source.PixelWidth * (source.Format.BitsPerPixel / 8);
                    byte[] data = new byte[stride * source.PixelHeight];

                    source.CopyPixels(data, stride, 0);

                    target.WritePixels(new Int32Rect(xOffset, i * maxTileSize, tileSize, tileSize), data, stride, 0);

                    xOffset += tileSize;
                }
            }

            target.Unlock();

            string tileSizesStr = string.Join(",", tileSizes.Select(i => i.ToString()));
            var pngEncoder = new PngBitmapEncoder();
            var metadata = new BitmapMetadata("png");
            metadata.SetQuery("/tEXt/Software", "Dwarrowdelf");
            metadata.SetQuery("/tEXt/tilesizes", tileSizesStr);
            var frame = BitmapFrame.Create(target, null, metadata, null);
            pngEncoder.Frames = new BitmapFrame[] { frame };

            string path = Path.Combine(dstPath, "TileSet.png");

            using (var stream = File.OpenWrite(path))
                pngEncoder.Save(stream);

            Console.WriteLine("Generated TileSet to {0}", path);
        }