01: /*
02: * $RCSfile: ImageFunctionRIF.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:29 $
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.RenderedImageFactory;
17: import java.awt.image.renderable.ParameterBlock;
18: import javax.media.jai.ImageFunction;
19: import javax.media.jai.ImageLayout;
20: import java.util.Map;
21:
22: /**
23: * A <code>RIF</code> supporting the "ImageFunction" operation in the rendered
24: * image layer.
25: *
26: * @see javax.media.jai.operator.ImageFunctionDescriptor
27: * @see javax.media.jai.ImageFunction
28: * @since EA4
29: */
30: public class ImageFunctionRIF implements RenderedImageFactory {
31:
32: /** Constructor. */
33: public ImageFunctionRIF() {
34: }
35:
36: /**
37: * Creates a new instance of ImageFunctionOpImage in the rendered layer.
38: * This method satisfies the implementation of RIF.
39: *
40: * @param paramBlock The source image, the X and Y scale factor,
41: * and the interpolation method for resampling.
42: */
43: public RenderedImage create(ParameterBlock paramBlock,
44: RenderingHints renderHints) {
45: // Get ImageLayout from renderHints if any.
46: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
47:
48: ImageFunction function = (ImageFunction) paramBlock
49: .getObjectParameter(0);
50:
51: // Ascertain that a supplied SampleModel has the requisite
52: // number of bands vis-a-vis the ImageFunction.
53: int numBandsRequired = function.isComplex() ? function
54: .getNumElements() * 2 : function.getNumElements();
55: if (layout != null
56: && layout.isValid(ImageLayout.SAMPLE_MODEL_MASK)
57: && layout.getSampleModel(null).getNumBands() != numBandsRequired) {
58: throw new RuntimeException(JaiI18N
59: .getString("ImageFunctionRIF0"));
60: }
61:
62: int minX = 0;
63: int minY = 0;
64: if (layout != null) {
65: if (layout.isValid(ImageLayout.MIN_X_MASK)) {
66: minX = layout.getMinX(null);
67: }
68: if (layout.isValid(ImageLayout.MIN_Y_MASK)) {
69: minY = layout.getMinX(null);
70: }
71: }
72:
73: int width = paramBlock.getIntParameter(1);
74: int height = paramBlock.getIntParameter(2);
75: float xScale = paramBlock.getFloatParameter(3);
76: float yScale = paramBlock.getFloatParameter(4);
77: float xTrans = paramBlock.getFloatParameter(5);
78: float yTrans = paramBlock.getFloatParameter(6);
79:
80: return new ImageFunctionOpImage(function, minX, minY, width,
81: height, xScale, yScale, xTrans, yTrans, renderHints,
82: layout);
83: }
84: }
|