📄 samplemodel.java
字号:
* @param y The Y coordinate of the pixel location. * @param dArray 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, double[], DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates are * not in bounds, or if dArray is too small to hold the output. */ public double[] getPixel(int x, int y, double dArray[], DataBuffer data) { double pixels[]; if(dArray != null) pixels = dArray; else pixels = new double[numBands]; for (int i=0; i<numBands; i++) pixels[i] = getSampleDouble(x, y, i, data); return pixels; } /** * Returns all samples for a rectangle of pixels in an * int array, one sample per array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate 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 specified region of pixels. * @see #setPixels(int, int, int, int, int[], DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates are * not in bounds, or if iArray is too small to hold the output. */ public int[] getPixels(int x, int y, int w, int h, int iArray[], DataBuffer data) { int pixels[]; int Offset=0; if (iArray != null) pixels = iArray; else pixels = new int[numBands * w * h]; for (int i=y; i<(h+y); i++) { for (int j=x; j<(w+x); j++) { for(int k=0; k<numBands; k++) { pixels[Offset++] = getSample(j, i, k, data); } } } return pixels; } /** * Returns all samples for a rectangle of pixels in a float * array, one sample per array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate of the upper left pixel location. * @param w The width of the pixel rectangle. * @param h The height of the pixel rectangle. * @param fArray If non-null, returns the samples in this array. * @param data The DataBuffer containing the image data. * @return the samples for the specified region of pixels. * @see #setPixels(int, int, int, int, float[], DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates are * not in bounds, or if fArray is too small to hold the output. */ public float[] getPixels(int x, int y, int w, int h, float fArray[], DataBuffer data) { float pixels[]; int Offset = 0; if (fArray != null) pixels = fArray; else pixels = new float[numBands * w * h]; for (int i=y; i<(h+y); i++) { for(int j=x; j<(w+x); j++) { for(int k=0; k<numBands; k++) { pixels[Offset++] = getSampleFloat(j, i, k, data); } } } return pixels; } /** * Returns all samples for a rectangle of pixels in a double * array, one sample per array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate of the upper left pixel location. * @param w The width of the pixel rectangle. * @param h The height of the pixel rectangle. * @param dArray If non-null, returns the samples in this array. * @param data The DataBuffer containing the image data. * @return the samples for the specified region of pixels. * @see #setPixels(int, int, int, int, double[], DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates are * not in bounds, or if dArray is too small to hold the output. */ public double[] getPixels(int x, int y, int w, int h, double dArray[], DataBuffer data) { double pixels[]; int Offset = 0; if (dArray != null) pixels = dArray; else pixels = new double[numBands * w * h]; // Fix 4217412 for (int i=y; i<(h+y); i++) { for (int j=x; j<(w+x); j++) { for (int k=0; k<numBands; k++) { pixels[Offset++] = getSampleDouble(j, i, k, data); } } } return pixels; } /** * Returns the sample in a specified band for the pixel located * at (x,y) as an int. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param b The band to return. * @param data The DataBuffer containing the image data. * @return the sample in a specified band for the specified pixel. * @see #setSample(int, int, int, int, DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates or * the band index are not in bounds. */ public abstract int getSample(int x, int y, int b, DataBuffer data); /** * 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 The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param b The band to return. * @param data The DataBuffer containing the image data. * @return the sample in a specified band for the specified pixel. * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates or * the band index are not in bounds. */ public float getSampleFloat(int x, int y, int b, DataBuffer data) { float sample; sample = (float) getSample(x, y, b, data); 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 The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param b The band to return. * @param data The DataBuffer containing the image data. * @return the sample in a specified band for the specified pixel. * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates or * the band index are not in bounds. */ public double getSampleDouble(int x, int y, int b, DataBuffer data) { double sample; sample = (double) getSample(x, y, b, data); return sample; } /** * Returns the samples for a specified band for the specified rectangle * of pixels in an int array, one sample per array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate 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 for the specified band for the specified region * of pixels. * @see #setSamples(int, int, int, int, int, int[], DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates or * the band index are not in bounds, or if iArray is too small to * hold the output. */ public int[] getSamples(int x, int y, int w, int h, int b, int iArray[], DataBuffer data) { int pixels[]; int Offset=0; if (iArray != null) pixels = iArray; else pixels = new int[w * h]; for(int i=y; i<(h+y); i++) { for (int j=x; j<(w+x); j++) { pixels[Offset++] = getSample(j, i, b, data); } } return pixels; } /** * Returns the samples for a specified band for the specified rectangle * of pixels in a float array, one sample per array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate 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 fArray If non-null, returns the samples in this array. * @param data The DataBuffer containing the image data. * @return the samples for the specified band for the specified region * of pixels. * @see #setSamples(int, int, int, int, int, float[], DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates or * the band index are not in bounds, or if fArray is too small to * hold the output. */ public float[] getSamples(int x, int y, int w, int h, int b, float fArray[], DataBuffer data) { float pixels[]; int Offset=0; if (fArray != null) pixels = fArray; else pixels = new float[w * h]; for (int i=y; i<(h+y); i++) { for (int j=x; j<(w+x); j++) { pixels[Offset++] = getSampleFloat(j, i, b, data); } } return pixels; } /** * Returns the samples for a specified band for a specified rectangle * of pixels in a double array, one sample per array element. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the upper left pixel location. * @param y The Y coordinate 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 dArray If non-null, returns the samples in this array. * @param data The DataBuffer containing the image data. * @return the samples for the specified band for the specified region * of pixels. * @see #setSamples(int, int, int, int, int, double[], DataBuffer) * * @throws NullPointerException if data is null. * @throws ArrayIndexOutOfBoundsException if the coordinates or * the band index are not in bounds, or if dArray is too small to * hold the output. */ public double[] getSamples(int x, int y, int w, int h, int b, double dArray[], DataBuffer data) { double pixels[]; int Offset=0; if (dArray != null) pixels = dArray; else pixels = new double[w * h]; for (int i=y; i<(y+h); i++) { for (int j=x; j<(x+w); j++) { pixels[Offset++] = getSampleDouble(j, i, b, data); } } return pixels; } /** * Sets a pixel in the DataBuffer using an int array of samples for input. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are * not in bounds. * @param x The X coordinate of the pixel location. * @param y The Y coordinate of the pixel location. * @param iArray The input samples in an int array. * @param data The DataBuffer containing the image data. * @see #getPixel(int, int, int[], DataBuffer)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -