*/
private static ImageLayout layoutHelper(ImageLayout layout,
RenderedImage source,
EnumeratedParameter dataNature) {
// Create an ImageLayout or clone the one passed in.
ImageLayout il = layout == null ?
new ImageLayout() : (ImageLayout)layout.clone();
// Force the origin to coincide with that of the source.
il.setMinX(source.getMinX());
il.setMinY(source.getMinY());
// Recalculate the non-unity dimensions to be a positive power of 2.
// XXX This calculation should not be effected if an implementation
// of the FFT which supports arbitrary dimensions is used.
int currentWidth = il.getWidth(source);
int currentHeight = il.getHeight(source);
int newWidth;
int newHeight;
if(currentWidth == 1 && currentHeight == 1) {
newWidth = newHeight = 1;
} else if(currentWidth == 1 && currentHeight > 1) {
newWidth = 1;
newHeight = MathJAI.nextPositivePowerOf2(currentHeight);
} else if(currentWidth > 1 && currentHeight == 1) {
newWidth = MathJAI.nextPositivePowerOf2(currentWidth);
newHeight = 1;
} else { // Neither dimension equal to unity.
newWidth = MathJAI.nextPositivePowerOf2(currentWidth);
newHeight = MathJAI.nextPositivePowerOf2(currentHeight);
}
il.setWidth(newWidth);
il.setHeight(newHeight);
// Set the complex flags for source and destination.
boolean isComplexSource =
!dataNature.equals(DFTDescriptor.REAL_TO_COMPLEX);
boolean isComplexDest =
!dataNature.equals(DFTDescriptor.COMPLEX_TO_REAL);
// Initialize the SampleModel creation flag.
boolean createNewSampleModel = false;
// Determine the number of required bands.
SampleModel srcSampleModel = source.getSampleModel();
int requiredNumBands = srcSampleModel.getNumBands();
if(isComplexSource && !isComplexDest) {
requiredNumBands /= 2;
} else if(!isComplexSource && isComplexDest) {
requiredNumBands *= 2;
}
// Set the number of bands.
SampleModel sm = il.getSampleModel(source);
int numBands = sm.getNumBands();
if(numBands != requiredNumBands) {
numBands = requiredNumBands;
createNewSampleModel = true;
}
// Force the image to contain floating point data.
int dataType = sm.getTransferType();
if(dataType != DataBuffer.TYPE_FLOAT &&
dataType != DataBuffer.TYPE_DOUBLE) {
dataType = DataBuffer.TYPE_FLOAT;
createNewSampleModel = true;
}
// Create a new SampleModel for the destination if necessary.
if(createNewSampleModel) {
sm = RasterFactory.createComponentSampleModel(sm,
dataType,
newWidth,
newHeight,
numBands);
il.setSampleModel(sm);
// Clear the ColorModel mask if needed.
ColorModel cm = il.getColorModel(null);
if(cm != null &&
!JDKWorkarounds.areCompatibleDataModels(sm, cm)) {
// Clear the mask bit if incompatible.
il.unsetValid(ImageLayout.COLOR_MODEL_MASK);
}
}
return il;
}