2362N/A * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class performs a pixel-by-pixel rescaling of the data in the 0N/A * source image by multiplying the sample values for each pixel by a scale 0N/A * factor and then adding an offset. The scaled sample values are clipped 0N/A * The pseudo code for the rescaling operation is as follows: 0N/A *for each pixel from Source object { 0N/A * dstElement = (srcElement*scaleFactor) + offset 0N/A * For Rasters, rescaling operates on bands. The number of 0N/A * sets of scaling constants may be one, in which case the same constants 0N/A * are applied to all bands, or it must equal the number of Source 0N/A * For BufferedImages, rescaling operates on color and alpha components. 0N/A * The number of sets of scaling constants may be one, in which case the 0N/A * same constants are applied to all color (but not alpha) components. 0N/A * Otherwise, the number of sets of scaling constants may 0N/A * equal the number of Source color components, in which case no 0N/A * rescaling of the alpha component (if present) is performed. 0N/A * If neither of these cases apply, the number of sets of scaling constants 0N/A * must equal the number of Source color components plus alpha components, 0N/A * in which case all color and alpha components are rescaled. 0N/A * BufferedImage sources with premultiplied alpha data are treated in the same 0N/A * manner as non-premultiplied images for purposes of rescaling. That is, 0N/A * the rescaling is done per band on the raw data of the BufferedImage source 0N/A * without regard to whether the data is premultiplied. If a color conversion 0N/A * is required to the destination ColorModel, the premultiplied state of 0N/A * both source and destination will be taken into account for this step. 0N/A * Images with an IndexColorModel cannot be rescaled. 0N/A * If a RenderingHints object is specified in the constructor, the 0N/A * color rendering hint and the dithering hint may be used when color 0N/A * conversion is required. 0N/A * Note that in-place operation is allowed (i.e. the source and destination can 0N/A * be the same object). 0N/A * @see java.awt.RenderingHints#KEY_COLOR_RENDERING 0N/A * @see java.awt.RenderingHints#KEY_DITHERING 0N/A * Constructs a new RescaleOp with the desired scale factors 0N/A * and offsets. The length of the scaleFactor and offset arrays 0N/A * must meet the restrictions stated in the class comments above. 0N/A * The RenderingHints argument may be null. 0N/A * @param scaleFactors the specified scale factors 0N/A * @param offsets the specified offsets 0N/A * @param hints the specified <code>RenderingHints</code>, or 0N/A * Constructs a new RescaleOp with the desired scale factor 0N/A * and offset. The scaleFactor and offset will be applied to 0N/A * all bands in a source Raster and to all color (but not alpha) 0N/A * components in a BufferedImage. 0N/A * The RenderingHints argument may be null. 0N/A * @param scaleFactor the specified scale factor 0N/A * @param offset the specified offset 0N/A * @param hints the specified <code>RenderingHints</code>, or 0N/A * Returns the scale factors in the given array. The array is also 0N/A * returned for convenience. If scaleFactors is null, a new array 0N/A * will be allocated. 0N/A * @param scaleFactors the array to contain the scale factors of 0N/A * this <code>RescaleOp</code> 0N/A * @return the scale factors of this <code>RescaleOp</code>. 0N/A * Returns the offsets in the given array. The array is also returned 0N/A * for convenience. If offsets is null, a new array 0N/A * will be allocated. 0N/A * @param offsets the array to contain the offsets of 0N/A * this <code>RescaleOp</code> 0N/A * @return the offsets of this <code>RescaleOp</code>. 0N/A * Returns the number of scaling factors and offsets used in this 0N/A * @return the number of scaling factors and offsets of this 0N/A * <code>RescaleOp</code>. 0N/A * Creates a ByteLookupTable to implement the rescale. 0N/A * The table may have either a SHORT or BYTE input. 0N/A * @param nElems Number of elements the table is to have. 0N/A * This will generally be 256 for byte and 0N/A if ((
val &
0xffffff00) !=
0) {
0N/A * Creates a ShortLookupTable to implement the rescale. 0N/A * The table may have either a SHORT or BYTE input. 0N/A * @param nElems Number of elements the table is to have. 0N/A * This will generally be 256 for byte and 0N/A if ((
val &
0xffff0000) !=
0) {
0N/A * Determines if the rescale can be performed as a lookup. 0N/A * The dst must be a byte or short type. 0N/A * The src must be less than 16 bits. 0N/A * All source band sizes must be the same and all dst band sizes 0N/A // Check that the src datatype is either a BYTE or SHORT 0N/A // Check dst sample sizes. All must be 8 or 16 bits. 0N/A // Check src sample sizes. All must be the same size 0N/A * Rescales the source BufferedImage. 0N/A * If the color model in the source image is not the same as that 0N/A * in the destination image, the pixels will be converted 0N/A * in the destination. If the destination image is null, 0N/A * a BufferedImage will be created with the source ColorModel. 0N/A * An IllegalArgumentException may be thrown if the number of 0N/A * restrictions stated in the class comments above, or if the 0N/A * source image has an IndexColorModel. 0N/A * @param src the <code>BufferedImage</code> to be filtered 0N/A * @param dst the destination for the filtering operation 0N/A * or <code>null</code> 0N/A * @return the filtered <code>BufferedImage</code>. 0N/A * @throws IllegalArgumentException if the <code>ColorModel</code> 0N/A * of <code>src</code> is an <code>IndexColorModel</code>, 0N/A * or if the number of scaling factors and offsets in this 0N/A * <code>RescaleOp</code> do not meet the requirements 0N/A * stated in the class comments. 0N/A "performed on an indexed image");
0N/A "does not equal the number of"+
0N/A ") not equal to dst width ("+
0N/A ") not equal to dst height ("+
0N/A // Try to use a native BI rescale operation first 0N/A // Native BI rescale failed - convert to rasters 0N/A // Call the raster filter method 0N/A // ColorModels are not the same 0N/A * Rescales the pixel data in the source Raster. 0N/A * If the destination Raster is null, a new Raster will be created. 0N/A * The source and destination must have the same number of bands. 0N/A * Otherwise, an IllegalArgumentException is thrown. 0N/A * meet the restrictions stated in the class comments above. 0N/A * Otherwise, an IllegalArgumentException is thrown. 0N/A * @param src the <code>Raster</code> to be filtered 0N/A * @param dst the destination for the filtering operation 0N/A * or <code>null</code> 0N/A * @return the filtered <code>WritableRaster</code>. 0N/A * @throws IllegalArgumentException if <code>src</code> and 0N/A * <code>dst</code> do not have the same number of bands, 0N/A * or if the number of scaling factors and offsets in this 0N/A * <code>RescaleOp</code> do not meet the requirements 0N/A * stated in the class comments. 0N/A // Create a new destination Raster, if needed 0N/A // Make sure that the number of bands are equal 0N/A +
" does not equal number of bands in dest " 0N/A // Make sure that the arrays match 0N/A "does not equal the number of"+
0N/A " of bands in the src raster");
0N/A // Try for a native raster rescale first 0N/A // Native raster rescale failed. 0N/A // Try to see if a lookup operation can be used 0N/A // Fall back to the slow code 0N/A // Determine bits per band to determine maxval for clamps. 0N/A // The min is assumed to be zero. 0N/A // REMIND: This must change if we ever support signed data types. 0N/A // Get data for all bands at this x,y position 0N/A // Put it back for all bands 0N/A * Returns the bounding box of the rescaled destination image. Since 0N/A * this is not a geometric operation, the bounding box does not 0N/A * Returns the bounding box of the rescaled destination Raster. Since 0N/A * this is not a geometric operation, the bounding box does not 0N/A * @param src the rescaled destination <code>Raster</code> 0N/A * @return the bounds of the specified <code>Raster</code>. 0N/A * Creates a zeroed destination image with the correct size and number of 0N/A * @param src Source image for the filter operation. 0N/A * @param destCM ColorModel of the destination. If null, the 0N/A * ColorModel of the source will be used. 0N/A * @return the zeroed-destination image. 0N/A * Creates a zeroed-destination <code>Raster</code> with the correct 0N/A * size and number of bands, given this source. 0N/A * @param src the source <code>Raster</code> 0N/A * @return the zeroed-destination <code>Raster</code>. 0N/A * Returns the location of the destination point given a 0N/A * point in the source. If dstPt is non-null, it will 0N/A * be used to hold the return value. Since this is not a geometric 0N/A * operation, the srcPt will equal the dstPt. 0N/A * @param srcPt a point in the source image 0N/A * @param dstPt the destination point or <code>null</code> 0N/A * @return the location of the destination point. 0N/A * Returns the rendering hints for this op. 0N/A * @return the rendering hints of this <code>RescaleOp</code>.