Class TileUtils

java.lang.Object
VASSAL.tools.image.tilecache.TileUtils

public class TileUtils extends Object
A class for reading and writing image tiles. The VASSAL tile format consists of the 18-byte header, followed by gzipped 4-bpp image data. The header is the signature 'VASSAL' (6 bytes), the tile width (4 bytes), the tile height (4 bytes), and the image type (4 bytes).
Since:
3.2.0
Author:
Joel Uckelman
  • Method Details

    • read

      public static BufferedImage read(String src) throws ImageIOException
      Reads an image tile file.
      Parameters:
      src - the path of the tile file
      Returns:
      the tile image
      Throws:
      ImageIOException - if the read fails
      TileNotFoundException - if the file isn't found
    • read

      public static BufferedImage read(File src) throws ImageIOException
      Reads an image tile file.
      Parameters:
      src - the path of the tile file
      Returns:
      the tile image
      Throws:
      ImageIOException - if the read fails
      TileNotFoundException - if the file isn't found
    • read

      public static BufferedImage read(InputStream in) throws IOException
      Reads an image tile.
      Parameters:
      in - a stream containing the tile data
      Returns:
      the tile image
      Throws:
      IOException - if the read fails
    • size

      public static Dimension size(String src) throws ImageIOException
      Reads the dimensions of the tile in an image tile file.
      Parameters:
      src - the path of the tile file
      Returns:
      the dimensions
      Throws:
      ImageIOException - if the read fails
      TileNotFoundException - if the file isn't found
    • size

      public static Dimension size(File src) throws ImageIOException
      Reads the dimensions of the tile in an image tile file.
      Parameters:
      src - the path of the tile file
      Returns:
      the dimensions
      Throws:
      ImageIOException - if the read fails
      TileNotFoundException - if the file isn't found
    • size

      public static Dimension size(InputStream in) throws IOException
      Reads the dimensions of the tile from a stream.
      Parameters:
      in - the stream
      Returns:
      the dimensions
      Throws:
      IOException - if the read fails
    • write

      public static void write(BufferedImage tile, String dst) throws ImageIOException
      Write a tile image to a tile file.
      Parameters:
      tile - the image
      dst - the tile file
      Throws:
      ImageIOException - if the write fails
    • write

      public static void write(BufferedImage tile, File dst) throws ImageIOException
      Write a tile image to a tile file.
      Parameters:
      tile - the image
      dst - the tile file
      Throws:
      ImageIOException - if the write fails
    • write

      public static void write(BufferedImage tile, OutputStream out) throws IOException
      Write a tile image to a stream.
      Parameters:
      tile - the image
      out - the stream
      Throws:
      ImageIOException - if the write fails
      IOException
    • tileCount

      public static int tileCount(Dimension i, Dimension t)
      Calculates the number of tiles needed to cover an image, summed over all sizes from 1:1 to the vanishing point.
      Parameters:
      i - the image dimensions
      t - the tile dimensions
      Returns:
      the number of tiles needed to cover the image
      Throws:
      IllegalArgumentException - if any argument is nonpositive
    • tileCount

      public static int tileCount(int iw, int ih, int tw, int th)
      Calculates the number of tiles needed to cover an image, summed over all sizes from 1:1 to the vanishing point.
      Parameters:
      iw - the image width
      ih - the image height
      tw - the tile width
      th - the tile height
      Returns:
      the number of tiles needed to cover the image
      Throws:
      IllegalArgumentException - if any argument is nonpositive
    • tileCountAtScale

      public static int tileCountAtScale(Dimension i, Dimension t, int div)
      Calculates the number of tiles needed to cover an image at a given scale.
      Parameters:
      i - the image dimensions
      t - the tile dimensions
      div - the scale divisor
      Returns:
      the number of tiles needed to cover the image
      Throws:
      IllegalArgumentException - if any argument is nonpositive
    • tileCountAtScale

      public static int tileCountAtScale(int iw, int ih, int tw, int th, int div)
      Calculates the number of tiles needed to cover an image at a given scale.
      Parameters:
      iw - the image width
      ih - the image height
      tw - the tile width
      th - the tile height
      div - the scale divisor
      Returns:
      the number of tiles needed to cover the image
      Throws:
      IllegalArgumentException - if any argument is nonpositive
    • tileName

      public static String tileName(String iname, int tileX, int tileY, int div)
      Gets the name of a tile file.
      Parameters:
      iname - the image name
      tileX - the X coordinate of the tile
      tileY - the Y coordinate of the tile
      div - the scale divisor
      Returns:
      the name of the tile file