01: /*
02: * $RCSfile: MlibTransposeRIF.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:08 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.mlib;
13:
14: import java.awt.RenderingHints;
15: import java.awt.image.DataBuffer;
16: import java.awt.image.MultiPixelPackedSampleModel;
17: import java.awt.image.RenderedImage;
18: import java.awt.image.SampleModel;
19: import java.awt.image.renderable.ParameterBlock;
20: import java.awt.image.renderable.RenderedImageFactory;
21: import javax.media.jai.EnumeratedParameter;
22: import javax.media.jai.ImageLayout;
23: import java.util.Map;
24: import com.sun.media.jai.opimage.RIFUtil;
25:
26: /**
27: * A <code>RIF</code> supporting the "Transpose" operation in the
28: * rendered image mode using MediaLib.
29: *
30: * @see javax.media.jai.operator.TransposeDescriptor
31: * @see MlibTransposeOpImage
32: *
33: * @since EA3
34: */
35: public class MlibTransposeRIF implements RenderedImageFactory {
36:
37: /** Constructor. */
38: public MlibTransposeRIF() {
39: }
40:
41: /**
42: * Creates a new instance of <code>MlibTransposeOpImage</code> in
43: * the rendered image mode.
44: *
45: * @param args The source image and the transpose type.
46: * @param hints May contain rendering hints and destination image layout.
47: */
48: public RenderedImage create(ParameterBlock args,
49: RenderingHints hints) {
50: /* Get ImageLayout and TileCache from RenderingHints. */
51: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
52:
53: if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
54: || !MediaLibAccessor.hasSameNumBands(args, layout)) {
55: return null;
56: }
57:
58: RenderedImage source = args.getRenderedSource(0);
59:
60: SampleModel sm = source.getSampleModel();
61: boolean isBilevel = (sm instanceof MultiPixelPackedSampleModel)
62: && (sm.getSampleSize(0) == 1)
63: && (sm.getDataType() == DataBuffer.TYPE_BYTE
64: || sm.getDataType() == DataBuffer.TYPE_USHORT || sm
65: .getDataType() == DataBuffer.TYPE_INT);
66: if (isBilevel) {
67: // Let Java code handle it, reformatting is slower
68: return null;
69: }
70:
71: EnumeratedParameter transposeType = (EnumeratedParameter) args
72: .getObjectParameter(0);
73: return new MlibTransposeOpImage(args.getRenderedSource(0),
74: hints, layout, transposeType.getValue());
75: }
76: }
|