|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jiu.util.ArrayRotation
public class ArrayRotation
Provides static methods to rotate (in steps of 90 degrees), flip and mirror array elements. The image data is expected to be available as an array of integer values, being stored as rows top-to-bottom. Within each row, the data is laid out from left to right. This class may also been useful for transposing matrices.
The rotation by 90 and 270 degrees in-place (i.e., without using a second array to copy to) is based on ideas and code developed by others. See Rotation of arrays by Thomas W. Christopher.
I also got very useful advice from Hans-Bernhard Broeker and others in comp.graphics.algorithms. There is a thread titled In-place rotation of pixel images starting Oct 11, 2000.
Note: This class should be adjusted if Java ever supports genericity. Then rotation functionality could be provided for all kinds of arrays.
Method Summary | |
---|---|
static void |
checkPixelArray(int[] pixels,
int width,
int height)
This method checks several properties of the arguments. |
static int[] |
flip(boolean inPlace,
int[] pixels,
int width,
int height)
Flips the image given by the arguments. |
static int[] |
rotate180(boolean inPlace,
int[] pixels,
int width,
int height)
Rotates the argument image by 180 degrees. |
static void |
rotate180(int width,
int height,
byte[] src,
int srcOffset,
byte[] dest,
int destOffset)
|
static void |
rotate90Left(int width,
int height,
byte[] src,
int srcOffset,
byte[] dest,
int destOffset)
|
static int[] |
rotate90Right(boolean inPlace,
int[] pixels,
int width,
int height)
|
static void |
rotate90Right(int width,
int height,
byte[] src,
int srcOffset,
byte[] dest,
int destOffset)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void checkPixelArray(int[] pixels, int width, int height)
IllegalArgumentException
is thrown.
Otherwise, nothing happens.
This method is supposed to be called at the beginning of several
other methods in this class.
Properties checked:
pixels
is non-nullwidth
and height
are larger than zeropixels
is at least width
times height
public static final int[] flip(boolean inPlace, int[] pixels, int width, int height)
inPlace
- if true
all work is done on the pixels
array;
otherwise, a second array is allocated and the pixels
array
remains unmodifiedpixels
- the array of pixels that form the image to be flippedwidth
- the horizontal resolution of the image; must be larger than 0height
- the vertical resolution of the image; must be larger than 0
pixels
if
inPlace
is true
IllegalArgumentException
- if the pixel resolution
is invalid or the pixels array is not initialized or its length smaller
than width
times height
public static int[] rotate180(boolean inPlace, int[] pixels, int width, int height)
If inPlace
is true, the rotation is done on the
argument pixels
array.
Otherwise a new array of sufficient length is allocated and the
rotated image will be stored in this new array, not modifying the
content of the pixels
array.
inPlace
- determines whether the rotated image is written to the argument arraypixels
- the array of pixels that form the image to be rotatedwidth
- the horizontal resolution of the image; must be larger than 0height
- the vertical resolution of the image; must be larger than 0
pixels
if
inPlace
is true
IllegalArgumentException
- if the pixel resolution
is invalid or the pixels array is not initialized or its length smaller
than width
times height
public static void rotate90Left(int width, int height, byte[] src, int srcOffset, byte[] dest, int destOffset)
public static void rotate90Right(int width, int height, byte[] src, int srcOffset, byte[] dest, int destOffset)
public static void rotate180(int width, int height, byte[] src, int srcOffset, byte[] dest, int destOffset)
public static int[] rotate90Right(boolean inPlace, int[] pixels, int width, int height)
|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |