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

📄 bandedsamplemodel.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @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 b The band to retrieve.   * @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[] getSamples(int x, int y, int w, int h, int b, int[] iArray,			  DataBuffer data)  {    if (iArray == null) iArray = new int[w*h];    int outOffset = 0;    int maxX = x + w;    int maxY = y + h;    for (int yy = y; yy < maxY; yy++)      {	for (int xx = x; xx < maxX; xx++)	  {	    int offset = bandOffsets[b] + yy * scanlineStride + xx;	    iArray[outOffset++] =	      data.getElem(bankIndices[b], offset);	  }      }    return iArray;	  }  /**   * Set the pixel at x, y to the value in the first element of the primitive   * array obj.   *   * @param x The x-coordinate of the data elements in <code>obj</code>.   * @param y The y-coordinate of the data elements in <code>obj</code>.   * @param obj The primitive array containing the data elements to set.   * @param data The DataBuffer to store the data elements into.   * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)   */  public void setDataElements(int x, int y, Object obj, DataBuffer data)  {    int transferType = getTransferType();    if (getTransferType() != data.getDataType())      {	throw new IllegalArgumentException("transfer type ("+					   getTransferType()+"), "+					   "does not match data "+					   "buffer type (" +					   data.getDataType() +					   ").");      }    int offset = y * scanlineStride + x;        try      {	switch (transferType)	  {	  case DataBuffer.TYPE_BYTE:	    {	      DataBufferByte out = (DataBufferByte) data;	      byte[] in = (byte[]) obj;	      for (int i=0; i < numBands; i++)		out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];	      return;	    }	  case DataBuffer.TYPE_SHORT:	    {	      DataBufferShort out = (DataBufferShort) data;	      short[] in = (short[]) obj;	      for (int i=0; i < numBands; i++)		out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];	      return;	    }	  case DataBuffer.TYPE_USHORT:	    {	      DataBufferUShort out = (DataBufferUShort) data;	      short[] in = (short[]) obj;	      for (int i=0; i < numBands; i++)		out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];	      return;	    }	  case DataBuffer.TYPE_INT:	    {	      DataBufferInt out = (DataBufferInt) data;	      int[] in = (int[]) obj;	      for (int i=0; i < numBands; i++)		out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];	      return;	    }	  case DataBuffer.TYPE_FLOAT:	    {	      DataBufferFloat out = (DataBufferFloat) data;	      float[] in = (float[]) obj;	      for (int i=0; i < numBands; i++)		out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];	      return;	    }	  case DataBuffer.TYPE_DOUBLE:	    {	      DataBufferDouble out = (DataBufferDouble) data;	      double[] in = (double[]) obj;	      for (int i=0; i < numBands; i++)		out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];	      return;	    }	  default:	    throw new ClassCastException("Unsupported data type");	  }      }    catch (ArrayIndexOutOfBoundsException aioobe)      {	String msg = "While writing data elements" +	  ", x="+x+", y="+y+	  ", width="+width+", height="+height+	  ", scanlineStride="+scanlineStride+	  ", offset="+offset+	  ", data.getSize()="+data.getSize()+	  ", data.getOffset()="+data.getOffset()+	  ": " +	  aioobe;	throw new ArrayIndexOutOfBoundsException(msg);      }    }  public void setPixel(int x, int y, int[] iArray, DataBuffer data)  {    for (int b=0; b < numBands; b++)      data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,		   iArray[b]);  }  public void setPixels(int x, int y, int w, int h, int[] iArray,			DataBuffer data)  {    int inOffset = 0;    for (int hh = 0; hh < h; hh++)      {	for (int ww = 0; ww < w; ww++)	  {	    int offset = y * scanlineStride + (x + ww);	    for (int b=0; b < numBands; b++)	      data.setElem(bankIndices[b], bandOffsets[b] + offset,			   iArray[inOffset++]);	  }	y++;      }  }  public void setSample(int x, int y, int b, int s, DataBuffer data)  {    data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);  }    public void setSample(int x, int y, int b, float s, DataBuffer data)  {    data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);  }    public void setSample(int x, int y, int b, double s, DataBuffer data)  {    data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);  }    public void setSamples(int x, int y, int w, int h, int b, int[] iArray,			 DataBuffer data)  {    int inOffset = 0;    switch (getTransferType())      {      case DataBuffer.TYPE_BYTE:	{	  DataBufferByte out = (DataBufferByte) data;	  byte[] bank = out.getData(bankIndices[b]);	  for (int hh = 0; hh < h; hh++)	    {	      for (int ww = 0; ww < w; ww++)		{		  int offset = bandOffsets[b] + y * scanlineStride + (x + ww);		  bank[offset] = (byte)iArray[inOffset++];		}	      y++;	    }	  return;	}      case DataBuffer.TYPE_SHORT:	{	  DataBufferShort out = (DataBufferShort) data;	  short[] bank = out.getData(bankIndices[b]);	  for (int hh = 0; hh < h; hh++)	    {	      for (int ww = 0; ww < w; ww++)		{		  int offset = bandOffsets[b] + y * scanlineStride + (x + ww);		  bank[offset] = (short)iArray[inOffset++];		}	      y++;	    }	  return;	}      case DataBuffer.TYPE_USHORT:	{	  DataBufferShort out = (DataBufferShort) data;	  short[] bank = out.getData(bankIndices[b]);	  for (int hh = 0; hh < h; hh++)	    {	      for (int ww = 0; ww < w; ww++)		{		  int offset = bandOffsets[b] + y * scanlineStride + (x + ww);		  bank[offset] = (short)iArray[inOffset++];		}	      y++;	    }	  return;	}      case DataBuffer.TYPE_INT:	{	  DataBufferInt out = (DataBufferInt) data;	  int[] bank = out.getData(bankIndices[b]);	  for (int hh = 0; hh < h; hh++)	    {	      for (int ww = 0; ww < w; ww++)		{		  int offset = bandOffsets[b] + y * scanlineStride + (x + ww);		  bank[offset] = iArray[inOffset++];		}	      y++;	    }	  return;	}      case DataBuffer.TYPE_FLOAT:      case DataBuffer.TYPE_DOUBLE:	break;      default:	throw new ClassCastException("Unsupported data type");      }    // Default implementation probably slower for float and double    for (int hh = 0; hh < h; hh++)      {	for (int ww = 0; ww < w; ww++)	  {	    int offset = bandOffsets[b] + y * scanlineStride + (x + ww);	    data.setElem(bankIndices[b], offset, iArray[inOffset++]);	  }	y++;      }  }  /**   * Creates a String with some information about this SampleModel.   * @return A String describing this SampleModel.   * @see java.lang.Object#toString()   */  public String toString()  {    StringBuffer result = new StringBuffer();    result.append(getClass().getName());    result.append("[");    result.append("scanlineStride=").append(scanlineStride);    for(int i=0; i < bitMasks.length; i+=1)    {      result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i]));    }        result.append("]");    return result.toString();  }}

⌨️ 快捷键说明

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