01: /*
02: * $RCSfile: DivideByConstCRIF.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:23 $
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 javax.media.jai.CRIFImpl;
18: import javax.media.jai.ImageLayout;
19: import java.util.Map;
20:
21: /**
22: * A <code>CRIF</code> supporting the "DivideByConst" operation in the rendered
23: * and renderable image layers.
24: *
25: * @see javax.media.jai.operator.DivideByConstDescriptor
26: * @see MultiplyConstOpImage
27: *
28: *
29: * @since EA2
30: */
31: public class DivideByConstCRIF extends CRIFImpl {
32:
33: /** Constructor. */
34: public DivideByConstCRIF() {
35: super ("dividebyconst");
36: }
37:
38: /**
39: * Creates a new instance of <code>DivideByConstOpImage</code> in the
40: * rendered layer.
41: *
42: * @param args The source image and the constants.
43: * @param hints Optionally contains destination image layout.
44: */
45: public RenderedImage create(ParameterBlock args,
46: RenderingHints renderHints) {
47: // Get ImageLayout from renderHints if any.
48: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
49:
50: /* Invert the constants. */
51: double[] constants = (double[]) args.getObjectParameter(0);
52: int length = constants.length;
53:
54: double[] invConstants = new double[length];
55:
56: for (int i = 0; i < length; i++) {
57: invConstants[i] = 1.0 / constants[i];
58: }
59:
60: return new MultiplyConstOpImage(args.getRenderedSource(0),
61: renderHints, layout, invConstants);
62: }
63: }
|