下面列出了java.awt.image.DataBuffer#TYPE_UNDEFINED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
static String getDTName(int dType) {
switch(dType) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
}
return "UNKNOWN";
}
/**
* Sets the data as vectors. The number of vectors must be equal to the {@linkplain #getNumBands() expected number of bands}.
* All vectors must be backed by arrays (indirectly, through {@linkplain Vector#buffer() buffers} backed by arrays) and have
* the same {@linkplain Vector#size() size}.
* This method wraps the underlying arrays of a primitive type into a Java2D buffer; data are not copied.
*
* <p><b>Implementation note:</b> the NIO buffers are set by a call to {@link #setData(int, Buffer...)},
* which can be overridden by subclasses if desired.</p>
*
* @param data the vectors wrapping arrays of primitive type.
* @throws NullArgumentException if {@code data} is null or one of {@code data} element is null.
* @throws MismatchedCoverageRangeException if the number of specified vectors is not equal to the number of bands.
* @throws UnsupportedOperationException if a vector is not backed by an accessible array or is read-only.
* @throws RasterFormatException if vectors do not have the same size.
* @throws ArithmeticException if a buffer position overflows the 32 bits integer capacity.
*/
public void setData(final Vector... data) {
ArgumentChecks.ensureNonNull("data", data);
ensureExpectedBandCount(data.length, true);
final Buffer[] buffers = new Buffer[data.length];
int dataType = DataBuffer.TYPE_UNDEFINED;
for (int i=0; i<data.length; i++) {
final Vector v = data[i];
ArgumentChecks.ensureNonNullElement("data", i, v);
final int t = RasterFactory.getType(v.getElementType(), v.isUnsigned());
if (dataType != t) {
if (i != 0) {
throw new RasterFormatException(Resources.format(Resources.Keys.MismatchedDataType));
}
dataType = t;
}
buffers[i] = v.buffer().orElseThrow(UnsupportedOperationException::new);
}
setData(dataType, buffers);
}
/** Turns a DataBuffer.TYPE_* integer into a string
@param datatype the DataBuffer.TYPE_* integer
@return human readable form */
public static String getDataType(int datatype) {
switch (datatype) {
case DataBuffer.TYPE_BYTE:
return "TYPE_BYTE";
case DataBuffer.TYPE_DOUBLE:
return "TYPE_DOUBLE";
case DataBuffer.TYPE_FLOAT:
return "TYPE_FLOAT";
case DataBuffer.TYPE_INT:
return "TYPE_INT";
case DataBuffer.TYPE_SHORT:
return "TYPE_SHORT";
case DataBuffer.TYPE_UNDEFINED:
return "TYPE_UNDEFINED";
case DataBuffer.TYPE_USHORT:
return "TYPE_USHORT";
default:
return "unknown";
}
}
/**
* Returns the {@link DataBuffer} constant for the given type. The given {@code sample} class
* should be a primitive type such as {@link Float#TYPE}. Wrappers class are also accepted.
*
* @param sample the primitive type or its wrapper class. May be {@code null}.
* @param unsigned whether the type should be considered unsigned.
* @return the {@link DataBuffer} type, or {@link DataBuffer#TYPE_UNDEFINED}.
*/
public static int getType(final Class<?> sample, final boolean unsigned) {
switch (Numbers.getEnumConstant(sample)) {
case Numbers.BYTE: if (unsigned) return DataBuffer.TYPE_BYTE; else break;
case Numbers.SHORT: return unsigned ? DataBuffer.TYPE_USHORT : DataBuffer.TYPE_SHORT;
case Numbers.INTEGER: if (!unsigned) return DataBuffer.TYPE_INT; else break;
case Numbers.FLOAT: return DataBuffer.TYPE_FLOAT;
case Numbers.DOUBLE: return DataBuffer.TYPE_DOUBLE;
}
return DataBuffer.TYPE_UNDEFINED;
}
/**
* Returns whether the given variable is used as a coordinate system axis, a coverage or something else.
* In particular this method shall return {@link VariableRole#AXIS} if the given variable seems to be a
* coordinate system axis instead than the actual data. By netCDF convention, coordinate system axes
* have the name of one of the dimensions defined in the netCDF header.
*
* <p>The default implementation returns {@link VariableRole#COVERAGE} if the given variable can be used
* for generating an image, by checking the following conditions:</p>
*
* <ul>
* <li>Images require at least {@value Grid#MIN_DIMENSION} dimensions of size equals or greater than {@value Grid#MIN_SPAN}.
* They may have more dimensions, in which case a slice will be taken later.</li>
* <li>Exclude axes. Axes are often already excluded by the above condition because axis are usually 1-dimensional,
* but some axes are 2-dimensional (e.g. a localization grid).</li>
* <li>Excludes characters, strings and structures, which can not be easily mapped to an image type.
* In addition, 2-dimensional character arrays are often used for annotations and we do not want
* to confuse them with images.</li>
* </ul>
*
* @param variable the variable for which to get the role.
* @return role of the given variable.
*/
public VariableRole roleOf(final Variable variable) {
if (variable.isCoordinateSystemAxis()) {
return VariableRole.AXIS;
}
int numVectors = 0; // Number of dimension having more than 1 value.
for (final Dimension dimension : variable.getGridDimensions()) {
if (dimension.length() >= Grid.MIN_SPAN) {
numVectors++;
}
}
if (numVectors >= Grid.MIN_DIMENSION) {
final DataType dataType = variable.getDataType();
if (dataType.rasterDataType != DataBuffer.TYPE_UNDEFINED) {
return VariableRole.COVERAGE;
}
}
return VariableRole.OTHER;
}