Class PowerOfTwoPaddedImage
- java.lang.Object
-
- gov.nasa.worldwindx.examples.util.PowerOfTwoPaddedImage
-
public class PowerOfTwoPaddedImage extends java.lang.ObjectThe 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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPowerOfTwoPaddedImage(java.awt.image.BufferedImage image, int width, int height)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PowerOfTwoPaddedImagefromBufferedImage(java.awt.image.BufferedImage image)Returns a new PowerOfTwoPaddedImage by converting the specifiedimageto a new image with power-of-two dimensions.static PowerOfTwoPaddedImagefromPath(java.lang.String path)Returns a new PowerOfTwoPaddedImage from the specifiedpath, or null if the file referenced bypathcannot be read, or is not a readable image.intgetOriginalHeight()Returns the height of the original non-power-of-two image, in pixels.intgetOriginalWidth()Returns the width of the original non-power-of-two image, in pixels.intgetPowerOfTwoHeight()Returns the height of the power-of-two image, in pixels.java.awt.image.BufferedImagegetPowerOfTwoImage()Returns a copy of the original image as aBufferedImagewith power-of-two dimensions.intgetPowerOfTwoWidth()Returns the width of the power-of-two image, in pixels.
-
-
-
Method Detail
-
fromBufferedImage
public static PowerOfTwoPaddedImage fromBufferedImage(java.awt.image.BufferedImage image)
Returns a new PowerOfTwoPaddedImage by converting the specifiedimageto a new image with power-of-two dimensions. Any pixels not covered by the original image are completely transparent. If the specifiedimagehas power-of-two dimensions, this maintains a reference to the original image instead of creating a copy. However, if the specifiedimagehas no alpha channel, this creates a copy of the original image with an alpha channel, regardless of the specifiedimage'sdimensions. This guarantees that the methodgetPowerOfTwoImage()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:
java.lang.IllegalArgumentException- if the image is null.
-
fromPath
public static PowerOfTwoPaddedImage fromPath(java.lang.String path)
Returns a new PowerOfTwoPaddedImage from the specifiedpath, or null if the file referenced bypathcannot be read, or is not a readable image. Thepathmust be a local file path, or a valid resource on the classpath. This usesImageIOto read the specifiedpathas aBufferedImage. Otherwise, this treats the resultant BufferedImage exactly asfromBufferedImage(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 bypathcannot be read. - Throws:
java.lang.IllegalArgumentException- if the path is null.
-
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.
-
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.
-
getPowerOfTwoImage
public java.awt.image.BufferedImage getPowerOfTwoImage()
Returns a copy of the original image as aBufferedImagewith 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.
-
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.
-
-