01: /*
02: * $RCSfile: BorderRIF.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:16 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.opimage;
13:
14: import java.awt.RenderingHints;
15: import java.awt.image.Raster;
16: import java.awt.image.RenderedImage;
17: import java.awt.image.renderable.ParameterBlock;
18: import java.awt.image.renderable.RenderedImageFactory;
19: import javax.media.jai.BorderExtender;
20: import javax.media.jai.ImageLayout;
21: import javax.media.jai.JAI;
22: import java.util.Map;
23: import javax.media.jai.operator.BorderDescriptor;
24:
25: /**
26: * A <code>RIF</code> supporting the "border" operation in the
27: * rendered image layer.
28: *
29: * @see java.awt.image.renderable.RenderedImageFactory
30: * @see javax.media.jai.operator.BorderDescriptor
31: * @see BorderOpImage
32: *
33: */
34: public class BorderRIF implements RenderedImageFactory {
35:
36: /** Constructor. */
37: public BorderRIF() {
38: }
39:
40: /**
41: * Creates a new instance of <code>BorderOpImage</code>
42: * in the rendered layer.
43: *
44: * @param args The source image and the border information
45: * @param hints Optionally contains destination image layout.
46: */
47: public RenderedImage create(ParameterBlock args,
48: RenderingHints renderHints) {
49: // Get ImageLayout from renderHints if any.
50: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
51:
52: RenderedImage source = args.getRenderedSource(0);
53: int leftPad = args.getIntParameter(0);
54: int rightPad = args.getIntParameter(1);
55: int topPad = args.getIntParameter(2);
56: int bottomPad = args.getIntParameter(3);
57: BorderExtender type = (BorderExtender) args
58: .getObjectParameter(4);
59:
60: if (type == BorderExtender
61: .createInstance(BorderExtender.BORDER_WRAP)) {
62: int minX = source.getMinX() - leftPad;
63: int minY = source.getMinY() - topPad;
64: int width = source.getWidth() + leftPad + rightPad;
65: int height = source.getHeight() + topPad + bottomPad;
66:
67: return new PatternOpImage(source.getData(), source
68: .getColorModel(), minX, minY, width, height);
69: } else {
70: return new BorderOpImage(source, renderHints, layout,
71: leftPad, rightPad, topPad, bottomPad, type);
72: }
73: }
74: }
|