// Create a SampleModel to get the transferType. This is
// absurd but is the only apparent way to retrieve this value.
SampleModel sm = cm.createCompatibleSampleModel(1, 1);
out.writeInt(sm.getTransferType());
} else if(colorModel instanceof IndexColorModel) {
IndexColorModel cm = (IndexColorModel)colorModel;
out.writeInt(COLORMODEL_INDEX);
int size = cm.getMapSize();
int[] cmap = new int[size];
cm.getRGBs(cmap);
out.writeInt(cm.getPixelSize());
out.writeInt(size);
out.writeObject(cmap);
out.writeBoolean(cm.hasAlpha());
out.writeInt(cm.getTransparentPixel());
// Create a SampleModel to get the transferType. This is
// absurd but is the only apparent way to retrieve this value.
SampleModel sm = cm.createCompatibleSampleModel(1, 1);
out.writeInt(sm.getTransferType());
} else if(colorModel instanceof DirectColorModel) {
DirectColorModel cm = (DirectColorModel)colorModel;
out.writeInt(COLORMODEL_DIRECT);
boolean csSerialized =
serializeColorSpace(cm.getColorSpace(), out);
if(!csSerialized) {
out.writeBoolean(cm.hasAlpha());
}
out.writeInt(cm.getPixelSize());
out.writeInt(cm.getRedMask());
out.writeInt(cm.getGreenMask());
out.writeInt(cm.getBlueMask());
if(csSerialized || cm.hasAlpha()) {
out.writeInt(cm.getAlphaMask());
}
if(csSerialized) {
out.writeBoolean(cm.isAlphaPremultiplied());
// Create a SampleModel to get the transferType. This is
// absurd but is the only apparent way to retrieve this
// value.
SampleModel sm = cm.createCompatibleSampleModel(1, 1);
out.writeInt(sm.getTransferType());
}
} else {
throw new RuntimeException(JaiI18N.getString("ColorModelState0"));
}