public byte[] getTiledImageData()
    {

        byte[] palettedImage = new byte[width * height];
        int tileCount = width * height / 64;
        int tileWidth = width / 8;

        for (int t = 0; t < tileCount; t++)
            for (int y = 0; y < 8; y++)
                for (int x = 0; x < 8; x++)
                {
                    int tx = (t % tileWidth) * 8;
                    int ty = (int) (t / tileWidth) * 8;
                    palettedImage[t * 64 + y * 8 + x] =
                            (byte) imageData[tx + x][ty + y];
                }
        return palettedImage;
    }