com.threerings.media.image
Class ImageUtil

java.lang.Object
  extended by com.threerings.media.image.ImageUtil

public class ImageUtil
extends Object

Image related utility functions.


Nested Class Summary
static interface ImageUtil.ImageCreator
           
 
Field Summary
protected static GraphicsConfiguration _gc
          The graphics configuration for the default screen device.
protected static int RGB_MASK
          Used when outlining.
protected static int TRANS_MASK
          Used when seeking fully transparent pixels for outlining.
 
Constructor Summary
ImageUtil()
           
 
Method Summary
protected static boolean bordersNonTransparentPixel(BufferedImage data, int wid, int hei, boolean[] traced, int x, int y)
          Returns whether the given pixel is bordered by any non-transparent pixel.
static BufferedImage composeMaskedImage(ImageUtil.ImageCreator isrc, BufferedImage mask, BufferedImage base)
          Create an image using the alpha channel from the first and the RGB values from the second.
static BufferedImage composeMaskedImage(ImageUtil.ImageCreator isrc, Shape mask, BufferedImage base)
          Create a new image using the supplied shape as a mask from which to cut out pixels from the supplied image.
static void computeTrimmedBounds(BufferedImage image, Rectangle tbounds)
          Computes the bounds of the smallest rectangle that contains all non-transparent pixels of this image.
static BufferedImage createCompatibleImage(BufferedImage source, int width, int height)
          Creates a new buffered image with the same sample model and color model as the source image but with the new width and height.
static BufferedImage createErrorImage(int width, int height)
          Creates an image with the word "Error" written in it.
static BufferedImage createTracedImage(BufferedImage src, BufferedImage dest, Color tcolor, int thickness, float startAlpha, float endAlpha)
          Creates and returns a new image consisting of the supplied image traced with the given color, thickness and alpha transparency.
static BufferedImage createTracedImage(ImageUtil.ImageCreator isrc, BufferedImage src, Color tcolor, int thickness)
          Creates and returns a new image consisting of the supplied image traced with the given color and thickness.
static BufferedImage createTracedImage(ImageUtil.ImageCreator isrc, BufferedImage src, Color tcolor, int thickness, float startAlpha, float endAlpha)
          Creates and returns a new image consisting of the supplied image traced with the given color, thickness and alpha transparency.
protected static GraphicsConfiguration getDefGC()
          Obtains the default graphics configuration for this VM.
static long getEstimatedMemoryUsage(BufferedImage image)
          Returns the estimated memory usage in bytes for the specified image.
static long getEstimatedMemoryUsage(Iterator<BufferedImage> iter)
          Returns the estimated memory usage in bytes for all buffered images in the supplied iterator.
static long getEstimatedMemoryUsage(Raster raster)
          Returns the estimated memory usage in bytes for the specified raster.
static boolean hitTest(BufferedImage image, int x, int y)
          Returns true if the supplied image contains a non-transparent pixel at the specified coordinates, false otherwise.
static BufferedImage recolorImage(BufferedImage image, Color rootColor, float[] dists, float[] offsets)
          Used to recolor images by shifting bands of color (in HSV color space) to a new hue.
static BufferedImage recolorImage(BufferedImage image, Colorization cz)
          Recolors the supplied image as in recolorImage(BufferedImage,Color,float[],float[]) obtaining the recoloring parameters from the supplied Colorization instance.
static BufferedImage recolorImage(BufferedImage image, Colorization[] zations)
          Recolors the supplied image using the supplied colorizations.
static void tileImage(Graphics2D gfx, Mirage image, int x, int y, int width, int height)
          Paints multiple copies of the supplied image using the supplied graphics context such that the requested area is filled with the image.
static void tileImageAcross(Graphics2D gfx, Mirage image, int x, int y, int width)
          Paints multiple copies of the supplied image using the supplied graphics context such that the requested width is filled with the image.
static void tileImageDown(Graphics2D gfx, Mirage image, int x, int y, int height)
          Paints multiple copies of the supplied image using the supplied graphics context such that the requested height is filled with the image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_gc

protected static GraphicsConfiguration _gc
The graphics configuration for the default screen device.


TRANS_MASK

protected static final int TRANS_MASK
Used when seeking fully transparent pixels for outlining.

See Also:
Constant Field Values

RGB_MASK

protected static final int RGB_MASK
Used when outlining.

See Also:
Constant Field Values
Constructor Detail

ImageUtil

public ImageUtil()
Method Detail

createCompatibleImage

public static BufferedImage createCompatibleImage(BufferedImage source,
                                                  int width,
                                                  int height)
