01: /*
02: * $RCSfile: AreaOpPropertyGenerator.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:59 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.util;
13:
14: import java.awt.Rectangle;
15: import java.awt.geom.AffineTransform;
16: import java.awt.image.renderable.ParameterBlock;
17: import javax.media.jai.AreaOpImage;
18: import javax.media.jai.PlanarImage;
19: import javax.media.jai.RenderedOp;
20: import javax.media.jai.ROI;
21: import javax.media.jai.ROIShape;
22:
23: public class AreaOpPropertyGenerator extends PropertyGeneratorImpl {
24: /** Constructor. */
25: public AreaOpPropertyGenerator() {
26: super (new String[] { "ROI" }, new Class[] { ROI.class },
27: new Class[] { RenderedOp.class });
28: }
29:
30: /**
31: * Returns the specified property in the rendered layer.
32: *
33: * @param name Property name.
34: * @param opNode Operation node.
35: */
36: public Object getProperty(String name, Object opNode) {
37: validate(name, opNode);
38:
39: if (opNode instanceof RenderedOp
40: && name.equalsIgnoreCase("roi")) {
41: RenderedOp op = (RenderedOp) opNode;
42:
43: ParameterBlock pb = op.getParameterBlock();
44:
45: // Retrieve the rendered source image and its ROI.
46: PlanarImage src = (PlanarImage) pb.getRenderedSource(0);
47: Object roiProperty = src.getProperty("ROI");
48: if (roiProperty == null
49: || roiProperty == java.awt.Image.UndefinedProperty
50: || !(roiProperty instanceof ROI)) {
51: return java.awt.Image.UndefinedProperty;
52: }
53: ROI roi = (ROI) roiProperty;
54:
55: // Determine the effective destination bounds.
56: Rectangle dstBounds = null;
57: PlanarImage dst = op.getRendering();
58: if (dst instanceof AreaOpImage
59: && ((AreaOpImage) dst).getBorderExtender() == null) {
60: AreaOpImage aoi = (AreaOpImage) dst;
61: dstBounds = new Rectangle(aoi.getMinX()
62: + aoi.getLeftPadding(), aoi.getMinY()
63: + aoi.getTopPadding(), aoi.getWidth()
64: - aoi.getLeftPadding() - aoi.getRightPadding(),
65: aoi.getHeight() - aoi.getTopPadding()
66: - aoi.getBottomPadding());
67: } else {
68: dstBounds = dst.getBounds();
69: }
70:
71: // If necessary, clip the ROI to the destination bounds.
72: // XXX Is this desirable?
73: if (!dstBounds.contains(roi.getBounds())) {
74: roi = roi.intersect(new ROIShape(dstBounds));
75: }
76:
77: return roi;
78: }
79:
80: return java.awt.Image.UndefinedProperty;
81: }
82: }
|