Esempio n. 1
0
 public PositionData(PositionData other)
 {
     x = other.x;
     y = other.y;
     tileAndPalette = other.tileAndPalette;
     notSetTile     = other.notSetTile;
 }
Esempio n. 2
0
        static void ConvertAllTiles(ushort[] pixels, PixelBuffer convertedPixels, PaletteList palettes, List <PositionData> positions, IConverterProfile profile)
#endif
        {
            List <ImageSlice> convertedTiles = new List <ImageSlice>();
            Dictionary <ImageSlice, TileInfo> uniqueTiles = new Dictionary <ImageSlice, TileInfo>();
            int tiles = 0;

            for (int y = 0; y < PixelBuffer.CANVAS_HEIGHT; y += PixelBuffer.TILE_HEIGHT)
            {
                for (int x = 0; x < PixelBuffer.CANVAS_WIDTH; x += PixelBuffer.TILE_WIDTH)
                {
#if USE_32BIT_SOURCE
                    int[] tile = GetTileData(pixels, x, y);
#else
                    ushort[] tile = GetTileData(pixels, x, y);
#endif
                    int          usedPalette;
                    PositionData pd;
                    ImageSlice   slice = palettes.NaturalizeTile(tile, out usedPalette);
                    if (slice != null)
                    {
                        ++tiles;
                        int uniqueTileId;
                        // see if this slice already exists
                        if (uniqueTiles.ContainsKey(slice))
                        {
                            TileInfo   info = uniqueTiles[slice];
                            ImageSlice dup  = convertedTiles[info.tileIndex];
                            Debug.Assert(AreArraysEqual(dup.rect, slice.rect), "In duplicate tile branch, but tiles aren't duplicates");
                            usedPalette  = info.paletteId;
                            uniqueTileId = info.tileIndex;
                        }
                        else
                        {
                            // it's a unique slice, add it
                            uniqueTileId = convertedTiles.Count;
                            TileInfo ti = new TileInfo(uniqueTileId, usedPalette);
                            convertedTiles.Add(slice);
                            uniqueTiles.Add(slice, ti);
                            convertedPixels.WriteTile(slice);
                        }
                        //Debug.Assert(usedPalette < profile.NumPalettes);
                        pd = new PositionData(
                            (byte)(x / PixelBuffer.TILE_WIDTH),
                            (byte)(y / PixelBuffer.TILE_HEIGHT),
                            profile.MakeTileAndPaletteValue(uniqueTileId, usedPalette)
                            );
                        positions.Add(pd);
                    }
                    else if (usedPalette != PaletteList.DISCARD_TILE) // these are all the same colour
                    {
#if USE_32BIT_SOURCE
                        ushort singleColour = profile.SwizzleSolidColour(Palette.ConvertColourToRGB555(tile[0]));
#else
                        ushort singleColour = profile.SwizzleSolidColour(tile[0]);
#endif
                        pd = new PositionData(
                            (byte)(x / PixelBuffer.TILE_WIDTH),
                            (byte)(y / PixelBuffer.TILE_HEIGHT)
                            ).SetSolidColour(singleColour);
                        positions.Add(pd);
#if DEBUG
                        Console.WriteLine("Found solid colour tile at {0}x{1} of colour {2:x}", x, y, singleColour);
#endif
                    }
                    // else this is a tile containing only black and/or transparent colours
                    // and the converter profile said it shouldn't be included in the image file
                }
            }
            Console.WriteLine("Total tiles: {0}, unique tiles: {1}", tiles, convertedTiles.Count);
        }