01: /*
02: * $RCSfile: MlibMosaicRIF.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:01 $
10: * $State: Exp $
11: */package com.sun.media.jai.mlib;
12:
13: import java.awt.RenderingHints;
14: import java.awt.image.DataBuffer;
15: import java.awt.image.RenderedImage;
16: import java.awt.image.SampleModel;
17: import java.awt.image.renderable.ParameterBlock;
18: import java.awt.image.renderable.RenderedImageFactory;
19: import java.util.Vector;
20: import javax.media.jai.ImageLayout;
21: import javax.media.jai.PlanarImage;
22: import javax.media.jai.ROI;
23: import javax.media.jai.operator.MosaicType;
24: import com.sun.media.jai.opimage.RIFUtil;
25:
26: /**
27: * A <code>RIF</code> supporting the "Mosaic" operation in the rendered
28: * image layer.
29: *
30: * @since JAI 1.1.2
31: * @see javax.media.jai.operator.MosaicDescriptor
32: */
33: public class MlibMosaicRIF implements RenderedImageFactory {
34:
35: /** Constructor. */
36: public MlibMosaicRIF() {
37: }
38:
39: /**
40: * Renders a "Mosaic" operation node.
41: */
42: public RenderedImage create(ParameterBlock paramBlock,
43: RenderingHints renderHints) {
44: // Get ImageLayout from renderHints if any.
45: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
46:
47: // Return if not mediaLib-compatible.
48: if (!MediaLibAccessor.isMediaLibCompatible(paramBlock, layout)
49: || !MediaLibAccessor
50: .hasSameNumBands(paramBlock, layout)) {
51: return null;
52: }
53:
54: // Get sources.
55: Vector sources = paramBlock.getSources();
56:
57: // Get target SampleModel.
58: SampleModel targetSM = null;
59: if (sources.size() > 0) {
60: targetSM = ((RenderedImage) sources.get(0))
61: .getSampleModel();
62: } else if (layout != null
63: && layout.isValid(ImageLayout.SAMPLE_MODEL_MASK)) {
64: targetSM = layout.getSampleModel(null);
65: }
66:
67: if (targetSM != null) {
68: // Return if target data type is floating point. Other more
69: // extensive type checking is done in MosaicOpImage constructor.
70: int dataType = targetSM.getDataType();
71: if (dataType == DataBuffer.TYPE_FLOAT
72: || dataType == DataBuffer.TYPE_DOUBLE) {
73: return null;
74: }
75: }
76:
77: return new MlibMosaicOpImage(sources, layout, renderHints,
78: (MosaicType) paramBlock.getObjectParameter(0),
79: (PlanarImage[]) paramBlock.getObjectParameter(1),
80: (ROI[]) paramBlock.getObjectParameter(2),
81: (double[][]) paramBlock.getObjectParameter(3),
82: (double[]) paramBlock.getObjectParameter(4));
83: }
84: }
|