org.jagatoo.util.image
Class ImageUtility

java.lang.Object
  extended by org.jagatoo.util.image.ImageUtility

public class ImageUtility
extends java.lang.Object

Mostly static methods to do some image manipulations.


Constructor Summary
ImageUtility()
           
 
Method Summary
static java.awt.Rectangle alphaBounds(java.awt.image.BufferedImage image)
          finds the maximum image bounds for the non-alpha masked object.
static java.awt.image.BufferedImage centerAndScale(java.awt.image.BufferedImage image, int width, int height, int margin)
          Takes the buffered image and builds a new one which is centered and scaled.
static java.awt.image.BufferedImage downSampleRGB(java.awt.image.BufferedImage source)
          Uses integer box filter to downsample an image two one half its size.
static java.awt.image.BufferedImage downSampleRGBA(java.awt.image.BufferedImage source)
           
static DirectBufferedImage flipImageVertical(java.awt.image.BufferedImage bi)
          Flips the given image vertically and returns the modified version
static java.awt.image.BufferedImage readImage(java.lang.String filename)
           
static java.awt.image.BufferedImage readImage(java.lang.String name, java.lang.Object c)
           
static int roundUpPower2(int v)
           
static
<BufferedImage_ extends java.awt.image.BufferedImage>
BufferedImage_
scaleImage(java.awt.Image srcImage, BufferedImage_ trgImage)
          Scales an Image to the size of trgImage and draws it onto trgImage.
static SharedBufferedImage scaleImage(java.awt.Image image, int width, int height, boolean alpha)
          Scales an Image and creates a BufferedImage in the desired format.
static byte[] toByteArray(java.awt.image.BufferedImage img)
          Converts a BufferedImage to a ByteBuffer.
static java.nio.ByteBuffer[] toByteBuffer(java.awt.image.BufferedImage img)
          Converts a BufferedImage to a ByteBuffer.
static void writeAlphaImage(java.awt.image.BufferedImage image, java.lang.String filename)
           
static void writeImage(java.awt.image.BufferedImage image, java.lang.String filename)
           
static void writeImage(java.awt.image.BufferedImage image, java.lang.String filename, float compression)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtility

public ImageUtility()
Method Detail

downSampleRGB

public static java.awt.image.BufferedImage downSampleRGB(java.awt.image.BufferedImage source)
Uses integer box filter to downsample an image two one half its size. This is used for making excellent mipmaps.

Parameters:
source -
Returns:
the down-sampled image

downSampleRGBA

public static java.awt.image.BufferedImage downSampleRGBA(java.awt.image.BufferedImage source)

alphaBounds

public static java.awt.Rectangle alphaBounds(java.awt.image.BufferedImage image)
finds the maximum image bounds for the non-alpha masked object. This assumes that the image has portions of it with an alpha of zero.


centerAndScale

public static java.awt.image.BufferedImage centerAndScale(java.awt.image.BufferedImage image,
                                                          int width,
                                                          int height,
                                                          int margin)
Takes the buffered image and builds a new one which is centered and scaled. Alpha blended edges are discarded. A margin is in pixels around the image.


writeImage

public static void writeImage(java.awt.image.BufferedImage image,
                              java.lang.String filename)

writeImage

public static void writeImage(java.awt.image.BufferedImage image,
                              java.lang.String filename,
                              float compression)

writeAlphaImage

public static void writeAlphaImage(java.awt.image.BufferedImage image,
                                   java.lang.String filename)

readImage

public static java.awt.image.BufferedImage readImage(java.lang.String filename)
                                              throws java.io.IOException
Throws:
java.io.IOException

readImage

public static java.awt.image.BufferedImage readImage(java.lang.String name,
                                                     java.lang.Object c)
                                              throws java.io.IOException
Throws:
java.io.IOException

flipImageVertical

public static DirectBufferedImage flipImageVertical(java.awt.image.BufferedImage bi)
Flips the given image vertically and returns the modified version

Parameters:
bi - the image to flip
Returns:
the modified version

toByteArray

public static byte[] toByteArray(java.awt.image.BufferedImage img)
                          throws java.io.IOException
Converts a BufferedImage to a ByteBuffer.

Throws:
java.io.IOException

toByteBuffer

public static java.nio.ByteBuffer[] toByteBuffer(java.awt.image.BufferedImage img)
                                          throws java.io.IOException
Converts a BufferedImage to a ByteBuffer.

Throws:
java.io.IOException

scaleImage

public static <BufferedImage_ extends java.awt.image.BufferedImage> BufferedImage_ scaleImage(java.awt.Image srcImage,
                                                                                              BufferedImage_ trgImage)
Scales an Image to the size of trgImage and draws it onto trgImage.

This uses AWT!

Parameters:
srcImage - The Image that should be scaled.
trgImage - the target image.
Returns:
The target image.

scaleImage

public static SharedBufferedImage scaleImage(java.awt.Image image,
                                             int width,
                                             int height,
                                             boolean alpha)
Scales an Image and creates a BufferedImage in the desired format. This uses AWT.

Parameters:
image - The Image that should be scaled.
width - The desired image width.
height - The desired image height.
alpha - create an alpha-channel for the new image?
Returns:
The scaled image as a SharedBufferedImage.

roundUpPower2

public static final int roundUpPower2(int v)
Parameters:
v - the value to be rounded
Returns:
the next power of two greater or equal to v