001: /*
002: * $RCSfile: RenderedImageState.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:56:53 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.rmi;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.RenderedImage;
016: import java.awt.image.WritableRenderedImage;
017: import java.io.IOException;
018: import java.io.ObjectInputStream;
019: import java.io.ObjectOutputStream;
020: import javax.media.jai.JAI;
021: import javax.media.jai.OperationRegistry;
022: import javax.media.jai.TiledImage;
023: import javax.media.jai.remote.SerializableRenderedImage;
024: import javax.media.jai.tilecodec.TileCodecParameterList;
025:
026: /**
027: * A <code>SerializableState</code> wrapper for a <code>RenderedImage</code>
028: * or <code>WritableRenderedImage</code>. This class simply uses a
029: * <code>SerializableRenderedImage</code> to do the work.
030: *
031: * @since 1.1
032: */
033: public final class RenderedImageState extends SerializableStateImpl {
034: private boolean isWritable;
035:
036: private transient boolean useDeepCopy;
037: private transient OperationRegistry registry;
038: private transient String formatName;
039: private transient TileCodecParameterList encodingParam;
040: private transient TileCodecParameterList decodingParam;
041:
042: public static Class[] getSupportedClasses() {
043: return new Class[] { RenderedImage.class,
044: WritableRenderedImage.class };
045: }
046:
047: public RenderedImageState(Class c, Object o, RenderingHints h) {
048: super (c, o, h);
049:
050: isWritable = o instanceof WritableRenderedImage;
051:
052: if (h != null) {
053: Object value = h.get(JAI.KEY_SERIALIZE_DEEP_COPY);
054: if (value != null) {
055: useDeepCopy = ((Boolean) value).booleanValue();
056: } else {
057: useDeepCopy = false;
058: }
059:
060: value = h.get(JAI.KEY_OPERATION_REGISTRY);
061: if (value != null) {
062: registry = (OperationRegistry) value;
063: }
064:
065: value = h.get(JAI.KEY_TILE_CODEC_FORMAT);
066: if (value != null) {
067: formatName = (String) value;
068: }
069:
070: value = h.get(JAI.KEY_TILE_ENCODING_PARAM);
071: if (value != null) {
072: encodingParam = (TileCodecParameterList) value;
073: }
074:
075: value = h.get(JAI.KEY_TILE_DECODING_PARAM);
076: if (value != null) {
077: decodingParam = (TileCodecParameterList) value;
078: }
079: }
080: }
081:
082: private void writeObject(ObjectOutputStream out) throws IOException {
083:
084: out.defaultWriteObject();
085:
086: SerializableRenderedImage sri;
087:
088: if (formatName == null || encodingParam == null
089: || decodingParam == null) {
090: sri = new SerializableRenderedImage(
091: (RenderedImage) theObject, useDeepCopy);
092: } else {
093: sri = new SerializableRenderedImage(
094: (RenderedImage) theObject, useDeepCopy, registry,
095: formatName, encodingParam, decodingParam);
096: }
097:
098: out.writeObject(sri);
099: }
100:
101: private void readObject(ObjectInputStream in) throws IOException,
102: ClassNotFoundException {
103: in.defaultReadObject();
104: theObject = in.readObject();
105: if (isWritable) {
106: theObject = new TiledImage((RenderedImage) theObject, true);
107: }
108: }
109: }
|