Class Colormap

java.lang.Object
net.mtrop.doom.graphics.Colormap
All Implemented Interfaces:
BinaryObject

public class Colormap extends Object implements BinaryObject
This is a single entry that indexes the palette indices for color lookup. The COLORMAP lump contains several of these. Other commercial IWAD lumps that are colormaps or contain many colormaps are the TRANTBL lumps in Hexen and TINTTAB.
Author:
Matthew Tropiano
  • Field Details

    • LENGTH

      public static final int LENGTH
      A single colormap's length in bytes.
      See Also:
    • NUM_INDICES

      public static final int NUM_INDICES
      The number of total indices in a standard Doom color map.
      See Also:
    • indices

      protected int[] indices
      The index list in this map.
  • Constructor Details

    • Colormap

      public Colormap()
      Creates a new identity colormap where all indices point to their own index.
    • Colormap

      public Colormap(Colormap map)
      Creates a new colormap by copying the contents of another.
      Parameters:
      map - the source map to copy.
  • Method Details

    • createIdentityMap

      public static Colormap createIdentityMap()
      Creates a color map where each color is mapped to its own index (index 0 is palette color 0 ... index 255 is palette color 255).
      Returns:
      a new color map with the specified indices already mapped.
    • setIdentity

      public Colormap setIdentity()
      Resets the color map to where each color is mapped to its own index (index 0 is palette color 0 ... index 255 is palette color 255).
      Returns:
      itself, to chain colormap calls.
    • setTranslation

      public Colormap setTranslation(int startIndex, int endIndex, int startValue, int endValue)
      Sets a colormap translation by remapping groups of contiguous indices.
      Parameters:
      startIndex - the starting replacement index (inclusive).
      endIndex - the ending replacement index (inclusive).
      startValue - the starting replacement value (inclusive).
      endValue - the ending replacement value (inclusive).
      Returns:
      itself, to chain colormap calls.
    • copy

      public Colormap copy()
      Creates a new colormap by copying the contents of this one.
      Returns:
      itself, to chain colormap calls.
    • getPaletteIndex

      public int getPaletteIndex(int index)
      Returns the palette index of a specific index in the map.
      Parameters:
      index - the index number of the entry.
      Returns:
      the corresponding palette index.
      Throws:
      ArrayIndexOutOfBoundsException - if index is greater than NUM_INDICES or less than 0.
    • setPaletteIndex

      public Colormap setPaletteIndex(int index, int paletteIndex)
      Sets the palette index of a specific index in the map.
      Parameters:
      index - the index number of the entry.
      paletteIndex - the new index.
      Returns:
      itself, to chain colormap calls.
      Throws:
      ArrayIndexOutOfBoundsException - if index is greater than 255 or less than 0.
      IllegalArgumentException - if paletteIndex is less than 0 or greater than 255.
    • readBytes

      public void readBytes(InputStream in) throws IOException
      Description copied from interface: BinaryObject
      Reads from an InputStream and sets this object's fields. Only reads the amount of bytes that it takes to read a single instance of the object. Note that not every object may have a consistent length!
      Specified by:
      readBytes in interface BinaryObject
      Parameters:
      in - the InputStream to read from.
      Throws:
      IOException - if a read error occurs.
    • writeBytes

      public void writeBytes(OutputStream out) throws IOException
      Description copied from interface: BinaryObject
      Writes this object to an OutputStream.
      Specified by:
      writeBytes in interface BinaryObject
      Parameters:
      out - the OutputStream to write to.
      Throws:
      IOException - if a write error occurs.
    • toString

      public String toString()
      Overrides:
      toString in class Object