com.jhlabs.image

Class TransformFilter

Implemented Interfaces:
BufferedImageOp, Cloneable
Known Direct Subclasses:
CircleFilter, DiffuseFilter, DisplaceFilter, FieldWarpFilter, KaleidoscopeFilter, MapFilter, MarbleFilter, OffsetFilter, PerspectiveFilter, PinchFilter, PolarFilter, RippleFilter, RotateFilter, ShearFilter, SphereFilter, SwimFilter, TwirlFilter, WaterFilter

public abstract class TransformFilter
extends AbstractBufferedImageOp

An abstract superclass for filters which distort images in some way. The subclass only needs to override two methods to provide the mapping between source and destination pixels.

Field Summary

static int
BILINEAR
Use bilinear interpolation.
static int
CLAMP
Clamp pixels to the image edges.
static int
NEAREST_NEIGHBOUR
Use nearest-neighbout interpolation.
static int
RGB_CLAMP
Clamp pixels RGB to the image edges, but zero the alpha.
static int
WRAP
Wrap pixels off the edge onto the oppsoite edge.
static int
ZERO
Treat pixels off the edge as zero.
protected int
edgeAction
The action to take for pixels off the image edge.
protected int
interpolation
The type of interpolation to use.
protected Rectangle
originalSpace
The input image rectangle.
protected Rectangle
transformedSpace
The output image rectangle.

Method Summary

BufferedImage
filter(BufferedImage src, BufferedImage dst)
protected BufferedImage
filterPixelsNN(BufferedImage dst, int width, int height, int[] inPixels, Rectangle transformedSpace)
int
getEdgeAction()
Get the action to perform for pixels off the edge of the image.
int
getInterpolation()
Get the type of interpolation to perform.
void
setEdgeAction(int edgeAction)
Set the action to perform for pixels off the edge of the image.
void
setInterpolation(int interpolation)
Set the type of interpolation to perform.
protected abstract void
transformInverse(int x, int y, float[] out)
Inverse transform a point.
protected void
transformSpace(Rectangle rect)
Forward transform a rectangle.

Methods inherited from class com.jhlabs.image.AbstractBufferedImageOp

clone, createCompatibleDestImage, getBounds2D, getPoint2D, getRGB, getRenderingHints, setRGB

Field Details

BILINEAR

public static final int BILINEAR
Use bilinear interpolation.
Field Value:
1

CLAMP

public static final int CLAMP
Clamp pixels to the image edges.
Field Value:
1

NEAREST_NEIGHBOUR

public static final int NEAREST_NEIGHBOUR
Use nearest-neighbout interpolation.
Field Value:
0

RGB_CLAMP

public static final int RGB_CLAMP
Clamp pixels RGB to the image edges, but zero the alpha. This prevents gray borders on your image.
Field Value:
3

WRAP

public static final int WRAP
Wrap pixels off the edge onto the oppsoite edge.
Field Value:
2

ZERO

public static final int ZERO
Treat pixels off the edge as zero.
Field Value:
0

edgeAction

protected int edgeAction
The action to take for pixels off the image edge.

interpolation

protected int interpolation
The type of interpolation to use.

originalSpace

protected Rectangle originalSpace
The input image rectangle.

transformedSpace

protected Rectangle transformedSpace
The output image rectangle.

Method Details

filter

public BufferedImage filter(BufferedImage src,
                            BufferedImage dst)

filterPixelsNN

protected BufferedImage filterPixelsNN(BufferedImage dst,
                                       int width,
                                       int height,
                                       int[] inPixels,
                                       Rectangle transformedSpace)

getEdgeAction

public int getEdgeAction()
Get the action to perform for pixels off the edge of the image.
Returns:
one of ZERO, CLAMP or WRAP

getInterpolation

public int getInterpolation()
Get the type of interpolation to perform.
Returns:
one of NEAREST_NEIGHBOUR or BILINEAR

setEdgeAction

public void setEdgeAction(int edgeAction)
Set the action to perform for pixels off the edge of the image.
Parameters:
edgeAction - one of ZERO, CLAMP or WRAP

setInterpolation

public void setInterpolation(int interpolation)
Set the type of interpolation to perform.
Parameters:
interpolation - one of NEAREST_NEIGHBOUR or BILINEAR

transformInverse

protected abstract void transformInverse(int x,
                                         int y,
                                         float[] out)
Inverse transform a point. This method needs to be overriden by all subclasses.
Parameters:
x - the X position of the pixel in the output image
y - the Y position of the pixel in the output image
out - the position of the pixel in the input image

transformSpace

protected void transformSpace(Rectangle rect)
Forward transform a rectangle. Used to determine the size of the output image.
Parameters:
rect - the rectangle to transform