Class GraphicUtils

java.lang.Object
net.mtrop.doom.util.GraphicUtils

public final class GraphicUtils extends Object
Graphics utility methods for image types.
Author:
Matthew Tropiano
  • Field Details

    • DOOM

      public static final Palette DOOM
      Default Doom palette.
    • HERETIC

      public static final Palette HERETIC
      Default Heretic palette.
    • HEXEN

      public static final Palette HEXEN
      Default Hexen palette.
    • STRIFE

      public static final Palette STRIFE
      Default Strife palette.
    • ANSI_COLORS

      public static final Color[] ANSI_COLORS
      ANSI color table.
  • Method Details

    • createFlat

      public static Flat createFlat(BufferedImage image, Palette palette)
      Creates a Flat from a BufferedImage. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are given index 0.
      Parameters:
      image - the image to convert.
      palette - the palette to use for color approximation.
      Returns:
      the resultant Flat.
    • createFlat

      public static Flat createFlat(BufferedImage image, Palette palette, Colormap colormap)
      Creates a Flat from a BufferedImage. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are given index 0.
      Parameters:
      image - the image to convert.
      palette - the palette to use for color approximation.
      colormap - the colormap to use for palette translation. Can be null for no translation.
      Returns:
      the resultant Flat.
    • createPicture

      public static Picture createPicture(BufferedImage image, Palette palette)
      Creates a Picture from a BufferedImage. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are considered transparent.
      Parameters:
      image - the image to convert.
      palette - the palette to use for color approximation.
      Returns:
      the resultant Picture.
    • createPicture

      public static Picture createPicture(BufferedImage image, Palette palette, Colormap colormap)
      Creates a Picture from a BufferedImage. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are considered transparent.
      Parameters:
      image - the image to convert.
      palette - the palette to use for color approximation.
      colormap - the colormap to use for palette translation. Can be null for no translation.
      Returns:
      the resultant Picture.
    • createFlat

      public static Flat createFlat(PNGPicture pngPicture, Palette palette)
      Creates a Flat from a PNGPicture. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are given index 0.
      Parameters:
      pngPicture - the PNGPicture to convert.
      palette - the palette to use for color approximation.
      Returns:
      the resultant Flat.
      Since:
      2.13.0
    • createFlat

      public static Flat createFlat(PNGPicture pngPicture, Palette palette, Colormap colormap)
      Creates a Flat from a PNGPicture. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are given index 0.
      Parameters:
      pngPicture - the PNGPicture to convert.
      palette - the palette to use for color approximation.
      colormap - the colormap to use for palette translation. Can be null for no translation.
      Returns:
      the resultant Flat.
      Since:
      2.13.0
    • createPicture

      public static Picture createPicture(PNGPicture pngPicture, Palette palette)
      Creates a Picture from a BufferedImage. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are considered transparent. Offset info from the PNG is preserved.
      Parameters:
      pngPicture - the PNGPicture to convert.
      palette - the palette to use for color approximation.
      Returns:
      the resultant Picture.
      Since:
      2.13.0
    • createPicture

      public static Picture createPicture(PNGPicture pngPicture, Palette palette, Colormap colormap)
      Creates a Picture from a BufferedImage. Colors are approximated using the provided Palette, and translated using the provided Colormap. Pixels that are not fully opaque are considered transparent. Offset info from the PNG is preserved.
      Parameters:
      pngPicture - the PNGPicture to convert.
      palette - the palette to use for color approximation.
      colormap - the colormap to use for palette translation. Can be null for no translation.
      Returns:
      the resultant Picture.
      Since:
      2.13.0
    • createImage

      public static BufferedImage createImage(Flat flat, Palette palette)
      Creates a BufferedImage from a Flat.
      Parameters:
      flat - the Flat to convert.
      palette - the palette to use as a color source.
      Returns:
      a full color image of the indexed-color Flat.
    • createImage

      public static BufferedImage createImage(Flat flat, Palette palette, Colormap colormap)
      Creates a BufferedImage from a Flat.
      Parameters:
      flat - the Flat to convert.
      palette - the palette to use as a color source.
      colormap - the colormap for palette translation, if any. Can be null for no translation.
      Returns:
      a full color image of the indexed-color Flat.
    • createImage

      public static BufferedImage createImage(Picture picture, Palette palette)
      Creates a BufferedImage from a Picture.
      Parameters:
      picture - the Picture to convert.
      palette - the palette to use as a color source.
      Returns:
      a full color image of the indexed-color Flat.
    • createImage

      public static BufferedImage createImage(Picture picture, Palette palette, Colormap colormap)
      Creates a BufferedImage from a Flat.
      Parameters:
      picture - the Picture to convert.
      palette - the palette to use as a color source.
      colormap - the colormap for palette translation, if any. Can be null for no translation.
      Returns:
      a full color image of the indexed-color Flat.
    • createPNGImage

      public static PNGPicture createPNGImage(Picture picture, Palette palette)
      Creates a PNGPicture from a Picture.
      Parameters:
      picture - the Picture to convert.
      palette - the palette to use as a color source.
      Returns:
      a full color image of the indexed-color Flat.
    • createPNGImage

      public static PNGPicture createPNGImage(Picture picture, Palette palette, Colormap colormap)
      Creates a PNGPicture from a Picture.
      Parameters:
      picture - the Picture to convert.
      palette - the palette to use as a color source.
      colormap - the colormap for palette translation, if any. Can be null for no translation.
      Returns:
      a full color image of the indexed-color Flat.
    • createImageForEndDoom

      public static BufferedImage createImageForEndDoom(EndDoom endoom, boolean blinking)
      Returns the EndDoom data rendered to a BufferedImage.
      Parameters:
      endoom - the EndDoom lump to render.
      blinking - if true, this will render the "blinking" characters.
      Returns:
      a BufferedImage that represents the graphic image in RGB color (including transparency).
      Throws:
      NullPointerException - if endoom is null.
    • setColormap

      public static void setColormap(Colormap colormap, Palette target, Palette sampled)
      Sets the indices of a Colormap by attempting to match colors in a palette from other colors in a different palette.

      This is a convenience for:

       for (int i = 0; i < Colormap.NUM_INDICES; i++)
           colormap.setPaletteIndex(i, target.getNearestColorIndex(sampled.getColorARGB(i)))
       
      Parameters:
      colormap - the colormap to set.
      target - the palette to match against.
      sampled - the palette to sample from for matching.
      Since:
      2.2.0
    • createColormapsFromGraphic

      public static Colormap[] createColormapsFromGraphic(GraphicObject graphic)
      Creates a series of colormaps using a two-dimensional graphic, assumed indexed. The provided indexed graphic must have a width of at least Colormap.NUM_INDICES. The amount of colormaps returned is equal to the graphic height. Translucent pixels are changed to index 0.
      Parameters:
      graphic - the source graphic to use.
      Returns:
      an array of new colormaps.
      Throws:
      NullPointerException - if graphic is null.
      ArrayIndexOutOfBoundsException - if the provided graphic's width is less than Colormap.NUM_INDICES.
      Since:
      2.2.0