001: /*
002: * $RCSfile: MlibShearRIF.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:56:06 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.mlib;
013:
014: import java.awt.RenderingHints;
015: import java.awt.geom.AffineTransform;
016: import java.awt.image.RenderedImage;
017: import java.awt.image.renderable.ParameterBlock;
018: import java.awt.image.renderable.RenderedImageFactory;
019: import javax.media.jai.EnumeratedParameter;
020: import javax.media.jai.BorderExtender;
021: import javax.media.jai.ImageLayout;
022: import javax.media.jai.Interpolation;
023: import javax.media.jai.InterpolationBicubic2;
024: import javax.media.jai.InterpolationBicubic;
025: import javax.media.jai.InterpolationBilinear;
026: import javax.media.jai.InterpolationNearest;
027: import javax.media.jai.InterpolationTable;
028: import java.util.Map;
029: import javax.media.jai.BorderExtender;
030: import javax.media.jai.operator.ShearDescriptor;
031: import com.sun.media.jai.opimage.RIFUtil;
032:
033: /**
034: * A <code>RIF</code> supporting the "Shear" operation in the
035: * rendered image mode using MediaLib.
036: *
037: * @see javax.media.jai.operator.ShearDescriptor
038: * @see MlibAffineOpImage
039: */
040: public class MlibShearRIF implements RenderedImageFactory {
041:
042: /** Constructor. */
043: public MlibShearRIF() {
044: }
045:
046: /**
047: * Creates a new instance of <code>MlibAffineOpImage</code> in
048: * the rendered image mode.
049: *
050: * @param args The source image, the <code>AffineTransform</code>,
051: * and the <code>Interpolation</code>.
052: * @param hints May contain rendering hints and destination image layout.
053: */
054: public RenderedImage create(ParameterBlock args,
055: RenderingHints hints) {
056: /* Get ImageLayout and TileCache from RenderingHints. */
057: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
058:
059: Interpolation interp = (Interpolation) args
060: .getObjectParameter(4);
061:
062: RenderedImage source = args.getRenderedSource(0);
063:
064: if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
065: || !MediaLibAccessor.hasSameNumBands(args, layout)
066: ||
067: // Medialib cannot deal with source image having tiles with any
068: // dimension greater than or equal to 32768
069: source.getTileWidth() >= 32768
070: || source.getTileHeight() >= 32768) {
071: return null;
072: }
073:
074: /* Get BorderExtender from hints if any. */
075: BorderExtender extender = RIFUtil.getBorderExtenderHint(hints);
076:
077: float shear_amt = args.getFloatParameter(0);
078: EnumeratedParameter shear_dir = (EnumeratedParameter) args
079: .getObjectParameter(1);
080: float xTrans = args.getFloatParameter(2);
081: float yTrans = args.getFloatParameter(3);
082: double[] backgroundValues = (double[]) args
083: .getObjectParameter(5);
084:
085: // Create the affine transform
086: AffineTransform tr = new AffineTransform();
087:
088: if (shear_dir.equals(ShearDescriptor.SHEAR_HORIZONTAL)) {
089: // SHEAR_HORIZONTAL
090: tr.setTransform(1.0, 0.0, shear_amt, 1.0, xTrans, 0.0);
091: } else {
092: // SHEAR_VERTICAL
093: tr.setTransform(1.0, shear_amt, 0.0, 1.0, 0.0, yTrans);
094: }
095:
096: if (interp instanceof InterpolationNearest) {
097: return new MlibAffineNearestOpImage(source, extender,
098: hints, layout, tr, interp, backgroundValues);
099: } else if (interp instanceof InterpolationBilinear) {
100: return new MlibAffineBilinearOpImage(source, extender,
101: hints, layout, tr, interp, backgroundValues);
102: } else if (interp instanceof InterpolationBicubic
103: || interp instanceof InterpolationBicubic2) {
104: return new MlibAffineBicubicOpImage(source, extender,
105: hints, layout, tr, interp, backgroundValues);
106: } else if (interp instanceof InterpolationTable) {
107: return new MlibAffineTableOpImage(source, extender, hints,
108: layout, tr, interp, backgroundValues);
109: } else {
110: return null;
111: }
112: }
113: }
|