private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
        ColorModel colorModel = null;

        // Read serialized form from the stream.
        ColorSpace cs = null;

        // Switch on first int which is a flag indicating the class.
        switch((int)in.readInt()) {
        case COLORMODEL_NULL:
            colorModel = null;
            break;
        case COLORMODEL_FLOAT_DOUBLE_COMPONENT:
            if((cs = deserializeColorSpace(in)) == null) {
                colorModel = null;
                return;
            }
            colorModel =
                new FloatDoubleColorModel(cs,
                                          in.readBoolean(),
                                          in.readBoolean(),
                                          in.readInt(), in.readInt());
            break;
        case COLORMODEL_COMPONENT:
            if((cs = deserializeColorSpace(in)) == null) {
                colorModel = null;
                return;
            }
            colorModel =
                new ComponentColorModel(cs, (int[])in.readObject(),
                                        in.readBoolean(), in.readBoolean(),
                                        in.readInt(), in.readInt());
            break;
        case COLORMODEL_INDEX:
            colorModel =
                new IndexColorModel(in.readInt(), in.readInt(),
                                    (int[])in.readObject(), 0,
                                    in.readBoolean(), in.readInt(),
                                    in.readInt());
            break;
        case COLORMODEL_DIRECT:
            if((cs = deserializeColorSpace(in)) != null) {
                colorModel =
                    new DirectColorModel(cs, in.readInt(), in.readInt(),
                                         in.readInt(), in.readInt(),
                                         in.readInt(), in.readBoolean(),
                                         in.readInt());
            } else if(in.readBoolean()) {
                colorModel =
                    new DirectColorModel(in.readInt(), in.readInt(),
                                         in.readInt(), in.readInt(),
                                         in.readInt());
            } else {
                colorModel =
                    new DirectColorModel(in.readInt(), in.readInt(),
                                         in.readInt(), in.readInt());
            }
            break;
        default:
            // NB: Should never get here.
            throw new RuntimeException(JaiI18N.getString("ColorModelState1"));
        }

        theObject = colorModel;
    }