01: /*
02: * $RCSfile: TileCodecUtils.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:56:58 $
10: * $State: Exp $
11: */package com.sun.media.jai.tilecodec;
12:
13: import java.awt.image.Raster;
14: import java.awt.image.SampleModel;
15: import java.text.MessageFormat;
16: import javax.media.jai.JAI;
17: import javax.media.jai.tilecodec.TileCodecDescriptor;
18: import javax.media.jai.remote.SerializableState;
19: import javax.media.jai.remote.SerializerFactory;
20:
21: /**
22: * A class containing methods of utility to all TileCodec implementations.
23: */
24: public class TileCodecUtils {
25: /* Required to I18N compound messages. */
26: private static MessageFormat formatter = new MessageFormat("");
27:
28: /**
29: * Get the <code>TileCodecDescriptor</code> associated with the
30: * specified registry mode.
31: */
32: public static TileCodecDescriptor getTileCodecDescriptor(
33: String registryMode, String formatName) {
34: return (TileCodecDescriptor) JAI.getDefaultInstance()
35: .getOperationRegistry().getDescriptor(registryMode,
36: formatName);
37: }
38:
39: /** Deserialize a <code>Raster</code> from its serialized version */
40: public static Raster deserializeRaster(Object object) {
41: if (!(object instanceof SerializableState))
42: return null;
43:
44: SerializableState ss = (SerializableState) object;
45: Class c = ss.getObjectClass();
46: if (Raster.class.isAssignableFrom(c)) {
47: return (Raster) ss.getObject();
48: }
49: return null;
50: }
51:
52: /** Deserialize a <code>SampleModel</code> from its serialized version */
53: public static SampleModel deserializeSampleModel(Object object) {
54: if (!(object instanceof SerializableState))
55: return null;
56:
57: SerializableState ss = (SerializableState) object;
58: Class c = ss.getObjectClass();
59: if (SampleModel.class.isAssignableFrom(c)) {
60: return (SampleModel) ss.getObject();
61: }
62: return null;
63: }
64:
65: /** Serialize a <code>Raster</code>. */
66: public static Object serializeRaster(Raster ras) {
67: return SerializerFactory.getState(ras, null);
68: }
69:
70: /** Serialize a <code>SampleModel</code>. */
71: public static Object serializeSampleModel(SampleModel sm) {
72: return SerializerFactory.getState(sm, null);
73: }
74: }
|