public class ImageUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static float[] |
BYTE_TO_FLOAT_LUT
Lookup table for byte->float conversion
|
static InputStreamObjectReader<FImage> |
FIMAGE_READER
An
InputStreamObjectReader for reading FImage s. |
static InputStreamObjectReader<MBFImage> |
MBFIMAGE_READER
An
InputStreamObjectReader for reading MBFImage s. |
Modifier and Type | Method and Description |
---|---|
static float[] |
alphaCompositePixel(float[] p1,
float[] p2)
Alpha composites the pixel p1 with the pixel p2, returning the value in
pixel p1
|
static float[] |
alphaCompositePixel(Float[] p1,
Float[] p2)
Alpha composites the pixel p1 with the pixel p2, returning the value in
pixel p1
|
static float[] |
alphaCompositePixel(float[] out,
float thisR,
float thisG,
float thisB,
float thisA,
float thatR,
float thatG,
float thatB,
float thatA) |
static <I extends Image<?,I>> |
assignBufferedImage(BufferedImage img,
I oiImage)
Assign the contents of a
BufferedImage to an Image . |
protected static boolean |
checkSameSize(Image<?,?>... images)
Checks whether the width and height of all the given images match.
|
protected static boolean |
checkSize(int h,
int w,
Image<?,?>... images)
Checks whether the width and height of all the given images match the
given width and height.
|
protected static boolean |
checkSize(int h,
int w,
Iterable<? extends Image<?,?>> images)
Checks whether the width and height of all the given images match the
given width and height.
|
static BufferedImage |
createBufferedImage(FImage img)
Efficiently create a TYPE_BYTE_GRAY for display.
|
static BufferedImage |
createBufferedImage(FImage img,
BufferedImage ret)
Efficiently create a TYPE_BYTE_GRAY for display.
|
static BufferedImage |
createBufferedImage(Image<?,?> img)
Convert any image to a
BufferedImage . |
static BufferedImage |
createBufferedImage(Image<?,?> img,
BufferedImage bimg)
Convert any image to a
BufferedImage . |
static BufferedImage |
createBufferedImageForDisplay(Image<?,?> img)
Convert any image to a
BufferedImage . |
static BufferedImage |
createBufferedImageForDisplay(Image<?,?> img,
BufferedImage bimg)
Convert any image to a
BufferedImage . |
static BufferedImage |
createBufferedImageForDisplay(MBFImage img)
Efficiently create a TYPE_3BYTE_BGR for display if possible.
|
static BufferedImage |
createBufferedImageForDisplay(MBFImage img,
BufferedImage ret)
Efficiently create a TYPE_3BYTE_BGR for display if possible.
|
static FImage |
createFImage(BufferedImage image)
Create an FImage from a buffered image.
|
static MBFImage |
createMBFImage(BufferedImage image,
boolean alpha)
Create an MBFImage from a buffered image.
|
static BufferedImage |
createWorkingImage(BufferedImage bimg)
Returns a ARGB BufferedImage, even if the input BufferedImage is not ARGB
format.
|
protected static byte[] |
getBytes(File file)
Returns the contents of a file in a byte array.
|
protected static byte[] |
getBytes(InputStream stream)
Converts the input stream to a byte array.
|
static FImage[] |
getNormalisedColourPlanes(BufferedImage bimg)
Calculate normalised RGB planes.
|
static boolean |
isWriteFormatSupported(File file)
Test if the image output format suggested by the extension of the given
filename is supported
|
static boolean |
isWriteFormatSupported(String fmt)
Test if a given image output format name is supported
|
protected static int |
pnmReadHeader(byte[] data,
Map<String,Integer> headerData)
Reads a PNM header from the byte array containing the PNM binary data.
|
static FImage |
readF(DataInput in)
Read an
FImage from a DataInput |
static FImage |
readF(File input)
Reads an
FImage from the given file. |
static FImage |
readF(InputStream input)
Reads an
FImage from the given input stream. |
static FImage |
readF(URL input)
Reads an
FImage from the given URL. |
static MBFImage |
readMBF(File input)
Reads an
MBFImage from the given file. |
static MBFImage |
readMBF(InputStream input)
Reads an
MBFImage from the given input stream. |
static MBFImage |
readMBF(URL input)
Reads an
MBFImage from the given URL. |
static MBFImage |
readMBFAlpha(File input)
Reads an
MBFImage from the given file. |
static MBFImage |
readMBFAlpha(InputStream input)
Reads an
MBFImage from the given input stream. |
static MBFImage |
readMBFAlpha(URL input)
Reads an
MBFImage from the given URL. |
static void |
write(Image<?,?> image,
File output)
Write the given image to the given file, guessing the format name from
the extension.
|
static void |
write(Image<?,?> img,
String formatName,
DataOutput out)
Write an image to a
DataOutput . |
static void |
write(Image<?,?> image,
String formatName,
File output)
Write the given image to the given file with the given format name.
|
static void |
write(Image<?,?> image,
String formatName,
ImageOutputStream output)
Write the given image to the given file with the given format name.
|
static void |
write(Image<?,?> image,
String formatName,
OutputStream output)
Write the given image to the given file with the given format name.
|
public static final InputStreamObjectReader<FImage> FIMAGE_READER
InputStreamObjectReader
for reading FImage
s.public static final InputStreamObjectReader<MBFImage> MBFIMAGE_READER
InputStreamObjectReader
for reading MBFImage
s.public static final float[] BYTE_TO_FLOAT_LUT
public static FImage[] getNormalisedColourPlanes(BufferedImage bimg)
bimg
- A BufferedImage
from which the planes are extracted.FImage
.public static BufferedImage createWorkingImage(BufferedImage bimg)
bimg
- The BufferedImage
to normalise to ARGBBufferedImage
public static void write(Image<?,?> image, String formatName, File output) throws IOException
ImageIO.write(java.awt.image.RenderedImage, String, File)
.image
- The image to write.formatName
- a String
containing the informal name of the format.output
- The File
to write the image to.IOException
- If the image cannot be written to the file.public static void write(Image<?,?> image, String formatName, OutputStream output) throws IOException
ImageIO.write(java.awt.image.RenderedImage, String, OutputStream)
.image
- The image to write.formatName
- a String
containing the informal name of the format.output
- The OutputStream
to write the image to.IOException
- If the image cannot be written to the file.public static void write(Image<?,?> image, String formatName, ImageOutputStream output) throws IOException
ImageIO.write(java.awt.image.RenderedImage, String, ImageOutputStream)
.image
- The image to write.formatName
- a String
containing the informal name of the format.output
- The ImageOutputStream
to write the image to.IOException
- If the image cannot be written to the file.public static void write(Image<?,?> image, File output) throws IOException
ImageIO.write(java.awt.image.RenderedImage, String, File)
.image
- The image to write.output
- The File
to write the image to.IOException
- If the image cannot be written to the file.public static FImage createFImage(BufferedImage image)
image
- the imagepublic static MBFImage createMBFImage(BufferedImage image, boolean alpha)
image
- the imagealpha
- should the resultant MBFImage have an alpha channelpublic static FImage readF(File input) throws IOException
FImage
from the given file.input
- The file to read the FImage
from.FImage
IOException
- if the file cannot be readpublic static FImage readF(InputStream input) throws IOException
FImage
from the given input stream.input
- The input stream to read the FImage
from.FImage
IOException
- if the stream cannot be readpublic static FImage readF(URL input) throws IOException
FImage
from the given URL.input
- The URL to read the FImage
from.FImage
IOException
- if the URL stream cannot be readpublic static MBFImage readMBF(File input) throws IOException
MBFImage
from the given file.input
- The file to read the MBFImage
from.MBFImage
IOException
- if the file cannot be readpublic static MBFImage readMBF(InputStream input) throws IOException
MBFImage
from the given input stream.input
- The input stream to read the MBFImage
from.MBFImage
IOException
- if the stream cannot be readpublic static MBFImage readMBF(URL input) throws IOException
MBFImage
from the given URL.input
- The URL to read the MBFImage
from.MBFImage
IOException
- if the URL stream cannot be readpublic static MBFImage readMBFAlpha(File input) throws IOException
MBFImage
from the given file. The resultant MBImage will
contain an alpha channelinput
- The file to read the MBFImage
from.MBFImage
IOException
- if the file cannot be readpublic static MBFImage readMBFAlpha(InputStream input) throws IOException
MBFImage
from the given input stream. The resultant
MBImage will contain an alpha channelinput
- The input stream to read the MBFImage
from.MBFImage
IOException
- if the stream cannot be readpublic static MBFImage readMBFAlpha(URL input) throws IOException
MBFImage
from the given URL. The resultant MBImage will
contain an alpha channelinput
- The URL to read the MBFImage
from.MBFImage
IOException
- if the URL stream cannot be readprotected static boolean checkSameSize(Image<?,?>... images)
images
- The images to compare sizes.protected static boolean checkSize(int h, int w, Image<?,?>... images)
h
- The height to match against all the imagesw
- The width to match against all the imagesimages
- The images to compare sizes.wxh
in size; FALSE
otherwiseprotected static boolean checkSize(int h, int w, Iterable<? extends Image<?,?>> images)
h
- The height to match against all the imagesw
- The width to match against all the imagesimages
- The images to compare sizes.wxh
in size; FALSE
otherwiseprotected static int pnmReadHeader(byte[] data, Map<String,Integer> headerData) throws IOException
headerData
variable will be populated with the header
information. Returns the number of bytes read from the array.data
- The PNM binary data.headerData
- A Map
to populate with header information.IOException
- if the byte array does not contain PNM information.protected static byte[] getBytes(File file) throws IOException
file
- The file to readIOException
- if the file cannot be read fully.protected static byte[] getBytes(InputStream stream) throws IOException
stream
- The InputStream
to convert to byte arrayInputStream
data.IOException
- if the input stream cannot be fully read.public static BufferedImage createBufferedImage(Image<?,?> img)
BufferedImage
.img
- image to convertpublic static BufferedImage createBufferedImage(Image<?,?> img, BufferedImage bimg)
BufferedImage
.img
- image to convertbimg
- BufferedImage to draw into if possible. Can be null.public static BufferedImage createBufferedImageForDisplay(Image<?,?> img)
BufferedImage
.img
- image to convertpublic static BufferedImage createBufferedImageForDisplay(Image<?,?> img, BufferedImage bimg)
BufferedImage
.img
- image to convertbimg
- BufferedImage to draw into if possible. Can be null.public static BufferedImage createBufferedImageForDisplay(MBFImage img)
img
- the image to convertpublic static BufferedImage createBufferedImageForDisplay(MBFImage img, BufferedImage ret)
img
- the image to convertret
- the image to draw into if possible. Can be null.public static BufferedImage createBufferedImage(FImage img)
img
- the image to convertpublic static BufferedImage createBufferedImage(FImage img, BufferedImage ret)
img
- the image to convertret
- BufferedImage to draw into if possible. Can be null.public static void write(Image<?,?> img, String formatName, DataOutput out) throws IOException
DataOutput
.img
- the imageformatName
- the formatout
- the outputIOException
- if an error occurspublic static FImage readF(DataInput in) throws IOException
FImage
from a DataInputin
- inputIOException
- if error occurspublic static <I extends Image<?,I>> I assignBufferedImage(BufferedImage img, I oiImage)
BufferedImage
to an Image
.I
- the type of Image
img
- the BufferedImage
to copyoiImage
- the Image
to fillpublic static float[] alphaCompositePixel(float[] p1, float[] p2)
p1
- The first pixelp2
- The second pixelpublic static float[] alphaCompositePixel(float[] out, float thisR, float thisG, float thisB, float thisA, float thatR, float thatG, float thatB, float thatA)
out
- where the write the compositionthisR
- thisG
- thisB
- thisA
- thatR
- thatG
- thatB
- thatA
- public static float[] alphaCompositePixel(Float[] p1, Float[] p2)
p1
- The first pixelp2
- The second pixelpublic static boolean isWriteFormatSupported(String fmt)
fmt
- the format namepublic static boolean isWriteFormatSupported(File file)
file
- the file