public final class Tools extends Object
Modifier and Type | Field and Description |
---|---|
static String |
FILE_TYPE_BMP
Key for BMP image file type.
|
static String |
FILE_TYPE_GIF
Key for GIF image file type.
|
static String |
FILE_TYPE_IMAGE
Key for all image file type.
|
static String |
FILE_TYPE_JPEG
Key for JPEG image file type.
|
static String |
FILE_TYPE_PNG
Key for PNG image file type.
|
static String |
FILE_TYPE_TIFF
Key for TIFF image file type.
|
(package private) static char[] |
HEXCHARS |
static long |
MAX_INT16 |
static long |
MAX_INT32 |
static long |
MAX_INT64 |
static long |
MAX_INT8 |
static long |
MAX_UINT16 |
static long |
MAX_UINT32 |
static BigInteger |
MAX_UINT64 |
static long |
MAX_UINT8 |
Constructor and Description |
---|
Tools() |
Modifier and Type | Method and Description |
---|---|
static boolean |
applyBitmask(Object theData,
BitSet theMask,
ViewProperties.BITMASK_OP op)
Apply bitmask to a data array.
|
static Object |
autoContrastApply(Object data_in,
Object data_out,
double[] params,
double[] minmax,
boolean isUnsigned)
Apply autocontrast parameters to the original data in place (destructive)
|
static int |
autoContrastCompute(Object data,
double[] params,
boolean isUnsigned)
Computes autocontrast parameters (gain equates to contrast and bias
equates to brightness) for integers.
|
static int |
autoContrastComputeMinMax(Object data,
double[] minmax)
Computes autocontrast parameters by
|
static int |
autoContrastConvertImageBuffer(Object src,
byte[] dst,
boolean isUnsigned)
Converts image raw data to bytes.
|
static File |
checkNewFile(String path,
String ext)
Check and find a non-exist file.
|
static boolean |
checkValidJavaArrayIndex(long value)
Since Java does not allow array indices to be larger than int type, check the
given value to see if it is within the valid range of a Java int.
|
static int |
computeStatistics(Object data,
double[] avgstd,
Object fillValue)
Computes mean and standard deviation of a data array
|
static void |
convertImageToHDF(String imgFileName,
String hFileName,
String fromType,
String toType)
Converts an image file into HDF4/5 file.
|
static BigInteger |
convertUINT64toBigInt(Long l)
Converts unsigned 64-bit integer data to a BigInteger since Java does not
have unsigned types.
|
static byte[][] |
createGrayPalette()
Creates the gray palette of the indexed 256-color table.
|
static byte[][] |
createGrayWavePalette()
Creates the gray wave palette of the indexed 256-color table.
|
static Image |
createIndexedImage(BufferedImage bufferedImage,
byte[] imageData,
byte[][] palette,
long w,
long h)
Creates a RGB indexed image of 256 colors.
|
static byte[][] |
createNaturePalette()
Creates the nature palette of the indexed 256-color table.
|
static FileFormat |
createNewFile(String filename,
String dir,
String type,
List<FileFormat> openFiles)
Create a new HDF file with default file creation properties
|
static byte[][] |
createRainbowPalette()
Creates the rainbow palette of the indexed 256-color table.
|
static byte[][] |
createReverseGrayPalette()
Creates the reverse gray palette of the indexed 256-color table.
|
static Image |
createTrueColorImage(byte[] imageData,
boolean planeInterlace,
long w,
long h)
Creates a true color image.
|
static byte[][] |
createWavePalette()
Creates the wave palette of the indexed 256-color table.
|
static void |
debug(Object caller,
Object msg)
Print out debug information
|
static int |
findDataDist(Object data,
int[] dataDist,
double[] minmax)
Finds the distribution of data values
|
static int |
findMinMax(Object data,
double[] minmax,
Object fillValue)
Finds the min and max values of the data array
|
static boolean |
getBinaryDataFromFile(Object dataOut,
String fileName,
ByteOrder order)
Reads data from a binary file into a buffer.
|
static byte[] |
getBytes(Object rawData,
double[] minmax,
long w,
long h,
boolean isTransposed,
byte[] byteData)
Convert an array of raw data into array of a byte data.
|
static byte[] |
getBytes(Object rawData,
double[] minmax,
long w,
long h,
boolean isTransposed,
List<Number> invalidValues,
boolean convertByteData,
byte[] byteData) |
static byte[] |
getBytes(Object rawData,
double[] minmax,
long w,
long h,
boolean isTransposed,
List<Number> invalidValues,
boolean convertByteData,
byte[] byteData,
List<Integer> list)
Convert an array of raw data into array of a byte data.
|
static byte[] |
getBytes(Object rawData,
double[] minmax,
long w,
long h,
boolean isTransposed,
List<Number> invalidValues,
byte[] byteData) |
static byte[] |
getHDF5UserBlock(String filename)
Read HDF5 user block data into byte array.
|
static char |
getJavaObjectRuntimeClass(Object o)
Retrieves the Java Runtime Class of the given Object.
|
static boolean |
hasAlpha(Image image)
This method returns true if the specified image has transparent pixels.
|
static boolean |
isHDF4(String filename)
look at the first 4 bytes of the file to see if it is an HDF4 file.
|
static boolean |
isHDF5(String filename)
look at the first 8 bytes of the file to see if it is an HDF5 file.
|
static boolean |
isNaNINF(double val)
Check if a given number if NaN or INF.
|
static boolean |
isNetcdf(String filename)
look at the first 4 bytes of the file to see if it is a netCDF file
byte[0]=67, byte[1]=68, byte[2]=70, byte[3]=1 or
|
static void |
launchBrowser(String url)
Launch default browser for a given URL.
|
static Object |
newInstance(Class<?> cls,
Object[] initargs)
Create and initialize a new instance of the given class.
|
static byte[][] |
readPalette(String filename)
read an image palette from a file.
|
static void |
saveAsBinary(DataOutputStream out,
Object data,
ByteOrder order) |
static void |
saveImageAs(BufferedImage image,
File file,
String type)
Save a BufferedImage into an image file.
|
static boolean |
setHDF5UserBlock(String fin,
String fout,
byte[] buf)
Write HDF5 user block data into byte array.
|
static boolean |
showConfirm(org.eclipse.swt.widgets.Shell parent,
String title,
String confMsg)
Show an SWT Confirm dialog with the given message.
|
static void |
showError(org.eclipse.swt.widgets.Shell parent,
String title,
String errorMsg)
Show an SWT error dialog with the given error message.
|
static void |
showInformation(org.eclipse.swt.widgets.Shell parent,
String title,
String infoMsg)
Show an SWT Information dialog with the given message.
|
static void |
showWarning(org.eclipse.swt.widgets.Shell parent,
String title,
String warnMsg)
Show an SWT Warning dialog with the given message.
|
static String |
toBinaryString(BigInteger v,
int nbytes) |
static String |
toBinaryString(long v,
int nbytes)
Returns a string representation of the long argument as an unsigned
integer in base 2.
|
static BufferedImage |
toBufferedImage(Image image)
This method returns a buffered image with the contents of an image.
|
static String |
toHexString(BigInteger v,
int nbytes)
Returns a string representation of the BigInteger argument as an unsigned integer in base 16.
|
static String |
toHexString(long v,
int nbytes)
Returns a string representation of the long argument as an unsigned integer in base 16.
|
public static final long MAX_INT8
public static final long MAX_UINT8
public static final long MAX_INT16
public static final long MAX_UINT16
public static final long MAX_INT32
public static final long MAX_UINT32
public static final long MAX_INT64
public static final BigInteger MAX_UINT64
public static final String FILE_TYPE_JPEG
public static final String FILE_TYPE_TIFF
public static final String FILE_TYPE_PNG
public static final String FILE_TYPE_GIF
public static final String FILE_TYPE_BMP
public static final String FILE_TYPE_IMAGE
static final char[] HEXCHARS
public Tools()
public static final void debug(Object caller, Object msg)
caller
- the caller object.msg
- the message to be displayed.public static BigInteger convertUINT64toBigInt(Long l)
l
- The long value to convert to a BigIntegerpublic static void convertImageToHDF(String imgFileName, String hFileName, String fromType, String toType) throws Exception
imgFileName
- the input image file.hFileName
- the name of the HDF4/5 file.fromType
- the type of image.toType
- the type of file converted to.Exception
- if a failure occurredpublic static void saveImageAs(BufferedImage image, File file, String type) throws Exception
image
- the BufferedImage to save.file
- the image file.type
- the image type.Exception
- if a failure occurredpublic static final byte[][] createGrayPalette()
The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.
public static final byte[][] createReverseGrayPalette()
The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.
public static final byte[][] createGrayWavePalette()
The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.
public static final byte[][] createRainbowPalette()
The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.
public static final byte[][] createNaturePalette()
The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.
public static final byte[][] createWavePalette()
The palette values are stored in a two-dimensional byte array and arrange by color components of red, green and blue. palette[][] = byte[3][256], where, palette[0][], palette[1][] and palette[2][] are the red, green and blue components respectively.
public static final byte[][] readPalette(String filename)
filename
- the name of the palette file.public static boolean hasAlpha(Image image)
image
- the image to be check if has alpha.public static Image createIndexedImage(BufferedImage bufferedImage, byte[] imageData, byte[][] palette, long w, long h)
bufferedImage
- the target image.imageData
- the byte array of the image data.palette
- the color lookup table.w
- the width of the image.h
- the height of the image.public static Image createTrueColorImage(byte[] imageData, boolean planeInterlace, long w, long h)
DirectColorModel is used to construct the image from raw data. The
DirectColorModel model is similar to an X11 TrueColor visual, which has
the following parameters:
Number of bits: 32 Red mask: 0x00ff0000 Green mask: 0x0000ff00 Blue mask: 0x000000ff Alpha mask: 0xff000000 Color space: sRGB isAlphaPremultiplied: False Transparency: Transparency.TRANSLUCENT transferType: DataBuffer.TYPE_INT
The data may be arranged in one of two ways: by pixel or by plane. In both cases, the dataset will have a dataspace with three dimensions, height, width, and components.
For HDF4, the interlace modes specify orders for the dimensions as:
INTERLACE_PIXEL = [width][height][pixel components] INTERLACE_PLANE = [pixel components][width][height]
For HDF5, the interlace modes specify orders for the dimensions as:
INTERLACE_PIXEL = [height][width][pixel components] INTERLACE_PLANE = [pixel components][height][width]
imageData
- the byte array of the image data.planeInterlace
- flag if the image is plane intelace.w
- the width of the image.h
- the height of the image.public static BufferedImage toBufferedImage(Image image)
image
- the plain image object.public static byte[] getBytes(Object rawData, double[] minmax, long w, long h, boolean isTransposed, byte[] byteData)
rawData
- The input raw data.minmax
- the range of the raw data.w
- the width of the raw data.h
- the height of the raw data.isTransposed
- if the data is transposed.byteData
- the data in.public static byte[] getBytes(Object rawData, double[] minmax, long w, long h, boolean isTransposed, List<Number> invalidValues, byte[] byteData)
public static byte[] getBytes(Object rawData, double[] minmax, long w, long h, boolean isTransposed, List<Number> invalidValues, boolean convertByteData, byte[] byteData)
public static byte[] getBytes(Object rawData, double[] minmax, long w, long h, boolean isTransposed, List<Number> invalidValues, boolean convertByteData, byte[] byteData, List<Integer> list)
rawData
- The input raw data.minmax
- the range of the raw data.w
- the width of the raw data.h
- the height of the raw data.isTransposed
- if the data is transposed.invalidValues
- the list of invalid values.convertByteData
- the converted data out.byteData
- the data in.list
- the list of integers.public static Object newInstance(Class<?> cls, Object[] initargs) throws Exception
cls
- the class of the instanceinitargs
- array of objects to be passed as arguments.Exception
- if a failure occurredpublic static int autoContrastCompute(Object data, double[] params, boolean isUnsigned)
The computation is based on the following scaling
int_8 [0, 127] uint_8 [0, 255] int_16 [0, 32767] uint_16 [0, 65535] int_32 [0, 2147483647] uint_32 [0, 4294967295] int_64 [0, 9223372036854775807] uint_64 [0, 18446744073709551615] // Not supported.
data
- the raw data array of signed/unsigned integersparams
- the auto gain parameter. params[0]=gain, params[1]=bias,isUnsigned
- the flag to indicate if the data array is unsigned integer.public static Object autoContrastApply(Object data_in, Object data_out, double[] params, double[] minmax, boolean isUnsigned)
data_in
- the original data array of signed/unsigned integersdata_out
- the converted data array of signed/unsigned integersparams
- the auto gain parameter. params[0]=gain, params[1]=biasminmax
- the data range. minmax[0]=min, minmax[1]=maxisUnsigned
- the flag to indicate if the data array is unsigned integerpublic static int autoContrastConvertImageBuffer(Object src, byte[] dst, boolean isUnsigned)
uint_8 x int_8 (x & 0x7F) << 1 uint_16 (x >> 8) & 0xFF int_16 (x >> 7) & 0xFF uint_32 (x >> 24) & 0xFF int_32 (x >> 23) & 0xFF uint_64 (x >> 56) & 0xFF int_64 (x >> 55) & 0xFF
src
- the source data array of signed integers or unsigned shortsdst
- the destination data array of bytesisUnsigned
- the flag to indicate if the data array is unsigned integer.public static int autoContrastComputeMinMax(Object data, double[] minmax)
min = mean - 3 * std.dev max = mean + 3 * std.dev
data
- the raw data arrayminmax
- the min and max values.public static int findMinMax(Object data, double[] minmax, Object fillValue)
data
- the raw data arrayminmax
- the mmin and max values of the array.fillValue
- the missing value or fill value. Exclude this value when check
for min/maxpublic static int findDataDist(Object data, int[] dataDist, double[] minmax)
data
- the raw data arraydataDist
- the data distirbution.minmax
- the data rangepublic static int computeStatistics(Object data, double[] avgstd, Object fillValue)
data
- the raw data arrayavgstd
- the statistics: avgstd[0]=mean and avgstd[1]=stdev.fillValue
- the missing value or fill value. Exclude this value when
compute statisticspublic static void saveAsBinary(DataOutputStream out, Object data, ByteOrder order) throws Exception
Exception
public static boolean getBinaryDataFromFile(Object dataOut, String fileName, ByteOrder order)
dataOut
- the output streamfileName
- the file to read binary data fromorder
- the new byte order, either BIG_ENDIAN or LITTLE_ENDIANpublic static final String toBinaryString(long v, int nbytes)
v
- the long valuenbytes
- number of bytes in the integerpublic static final String toBinaryString(BigInteger v, int nbytes)
public static final String toHexString(long v, int nbytes)
v
- the long valuenbytes
- number of bytes in the integerpublic static final String toHexString(BigInteger v, int nbytes)
v
- the BigInteger valuenbytes
- number of bytes in the integerpublic static final boolean applyBitmask(Object theData, BitSet theMask, ViewProperties.BITMASK_OP op)
theData
- the data array which the bitmask is applied to.theMask
- the bitmask to be applied to the data array.op
- the bitmask op to be appliedpublic static byte[] getHDF5UserBlock(String filename)
filename
- the HDF5 file from which to get the user blockpublic static boolean setHDF5UserBlock(String fin, String fout, byte[] buf)
fin
- the input filenamefout
- the output filenamebuf
- the data to write into the user blockpublic static boolean isHDF4(String filename)
filename
- the file to test if HDF4public static boolean isHDF5(String filename)
filename
- the file to test if HDF5public static boolean isNetcdf(String filename)
filename
- the file to test if netcdfpublic static final void launchBrowser(String url) throws Exception
url
- the URL to open.Exception
- if a failure occurredpublic static FileFormat createNewFile(String filename, String dir, String type, List<FileFormat> openFiles) throws Exception
filename
- the file to createdir
- the directory for filetype
- the type of the fileopenFiles
- the list of already opened filesException
- if a failure occurredpublic static final File checkNewFile(String path, String ext)
path
- -- the path that the new file will be checked.ext
- -- the extention of the new file.public static final boolean isNaNINF(double val)
val
- the nubmer to be checkedpublic static boolean checkValidJavaArrayIndex(long value)
value
- The value to checkpublic static char getJavaObjectRuntimeClass(Object o)
o
- the Object to determine the Runtime Class ofpublic static void showError(org.eclipse.swt.widgets.Shell parent, String title, String errorMsg)
parent
- The parent Shell of the MessageDialogtitle
- The title to set for the MessageDialogerrorMsg
- The error message to display in the MessageDialogpublic static void showInformation(org.eclipse.swt.widgets.Shell parent, String title, String infoMsg)
parent
- The parent Shell of the MessageDialogtitle
- The title to set for the MessageDialoginfoMsg
- The message to display in the MessageDialogpublic static boolean showConfirm(org.eclipse.swt.widgets.Shell parent, String title, String confMsg)
parent
- The parent Shell of the MessageDialogtitle
- The title to set for the MessageDialogconfMsg
- The message to display in the MessageDialogpublic static void showWarning(org.eclipse.swt.widgets.Shell parent, String title, String warnMsg)
parent
- The parent Shell of the MessageDialogtitle
- The title to set for the MessageDialogwarnMsg
- The message to display in the MessageDialogCopyright © 2018. All Rights Reserved.