001: /*
002: * $RCSfile: ShearRIF.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:43 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.opimage;
013:
014: import java.awt.RenderingHints;
015: import java.awt.geom.AffineTransform;
016: import java.awt.image.DataBuffer;
017: import java.awt.image.MultiPixelPackedSampleModel;
018: import java.awt.image.SampleModel;
019: import java.awt.image.RenderedImage;
020: import java.awt.image.renderable.ParameterBlock;
021: import java.awt.image.renderable.RenderedImageFactory;
022: import javax.media.jai.EnumeratedParameter;
023: import javax.media.jai.BorderExtender;
024: import javax.media.jai.ImageLayout;
025: import javax.media.jai.Interpolation;
026: import javax.media.jai.InterpolationBicubic2;
027: import javax.media.jai.InterpolationBicubic;
028: import javax.media.jai.InterpolationBilinear;
029: import javax.media.jai.InterpolationNearest;
030: import javax.media.jai.InterpolationTable;
031: import javax.media.jai.PlanarImage;
032: import javax.media.jai.RenderedOp;
033: import java.util.Map;
034: import javax.media.jai.operator.ShearDescriptor;
035:
036: /**
037: * @see AffineOpimage
038: */
039: public class ShearRIF implements RenderedImageFactory {
040:
041: /** Constructor. */
042: public ShearRIF() {
043: }
044:
045: /**
046: * Creates an shear operation as an instance of AffineOpImage.
047: */
048: public RenderedImage create(ParameterBlock paramBlock,
049: RenderingHints renderHints) {
050: // Get ImageLayout from renderHints if any.
051: ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
052:
053: // Get BorderExtender from renderHints if any.
054: BorderExtender extender = RIFUtil
055: .getBorderExtenderHint(renderHints);
056:
057: RenderedImage source = paramBlock.getRenderedSource(0);
058:
059: float shear_amt = paramBlock.getFloatParameter(0);
060: EnumeratedParameter shear_dir = (EnumeratedParameter) paramBlock
061: .getObjectParameter(1);
062:
063: float xTrans = paramBlock.getFloatParameter(2);
064: float yTrans = paramBlock.getFloatParameter(3);
065:
066: Object arg1 = paramBlock.getObjectParameter(4);
067: Interpolation interp = (Interpolation) arg1;
068:
069: double[] backgroundValues = (double[]) paramBlock
070: .getObjectParameter(5);
071:
072: // Create the affine transform
073: AffineTransform tr = new AffineTransform();
074:
075: if (shear_dir.equals(ShearDescriptor.SHEAR_HORIZONTAL)) {
076: // SHEAR_HORIZONTAL
077: tr.setTransform(1.0, 0.0, shear_amt, 1.0, xTrans, 0.0);
078: } else {
079: // SHEAR_VERTICAL
080: tr.setTransform(1.0, shear_amt, 0.0, 1.0, 0.0, yTrans);
081: }
082:
083: // Do Affine
084: if (interp instanceof InterpolationNearest) {
085: SampleModel sm = source.getSampleModel();
086: boolean isBinary = (sm instanceof MultiPixelPackedSampleModel)
087: && (sm.getSampleSize(0) == 1)
088: && (sm.getDataType() == DataBuffer.TYPE_BYTE
089: || sm.getDataType() == DataBuffer.TYPE_USHORT || sm
090: .getDataType() == DataBuffer.TYPE_INT);
091: if (isBinary) {
092: return new AffineNearestBinaryOpImage(source, extender,
093: renderHints, layout, tr, interp,
094: backgroundValues);
095: } else {
096: return new AffineNearestOpImage(source, extender,
097: renderHints, layout, tr, interp,
098: backgroundValues);
099: }
100: } else if (interp instanceof InterpolationBilinear) {
101: return new AffineBilinearOpImage(source, extender,
102: renderHints, layout, tr, interp, backgroundValues);
103: } else if (interp instanceof InterpolationBicubic) {
104: return new AffineBicubicOpImage(source, extender,
105: renderHints, layout, tr, interp, backgroundValues);
106: } else if (interp instanceof InterpolationBicubic2) {
107: return new AffineBicubic2OpImage(source, extender,
108: renderHints, layout, tr, interp, backgroundValues);
109: } else {
110: return new AffineGeneralOpImage(source, extender,
111: renderHints, layout, tr, interp, backgroundValues);
112: }
113: }
114: }
|