// band offsets.
int[] reverseOffsets = new int[numBands];
for (int i=0; i<numBands; i++) {
reverseOffsets[i] = numBands - 1 - i;
}
sampleModel = new PixelInterleavedSampleModel
(dataType, tileWidth, tileHeight,
numBands, numBands*tileWidth, reverseOffsets);
if(imageType == TYPE_GRAY) {
colorModel = new ComponentColorModel
(ColorSpace.getInstance(ColorSpace.CS_GRAY),
new int[] { sampleSize }, false, false,
Transparency.OPAQUE, dataType);
} else if (imageType == TYPE_RGB) {
colorModel = new ComponentColorModel
(ColorSpace.getInstance(ColorSpace.CS_sRGB),
new int[] { sampleSize, sampleSize, sampleSize },
false, false, Transparency.OPAQUE, dataType);
} else { // hasAlpha
// Transparency.OPAQUE signifies image data that is
// completely opaque, meaning that all pixels have an alpha
// value of 1.0. So the extra band gets ignored, which is
// what we want.
int transparency = Transparency.OPAQUE;
if(extraSamples == 1) { // associated (premultiplied) alpha
transparency = Transparency.TRANSLUCENT;
} else if(extraSamples == 2) { // unassociated alpha
transparency = Transparency.BITMASK;
}
colorModel =
createAlphaComponentColorModel(dataType,
numBands,
extraSamples == 1,
transparency);
}
break;
case TYPE_GENERIC:
case TYPE_YCBCR_SUB:
// For this case we can't display the image, so we create a
// SampleModel with increasing bandOffsets, and keep the
// ColorModel as null, as there is no appropriate ColorModel.
int[] bandOffsets = new int[numBands];
for (int i=0; i<numBands; i++) {
bandOffsets[i] = i;
}
sampleModel = new PixelInterleavedSampleModel
(dataType, tileWidth, tileHeight,
numBands, numBands * tileWidth, bandOffsets);
colorModel = null;
break;