Creates a new buffered image with the same sample model and color model as the source image but with the new width and height.


createErrorImage

public static BufferedImage createErrorImage(int width,
                                             int height)
Creates an image with the word "Error" written in it.


recolorImage

public static BufferedImage recolorImage(BufferedImage image,
                                         Color rootColor,
                                         float[] dists,
                                         float[] offsets)
Used to recolor images by shifting bands of color (in HSV color space) to a new hue. The source images must be 8-bit color mapped images, as the recoloring process works by analysing the color map and modifying it.


recolorImage

public static BufferedImage recolorImage(BufferedImage image,
                                         Colorization cz)
Recolors the supplied image as in recolorImage(BufferedImage,Color,float[],float[]) obtaining the recoloring parameters from the supplied Colorization instance.


recolorImage

public static BufferedImage recolorImage(BufferedImage image,
                                         Colorization[] zations)
Recolors the supplied image using the supplied colorizations.


tileImage

public static void tileImage(Graphics2D gfx,
                             Mirage image,
                             int x,
                             int y,
                             int width,
                             int height)
Paints multiple copies of the supplied image using the supplied graphics context such that the requested area is filled with the image.


tileImageAcross

public static void tileImageAcross(Graphics2D gfx,
                                   Mirage image,
                                   int x,
                                   int y,
                                   int width)
Paints multiple copies of the supplied image using the supplied graphics context such that the requested width is filled with the image.


tileImageDown

public static void tileImageDown(Graphics2D gfx,
                                 Mirage image,
                                 int x,
                                 int y,
                                 int height)
Paints multiple copies of the supplied image using the supplied graphics context such that the requested height is filled with the image.


createTracedImage

public static BufferedImage createTracedImage(ImageUtil.ImageCreator isrc,
                                              BufferedImage src,
                                              Color tcolor,
                                              int thickness)
Creates and returns a new image consisting of the supplied image traced with the given color and thickness.


createTracedImage

public static BufferedImage createTracedImage(ImageUtil.ImageCreator isrc,
                                              BufferedImage src,
                                              Color tcolor,
                                              int thickness,
                                              float startAlpha,
                                              float endAlpha)
Creates and returns a new image consisting of the supplied image traced with the given color, thickness and alpha transparency.


createTracedImage

public static BufferedImage createTracedImage(BufferedImage src,
                                              BufferedImage dest,
                                              Color tcolor,
                                              int thickness,
                                              float startAlpha,
                                              float endAlpha)
Creates and returns a new image consisting of the supplied image traced with the given color, thickness and alpha transparency.


bordersNonTransparentPixel

protected static boolean bordersNonTransparentPixel(BufferedImage data,
                                                    int wid,
                                                    int hei,
                                                    boolean[] traced,
                                                    int x,
                                                    int y)
Returns whether the given pixel is bordered by any non-transparent pixel.


composeMaskedImage

public static BufferedImage composeMaskedImage(ImageUtil.ImageCreator isrc,
                                               BufferedImage mask,
                                               BufferedImage base)
Create an image using the alpha channel from the first and the RGB values from the second.


composeMaskedImage

public static BufferedImage composeMaskedImage(ImageUtil.ImageCreator isrc,
                                               Shape mask,
                                               BufferedImage base)
Create a new image using the supplied shape as a mask from which to cut out pixels from the supplied image. Pixels inside the shape will be added to the final image, pixels outside the shape will be clear.


hitTest

public static boolean hitTest(BufferedImage image,
                              int x,
                              int y)
Returns true if the supplied image contains a non-transparent pixel at the specified coordinates, false otherwise.


computeTrimmedBounds

public static void computeTrimmedBounds(BufferedImage image,
                                        Rectangle tbounds)
Computes the bounds of the smallest rectangle that contains all non-transparent pixels of this image. This isn't extremely efficient, so you shouldn't be doing this anywhere exciting.


getEstimatedMemoryUsage

public static long getEstimatedMemoryUsage(BufferedImage image)
Returns the estimated memory usage in bytes for the specified image.


getEstimatedMemoryUsage

public static long getEstimatedMemoryUsage(Raster raster)
Returns the estimated memory usage in bytes for the specified raster.


getEstimatedMemoryUsage

public static long getEstimatedMemoryUsage(Iterator<BufferedImage> iter)
Returns the estimated memory usage in bytes for all buffered images in the supplied iterator.


getDefGC

protected static GraphicsConfiguration getDefGC()
Obtains the default graphics configuration for this VM. If the JVM is in headless mode, this method will return null.