Package net.mtrop.doom.util
Class GraphicUtils
java.lang.Object
net.mtrop.doom.util.GraphicUtils
Graphics utility methods for image types.
- Author:
- Matthew Tropiano
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Colormap[]
createColormapsFromGraphic
(GraphicObject graphic) Creates a series of colormaps using a two-dimensional graphic, assumed indexed.static Flat
createFlat
(BufferedImage image, Palette palette) Creates aFlat
from aBufferedImage
.static Flat
createFlat
(BufferedImage image, Palette palette, Colormap colormap) Creates aFlat
from aBufferedImage
.static Flat
createFlat
(PNGPicture pngPicture, Palette palette) Creates aFlat
from aPNGPicture
.static Flat
createFlat
(PNGPicture pngPicture, Palette palette, Colormap colormap) Creates aFlat
from aPNGPicture
.static BufferedImage
createImage
(Flat flat, Palette palette) Creates aBufferedImage
from aFlat
.static BufferedImage
createImage
(Flat flat, Palette palette, Colormap colormap) Creates aBufferedImage
from aFlat
.static BufferedImage
createImage
(Picture picture, Palette palette) Creates aBufferedImage
from aPicture
.static BufferedImage
createImage
(Picture picture, Palette palette, Colormap colormap) Creates aBufferedImage
from aFlat
.static BufferedImage
createImageForEndDoom
(EndDoom endoom, boolean blinking) Returns the EndDoom data rendered to a BufferedImage.static Picture
createPicture
(BufferedImage image, Palette palette) Creates aPicture
from aBufferedImage
.static Picture
createPicture
(BufferedImage image, Palette palette, Colormap colormap) Creates aPicture
from aBufferedImage
.static Picture
createPicture
(PNGPicture pngPicture, Palette palette) Creates aPicture
from aBufferedImage
.static Picture
createPicture
(PNGPicture pngPicture, Palette palette, Colormap colormap) Creates aPicture
from aBufferedImage
.static PNGPicture
createPNGImage
(Picture picture, Palette palette) Creates aPNGPicture
from aPicture
.static PNGPicture
createPNGImage
(Picture picture, Palette palette, Colormap colormap) Creates aPNGPicture
from aPicture
.static void
setColormap
(Colormap colormap, Palette target, Palette sampled) Sets the indices of aColormap
by attempting to match colors in a palette from other colors in a different palette.
-
Field Details
-
DOOM
Default Doom palette. -
HERETIC
Default Heretic palette. -
HEXEN
Default Hexen palette. -
STRIFE
Default Strife palette. -
ANSI_COLORS
ANSI color table.
-
-
Method Details
-
createFlat
Creates aFlat
from aBufferedImage
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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
Creates aFlat
from aBufferedImage
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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 benull
for no translation.- Returns:
- the resultant Flat.
-
createPicture
Creates aPicture
from aBufferedImage
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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
Creates aPicture
from aBufferedImage
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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 benull
for no translation.- Returns:
- the resultant Picture.
-
createFlat
Creates aFlat
from aPNGPicture
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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
Creates aFlat
from aPNGPicture
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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 benull
for no translation.- Returns:
- the resultant Flat.
- Since:
- 2.13.0
-
createPicture
Creates aPicture
from aBufferedImage
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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
Creates aPicture
from aBufferedImage
. Colors are approximated using the providedPalette
, and translated using the providedColormap
. 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 benull
for no translation.- Returns:
- the resultant Picture.
- Since:
- 2.13.0
-
createImage
Creates aBufferedImage
from aFlat
.- 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
Creates aBufferedImage
from aFlat
.- 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
Creates aBufferedImage
from aPicture
.- 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
Creates aBufferedImage
from aFlat
.- 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
Creates aPNGPicture
from aPicture
.- 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
Creates aPNGPicture
from aPicture
.- 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
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
Sets the indices of aColormap
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
Creates a series of colormaps using a two-dimensional graphic, assumed indexed. The provided indexed graphic must have a width of at leastColormap.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 thanColormap.NUM_INDICES
.- Since:
- 2.2.0
-