01: /*
02: * $RCSfile: MlibScaleOpImage.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:04 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.mlib;
13:
14: import java.awt.Rectangle;
15: import java.awt.image.RenderedImage;
16: import javax.media.jai.BorderExtender;
17: import javax.media.jai.ImageLayout;
18: import javax.media.jai.Interpolation;
19: import javax.media.jai.ScaleOpImage;
20: import java.util.Map;
21:
22: /**
23: * MlibScaleOpImage extends ScaleOpImage for use by further extension
24: * classes.
25: *
26: * @see ScaleOpImage
27: *
28: */
29: abstract class MlibScaleOpImage extends ScaleOpImage {
30:
31: /**
32: * Constructs a MlibScaleOpImage from a RenderedImage source,
33: * Interpolation object, x and y scale values. The image
34: * dimensions are determined by forward-mapping the source bounds.
35: * The tile grid layout, SampleModel, and ColorModel are specified
36: * by the image source, possibly overridden by values from the
37: * ImageLayout parameter.
38: *
39: * @param source a RenderedImage.
40: * @param extender a BorderExtender, or null.
41:
42: * or null. If null, a default cache will be used.
43: * @param layout an ImageLayout optionally containing the tile grid layout,
44: * SampleModel, and ColorModel, or null.
45: * @param scaleX scale factor along x axis.
46: * @param scaleY scale factor along y axis.
47: * @param transX translation factor along x axis.
48: * @param transY translation factor along y axis.
49: * @param interp an Interpolation object to use for resampling.
50: * @param cobbleSources a boolean indicating whether computeRect()
51: * expects contiguous sources.
52: */
53: public MlibScaleOpImage(RenderedImage source,
54: BorderExtender extender, Map config, ImageLayout layout,
55: float scaleX, float scaleY, float transX, float transY,
56: Interpolation interp, boolean cobbleSources) {
57: super (source, layout, config, cobbleSources, extender, interp,
58: scaleX, scaleY, transX, transY);
59:
60: // If the user did not provide a BorderExtender, attach a
61: // BorderExtenderCopy to Medialib such that when Medialib
62: // ask for additional source which may lie outside the
63: // bounds, it always gets it.
64: this .extender = (extender == null) ? BorderExtender
65: .createInstance(BorderExtender.BORDER_COPY) : extender;
66: }
67:
68: // Override backwardMapRect to pad the source by one extra pixel
69: // in all directions for non Nearest Neighbor interpolations, so
70: // that precision issues don't cause Medialib to not write areas
71: // in the destination rectangle.
72:
73: /**
74: * Returns the minimum bounding box of the region of the specified
75: * source to which a particular <code>Rectangle</code> of the
76: * destination will be mapped.
77: *
78: * @param destRect the <code>Rectangle</code> in destination coordinates.
79: * @param sourceIndex the index of the source image.
80: *
81: * @return a <code>Rectangle</code> indicating the source bounding box,
82: * or <code>null</code> if the bounding box is unknown.
83: *
84: * @throws IllegalArgumentException if <code>sourceIndex</code> is
85: * negative or greater than the index of the last source.
86: * @throws IllegalArgumentException if <code>destRect</code> is
87: * <code>null</code>.
88: */
89: protected Rectangle backwardMapRect(Rectangle destRect,
90: int sourceIndex) {
91:
92: Rectangle srcRect = super
93: .backwardMapRect(destRect, sourceIndex);
94: Rectangle paddedSrcRect = new Rectangle(srcRect.x - 1,
95: srcRect.y - 1, srcRect.width + 2, srcRect.height + 2);
96:
97: return paddedSrcRect;
98: }
99: }
|