summaryrefslogtreecommitdiff
path: root/java/awt/image/SampleModel.java
diff options
context:
space:
mode:
authorGuilhem Lavaux <guilhem@kaffe.org>2006-08-14 09:40:47 +0000
committerGuilhem Lavaux <guilhem@kaffe.org>2006-08-14 09:40:47 +0000
commit310be467f8f83b189b4a40faece32478fad67bc9 (patch)
tree777d0c539432a12c86f450e8d3bf90e8e5677f57 /java/awt/image/SampleModel.java
parent8f2887fc8c74aae0d541cbd59ea36c37d420267d (diff)
downloadclasspath-310be467f8f83b189b4a40faece32478fad67bc9.tar.gz
2006-08-14 Guilhem Lavaux <guilhem@kaffe.org>
* Merged HEAD as of 2006-08-14 0:00.
Diffstat (limited to 'java/awt/image/SampleModel.java')
-rw-r--r--java/awt/image/SampleModel.java461
1 files changed, 455 insertions, 6 deletions
diff --git a/java/awt/image/SampleModel.java b/java/awt/image/SampleModel.java
index 6e3fd4069..cb352bb4d 100644
--- a/java/awt/image/SampleModel.java
+++ b/java/awt/image/SampleModel.java
@@ -37,6 +37,9 @@ exception statement from your version. */
package java.awt.image;
/**
+ * A <code>SampleModel</code> is used to access pixel data from a
+ * {@link DataBuffer}. This is used by the {@link Raster} class.
+ *
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
*/
public abstract class SampleModel
@@ -100,16 +103,37 @@ public abstract class SampleModel
this.numBands = numBands;
}
+ /**
+ * Returns the width of the pixel data accessible via this
+ * <code>SampleModel</code>.
+ *
+ * @return The width.
+ *
+ * @see #getHeight()
+ */
public final int getWidth()
{
return width;
}
+ /**
+ * Returns the height of the pixel data accessible via this
+ * <code>SampleModel</code>.
+ *
+ * @return The height.
+ *
+ * @see #getWidth()
+ */
public final int getHeight()
{
return height;
}
+ /**
+ * Returns the number of bands for this <code>SampleModel</code>.
+ *
+ * @return The number of bands.
+ */
public final int getNumBands()
{
return numBands;
@@ -117,6 +141,12 @@ public abstract class SampleModel
public abstract int getNumDataElements();
+ /**
+ * Returns the type of the {@link DataBuffer} that this
+ * <code>SampleModel</code> accesses.
+ *
+ * @return The data buffer type.
+ */
public final int getDataType()
{
return dataType;
@@ -128,6 +158,22 @@ public abstract class SampleModel
return dataType;
}
+ /**
+ * Returns an array containing the samples for the pixel at (x, y) in the
+ * specified data buffer. If <code>iArray</code> is not <code>null</code>,
+ * it will be populated with the sample values and returned as the result of
+ * this function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param iArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The pixel sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
{
if (iArray == null)
@@ -234,6 +280,22 @@ public abstract class SampleModel
}
}
+ /**
+ * Returns an array containing the samples for the pixel at (x, y) in the
+ * specified data buffer. If <code>fArray</code> is not <code>null</code>,
+ * it will be populated with the sample values and returned as the result of
+ * this function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param fArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The pixel sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public float[] getPixel(int x, int y, float[] fArray, DataBuffer data)
{
if (fArray == null)
@@ -246,6 +308,22 @@ public abstract class SampleModel
return fArray;
}
+ /**
+ * Returns an array containing the samples for the pixel at (x, y) in the
+ * specified data buffer. If <code>dArray</code> is not <code>null</code>,
+ * it will be populated with the sample values and returned as the result of
+ * this function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param dArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The pixel sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public double[] getPixel(int x, int y, double[] dArray, DataBuffer data) {
if (dArray == null)
dArray = new double[numBands];
@@ -256,8 +334,27 @@ public abstract class SampleModel
return dArray;
}
- /* FIXME: Should it return a banded or pixel interleaved array of
- samples? (Assume interleaved.) */
+ /**
+ * Returns an array containing the samples for the pixels in the region
+ * specified by (x, y, w, h) in the specified data buffer. The array is
+ * ordered by pixels (that is, all the samples for the first pixel are
+ * grouped together, followed by all the samples for the second pixel, and so
+ * on). If <code>iArray</code> is not <code>null</code>, it will be
+ * populated with the sample values and returned as the result of this
+ * function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param iArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The pixel sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public int[] getPixels(int x, int y, int w, int h, int[] iArray,
DataBuffer data)
{
@@ -278,8 +375,27 @@ public abstract class SampleModel
return iArray;
}
- /* FIXME: Should it return a banded or pixel interleaved array of
- samples? (Assume interleaved.) */
+ /**
+ * Returns an array containing the samples for the pixels in the region
+ * specified by (x, y, w, h) in the specified data buffer. The array is
+ * ordered by pixels (that is, all the samples for the first pixel are
+ * grouped together, followed by all the samples for the second pixel, and so
+ * on). If <code>fArray</code> is not <code>null</code>, it will be
+ * populated with the sample values and returned as the result of this
+ * function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param fArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The pixel sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public float[] getPixels(int x, int y, int w, int h, float[] fArray,
DataBuffer data)
{
@@ -299,8 +415,27 @@ public abstract class SampleModel
return fArray;
}
- /* FIXME: Should it return a banded or pixel interleaved array of
- samples? (Assume interleaved.) */
+ /**
+ * Returns an array containing the samples for the pixels in the region
+ * specified by (x, y, w, h) in the specified data buffer. The array is
+ * ordered by pixels (that is, all the samples for the first pixel are
+ * grouped together, followed by all the samples for the second pixel, and so
+ * on). If <code>dArray</code> is not <code>null</code>, it will be
+ * populated with the sample values and returned as the result of this
+ * function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param dArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The pixel sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public double[] getPixels(int x, int y, int w, int h, double[] dArray,
DataBuffer data)
{
@@ -321,18 +456,85 @@ public abstract class SampleModel
return dArray;
}
+ /**
+ * Returns the sample value for the pixel at (x, y) in the specified data
+ * buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample value.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public abstract int getSample(int x, int y, int b, DataBuffer data);
+ /**
+ * Returns the sample value for the pixel at (x, y) in the specified data
+ * buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample value.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ *
+ * @see #getSample(int, int, int, DataBuffer)
+ */
public float getSampleFloat(int x, int y, int b, DataBuffer data)
{
return getSample(x, y, b, data);
}
+ /**
+ * Returns the sample value for the pixel at (x, y) in the specified data
+ * buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample value.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ *
+ * @see #getSample(int, int, int, DataBuffer)
+ */
public double getSampleDouble(int x, int y, int b, DataBuffer data)
{
return getSampleFloat(x, y, b, data);
}
+ /**
+ * Returns an array containing the samples from one band for the pixels in
+ * the region specified by (x, y, w, h) in the specified data buffer. If
+ * <code>iArray</code> is not <code>null</code>, it will be
+ * populated with the sample values and returned as the result of this
+ * function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param b the band (in the range <code>0</code> to
+ * </code>getNumBands() - 1</code>).
+ * @param iArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public int[] getSamples(int x, int y, int w, int h, int b,
int[] iArray, DataBuffer data)
{
@@ -350,6 +552,27 @@ public abstract class SampleModel
return iArray;
}
+ /**
+ * Returns an array containing the samples from one band for the pixels in
+ * the region specified by (x, y, w, h) in the specified data buffer. If
+ * <code>fArray</code> is not <code>null</code>, it will be
+ * populated with the sample values and returned as the result of this
+ * function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param b the band (in the range <code>0</code> to
+ * </code>getNumBands() - 1</code>).
+ * @param fArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public float[] getSamples(int x, int y, int w, int h, int b,
float[] fArray, DataBuffer data)
{
@@ -367,6 +590,27 @@ public abstract class SampleModel
return fArray;
}
+ /**
+ * Returns an array containing the samples from one band for the pixels in
+ * the region specified by (x, y, w, h) in the specified data buffer. If
+ * <code>dArray</code> is not <code>null</code>, it will be
+ * populated with the sample values and returned as the result of this
+ * function (this avoids allocating a new array instance).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param b the band (in the range <code>0</code> to
+ * </code>getNumBands() - 1</code>).
+ * @param dArray an array to populate with the sample values and return as
+ * the result (if <code>null</code>, a new array will be allocated).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @return The sample values.
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public double[] getSamples(int x, int y, int w, int h, int b,
double[] dArray, DataBuffer data)
{
@@ -384,24 +628,77 @@ public abstract class SampleModel
return dArray;
}
+ /**
+ * Sets the samples for the pixel at (x, y) in the specified data buffer to
+ * the specified values.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param iArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setPixel(int x, int y, int[] iArray, DataBuffer data)
{
for (int b = 0; b < numBands; b++)
setSample(x, y, b, iArray[b], data);
}
+ /**
+ * Sets the samples for the pixel at (x, y) in the specified data buffer to
+ * the specified values.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param fArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>fArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setPixel(int x, int y, float[] fArray, DataBuffer data)
{
for (int b = 0; b < numBands; b++)
setSample(x, y, b, fArray[b], data);
}
+ /**
+ * Sets the samples for the pixel at (x, y) in the specified data buffer to
+ * the specified values.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param dArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>dArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setPixel(int x, int y, double[] dArray, DataBuffer data)
{
for (int b = 0; b < numBands; b++)
setSample(x, y, b, dArray[b], data);
}
+ /**
+ * Sets the sample values for the pixels in the region specified by
+ * (x, y, w, h) in the specified data buffer. The array is
+ * ordered by pixels (that is, all the samples for the first pixel are
+ * grouped together, followed by all the samples for the second pixel, and so
+ * on).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param iArray the pixel sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setPixels(int x, int y, int w, int h, int[] iArray,
DataBuffer data)
{
@@ -418,6 +715,23 @@ public abstract class SampleModel
}
}
+ /**
+ * Sets the sample values for the pixels in the region specified by
+ * (x, y, w, h) in the specified data buffer. The array is
+ * ordered by pixels (that is, all the samples for the first pixel are
+ * grouped together, followed by all the samples for the second pixel, and so
+ * on).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param fArray the pixel sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>fArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setPixels(int x, int y, int w, int h, float[] fArray,
DataBuffer data)
{
@@ -434,6 +748,23 @@ public abstract class SampleModel
}
}
+ /**
+ * Sets the sample values for the pixels in the region specified by
+ * (x, y, w, h) in the specified data buffer. The array is
+ * ordered by pixels (that is, all the samples for the first pixel are
+ * grouped together, followed by all the samples for the second pixel, and so
+ * on).
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param dArray the pixel sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>dArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setPixels(int x, int y, int w, int h, double[] dArray,
DataBuffer data)
{
@@ -450,21 +781,76 @@ public abstract class SampleModel
}
}
+ /**
+ * Sets the sample value for a band for the pixel at (x, y) in the
+ * specified data buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param s the sample value.
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public abstract void setSample(int x, int y, int b, int s,
DataBuffer data);
+ /**
+ * Sets the sample value for a band for the pixel at (x, y) in the
+ * specified data buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param s the sample value.
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public void setSample(int x, int y, int b, float s,
DataBuffer data)
{
setSample(x, y, b, (int) s, data);
}
+ /**
+ * Sets the sample value for a band for the pixel at (x, y) in the
+ * specified data buffer.
+ *
+ * @param x the x-coordinate of the pixel.
+ * @param y the y-coordinate of the pixel.
+ * @param b the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ * @param s the sample value.
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if <code>data</code> is <code>null</code>.
+ */
public void setSample(int x, int y, int b, double s,
DataBuffer data)
{
setSample(x, y, b, (float) s, data);
}
+ /**
+ * Sets the sample values for one band for the pixels in the region
+ * specified by (x, y, w, h) in the specified data buffer.
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param b the band (in the range <code>0</code> to
+ * </code>getNumBands() - 1</code>).
+ * @param iArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setSamples(int x, int y, int w, int h, int b,
int[] iArray, DataBuffer data)
{
@@ -475,6 +861,22 @@ public abstract class SampleModel
setSample(xx, yy, b, iArray[inOffset++], data);
}
+ /**
+ * Sets the sample values for one band for the pixels in the region
+ * specified by (x, y, w, h) in the specified data buffer.
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param b the band (in the range <code>0</code> to
+ * </code>getNumBands() - 1</code>).
+ * @param fArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setSamples(int x, int y, int w, int h, int b,
float[] fArray, DataBuffer data)
{
@@ -486,6 +888,22 @@ public abstract class SampleModel
}
+ /**
+ * Sets the sample values for one band for the pixels in the region
+ * specified by (x, y, w, h) in the specified data buffer.
+ *
+ * @param x the x-coordinate of the top-left pixel.
+ * @param y the y-coordinate of the top-left pixel.
+ * @param w the width of the region of pixels.
+ * @param h the height of the region of pixels.
+ * @param b the band (in the range <code>0</code> to
+ * </code>getNumBands() - 1</code>).
+ * @param dArray the sample values (<code>null</code> not permitted).
+ * @param data the data buffer (<code>null</code> not permitted).
+ *
+ * @throws NullPointerException if either <code>iArray</code> or
+ * <code>data</code> is <code>null</code>.
+ */
public void setSamples(int x, int y, int w, int h, int b,
double[] dArray, DataBuffer data) {
int size = w * h;
@@ -495,6 +913,15 @@ public abstract class SampleModel
setSample(xx, yy, b, dArray[inOffset++], data);
}
+ /**
+ * Creates a new <code>SampleModel</code> that is compatible with this
+ * model and has the specified width and height.
+ *
+ * @param w the width (in pixels).
+ * @param h the height (in pixels).
+ *
+ * @return The new sample model.
+ */
public abstract SampleModel createCompatibleSampleModel(int w, int h);
/**
@@ -510,9 +937,31 @@ public abstract class SampleModel
*/
public abstract SampleModel createSubsetSampleModel(int[] bands);
+ /**
+ * Creates a new {@link DataBuffer} of the correct type and size for this
+ * <code>SampleModel</code>.
+ *
+ * @return The data buffer.
+ */
public abstract DataBuffer createDataBuffer();
+ /**
+ * Returns an array containing the size (in bits) for each band accessed by
+ * the <code>SampleModel</code>.
+ *
+ * @return An array.
+ *
+ * @see #getSampleSize(int)
+ */
public abstract int[] getSampleSize();
+ /**
+ * Returns the size (in bits) of the samples for the specified band.
+ *
+ * @param band the band (in the range <code>0</code> to
+ * <code>getNumBands() - 1</code>).
+ *
+ * @return The sample size (in bits).
+ */
public abstract int getSampleSize(int band);
}