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

📄 bandedsamplemodel.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2004, 2005, Free Software FoundationThis 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 java.awt.image;/** * MultiPixelPackedSampleModel provides a single band model that supports * multiple pixels in a single unit.  Pixels have 2^n bits and 2^k pixels fit * per data element. * * @author Jerry Quinn (jlquinn@optonline.net) */public final class BandedSampleModel extends ComponentSampleModel{  private int[] bitMasks;  private int[] bitOffsets;  private int[] sampleSize;  private int dataBitOffset;  private int elemBits;  private int numberOfBits;  private int numElems;  private static int[] createBankArray(int size)   {    int[] result = new int[size];    for (int i = 0; i < size; i++)      result[i] = i;    return result;  }  public BandedSampleModel(int dataType, int w, int h, int numBands)  {    this(dataType, w, h, w, createBankArray(numBands), new int[numBands]);  }  public BandedSampleModel(int dataType, int w, int h, int scanlineStride,			   int[] bankIndices, int[] bandOffsets)  {    super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets);  }  public SampleModel createCompatibleSampleModel(int w, int h)  {    // NOTE: blackdown 1.4.1 sets all offsets to 0.  Sun's 1.4.2 docs    // disagree.    // Compress offsets so minimum is 0, others w*scanlineStride    int[] newoffsets = new int[bandOffsets.length];    int[] order = new int[bandOffsets.length];    for (int i=0; i < bandOffsets.length; i++)      order[i] = i;    // FIXME: This is N^2, but not a big issue, unless there's a lot of    // bands...    for (int i=0; i < bandOffsets.length; i++)      for (int j=i+1; j < bandOffsets.length; i++)	if (bankIndices[order[i]] > bankIndices[order[j]]	    || (bankIndices[order[i]] == bankIndices[order[j]]		&& bandOffsets[order[i]] > bandOffsets[order[j]]))	  {	    int t = order[i]; order[i] = order[j]; order[j] = t;	  }    int bank = 0;    int offset = 0;    for (int i=0; i < bandOffsets.length; i++)      {	if (bankIndices[order[i]] != bank)	  {	    bank = bankIndices[order[i]];	    offset = 0;	  }	newoffsets[order[i]] = offset;	offset += w * scanlineStride;      }        return new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices, newoffsets);  }  public SampleModel createSubsetSampleModel(int[] bands)  {    if (bands.length > bankIndices.length)      throw new	RasterFormatException("BandedSampleModel createSubsetSampleModel too"			      +" many bands");    int[] newoff = new int[bands.length];    int[] newbanks = new int[bands.length];    for (int i=0; i < bands.length; i++)      {	int b = bands[i];	newoff[i] = bandOffsets[b];	newbanks[i] = bankIndices[b];      }    return new BandedSampleModel(dataType, width, height, scanlineStride,				 newbanks, newoff);  }  /**   * Extract all samples of one pixel and return in an array of transfer type.   *   * Extracts the pixel at x, y from data and stores samples into the array   * obj.  If obj is null, a new array of getTransferType() is created.   *   * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>.   * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>.   * @param obj The primitive array to store the pixels into or null to force creation.   * @param data The DataBuffer that is the source of the pixel data.   * @return The primitive array containing the pixel data.   * @see java.awt.image.SampleModel#getDataElements(int, int, java.lang.Object, java.awt.image.DataBuffer)   */  public Object getDataElements(int x, int y, Object obj,				DataBuffer data)  {    int pixel = getSample(x, y, 0, data);    switch (getTransferType())    {    case DataBuffer.TYPE_BYTE:      {	byte[] b = (byte[])obj;	if (b == null) b = new byte[numBands];	for (int i=0; i < numBands; i++)	  b[i] = (byte)getSample(x, y, i, data);	return b;      }    case DataBuffer.TYPE_SHORT:    case DataBuffer.TYPE_USHORT:      {	short[] b = (short[])obj;	if (b == null) b = new short[numBands];	for (int i=0; i < numBands; i++)	  b[i] = (short)getSample(x, y, i, data);	return b;      }    case DataBuffer.TYPE_INT:      {	int[] b = (int[])obj;	if (b == null) b = new int[numBands];	for (int i=0; i < numBands; i++)	  b[i] = getSample(x, y, i, data);	return b;      }    case DataBuffer.TYPE_FLOAT:      {	float[] b = (float[])obj;	if (b == null) b = new float[numBands];	for (int i=0; i < numBands; i++)	  b[i] = getSampleFloat(x, y, i, data);	return b;      }    case DataBuffer.TYPE_DOUBLE:      {	double[] b = (double[])obj;	if (b == null) b = new double[numBands];	for (int i=0; i < numBands; i++)	  b[i] = getSample(x, y, i, data);	return b;      }    default:      // Seems like the only sensible thing to do.      throw new ClassCastException();    }  }  public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)  {    if (iArray == null) iArray = new int[numBands];    for (int i=0; i < numBands; i++)      iArray[i] = getSample(x, y, i, data);	    return iArray;  }  /**   * Copy pixels from a region into an array.   *   * Copies the samples of the pixels in the rectangle starting at x, y that   * is w pixels wide and h scanlines high.  When there is more than one band,   * the samples stored in order before the next pixel.  This ordering isn't   * well specified in Sun's docs as of 1.4.2.   *   * If iArray is null, a new array is allocated, filled, and returned.   *   * @param x The x-coordinate of the pixel rectangle to store in   * <code>iArray</code>.   * @param y The y-coordinate of the pixel rectangle to store in   * <code>iArray</code>.   * @param w The width in pixels of the rectangle.   * @param h The height in pixels of the rectangle.   * @param iArray The int array to store the pixels into or null to force   * creation.   * @param data The DataBuffer that is the source of the pixel data.   * @return The primitive array containing the pixel data.   */  public int[] getPixels(int x, int y, int w, int h, int[] iArray,			 DataBuffer data)  {    if (iArray == null) iArray = new int[w*h*numBands];    int outOffset = 0;    int maxX = x + w;    int maxY = y + h;    for (int yy = x; yy < maxY; yy++)      {	for (int xx = x; xx < maxX; xx++)	  {	    for (int b = 0; b < numBands; b++)	      {		int offset = bandOffsets[b] + yy * scanlineStride + xx;		iArray[outOffset++] =		  data.getElem(bankIndices[b], offset);	      }	  }      }    return iArray;	  }  public int getSample(int x, int y, int b, DataBuffer data)  {    int offset = bandOffsets[b] + y * scanlineStride + x;    return data.getElem(bankIndices[b], offset);  }    public float getSampleFloat(int x, int y, int b, DataBuffer data)  {    int offset = bandOffsets[b] + y * scanlineStride + x;    return data.getElemFloat(bankIndices[b], offset);  }    public double getSampleDouble(int x, int y, int b, DataBuffer data)  {    int offset = bandOffsets[b] + y * scanlineStride + x;    return data.getElemDouble(bankIndices[b], offset);  }    /**   * Copy one band's samples from a region into an array.   *   * Copies from one band the samples of the pixels in the rectangle starting   * at x, y that is w pixels wide and h scanlines high.   *   * If iArray is null, a new array is allocated, filled, and returned.   *

⌨️ 快捷键说明

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