NASA World Wind

gov.nasa.worldwindx.examples.util
Class PowerOfTwoPaddedImage

java.lang.Object
  extended by gov.nasa.worldwindx.examples.util.PowerOfTwoPaddedImage

public class PowerOfTwoPaddedImage
extends Object

The PowerOfTwoPaddedImage class converts images with non-power-of-two dimensions to images with power-of-two dimensions. The original image is copied into a power-of-two image, where any pixels not covered by the original image are completely transparent. This is a useful property when converting images to OpenGL textures. Non-power-of-two textures are handled inconsistently by graphics hardware. Not all hardware supports them, and many that do lack full support for the the texturing functionality avialable for power-of-two textures.

PowerOfTwoPaddedImage provides accessors to the converted power-of-two image, the power-of-two image's width and height, and the original image's width and height.


Field Summary
protected  int height
           
protected  BufferedImage image
           
protected  int width
           
 
Constructor Summary
protected PowerOfTwoPaddedImage(BufferedImage image, int width, int height)
           
 
Method Summary
static PowerOfTwoPaddedImage fromBufferedImage(BufferedImage image)
          Returns a new PowerOfTwoPaddedImage by converting the specified image to a new image with power-of-two dimensions.
static PowerOfTwoPaddedImage fromPath(String path)
          Returns a new PowerOfTwoPaddedImage from the specified path, or null if the file referenced by path cannot be read, or is not a readable image.
 int getOriginalHeight()
          Returns the height of the original non-power-of-two image, in pixels.
 int getOriginalWidth()
          Returns the width of the original non-power-of-two image, in pixels.
 int getPowerOfTwoHeight()
          Returns the height of the power-of-two image, in pixels.
 BufferedImage getPowerOfTwoImage()
          Returns a copy of the original image as a BufferedImage with power-of-two dimensions.
 int getPowerOfTwoWidth()
          Returns the width of the power-of-two image, in pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

height

protected int height

image

protected BufferedImage image

width

protected int width
Constructor Detail

PowerOfTwoPaddedImage

protected PowerOfTwoPaddedImage(BufferedImage image,
                                int width,
                                int height)
Method Detail

fromBufferedImage

public static PowerOfTwoPaddedImage fromBufferedImage(BufferedImage image)
Returns a new PowerOfTwoPaddedImage by converting the specified image to a new image with power-of-two dimensions. Any pixels not covered by the original image are completely transparent. If the specified image has power-of-two dimensions, this maintains a reference to the original image instead of creating a copy. However, if the specified image has no alpha channel, this creates a copy of the original image with an alpha channel, regardless of the specified image's dimensions. This guarantees that the method getPowerOfTwoImage() always returns a BufferedImage with an alpha channel. This is a useful property when converting images to OpenGL texture's, when both power-of-two and non-power-of-two textures must have an alpha channel for consistent handling.

Parameters:
image - the BufferedImage to convert to an image with power-of-two dimensions.
Returns:
a new PowerOfTwoPaddedImage representing a power-of-two copy of the specified image.
Throws:
IllegalArgumentException - if the image is null.

fromPath

public static PowerOfTwoPaddedImage fromPath(String path)
Returns a new PowerOfTwoPaddedImage from the specified path, or null if the file referenced by path cannot be read, or is not a readable image. The path must be a local file path, or a valid resource on the classpath. This uses ImageIO to read the specified path as a BufferedImage. Otherwise, this treats the resultant BufferedImage exactly as fromBufferedImage(java.awt.image.BufferedImage).

Parameters:
path - a local file path, or a valid resource on the classpath.
Returns:
a new PowerOfTwoPaddedImage representing a power-of-two copy of the image located at the specified path, or null if the image file reference by path cannot be read.
Throws:
IllegalArgumentException - if the path is null.

getOriginalHeight

public int getOriginalHeight()
Returns the height of the original non-power-of-two image, in pixels.

Returns:
the original image's height, in pixels.

getOriginalWidth

public int getOriginalWidth()
Returns the width of the original non-power-of-two image, in pixels.

Returns:
the original image's width, in pixels.

getPowerOfTwoHeight

public int getPowerOfTwoHeight()
Returns the height of the power-of-two image, in pixels.

Returns:
the power-of-two image's height, in pixels.

getPowerOfTwoImage

public BufferedImage getPowerOfTwoImage()
Returns a copy of the original image as a BufferedImage with power-of-two dimensions. Any pixels not covered by the original image are completely transparent.

Returns:
a copy of the original image as a BufferedImage.

getPowerOfTwoWidth

public int getPowerOfTwoWidth()
Returns the width of the power-of-two image, in pixels.

Returns:
the power-of-two image's width, in pixels.

NASA World Wind