⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagetypespecifier.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ImageTypeSpecifier.java --   Copyright (C) 2004  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.imageio;import java.awt.Transparency;import java.awt.color.ColorSpace;import java.awt.image.DataBuffer;import java.awt.image.BandedSampleModel;import java.awt.image.BufferedImage;import java.awt.image.ColorModel;import java.awt.image.ComponentColorModel;import java.awt.image.DirectColorModel;import java.awt.image.IndexColorModel;import java.awt.image.MultiPixelPackedSampleModel;import java.awt.image.PixelInterleavedSampleModel;import java.awt.image.RenderedImage;import java.awt.image.SampleModel;/** * ImageTypeSpecifier store the color and sample models associated * with an IIOImage. */public class ImageTypeSpecifier{  /**   * The image's color model.   */  protected ColorModel colorModel;  /**   * The image's sample model.   */  protected SampleModel sampleModel;  /**   * Construct an image type specifier with the given models.   *   * @param colorModel the color model   * @param sampleModel the sample model   *   * @exception IllegalArgumentException if either model argument is   * null   * @exception IllegalArgumentException if the models are   * incompatible with one another   */  public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel)  {    if (colorModel == null)      throw new IllegalArgumentException("colorModel may not be null");    if (sampleModel == null)      throw new IllegalArgumentException("sampleModel may not be null");    if (!colorModel.isCompatibleSampleModel(sampleModel))      throw new IllegalArgumentException        ("sample Model not compatible with colorModel");        this.colorModel = colorModel;    this.sampleModel = sampleModel;  }  /**   * Construct an image type specifier that describes the given   * rendered image.   *   * @param image a rendered image   *   * @exception IllegalArgumentException if image is null   */  public ImageTypeSpecifier(RenderedImage image)  {    if (image == null)      throw new IllegalArgumentException("image may not be null");        this.colorModel = image.getColorModel();    this.sampleModel = image.getSampleModel();  }  /**   * Create an image type specifier for a banded image using a   * component color model and a banded sample model.   *   * @param colorSpace the color space   * @param bankIndices the bank indices at which each band will be   * stored   * @param bandOffsets the starting band offset for each band within   * its bank   * @param dataType the data type, a DataBuffer constant   * @param hasAlpha true if this image type specifier should have an   * alpha component, false otherwise   * @param isAlphaPremultiplied true if other color components should   * be premultiplied by the alpha component, false otherwise   *   * @return a banded image type specifier   *   * @exception IllegalArgumentException if any of colorSpace,   * bankIndices or bankOffsets is null   * @exception IllegalArgumentException if bankIndices and   * bankOffsets differ in length   * @excpetion IllegalArgumentException if the number of color space   * components, including the alpha component if requested, is   * different from bandOffsets.length   * @exception if dataType is not a valid DataBuffer constant   */  public static ImageTypeSpecifier createBanded (ColorSpace colorSpace,                                                 int[] bankIndices,                                                 int[] bankOffsets,                                                 int dataType,                                                 boolean hasAlpha,                                                 boolean isAlphaPremultiplied)  {    if (colorSpace == null || bankIndices == null || bankOffsets == null)      throw new IllegalArgumentException ("null argument");    if (bankIndices.length != bankOffsets.length)      throw new IllegalArgumentException ("array lengths differ");    if (bankOffsets.length != (colorSpace.getNumComponents() + (hasAlpha ? 1 : 0)))      throw new IllegalArgumentException ("invalid bankOffsets length");    return new ImageTypeSpecifier (new ComponentColorModel (colorSpace,                                                            hasAlpha,                                                            isAlphaPremultiplied,                                                            hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE,                                                            dataType),                                   new BandedSampleModel (dataType, 1, 1, 1,                                                          bankIndices,                                                          bankOffsets));  }  /**   * Create a buffered image with the given dimensions using that has   * the characteristics specified by this image type specifier.   *   * @param the width of the buffered image, in pixels   * @param the height of the buffered image, in pixels   *   * @return a buffered image   *   * @exception IllegalArgumentException if either width or height is   * less than or equal to zero   * @exception IllegalArgumentException if width * height is greater   * than Integer.MAX_VALUE or if the storage required is greater than   * Integer.MAX_VALUE   */  public BufferedImage createBufferedImage (int width, int height)  {    if (width <= 0 || height <= 0)      throw new IllegalArgumentException ("dimension <= 0");    // test for overflow    if (width * height < Math.min (width, height))      throw new IllegalArgumentException ("width * height > Integer.MAX_VALUE");    if (width * height * sampleModel.getNumBands() < Math.min (width, height))      throw new IllegalArgumentException ("storage required >"                                          + " Integer.MAX_VALUE");    // FIXME: this is probably wrong:    return new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);  }  /**   * Create an image type specifier that describes the given buffered   * image type.   *   * @param bufferedImageType the buffered image type to represent   * with the returned image type specifier   *   * @return a new image type specifier   *   * @exception IllegalArgumentException if bufferedImageType is not a   * BufferedImage constant or is BufferedImage.TYPE_CUSTOM   */  public static ImageTypeSpecifier createFromBufferedImageType (int bufferedImageType)  {    if (bufferedImageType <= BufferedImage.TYPE_CUSTOM        || bufferedImageType > BufferedImage.TYPE_BYTE_INDEXED)      throw new IllegalArgumentException ("invalid buffered image type");    return new ImageTypeSpecifier (new BufferedImage (1, 1, bufferedImageType));  }  /**   * Create an image type specifier that describes the given rendered   * image's type.   *   * @param image the rendered image   *   * @return a new image type specifier   *   * @exception IllegalArgumentException if image is null   */  public static ImageTypeSpecifier createFromRenderedImage (RenderedImage image)  {    if (image == null)      throw new IllegalArgumentException ("image null");    return new ImageTypeSpecifier (image);  }  /**   * Create a grayscale image type specifier, given the number of   * bits, data type and whether or not the data is signed.   *   * @param bits the number of bits used to specify a greyscale value   * @param dataType a DataBuffer type constant   * @param isSigned true if this type specifier should support   * negative values, false otherwise   *   * @return a greyscal image type specifier   *   * @exception IllegalArgumentException if bits is not 1, 2, 4, 8 or 16   * @exception IllegalArgumentException if dataType is not   * DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or   * DataBuffer.TYPE_USHORT   * @exception if bits is larger than the number of bits in the given   * data type   */  public static ImageTypeSpecifier createGrayscale (int bits, int dataType, boolean isSigned)  {    return createGrayscale (bits, dataType, isSigned, false);  }  /**   * Create a grayscale image type specifier, given the number of   * bits, data type and whether or not the data is signed.   *   * @param bits the number of bits used to specify a greyscale value   * @param dataType a DataBuffer type constant   * @param isSigned true if this type specifier should support   * negative values, false otherwise   *   * @return a greyscal image type specifier   *   * @exception IllegalArgumentException if bits is not 1, 2, 4, 8 or   * 16   * @exception IllegalArgumentException if dataType is not   * DataBuffer.TYPE_BYTE, DataBuffer.TYPE_SHORT or   * DataBuffer.TYPE_USHORT   * @exception if bits is larger than the number of bits in the given   * data type   */  public static ImageTypeSpecifier createGrayscale (int bits, int dataType,                                                    boolean isSigned,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -