01: /*
02: * $RCSfile: MlibDivideByConstRIF.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:55:54 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.mlib;
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.RenderedImageFactory;
18: import javax.media.jai.ImageLayout;
19: import java.util.Map;
20: import com.sun.media.jai.opimage.RIFUtil;
21:
22: /**
23: * A <code>RIF</code> supporting the "DivideByConst" operation in the
24: * rendered image mode using MediaLib.
25: *
26: * @see javax.media.jai.operator.DivideByConstDescriptor
27: * @see MlibMultiplyConstOpImage
28: *
29: */
30: public class MlibDivideByConstRIF implements RenderedImageFactory {
31:
32: /** Constructor. */
33: public MlibDivideByConstRIF() {
34: }
35:
36: /**
37: * Creates a new instance of <code>MlibMultiplyConstOpImage</code> in
38: * the rendered image mode. By inverting the constants, the result
39: * of "DivideByConst" is obtained.
40: *
41: * @param args The source image and the constants.
42: * @param hints May contain rendering hints and destination image layout.
43: */
44: public RenderedImage create(ParameterBlock args,
45: RenderingHints hints) {
46: /* Get ImageLayout and TileCache from RenderingHints. */
47: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
48:
49: if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
50: || !MediaLibAccessor.hasSameNumBands(args, layout)) {
51: return null;
52: }
53:
54: /* Negate the constants vector. */
55: double[] constants = (double[]) args.getObjectParameter(0);
56: int length = constants.length;
57:
58: double[] invConstants = new double[length];
59:
60: for (int i = 0; i < length; i++) {
61: invConstants[i] = 1.0D / constants[i];
62: }
63:
64: return new MlibMultiplyConstOpImage(args.getRenderedSource(0),
65: hints, layout, invConstants);
66: }
67: }
|