📄 bandedsamplemodel.java
字号:
if (obj == null) { sdata = new short[numDataElems]; } else { sdata = (short[])obj; } for (int i=0; i<numDataElems; i++) { sdata[i] = (short)data.getElem(bankIndices[i], pixelOffset + bandOffsets[i]); } obj = (Object)sdata; break; case DataBuffer.TYPE_INT: int[] idata; if (obj == null) { idata = new int[numDataElems]; } else { idata = (int[])obj; } for (int i=0; i<numDataElems; i++) { idata[i] = data.getElem(bankIndices[i], pixelOffset + bandOffsets[i]); } obj = (Object)idata; break; case DataBuffer.TYPE_FLOAT: float[] fdata; if (obj == null) { fdata = new float[numDataElems]; } else { fdata = (float[])obj; } for (int i=0; i<numDataElems; i++) { fdata[i] = data.getElemFloat(bankIndices[i], pixelOffset + bandOffsets[i]); } obj = (Object)fdata; break; case DataBuffer.TYPE_DOUBLE: double[] ddata; if (obj == null) { ddata = new double[numDataElems]; } else { ddata = (double[])obj; } for (int i=0; i<numDataElems; i++) { ddata[i] = data.getElemDouble(bankIndices[i], pixelOffset + bandOffsets[i]); } obj = (Object)ddata; break; } return obj; } /** * Returns all samples for the specified pixel in an int array. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x, y The coordinates of the pixel location * @param iArray If non-null, returns the samples in this array * @param data The DataBuffer containing the image data * @return the samples for the specified pixel. * @see #setPixel(int, int, int[], DataBuffer) */ public int[] getPixel(int x, int y, int iArray[], DataBuffer data) { if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } int[] pixels; if (iArray != null) { pixels = iArray; } else { pixels = new int [numBands]; } int pixelOffset = y*scanlineStride + x; for (int i=0; i<numBands; i++) { pixels[i] = data.getElem(bankIndices[i], pixelOffset + bandOffsets[i]); } return pixels; } /** * Returns all samples for the specified rectangle of pixels in * an int array, one sample per data array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x, y The coordinates of the upper left pixel location * @param w The width of the pixel rectangle * @param h The height of the pixel rectangle * @param iArray If non-null, returns the samples in this array * @param data The DataBuffer containing the image data * @return the samples for the pixels within the specified region. * @see #setPixels(int, int, int, int, int[], DataBuffer) */ public int[] getPixels(int x, int y, int w, int h, int iArray[], DataBuffer data) { if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } int[] pixels; if (iArray != null) { pixels = iArray; } else { pixels = new int[w*h*numBands]; } for (int k = 0; k < numBands; k++) { int lineOffset = y*scanlineStride + x + bandOffsets[k]; int srcOffset = k; int bank = bankIndices[k]; for (int i = 0; i < h; i++) { int pixelOffset = lineOffset; for (int j = 0; j < w; j++) { pixels[srcOffset] = data.getElem(bank, pixelOffset++); srcOffset += numBands; } lineOffset += scanlineStride; } } return pixels; } /** * Returns as int the sample in a specified band for the pixel * located at (x,y). * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x, y The coordinates of the pixel location * @param b The band to return * @param data The DataBuffer containing the image data * @return the sample in the specified band for the specified pixel. * @see #setSample(int, int, int, int, DataBuffer) */ public int getSample(int x, int y, int b, DataBuffer data) { // Bounds check for 'b' will be performed automatically if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } int sample = data.getElem(bankIndices[b], y*scanlineStride + x + bandOffsets[b]); return sample; } /** * Returns the sample in a specified band * for the pixel located at (x,y) as a float. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x, y Thecoordinates of the pixel location * @param b The band to return * @param data The DataBuffer containing the image data * @return a float value that represents the sample in the specified * band for the specified pixel. */ public float getSampleFloat(int x, int y, int b, DataBuffer data) { // Bounds check for 'b' will be performed automatically if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } float sample = data.getElemFloat(bankIndices[b], y*scanlineStride + x + bandOffsets[b]); return sample; } /** * Returns the sample in a specified band * for a pixel located at (x,y) as a double. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x, y The coordinates of the pixel location * @param b The band to return * @param data The DataBuffer containing the image data * @return a double value that represents the sample in the specified * band for the specified pixel. */ public double getSampleDouble(int x, int y, int b, DataBuffer data) { // Bounds check for 'b' will be performed automatically if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } double sample = data.getElemDouble(bankIndices[b], y*scanlineStride + x + bandOffsets[b]); return sample; } /** * Returns the samples in a specified band for the specified rectangle * of pixels in an int array, one sample per data array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x, y The coordinates of the upper left pixel location * @param w The width of the pixel rectangle * @param h The height of the pixel rectangle * @param b The band to return * @param iArray If non-null, returns the samples in this array * @param data The DataBuffer containing the image data * @return the samples in the specified band for the pixels within * the specified region. * @see #setSamples(int, int, int, int, int, int[], DataBuffer) */ public int[] getSamples(int x, int y, int w, int h, int b, int iArray[], DataBuffer data) { // Bounds check for 'b' will be performed automatically if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) { throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!"); } int samples[]; if (iArray != null) { samples = iArray; } else { samples = new int [w*h]; } int lineOffset = y*scanlineStride + x + bandOffsets[b]; int srcOffset = 0; int bank = bankIndices[b]; for (int i = 0; i < h; i++) { int sampleOffset = lineOffset; for (int j = 0; j < w; j++) { samples[srcOffset++] = data.getElem(bank, sampleOffset++); } lineOffset += scanlineStride; } return samples; } /** * Sets the data for a single pixel in the specified DataBuffer from a * primitive array of type TransferType. For a BandedSampleModel, * this will be the same as the data type, and samples are transferred * one per array element. * <p> * The following code illustrates transferring data for one pixel from * DataBuffer <code>db1</code>, whose storage layout is described by * BandedSampleModel <code>bsm1</code>, to DataBuffer <code>db2</code>, * whose storage layout is described by
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -