Enum Class DataType
- All Implemented Interfaces:
Serializable,Comparable<DataType>,Constable
Identification of the primitive type used for storing sample values in an image.
This is a type-safe version of the
TYPE_* constants defined in DataBuffer,
except that this enumeration distinguishes signed and unsigned 32 bits integers.- Since:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionfinal intbytes()Returns the size in bytes of this data type.final NumberReturns the default fill value, which is 0 for integer types and NaN for floating point types.static DataTypeforBands(RenderedImage image) Returns the data type of the bands in the given image.static DataTypeReturns the data type of the bands managed by the given the sample model.static DataTypeforDataBufferType(int type) Returns the enumeration value for the givenDataBufferconstant.static DataTypeforNumberOfBits(int size, boolean real, boolean signed) Returns the enumeration value for the given number of bits.static DataTypeforPrimitiveType(Class<?> type, boolean unsigned) Returns the data type for the given primitive type.static DataTypeforRange(NumberRange<?> range, boolean forceInteger) Returns the smallest data type capable to store the given range of values.final booleanReturns whether this type is an integer type, signed or not.static booleanReturnstrueif the given sample model uses an integer type.final booleanReturns whether this type is an unsigned integer type.static booleanReturnstrueif the type of sample values is an unsigned integer type.final intsize()Returns the size in bits of this data type.final intReturns theDataBufferconstant for this enumeration value.final DataTypetoFloat()Returns the smallest floating point type capable to store all values of this type without precision lost.final DataTypeReturns the primitive (signed) variant of this data type.static DataTypeReturns the enum constant of this class with the specified name.static DataType[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Enum Constant Details
-
BYTE
Unsigned 8-bits data. Mapped toDataBuffer.TYPE_BYTEin Java2D API. -
USHORT
Unsigned 16-bits data. Mapped toDataBuffer.TYPE_USHORTin Java2D API. -
SHORT
Signed 16-bits data. Mapped toDataBuffer.TYPE_SHORTin Java2D API. -
INT
Signed 32-bits data. Mapped toDataBuffer.TYPE_INTin Java2D API. Note that the sign of the latter Java2D type is ambiguous. SeeforDataBufferType(int)for more information.This type is selected by default for all
DataBuffer.TYPE_INTcases that cannot be resolved as anUINTcase. -
UINT
Unsigned 32-bits data. Mapped toDataBuffer.TYPE_INTin Java2D API. Note that the sign of the latter Java2D type is ambiguous. SeeforDataBufferType(int)for more information.This case is selected when the data are used with any packed sample model:
SinglePixelPackedSampleModelorMultiPixelPackedSampleModel.- Since:
- 1.5
-
FLOAT
Single precision (32-bits) floating point data. Mapped toDataBuffer.TYPE_FLOATin Java2D API. -
DOUBLE
Double precision (64-bits) floating point data. Mapped toDataBuffer.TYPE_DOUBLEin Java2D API.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
forBands
Returns the data type of the bands in the given image. This is often the storage data type, but not necessarily. SeeforBands(SampleModel)for more information.- Parameters:
image- the image for which to get the band data type.- Returns:
- type of sample values in the given image (never
null). - Throws:
RasterFormatException- if the image does not use a recognized data type.
-
forBands
Returns the data type of the bands managed by the given the sample model. This is often the storage data type, but not necessarily. For example, if an ARGB image uses a storage mode where the sample values in the four bands are packed in a single 32-bits integer, then this method returnsBYTE(the type of a single band) rather thanINT(the type of a whole pixel).- Parameters:
sm- the sample model for which to get the band data type.- Returns:
- type of sample values in the bands managed by the given sample model (never
null). - Throws:
RasterFormatException- if the sample model does not use a recognized data type.- Since:
- 1.5
-
forRange
Returns the smallest data type capable to store the given range of values. If the given range uses a floating point type, there there is a choice:- Parameters:
range- the range of values.forceInteger- whether to handle floating point values as integers.- Returns:
- smallest data type for the given range of values.
-
forPrimitiveType
Returns the data type for the given primitive type. The giventypeshould be a primitive type such asShort.TYPE, but wrappers class such asShort.classare also accepted.- Parameters:
type- the primitive type or its wrapper class.unsigned- whether the type should be considered unsigned.- Returns:
- the data type (never
null) for the given primitive type. - Throws:
RasterFormatException- if the given type is not a recognized.
-
forDataBufferType
Returns the enumeration value for the givenDataBufferconstant. This method is the converse oftoDataBufferType(). It is provided for interoperability with Java2D.32 bit integers
The case ofDataBuffer.TYPE_INTis ambiguous. Whether this type is considered as signed or unsigned depends on the context:- The sign is indistinguishable when using Java2D API working on integer values
such as the
Raster.getSample(…)method. - When converted to floating point values by Java2D API such as
Raster.getSampleFloat(…), sample values are:- Unsigned when the raster uses
SinglePixelPackedSampleModelorMultiPixelPackedSampleModel. - Signed when the raster uses any other type of sample model.
- Unsigned when the raster uses
- The type is unsigned when converted to a color by
ComponentColorModel.
forBands(SampleModel)instead of this method.- Parameters:
type- one ofDataBuffer.TYPE_*constants.- Returns:
- the data type (never
null) for the given data buffer type. - Throws:
RasterFormatException- if the given type is not a recognizedDataBuffer.TYPE_*constant.
- The sign is indistinguishable when using Java2D API working on integer values
such as the
-
forNumberOfBits
Returns the enumeration value for the given number of bits. Only the following combinations of argument values are accepted:Valid combinations of argument values size real signed 1 falsefalse2 falsefalse4 falsefalse8 falsefalse16 falsefalseortrue32 falsefalseortrue32 trueignored 64 trueignored - Parameters:
size- number of bits as a power of 2 between 1 and 64 inclusive.real-truefor floating point numbers orfalsefor integers.signed-truefor signed numbers offalsefor unsigned numbers.- Returns:
- the data type (never
null) for the given number of bits. - Throws:
RasterFormatException- if the combination of argument values is invalid.- Since:
- 1.2
-
size
public final int size()Returns the size in bits of this data type.- Returns:
- size in bits of this data type.
-
bytes
public final int bytes()Returns the size in bytes of this data type.- Returns:
- size in bytes of this data type, from 1 to 4 inclusive.
- Since:
- 1.3
-
isInteger
-
isInteger
Returnstrueif the given sample model uses an integer type. Returnsfalseif the type is a floating point type or in case of doubt (e.g. forDataBuffer.TYPE_UNDEFINED).- Parameters:
sm- the sample model, ornull.- Returns:
- whether the given sample model uses an integer type.
- Since:
- 1.5
-
isUnsigned
-
isUnsigned
Returnstrueif the type of sample values is an unsigned integer type. Returnsfalseif the type is a floating point type or in case of doubt (e.g. forDataBuffer.TYPE_UNDEFINED).- Parameters:
sm- the sample model, ornull.- Returns:
- whether the given sample model provides unsigned sample values.
- Since:
- 1.5
-
toPrimitive
Returns the primitive (signed) variant of this data type. This method returns the value that most closely maps to a Java primitive type of the same number of bits. Since all Java primitive types are signed, this method returns the signed variant of this type except for the special case ofBYTE(becauseDataTypedoes not define signed variant of that type).More specifically, this methods replaces
UINTbyINT, replacesUSHORTbySHORT, and returns all other types unchanged. The purpose of this method is to simplify theswitchstatements with cases restricted to Java primitive types, such as mapping to specific NIOBuffersubclasses.- Returns:
- the data type that most closely corresponds to a Java primitive type.
- Since:
- 1.5
-
toFloat
Returns the smallest floating point type capable to store all values of this type without precision lost. This method returns: The promotion of integer values to floating point values is sometimes necessary when the image may containFloat.NaNvalues. -
toDataBufferType
public final int toDataBufferType()Returns theDataBufferconstant for this enumeration value. This method is the converse offorDataBufferType(int). It is provided for interoperability with Java2D.- Returns:
- one of the
DataBufferconstants.
-
fillValue
Returns the default fill value, which is 0 for integer types and NaN for floating point types. The class of this number is the wrapper class corresponding to the type of sample values, ignoring whether the type is signed or unsigned. For example, forUSHORT, the returned fill value is an instance of theShortclass.- Returns:
- 0 of NaN in an instance of the wrapper class of the sample values.
- Since:
- 1.5
-