// MlibDFTRIF and MlibIDFTRIF.
throw new RuntimeException(JaiI18N.getString("MlibDFTOpImage0"));
}
// 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);
// Initialize the SampleModel creation flag.
boolean createNewSampleModel = false;
// Determine the number of required bands.
int requiredNumBands = numSourceBands;
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) {
int[] bandOffsets = new int[numBands];
// Force the band offsets to be monotonically increasing as
// mediaLib expects the real part to be in band 0 and the
// imaginary part in band 1.
for(int b = 0; b < numBands; b++) {
bandOffsets[b] = b;
}
int lineStride = newWidth*numBands;
sm = RasterFactory.createPixelInterleavedSampleModel(dataType,
newWidth,
newHeight,
numBands,
lineStride,
bandOffsets);
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;
}