001: /*
002: * $RCSfile: MlibWarpRIF.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:09 $
010: * $State: Exp $
011: */
012: package com.sun.media.jai.mlib;
013:
014: import java.awt.RenderingHints;
015: import java.awt.image.RenderedImage;
016: import java.awt.image.renderable.ParameterBlock;
017: import java.awt.image.renderable.RenderedImageFactory;
018: import javax.media.jai.BorderExtender;
019: import javax.media.jai.ImageLayout;
020: import javax.media.jai.Interpolation;
021: import javax.media.jai.InterpolationNearest;
022: import javax.media.jai.InterpolationBilinear;
023: import javax.media.jai.InterpolationBicubic;
024: import javax.media.jai.InterpolationBicubic2;
025: import javax.media.jai.InterpolationTable;
026: import java.util.Map;
027: import javax.media.jai.Warp;
028: import javax.media.jai.WarpGrid;
029: import javax.media.jai.WarpPolynomial;
030: import com.sun.media.jai.opimage.RIFUtil;
031:
032: import com.sun.medialib.mlib.*;
033:
034: /**
035: * A <code>RIF</code> supporting the "Warp" operation in the
036: * rendered image mode using MediaLib.
037: *
038: * @see javax.media.jai.operator.WarpDescriptor
039: * @see MlibWarpNearestOpImage
040: * @see MlibWarpBilinearOpImage
041: * @see MlibWarpBicubicOpImage
042: *
043: * @since 1.0
044: *
045: */
046: public class MlibWarpRIF implements RenderedImageFactory {
047:
048: /** Constructor. */
049: public MlibWarpRIF() {
050: }
051:
052: /**
053: * Creates a new instance of <code>MlibWarpOpImage</code> in
054: * the rendered image mode.
055: *
056: * @param args The source images.
057: * @param hints May contain rendering hints and destination image layout.
058: */
059: public RenderedImage create(ParameterBlock args,
060: RenderingHints hints) {
061: /* Get ImageLayout and TileCache from RenderingHints. */
062: ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
063:
064: RenderedImage source = args.getRenderedSource(0);
065:
066: if (!MediaLibAccessor.isMediaLibCompatible(args, layout)
067: || !MediaLibAccessor.hasSameNumBands(args, layout)
068: ||
069: // Medialib cannot deal with source image having tiles with any
070: // dimension greater than or equal to 32768
071: source.getTileWidth() >= 32768
072: || source.getTileHeight() >= 32768) {
073: return null;
074: }
075:
076: /* Get BorderExtender from hints if any. */
077: BorderExtender extender = RIFUtil.getBorderExtenderHint(hints);
078:
079: Warp warp = (Warp) args.getObjectParameter(0);
080: Interpolation interp = (Interpolation) args
081: .getObjectParameter(1);
082: double[] backgroundValues = (double[]) args
083: .getObjectParameter(2);
084:
085: int filter = -1;
086: if (interp instanceof InterpolationNearest) {
087: filter = Constants.MLIB_NEAREST;
088: } else if (interp instanceof InterpolationBilinear) {
089: filter = Constants.MLIB_BILINEAR;
090: } else if (interp instanceof InterpolationBicubic) {
091: filter = Constants.MLIB_BICUBIC;
092: } else if (interp instanceof InterpolationBicubic2) {
093: filter = Constants.MLIB_BICUBIC2;
094: } else if (interp instanceof InterpolationTable) {
095: ;
096: // filter = Constants.MLIB_TABLE; not defined yet;
097: } else {
098: /* Other kinds of interpolation cannot be handled via mlib. */
099: return null;
100: }
101:
102: if (warp instanceof WarpGrid) {
103: if (interp instanceof InterpolationTable) {
104: return new MlibWarpGridTableOpImage(source, extender,
105: hints, layout, (WarpGrid) warp, interp,
106: backgroundValues);
107: } else {
108: return new MlibWarpGridOpImage(source, extender, hints,
109: layout, (WarpGrid) warp, interp, filter,
110: backgroundValues);
111: }
112:
113: } else if (warp instanceof WarpPolynomial) {
114: if (interp instanceof InterpolationTable) {
115: return new MlibWarpPolynomialTableOpImage(source,
116: extender, hints, layout, (WarpPolynomial) warp,
117: interp, backgroundValues);
118: } else {
119: return new MlibWarpPolynomialOpImage(source, extender,
120: hints, layout, (WarpPolynomial) warp, interp,
121: filter, backgroundValues);
122: }
123: } else {
124: return null;
125: }
126:
127: }
128: }
|