Class FloatDoubleColorModel
- All Implemented Interfaces:
Transparency
ColorModel class that works with pixel values that represent color and alpha information as separate
samples, using float or double elements. This class can be used with an arbitrary ColorSpace. The number
of color samples in the pixel values must be same as the number of color components in the ColorSpace.
There may be a single alpha sample.
Sample values are taken as ranging from 0.0 to 1.0; that is, when converting to 8-bit RGB, a multiplication by 255 is performed and values outside of the range 0-255 are clamped at the closest endpoint.
For maximum efficiency, pixel data being interpreted by this class should be in the sRGB color space. This will result in only the trivial conversion (scaling by 255 and dividing by any premultiplied alpha) to be performed. Other color spaces require more general conversions.
For those methods that use a primitive array pixel representation of type transferType, the array
length is the same as the number of color and alpha samples. Color samples are stored first in the array followed by
the alpha sample, if present. The order of the color samples is specified by the ColorSpace. Typically,
this order reflects the name of the color space type. For example, for TYPE_RGB, index 0 corresponds to
red, index 1 to green, and index 2 to blue. The transfer types supported are DataBuffer.TYPE_FLOAT,
DataBuffer.TYPE_DOUBLE.
The translation from pixel values to color/alpha components for display or processing purposes is a one-to-one correspondence of samples to components.
Methods that use a single int pixel representation throw an IllegalArgumentException.
A FloatDoubleColorModel can be used in conjunction with a ComponentSampleModelImageN.
-
Field Summary
Fields inherited from interface Transparency
BITMASK, OPAQUE, TRANSLUCENT -
Constructor Summary
ConstructorsConstructorDescriptionFloatDoubleColorModel(ColorSpace colorSpace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType) Constructs aComponentColorModelfrom the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptioncoerceData(WritableRaster raster, boolean isAlphaPremultiplied) Forces therasterdata to match the state specified in theisAlphaPremultipliedvariable, assuming the data is currently correctly described by thisColorModel.createCompatibleSampleModel(int w, int h) Creates aSampleModelwith the specified width and height that has a data layout compatible with thisColorModel.createCompatibleWritableRaster(int w, int h) Creates aWritableRasterwith the specified width and height, that has a data layout (SampleModel) compatible with thisColorModel.intgetAlpha(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.intReturns the alpha component for the specified pixel, scaled from 0 to 255.intgetBlue(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.intReturns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace, sRGB.int[]getComponents(int pixel, int[] components, int offset) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.int[]getComponents(Object pixel, int[] components, int offset) Throws anIllegalArgumentExceptionsince the pixel values cannot be placed into anintarray.intgetDataElement(int[] components, int offset) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.getDataElements(int[] components, int offset, Object obj) Returns a data element array representation of a pixel in thisColorModel, given an array of unnormalized color/alpha components.getDataElements(int rgb, Object pixel) Returns a data element array representation of a pixel in thisColorModel, given an integer pixel representation in the default RGB color model.intgetGreen(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.intReturns the green color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace, sRGB.intgetRed(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.intReturns the red color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace, sRGB.intgetRGB(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.intReturns the color/alpha components for the specified pixel in the default RGB color model format.booleanisCompatibleRaster(Raster raster) Returnstrueif the suppliedRaster'sSampleModelis compatible with thisFloatDoubleColorModel.booleanChecks whether or not the specifiedSampleModelis compatible with thisColorModel.toString()Returns aStringcontaining the values of all valid fields.Methods inherited from class ComponentColorModel
equals, getAlphaRaster, getDataElement, getDataElements, getNormalizedComponents, getNormalizedComponents, getUnnormalizedComponents, hashCodeMethods inherited from class ColorModel
finalize, getColorSpace, getComponentSize, getComponentSize, getNumColorComponents, getNumComponents, getPixelSize, getRGBdefault, getTransferType, getTransparency, hasAlpha, isAlphaPremultiplied
-
Constructor Details
-
FloatDoubleColorModel
public FloatDoubleColorModel(ColorSpace colorSpace, boolean hasAlpha, boolean isAlphaPremultiplied, int transparency, int transferType) Constructs aComponentColorModelfrom the specified parameters. Color components will be in the specifiedColorSpace.hasAlphaindicates whether alpha information is present. IfhasAlphais true, then the booleanisAlphaPremultipliedspecifies how to interpret color and alpha samples in pixel values. If the boolean istrue, color samples are assumed to have been multiplied by the alpha sample. Thetransparencyspecifies what alpha values can be represented by this color model. ThetransferTypeis the type of primitive array used to represent pixel values.- Parameters:
colorSpace- TheColorSpaceassociated with this color model.hasAlpha- If true, this color model supports alpha.isAlphaPremultiplied- If true, alpha is premultiplied.transparency- Specifies what alpha values can be represented by this color model.transferType- Specifies the type of primitive array used to represent pixel values, one of DataBuffer.TYPE_FLOAT or TYPE_DOUBLE.- Throws:
IllegalArgumentException- If the transfer type is not DataBuffer.TYPE_FLOAT or TYPE_DOUBLE.- See Also:
-
-
Method Details
-
getRed
public int getRed(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.- Overrides:
getRedin classComponentColorModel
-
getGreen
public int getGreen(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.- Overrides:
getGreenin classComponentColorModel
-
getBlue
public int getBlue(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.- Overrides:
getBluein classComponentColorModel
-
getAlpha
public int getAlpha(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.- Overrides:
getAlphain classComponentColorModel
-
getRGB
public int getRGB(int pixel) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.- Overrides:
getRGBin classComponentColorModel
-
getRed
Returns the red color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace, sRGB. A color conversion is done if necessary. Thepixelvalue is specified by an array of data elements of typetransferTypepassed in as an object reference. The returned value will be a non pre-multiplied value. If the alpha is premultiplied, this method divides it out before returning the value (if the alpha value is 0, the red value will be 0).- Overrides:
getRedin classComponentColorModel- Parameters:
inData- The pixel from which to get the red color component, specified by an array of data elements of typetransferType.- Returns:
- The red color component for the specified pixel, as an int.
- Throws:
ClassCastException- IfinDatais not a primitive array of typetransferType.ArrayIndexOutOfBoundsException- ifinDatais not large enough to hold a pixel value for thisColorModel.
-
getGreen
Returns the green color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace, sRGB. A color conversion is done if necessary. Thepixelvalue is specified by an array of data elements of typetransferTypepassed in as an object reference. The returned value will be a non pre-multiplied value. If the alpha is premultiplied, this method divides it out before returning the value (if the alpha value is 0, the green value will be 0).- Overrides:
getGreenin classComponentColorModel- Parameters:
inData- The pixel from which to get the green color component, specified by an array of data elements of typetransferType.- Returns:
- The green color component for the specified pixel, as an int.
- Throws:
ClassCastException- IfinDatais not a primitive array of typetransferType.ArrayIndexOutOfBoundsException- ifinDatais not large enough to hold a pixel value for thisColorModel.
-
getBlue
Returns the blue color component for the specified pixel, scaled from 0 to 255 in the default RGBColorSpace, sRGB. A color conversion is done if necessary. Thepixelvalue is specified by an array of data elements of typetransferTypepassed in as an object reference. The returned value will be a non pre-multiplied value. If the alpha is premultiplied, this method divides it out before returning the value (if the alpha value is 0, the blue value will be 0).- Overrides:
getBluein classComponentColorModel- Parameters:
inData- The pixel from which to get the blue color component, specified by an array of data elements of typetransferType.- Returns:
- The blue color component for the specified pixel, as an int.
- Throws:
ClassCastException- IfinDatais not a primitive array of typetransferType.ArrayIndexOutOfBoundsException- ifinDatais not large enough to hold a pixel value for thisColorModel.
-
getAlpha
Returns the alpha component for the specified pixel, scaled from 0 to 255. The pixel value is specified by an array of data elements of typetransferTypepassed in as an object reference. If theColorModeldoes not have alpha, 255 is returned.- Overrides:
getAlphain classComponentColorModel- Parameters:
inData- The pixel from which to get the alpha component, specified by an array of data elements of typetransferType.- Returns:
- The alpha component for the specified pixel, as an int.
- Throws:
IllegalArgumentException- ifinDataisnulland thecolorModelhas alpha.ClassCastException- IfinDatais not a primitive array of typetransferTypeand theColorModelhas alpha.ArrayIndexOutOfBoundsException- ifinDatais not large enough to hold a pixel value for thisColorModeland theColorModelhas alpha.
-
getRGB
Returns the color/alpha components for the specified pixel in the default RGB color model format. A color conversion is done if necessary. The pixel value is specified by an array of data elements of typetransferTypepassed in as an object reference. The returned value is in a non pre-multiplied format. If the alpha is premultiplied, this method divides it out of the color components (if the alpha value is 0, the color values will be 0).- Overrides:
getRGBin classComponentColorModel- Parameters:
inData- The pixel from which to get the color/alpha components, specified by an array of data elements of typetransferType.- Returns:
- The color/alpha components for the specified pixel, as an int.
- Throws:
ClassCastException- IfinDatais not a primitive array of typetransferType.ArrayIndexOutOfBoundsException- ifinDatais not large enough to hold a pixel value for thisColorModel.
-
getDataElements
Returns a data element array representation of a pixel in thisColorModel, given an integer pixel representation in the default RGB color model. This array can then be passed to thesetDataElementsmethod of aWritableRasterobject. If thepixelparameter is null, a new array is allocated. If the colorSpaceType is of TYPE_GRAY then the rgb components are converted to gray using appropriate weights- Overrides:
getDataElementsin classComponentColorModel- Parameters:
rgb- An ARGB value packed into an int.pixel- The float or double array representation of the pixel.- Throws:
ClassCastException- Ifpixelis not null and is not a primitive array of typetransferType.ArrayIndexOutOfBoundsException- Ifpixelis not large enough to hold a pixel value for thisColorModel.
-
getComponents
public int[] getComponents(int pixel, int[] components, int offset) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.- Overrides:
getComponentsin classComponentColorModel
-
getComponents
Throws anIllegalArgumentExceptionsince the pixel values cannot be placed into anintarray.- Overrides:
getComponentsin classComponentColorModel
-
getDataElement
public int getDataElement(int[] components, int offset) Throws anIllegalArgumentException, since pixel values for thisColorModelare not conveniently representable as a singleint.- Overrides:
getDataElementin classComponentColorModel
-
getDataElements
Returns a data element array representation of a pixel in thisColorModel, given an array of unnormalized color/alpha components. This array can then be passed to thesetDataElementsmethod of aWritableRasterobject.- Overrides:
getDataElementsin classComponentColorModel- Parameters:
components- An array of unnormalized color/alpha components.offset- The integer offset into thecomponentsarray.obj- The object in which to store the data element array representation of the pixel. Ifobjvariable is null, a new array is allocated. Ifobjis not null, it must be a primitive array of typetransferType. AnArrayIndexOutOfBoundsExceptionis thrown ifobjis not large enough to hold a pixel value for thisColorModel.- Returns:
- The data element array representation of a pixel in this
ColorModel. - Throws:
IllegalArgumentException- If the components array is not large enough to hold all the color and alpha components (starting at offset).ClassCastException- Ifobjis not null and is not a primitive array of typetransferType.ArrayIndexOutOfBoundsException- Ifobjis not large enough to hold a pixel value for thisColorModel.
-
coerceData
Forces therasterdata to match the state specified in theisAlphaPremultipliedvariable, assuming the data is currently correctly described by thisColorModel. It may multiply or divide the colorrasterdata by alpha, or do nothing if the data is in the correct state. If the data needs to be coerced, this method also returns an instance ofFloatDoubleColorModelwith theisAlphaPremultipliedflag set appropriately.- Overrides:
coerceDatain classComponentColorModel- Throws:
IllegalArgumentException- if transfer type ofrasteris not the same as that of thisFloatDoubleColorModel.
-
isCompatibleRaster
Returnstrueif the suppliedRaster'sSampleModelis compatible with thisFloatDoubleColorModel.- Overrides:
isCompatibleRasterin classComponentColorModel- Parameters:
raster- aRasterto be checked for compatibility.
-
createCompatibleWritableRaster
Creates aWritableRasterwith the specified width and height, that has a data layout (SampleModel) compatible with thisColorModel. The returnedWritableRaster'sSampleModelwill be an instance ofComponentSampleModel.- Overrides:
createCompatibleWritableRasterin classComponentColorModel- Parameters:
w- The width of theWritableRasterh- The height of theWritableRaster- Returns:
- A
WritableRasterthat is compatible with thisColorModel. - See Also:
-
createCompatibleSampleModel
Creates aSampleModelwith the specified width and height that has a data layout compatible with thisColorModel. The returnedSampleModelwill be an instance ofComponentSampleModel.- Overrides:
createCompatibleSampleModelin classComponentColorModel- Parameters:
w- The width of theSampleModel.h- The height of theSampleModel.- Returns:
- A
SampleModelthat is compatible with thisColorModel. - See Also:
-
isCompatibleSampleModel
Checks whether or not the specifiedSampleModelis compatible with thisColorModel. ASampleModelis compatible if it is an instance ofComponentSampleModel, has the sample number of bands as the total number of components (including alpha) in theColorSpaceused by thisColorModel, and has the same data type (float or double) as thisColorModel.- Overrides:
isCompatibleSampleModelin classComponentColorModel- Parameters:
sm- TheSampleModelto test for compatibility.- Returns:
trueif theSampleModelis compatible with thisColorModel,falseif it is not.- See Also:
-
toString
Returns aStringcontaining the values of all valid fields.- Overrides:
toStringin classColorModel
-