public static List <UInt32> GenerateTileSetData(Tile[] tiles, Compression.CompressionType compressionType, uint destBpp)
        {
            UInt32 compressionTypeSize = Compression.ToGBACompressionHeader(compressionType, destBpp);

            List <UInt32> allCompressedIndicies = new List <UInt32>();

            foreach (Tile tile in tiles)
            {
                List <UInt32> compressedIndicies;
                List <int>    linearIndicies = new List <int>();

                for (int j = 0; j < tile.paletteIndicies.GetLength(1); ++j)
                {
                    for (int i = 0; i < tile.paletteIndicies.GetLength(0); ++i)
                    {
                        linearIndicies.Add(tile.paletteIndicies[i, j]);
                    }
                }

                Compression.BitPack(linearIndicies, destBpp, out compressedIndicies);

                allCompressedIndicies.AddRange(compressedIndicies);
            }

            return(allCompressedIndicies);
        }
示例#2
0
        List <UInt32> WriteSpriteData(
            Bitmap bitmap,
            Color[] palette,
            int width,
            int height,
            int xPos,
            int yPos,
            Compression.CompressionType compressionType,
            uint destBpp)
        {
            int        tilesWide             = width / TileConfig.TileWidth;
            int        tilesTall             = height / TileConfig.TileHeight;
            int        totalTiles            = (width * height) / (TileConfig.TileWidth * TileConfig.TileHeight);
            List <int> colourPaletteIndicies = new List <int>();

            for (int tileY = 0; tileY < tilesTall; ++tileY)
            {
                for (int tileX = 0; tileX < tilesWide; ++tileX)
                {
                    int tileXOffset = xPos + tileX * TileConfig.TileWidth;
                    int tileYOffset = yPos + tileY * TileConfig.TileHeight;

                    for (int y = 0; y < TileConfig.TileHeight; ++y)
                    {
                        for (int x = 0; x < TileConfig.TileWidth; ++x)
                        {
                            Color color = bitmap.GetPixel(tileXOffset + x, tileYOffset + y);
                            int   index = PaletteHelper.ColorToPaletteIndex(palette, color);
                            colourPaletteIndicies.Add(index);
                        }
                    }
                }
            }

            List <UInt32> compressedIndicies;

            switch (compressionType)
            {
            case Compression.CompressionType.BitPacked:
            {
                Compression.BitPack(colourPaletteIndicies, destBpp, out compressedIndicies);
            }
            break;

            default:
                throw new NotImplementedException();
            }

            return(compressedIndicies);
        }
        void WriteTileSet(Tile[] tiles, StringBuilder sb, Compression.CompressionType compressionType, uint destBpp, out int totalLength)
        {
            UInt32 compressionTypeSize = Compression.ToGBACompressionHeader(compressionType, destBpp);

            sb.Append('\n');
            sb.AppendFormat(VAR_TILESET_COMPRESSION_FORMAT, compressionTypeSize);

            sb.Append(VAR_TILESET);
            sb.Append(namespaceTabs + "{\n\t" + namespaceTabs);

            totalLength = 0;

            foreach (Tile tile in tiles)
            {
                List <UInt32> compressedIndicies;
                List <int>    linearIndicies = new List <int>();

                for (int j = 0; j < tile.paletteIndicies.GetLength(1); ++j)
                {
                    for (int i = 0; i < tile.paletteIndicies.GetLength(0); ++i)
                    {
                        linearIndicies.Add(tile.paletteIndicies[i, j]);
                    }
                }

                Compression.BitPack(linearIndicies, destBpp, out compressedIndicies);

                int          hexCount = 0;
                const string tabs     = namespaceTabs;
                foreach (var hexNum in compressedIndicies)
                {
                    sb.AppendFormat("0x{0:X8}, ", hexNum);
                    if ((hexCount + 1) % c_arrayNewlineCount == 0)
                    {
                        sb.Append("\n\t" + tabs);
                    }
                    ++totalLength;
                    ++hexCount;
                }

                sb.Append("\n\n\t" + tabs);
            }

            sb.Append("\n" + namespaceTabs + "};\n\n");
        }
        int WriteSpriteData(
            StringBuilder sbOutput,
            Bitmap bitmap,
            Color[] palette,
            int width,
            int height,
            int xPos,
            int yPos,
            Compression.CompressionType compressionType,
            uint destBpp)
        {
            const string tabs = namespaceTabs;

            int        tilesWide             = width / TileConfig.c_TILEWIDTH;
            int        tilesTall             = height / TileConfig.c_TILEHEIGHT;
            int        totalTiles            = (width * height) / (TileConfig.c_TILEWIDTH * TileConfig.c_TILEHEIGHT);
            int        hexCount              = 0;
            List <int> colourPaletteIndicies = new List <int>();

            sbOutput.Append(namespaceTabs + TAB_CHAR);

            for (int tileY = 0; tileY < tilesTall; ++tileY)
            {
                for (int tileX = 0; tileX < tilesWide; ++tileX)
                {
                    int tileXOffset = xPos + tileX * TileConfig.c_TILEWIDTH;
                    int tileYOffset = yPos + tileY * TileConfig.c_TILEHEIGHT;

                    for (int y = 0; y < TileConfig.c_TILEHEIGHT; ++y)
                    {
                        for (int x = 0; x < TileConfig.c_TILEWIDTH; ++x)
                        {
                            Color color = bitmap.GetPixel(tileXOffset + x, tileYOffset + y);
                            int   index = PaletteHelper.ColorToPaletteIndex(palette, color);
                            colourPaletteIndicies.Add(index);
                        }
                    }
                }
            }

            List <UInt32> compressedIndicies;

            switch (compressionType)
            {
            case Compression.CompressionType.BitPacked:
            {
                Compression.BitPack(colourPaletteIndicies, destBpp, out compressedIndicies);
            }
            break;

            default:
                throw new NotImplementedException();
            }

            foreach (var hexNum in compressedIndicies)
            {
                sbOutput.AppendFormat("0x{0:X8}, ", hexNum);
                if ((hexCount + 1) % c_arrayNewlineCount == 0)
                {
                    sbOutput.Append("\n\t" + tabs);
                }
                ++hexCount;
            }

            sbOutput.Append("\n\n");

            return(hexCount);
        }