net.sf.jomic.tools
Class ImageTools

java.lang.Object
  extended by net.sf.jomic.tools.ImageTools

public final class ImageTools
extends Object

Utility methods for working with images.

Author:
Thomas Aglassinger

Field Summary
static String DIFFERENCE_BLUR
           
static int DISTINCT_ROTATIONS_COUNT
           
static int ROTATE_CLOCKWISE
           
static int ROTATE_COUNTERCLOCKWISE
           
static int ROTATE_NONE
           
static int ROTATE_UPSIDE_DOWN
           
static String SCALE_ACTUAL
           
static String SCALE_FIT
           
static String SCALE_HEIGHT
           
static String SCALE_WIDTH
           
static String THRESHOLD_BLUR
           
 
Method Summary
 void assertIsValidRotation(int rotation)
           
 void assertIsValidScaleMode(String scaleMode)
           
 RenderedImage combinedImage(RenderedImage leftImage, RenderedImage rightImage)
          Get an image that contains leftImage and rightImage.
 RenderedImage combinedImage(RenderedImage leftImage, RenderedImage rightImage, Color background)
          Get an image that contains leftImage and rightImage, with possible blank pixels filled with background color..
 RenderedImage convertedToRGB(RenderedImage image)
          Gets a 24 bit version of image.
 RenderedImage createBrokenImage(int width, int height, Color background, Color foreground)
          Create image to represent a broken item.
 RenderedImage createBusyImage(int width, int height, Color background, Color foreground)
          Create image to represent a busy image that is in process of being rendered.
 BufferedImage createColorBox(int width, int height, Color color)
          Create a rectangle of a certain color.
 javax.media.jai.LookupTableJAI createGreyScaleLookupTableJAI(int bits)
          Create a lookup table to convert a grey scale image using bits to a sRGB image.
 ImageInputStream createImageInputStream(File imageFile)
          Same as ImageIO.createImageInputStream, but throws a FileNotFoundException if imageFile cannot be found (instead of returning null).
 double[] fillColorValues(Color color, ColorModel colorModel)
          Compute fill values for color when it should be used by the "border" operater on an image with a ColorModel of colorModel.
 BufferedImage getAsBufferedImage(RenderedImage image)
          Convert image to BufferedImage.
 ImageIcon getAsImageIcon(RenderedImage image)
          Convert image to ImageIcon.
 RenderedImage getBluredImage(RenderedImage image, String blurMode)
           
 int getDeltaRotation(int oldRotation, int newRotation)
          Get relative Rotation needed to go from absolute rotation oldRotation to newRotation .
 Dimension getImageDimension(File imageFile)
           
 Dimension getImageDimension(ImageInputStream imageStream)
          Get the image dimension of imageStream or null if no reader can be found.
 String getImageFormat(File imageFile)
          Get the format of imageFile or null if no image reader is available for it.
 String getImageFormat(ImageInputStream imageStream)
          Get the format of imageStream or null if no image stream or reader is available.
 Map getImageProviderMap()
          Get a map with the keys being an image file suffix, and the value being the name of the provider handling it.
 ImageReader getImageReader(ImageInputStream imageStream)
          Get an reader for in the image in imageStream.
 int getLeftRotation(int rotation)
           
 int getNumBands(RenderedImage image)
          Like PlanarImage.getNumBands(), but also works on RenderedImage.
 String[] getPossibleBlurModes()
           
 int getRightRotation(int rotation)
           
 RenderedImage getRotatedImage(RenderedImage image, float radians)
           
 RenderedImage getRotatedImage(RenderedImage image, int rotation)
          Rotate image in steps of 90 degrees.
 double getScaleToSqueeze(int areaWidth, int areaHeight, int sourceWidth, int sourceHeight, String scaleMode)
          Compute scale to squeeze into an area of size areaWidthxareaHeight an image of size sourceWidthxsourceHeight.
 RenderedImage getSqueezed(RenderedImage source, int areaWidth, int areaHeight, String scaleMode)
          Get a rescaled version of source that depending on scaleMode possibly fits width and/or height while keeping proportions.
 Dimension getSqueezedDimension(int areaWidth, int areaHeight, int sourceWidth, int sourceHeight, String scaleMode)
          Get the size of the actual area used by a sourceWidth x sourceHeight image squeezed in an areaWidth x areaHeight area.
