| Constructor: |
public ColorConvertOp(RenderingHints hints) {
if (ProfileDeferralMgr.deferring) {
ProfileDeferralMgr.activateProfiles();
}
profileList = new ICC_Profile [0]; /* 0 length list */
this.hints = hints;
}
Constructs a new ColorConvertOp which will convert
from a source color space to a destination color space.
The RenderingHints argument may be null.
This Op can be used only with BufferedImages, and will convert
directly from the ColorSpace of the source image to that of the
destination. The destination argument of the filter method
cannot be specified as null. Parameters:
hints - the RenderingHints object used to control
the color conversion, or null
|
public ColorConvertOp(ColorSpace cspace,
RenderingHints hints) {
if (cspace == null) {
throw new NullPointerException("ColorSpace cannot be null");
}
if (cspace instanceof ICC_ColorSpace) {
profileList = new ICC_Profile [1]; /* 1 profile in the list */
profileList [0] = ((ICC_ColorSpace) cspace).getProfile();
}
else {
CSList = new ColorSpace[1]; /* non-ICC case: 1 ColorSpace in list */
CSList[0] = cspace;
}
this.hints = hints;
}
Constructs a new ColorConvertOp from a ColorSpace object.
The RenderingHints argument may be null. This
Op can be used only with BufferedImages, and is primarily useful
when the filter
method is invoked with a destination argument of null.
In that case, the ColorSpace defines the destination color space
for the destination created by the filter method. Otherwise, the
ColorSpace defines an intermediate space to which the source is
converted before being converted to the destination space. Parameters:
cspace - defines the destination ColorSpace or an
intermediate ColorSpace
hints - the RenderingHints object used to control
the color conversion, or null
Throws:
NullPointerException - if cspace is null
|
public ColorConvertOp(ICC_Profile[] profiles,
RenderingHints hints) {
if (profiles == null) {
throw new NullPointerException("Profiles cannot be null");
}
gotProfiles = true;
profileList = new ICC_Profile[profiles.length];
for (int i1 = 0; i1 < profiles.length; i1++) {
profileList[i1] = profiles[i1];
}
this.hints = hints;
}
Constructs a new ColorConvertOp from an array of ICC_Profiles.
The RenderingHints argument may be null.
The sequence of profiles may include profiles that represent color
spaces, profiles that represent effects, etc. If the whole sequence
does not represent a well-defined color conversion, an exception is
thrown.
For BufferedImages, if the ColorSpace
of the source BufferedImage does not match the requirements of the
first profile in the array,
the first conversion is to an appropriate ColorSpace.
If the requirements of the last profile in the array are not met
by the ColorSpace of the destination BufferedImage,
the last conversion is to the destination's ColorSpace.
For Rasters, the number of bands in the source Raster must match
the requirements of the first profile in the array, and the
number of bands in the destination Raster must match the requirements
of the last profile in the array. The array must have at least two
elements or calling the filter method for Rasters will throw an
IllegalArgumentException. Parameters:
profiles - the array of ICC_Profile objects
hints - the RenderingHints object used to control
the color conversion, or null
Throws:
IllegalArgumentException - when the profile sequence does not
specify a well-defined color conversion
NullPointerException - if profiles is null
- exception:
IllegalArgumentException - when the profile sequence does not
specify a well-defined color conversion
- exception:
NullPointerException - if profiles is null
|
public ColorConvertOp(ColorSpace srcCspace,
ColorSpace dstCspace,
RenderingHints hints) {
if ((srcCspace == null) || (dstCspace == null)) {
throw new NullPointerException("ColorSpaces cannot be null");
}
if ((srcCspace instanceof ICC_ColorSpace) &&
(dstCspace instanceof ICC_ColorSpace)) {
profileList = new ICC_Profile [2]; /* 2 profiles in the list */
profileList [0] = ((ICC_ColorSpace) srcCspace).getProfile();
profileList [1] = ((ICC_ColorSpace) dstCspace).getProfile();
getMinMaxValsFromColorSpaces(srcCspace, dstCspace);
} else {
/* non-ICC case: 2 ColorSpaces in list */
CSList = new ColorSpace[2];
CSList[0] = srcCspace;
CSList[1] = dstCspace;
}
this.hints = hints;
}
Constructs a new ColorConvertOp from two ColorSpace objects.
The RenderingHints argument may be null.
This Op is primarily useful for calling the filter method on
Rasters, in which case the two ColorSpaces define the operation
to be performed on the Rasters. In that case, the number of bands
in the source Raster must match the number of components in
srcCspace, and the number of bands in the destination Raster
must match the number of components in dstCspace. For BufferedImages,
the two ColorSpaces define intermediate spaces through which the
source is converted before being converted to the destination space. Parameters:
srcCspace - the source ColorSpace
dstCspace - the destination ColorSpace
hints - the RenderingHints object used to control
the color conversion, or null
Throws:
NullPointerException - if either srcCspace or dstCspace is null
|
| Method from java.awt.image.ColorConvertOp Detail: |
public BufferedImage createCompatibleDestImage(BufferedImage src,
ColorModel destCM) {
ColorSpace cs = null;;
if (destCM == null) {
if (CSList == null) {
/* ICC case */
int nProfiles = profileList.length;
if (nProfiles == 0) {
throw new IllegalArgumentException(
"Destination ColorSpace is undefined");
}
ICC_Profile destProfile = profileList[nProfiles - 1];
cs = new ICC_ColorSpace(destProfile);
} else {
/* non-ICC case */
int nSpaces = CSList.length;
cs = CSList[nSpaces - 1];
}
}
return createCompatibleDestImage(src, destCM, cs);
}
Creates a zeroed destination image with the correct size and number of
bands, given this source. |
public WritableRaster createCompatibleDestRaster(Raster src) {
int ncomponents;
if (CSList != null) {
/* non-ICC case */
if (CSList.length != 2) {
throw new IllegalArgumentException(
"Destination ColorSpace is undefined");
}
ncomponents = CSList[1].getNumComponents();
} else {
/* ICC case */
int nProfiles = profileList.length;
if (nProfiles < 2) {
throw new IllegalArgumentException(
"Destination ColorSpace is undefined");
}
ncomponents = profileList[nProfiles-1].getNumComponents();
}
WritableRaster dest =
Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
src.getWidth(),
src.getHeight(),
ncomponents,
new Point(src.getMinX(), src.getMinY()));
return dest;
}
Creates a zeroed destination Raster with the correct size and number of
bands, given this source. |
public final BufferedImage filter(BufferedImage src,
BufferedImage dest) {
ColorSpace srcColorSpace, destColorSpace;
BufferedImage savdest = null;
if (src.getColorModel() instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel) src.getColorModel();
src = icm.convertToIntDiscrete(src.getRaster(), true);
}
srcColorSpace = src.getColorModel().getColorSpace();
if (dest != null) {
if (dest.getColorModel() instanceof IndexColorModel) {
savdest = dest;
dest = null;
destColorSpace = null;
} else {
destColorSpace = dest.getColorModel().getColorSpace();
}
} else {
destColorSpace = null;
}
if ((CSList != null) ||
(!(srcColorSpace instanceof ICC_ColorSpace)) ||
((dest != null) &&
(!(destColorSpace instanceof ICC_ColorSpace)))) {
/* non-ICC case */
dest = nonICCBIFilter(src, srcColorSpace, dest, destColorSpace);
} else {
dest = ICCBIFilter(src, srcColorSpace, dest, destColorSpace);
}
if (savdest != null) {
Graphics2D big = savdest.createGraphics();
try {
big.drawImage(dest, 0, 0, null);
} finally {
big.dispose();
}
return savdest;
} else {
return dest;
}
}
ColorConverts the source BufferedImage.
If the destination image is null,
a BufferedImage will be created with an appropriate ColorModel. |
public final WritableRaster filter(Raster src,
WritableRaster dest) {
if (CSList != null) {
/* non-ICC case */
return nonICCRasterFilter(src, dest);
}
int nProfiles = profileList.length;
if (nProfiles < 2) {
throw new IllegalArgumentException(
"Source or Destination ColorSpace is undefined");
}
if (src.getNumBands() != profileList[0].getNumComponents()) {
throw new IllegalArgumentException(
"Numbers of source Raster bands and source color space " +
"components do not match");
}
if (dest == null) {
dest = createCompatibleDestRaster(src);
}
else {
if (src.getHeight() != dest.getHeight() ||
src.getWidth() != dest.getWidth()) {
throw new IllegalArgumentException(
"Width or height of Rasters do not match");
}
if (dest.getNumBands() !=
profileList[nProfiles-1].getNumComponents()) {
throw new IllegalArgumentException(
"Numbers of destination Raster bands and destination " +
"color space components do not match");
}
}
/* make a new transform if needed */
if (thisRasterTransform == null) {
int i1, whichTrans, renderState;
ColorTransform[] theTransforms;
/* make the transform list */
theTransforms = new ColorTransform [nProfiles];
/* initialize transform get loop */
if (profileList[0].getProfileClass() == ICC_Profile.CLASS_OUTPUT) {
/* if first profile is a printer
render as colorimetric */
renderState = ICC_Profile.icRelativeColorimetric;
}
else {
renderState = ICC_Profile.icPerceptual; /* render any other
class perceptually */
}
whichTrans = ColorTransform.In;
PCMM mdl = CMSManager.getModule();
/* get the transforms from each profile */
for (i1 = 0; i1 < nProfiles; i1++) {
if (i1 == nProfiles -1) { /* last profile? */
whichTrans = ColorTransform.Out; /* get output transform */
}
else { /* check for abstract profile */
if ((whichTrans == ColorTransform.Simulation) &&
(profileList[i1].getProfileClass () ==
ICC_Profile.CLASS_ABSTRACT)) {
renderState = ICC_Profile.icPerceptual;
whichTrans = ColorTransform.In;
}
}
theTransforms[i1] = mdl.createTransform (
profileList[i1], renderState, whichTrans);
/* get this profile's rendering intent to select transform
from next profile */
renderState = getRenderingIntent(profileList[i1]);
/* "middle" profiles use simulation transform */
whichTrans = ColorTransform.Simulation;
}
/* make the net transform */
thisRasterTransform = mdl.createTransform(theTransforms);
}
int srcTransferType = src.getTransferType();
int dstTransferType = dest.getTransferType();
if ((srcTransferType == DataBuffer.TYPE_FLOAT) ||
(srcTransferType == DataBuffer.TYPE_DOUBLE) ||
(dstTransferType == DataBuffer.TYPE_FLOAT) ||
(dstTransferType == DataBuffer.TYPE_DOUBLE)) {
if (srcMinVals == null) {
getMinMaxValsFromProfiles(profileList[0],
profileList[nProfiles-1]);
}
/* color convert the raster */
thisRasterTransform.colorConvert(src, dest,
srcMinVals, srcMaxVals,
dstMinVals, dstMaxVals);
} else {
/* color convert the raster */
thisRasterTransform.colorConvert(src, dest);
}
return dest;
}
ColorConverts the image data in the source Raster.
If the destination Raster is null, a new Raster will be created.
The number of bands in the source and destination Rasters must
meet the requirements explained above. The constructor used to
create this ColorConvertOp must have provided enough information
to define both source and destination color spaces. See above.
Otherwise, an exception is thrown. |
public final Rectangle2D getBounds2D(BufferedImage src) {
return getBounds2D(src.getRaster());
}
Returns the bounding box of the destination, given this source.
Note that this will be the same as the the bounding box of the
source. |
public final Rectangle2D getBounds2D(Raster src) {
/* return new Rectangle (src.getXOffset(),
src.getYOffset(),
src.getWidth(), src.getHeight()); */
return src.getBounds();
}
Returns the bounding box of the destination, given this source.
Note that this will be the same as the the bounding box of the
source. |
public final ICC_Profile[] getICC_Profiles() {
if (gotProfiles) {
ICC_Profile[] profiles = new ICC_Profile[profileList.length];
for (int i1 = 0; i1 < profileList.length; i1++) {
profiles[i1] = profileList[i1];
}
return profiles;
}
return null;
}
Returns the array of ICC_Profiles used to construct this ColorConvertOp.
Returns null if the ColorConvertOp was not constructed from such an
array. |
public final Point2D getPoint2D(Point2D srcPt,
Point2D dstPt) {
if (dstPt == null) {
dstPt = new Point2D.Float();
}
dstPt.setLocation(srcPt.getX(), srcPt.getY());
return dstPt;
}
Returns the location of the destination point given a
point in the source. If dstPt is non-null,
it will be used to hold the return value. Note that
for this class, the destination point will be the same
as the source point. |
public final RenderingHints getRenderingHints() {
return hints;
}
Returns the rendering hints used by this op. |