01: /*
02: * $RCSfile: SubtractConstCRIF.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:44 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.opimage;
13:
14: import java.awt.RenderingHints;
15: import java.awt.image.RenderedImage;
16: import java.awt.image.renderable.ParameterBlock;
17: import java.awt.image.renderable.RenderableImage;
18: import javax.media.jai.CRIFImpl;
19: import javax.media.jai.ImageLayout;
20: import java.util.Map;
21:
22: /**
23: * A <code>CRIF</code> supporting the "SubtractConst" operation in the rendered
24: * and renderable image layers.
25: *
26: * @see javax.media.jai.operator.SubtractConstDescriptor
27: * @see AddConstOpImage
28: *
29: */
30: public class SubtractConstCRIF extends CRIFImpl {
31:
32: /** Constructor. */
33: public SubtractConstCRIF() {
34: super ("subtractconst");
35: }
36:
37: /**
38: * Creates a new instance of <code>SubtractConstOpImage</code> in the
39: * rendered layer. This method satisfies the implementation of RIF.
40: *
41: * @param args The source image and the constants.
42: * @param hints Optionally contains destination image layout.
43: */
44: public RenderedImage create(ParameterBlock args,
45: RenderingHints hints) {
46: // Get ImageLayout from redering hints if any.
47: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
48:
49: // Negate the constants vector
50: double[] constants = (double[]) args.getObjectParameter(0);
51: int length = constants.length;
52:
53: double[] negConstants = new double[length];
54:
55: for (int i = 0; i < length; i++) {
56: negConstants[i] = -constants[i];
57: }
58:
59: return new AddConstOpImage(args.getRenderedSource(0), hints,
60: layout, negConstants);
61: }
62: }
|