static ImageTools instance()
          Get accessor to unique instance.
 boolean isCompressedImageFormat(String imageFormat)
          Yield true if imageFormat indicates a compressed reformat.
 boolean isImageFile(File file)
           
 boolean isImageFile(String fileName)
           
 boolean isImageSuffix(String suffix)
           
 boolean isLandscape(Dimension size)
           
 boolean isLandscape(int width, int height)
           
 boolean isLandscape(RenderedImage image)
           
 boolean isValidBlurMode(String some)
           
 boolean isValidRotation(int rotation)
           
 boolean isValidScaleMode(String mode)
           
 void loadImageToMemory(RenderedImage image)
          Attempty to preload whole image in memory.
 RenderedImage readImage(File imageFile)
          Read the specified imageFile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIFFERENCE_BLUR

public static final String DIFFERENCE_BLUR
See Also:
Constant Field Values

DISTINCT_ROTATIONS_COUNT

public static final int DISTINCT_ROTATIONS_COUNT
See Also:
Constant Field Values

ROTATE_CLOCKWISE

public static final int ROTATE_CLOCKWISE
See Also:
Constant Field Values

ROTATE_COUNTERCLOCKWISE

public static final int ROTATE_COUNTERCLOCKWISE
See Also:
Constant Field Values

ROTATE_NONE

public static final int ROTATE_NONE
See Also:
Constant Field Values

ROTATE_UPSIDE_DOWN

public static final int ROTATE_UPSIDE_DOWN
See Also:
Constant Field Values

SCALE_ACTUAL

public static final String SCALE_ACTUAL
See Also:
Constant Field Values

SCALE_FIT

public static final String SCALE_FIT
See Also:
Constant Field Values

SCALE_HEIGHT

public static final String SCALE_HEIGHT
See Also:
Constant Field Values

SCALE_WIDTH

public static final String SCALE_WIDTH
See Also:
Constant Field Values

THRESHOLD_BLUR

public static final String THRESHOLD_BLUR
See Also:
Constant Field Values
Method Detail

getAsBufferedImage

public BufferedImage getAsBufferedImage(RenderedImage image)
Convert image to BufferedImage. This is slow.


getAsImageIcon

public ImageIcon getAsImageIcon(RenderedImage image)
Convert image to ImageIcon. This is slow.


getBluredImage

public RenderedImage getBluredImage(RenderedImage image,
                                    String blurMode)

getDeltaRotation

public int getDeltaRotation(int oldRotation,
                            int newRotation)
Get relative Rotation needed to go from absolute rotation oldRotation to newRotation .


getImageDimension

public Dimension getImageDimension(ImageInputStream imageStream)
                            throws IOException
Get the image dimension of imageStream or null if no reader can be found.

Throws:
IOException

getImageDimension

public Dimension getImageDimension(File imageFile)
                            throws IOException
Throws:
IOException

getImageFormat

public String getImageFormat(ImageInputStream imageStream)
                      throws IOException
Get the format of imageStream or null if no image stream or reader is available.

Throws:
IOException
See Also:
ImageIO.getImageReaders(java.lang.Object), ImageIO.createImageInputStream(Object), ImageReader.getFormatName()

getImageFormat

public String getImageFormat(File imageFile)
                      throws IOException
Get the format of imageFile or null if no image reader is available for it.

Throws:
IOException
See Also:
ImageIO.getImageReaders(java.lang.Object), ImageReader.getFormatName()

getImageProviderMap

public Map getImageProviderMap()
Get a map with the keys being an image file suffix, and the value being the name of the provider handling it.


getImageReader

public ImageReader getImageReader(ImageInputStream imageStream)
Get an reader for in the image in imageStream.


getLeftRotation

public int getLeftRotation(int rotation)

getNumBands

public int getNumBands(RenderedImage image)
Like PlanarImage.getNumBands(), but also works on RenderedImage.

See Also:
PlanarImage.getNumBands()

getPossibleBlurModes

public String[] getPossibleBlurModes()
See Also:
getBluredImage(RenderedImage, String)

getRightRotation

public int getRightRotation(int rotation)

getRotatedImage

public RenderedImage getRotatedImage(RenderedImage image,
                                     float radians)

getRotatedImage

public RenderedImage getRotatedImage(RenderedImage image,
                                     int rotation)
Rotate image in steps of 90 degrees.

Parameters:
rotation - -1=counter clockwise, 0=no rotation, 1=clockwise, 2=upside down

getScaleToSqueeze

public double getScaleToSqueeze(int areaWidth,
                                int areaHeight,
                                int sourceWidth,
                                int sourceHeight,
                                String scaleMode)
Compute scale to squeeze into an area of size areaWidthxareaHeight an image of size sourceWidthxsourceHeight.


getSqueezed

public RenderedImage getSqueezed(RenderedImage source,
                                 int areaWidth,
                                 int areaHeight,
                                 String scaleMode)
Get a rescaled version of source that depending on scaleMode possibly fits width and/or height while keeping proportions.

Parameters:
scaleMode - one of: SCALE_ACTUAL, SCALE_FIT, SCALE_WIDTH, SCALE_HEIGHT

getSqueezedDimension

public Dimension getSqueezedDimension(int areaWidth,
                                      int areaHeight,
                                      int sourceWidth,
                                      int sourceHeight,
                                      String scaleMode)
Get the size of the actual area used by a sourceWidth x sourceHeight image squeezed in an areaWidth x areaHeight area.


isCompressedImageFormat

public boolean isCompressedImageFormat(String imageFormat)
Yield true if imageFormat indicates a compressed reformat. Images in such formats will not shrink significantly by compressing them using for example ZIP.

See Also:
getImageFormat(ImageInputStream)

isImageFile

public boolean isImageFile(String fileName)

isImageFile

public boolean isImageFile(File file)

isImageSuffix

public boolean isImageSuffix(String suffix)

isLandscape

public boolean isLandscape(int width,
                           int height)

isLandscape

public boolean isLandscape(Dimension size)

isLandscape

public boolean isLandscape(RenderedImage image)

isValidBlurMode

public boolean isValidBlurMode(String some)

isValidRotation

public boolean isValidRotation(int rotation)

isValidScaleMode

public boolean isValidScaleMode(String mode)

instance

public static ImageTools instance()
Get accessor to unique instance.


assertIsValidRotation

public void assertIsValidRotation(int rotation)

assertIsValidScaleMode

public void assertIsValidScaleMode(String scaleMode)

combinedImage

public RenderedImage combinedImage(RenderedImage leftImage,
                                   RenderedImage rightImage)
Get an image that contains leftImage and rightImage.


combinedImage

public RenderedImage combinedImage(RenderedImage leftImage,
                                   RenderedImage rightImage,
                                   Color background)
Get an image that contains leftImage and rightImage, with possible blank pixels filled with background color..


convertedToRGB

public RenderedImage convertedToRGB(RenderedImage image)
Gets a 24 bit version of image. If the image already was 24 bit, do nothing. This is most useful to load a index image like GIFs, and combine them with images of any other format.


createBrokenImage

public RenderedImage createBrokenImage(int width,
                                       int height,
                                       Color background,
                                       Color foreground)
Create image to represent a broken item.


createBusyImage

public RenderedImage createBusyImage(int width,
                                     int height,
                                     Color background,
                                     Color foreground)
Create image to represent a busy image that is in process of being rendered.


createColorBox

public BufferedImage createColorBox(int width,
                                    int height,
                                    Color color)
Create a rectangle of a certain color.


createGreyScaleLookupTableJAI

public javax.media.jai.LookupTableJAI createGreyScaleLookupTableJAI(int bits)
Create a lookup table to convert a grey scale image using bits to a sRGB image.


createImageInputStream

public ImageInputStream createImageInputStream(File imageFile)
                                        throws IOException
Same as ImageIO.createImageInputStream, but throws a FileNotFoundException if imageFile cannot be found (instead of returning null). Why the original does not work that way already is beyond me.

Note that a non-image (such as a text file) still returns proper stream.

Throws:
IOException

fillColorValues

public double[] fillColorValues(Color color,
                                ColorModel colorModel)
Compute fill values for color when it should be used by the "border" operater on an image with a ColorModel of colorModel.


loadImageToMemory

public void loadImageToMemory(RenderedImage image)
Attempty to preload whole image in memory.


readImage

public RenderedImage readImage(File imageFile)
                        throws IOException
Read the specified imageFile.

Throws:
IOException