This patch (committed) adds a few more API doc comments, and fixes some source code
formatting issues:
2006-07-13 David Gilbert <[EMAIL PROTECTED]>
* java/awt/image/BandedSampleModel.java: API doc updates and source
code reformatting,
* java/awt/image/SinglePixelPackageSampleModel.java: Likewise.
Regards,
Dave
Index: java/awt/image/BandedSampleModel.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/image/BandedSampleModel.java,v
retrieving revision 1.6
diff -u -r1.6 BandedSampleModel.java
--- java/awt/image/BandedSampleModel.java 13 Jul 2006 13:24:05 -0000
1.6
+++ java/awt/image/BandedSampleModel.java 13 Jul 2006 13:52:09 -0000
@@ -37,9 +37,8 @@
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.
+ * A sample model that reads each sample value from a separate band in the
+ * [EMAIL PROTECTED] DataBuffer}.
*
* @author Jerry Quinn ([EMAIL PROTECTED])
*/
@@ -108,12 +107,12 @@
// 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++)
+ 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++)
+ 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]]))
@@ -122,7 +121,7 @@
}
int bank = 0;
int offset = 0;
- for (int i=0; i < bandOffsets.length; i++)
+ for (int i = 0; i < bandOffsets.length; i++)
{
if (bankIndices[order[i]] != bank)
{
@@ -133,7 +132,8 @@
offset += w * scanlineStride;
}
- return new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices,
newoffsets);
+ return new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices,
+ newoffsets);
}
@@ -145,7 +145,7 @@
+" many bands");
int[] newoff = new int[bands.length];
int[] newbanks = new int[bands.length];
- for (int i=0; i < bands.length; i++)
+ for (int i = 0; i < bands.length; i++)
{
int b = bands[i];
newoff[i] = bandOffsets[b];
@@ -162,57 +162,61 @@
* 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 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)
+ * @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)
+ 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;
+ byte[] b = (byte[]) obj;
if (b == null) b = new byte[numBands];
- for (int i=0; i < numBands; i++)
+ 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;
+ short[] b = (short[]) obj;
if (b == null) b = new short[numBands];
- for (int i=0; i < numBands; i++)
+ 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;
+ int[] b = (int[]) obj;
if (b == null) b = new int[numBands];
- for (int i=0; i < numBands; i++)
+ for (int i = 0; i < numBands; i++)
b[i] = getSample(x, y, i, data);
return b;
}
case DataBuffer.TYPE_FLOAT:
{
- float[] b = (float[])obj;
+ float[] b = (float[]) obj;
if (b == null) b = new float[numBands];
- for (int i=0; i < numBands; i++)
+ 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++)
+ 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;
}
@@ -241,8 +245,9 @@
*/
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++)
+ if (iArray == null)
+ iArray = new int[numBands];
+ for (int i = 0; i < numBands; i++)
iArray[i] = getSample(x, y, i, data);
return iArray;
@@ -272,7 +277,8 @@
public int[] getPixels(int x, int y, int w, int h, int[] iArray,
DataBuffer data)
{
- if (iArray == null) iArray = new int[w*h*numBands];
+ if (iArray == null)
+ iArray = new int[w * h * numBands];
int outOffset = 0;
int maxX = x + w;
int maxY = y + h;
@@ -378,7 +384,8 @@
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];
+ if (iArray == null)
+ iArray = new int[w * h];
int outOffset = 0;
int maxX = x + w;
int maxY = y + h;
@@ -427,7 +434,7 @@
{
DataBufferByte out = (DataBufferByte) data;
byte[] in = (byte[]) obj;
- for (int i=0; i < numBands; i++)
+ for (int i = 0; i < numBands; i++)
out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
return;
}
@@ -435,7 +442,7 @@
{
DataBufferShort out = (DataBufferShort) data;
short[] in = (short[]) obj;
- for (int i=0; i < numBands; i++)
+ for (int i = 0; i < numBands; i++)
out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
return;
}
@@ -443,7 +450,7 @@
{
DataBufferUShort out = (DataBufferUShort) data;
short[] in = (short[]) obj;
- for (int i=0; i < numBands; i++)
+ for (int i = 0; i < numBands; i++)
out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
return;
}
@@ -451,7 +458,7 @@
{
DataBufferInt out = (DataBufferInt) data;
int[] in = (int[]) obj;
- for (int i=0; i < numBands; i++)
+ for (int i = 0; i < numBands; i++)
out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
return;
}
@@ -459,7 +466,7 @@
{
DataBufferFloat out = (DataBufferFloat) data;
float[] in = (float[]) obj;
- for (int i=0; i < numBands; i++)
+ for (int i = 0; i < numBands; i++)
out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
return;
}
@@ -467,7 +474,7 @@
{
DataBufferDouble out = (DataBufferDouble) data;
double[] in = (double[]) obj;
- for (int i=0; i < numBands; i++)
+ for (int i = 0; i < numBands; i++)
out.getData(bankIndices[i])[offset + bandOffsets[i]] = in[i];
return;
}
@@ -477,15 +484,14 @@
}
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;
+ 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);
}
}
@@ -504,7 +510,7 @@
*/
public void setPixel(int x, int y, int[] iArray, DataBuffer data)
{
- for (int b=0; b < numBands; b++)
+ for (int b = 0; b < numBands; b++)
data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
iArray[b]);
}
@@ -535,7 +541,7 @@
for (int ww = 0; ww < w; ww++)
{
int offset = y * scanlineStride + (x + ww);
- for (int b=0; b < numBands; b++)
+ for (int b = 0; b < numBands; b++)
data.setElem(bankIndices[b], bandOffsets[b] + offset,
iArray[inOffset++]);
}
@@ -711,7 +717,7 @@
result.append(getClass().getName());
result.append("[");
result.append("scanlineStride=").append(scanlineStride);
- for(int i=0; i < bitMasks.length; i+=1)
+ for(int i = 0; i < bitMasks.length; i+=1)
{
result.append(", mask[").append(i).append("]=0x").append(
Integer.toHexString(bitMasks[i]));
Index: java/awt/image/SinglePixelPackedSampleModel.java
===================================================================
RCS file:
/sources/classpath/classpath/java/awt/image/SinglePixelPackedSampleModel.java,v
retrieving revision 1.10
diff -u -r1.10 SinglePixelPackedSampleModel.java
--- java/awt/image/SinglePixelPackedSampleModel.java 13 Jul 2006 11:18:16
-0000 1.10
+++ java/awt/image/SinglePixelPackedSampleModel.java 13 Jul 2006 13:52:10
-0000
@@ -40,6 +40,10 @@
import gnu.java.awt.Buffers;
/**
+ * A <code>SampleModel</code> used when all samples are stored in a single
+ * data element in the [EMAIL PROTECTED] DataBuffer}, and each data element
contains
+ * samples for one pixel only.
+ *
* @author Rolf W. Rasmussen ([EMAIL PROTECTED])
*/
public class SinglePixelPackedSampleModel extends SampleModel
@@ -49,12 +53,32 @@
private int[] bitOffsets;
private int[] sampleSize;
+ /**
+ * Creates a new <code>SinglePixelPackedSampleModel</code>.
+ *
+ * @param dataType the data buffer type.
+ * @param w the width (in pixels).
+ * @param h the height (in pixels).
+ * @param bitMasks an array containing the bit mask used to extract the
+ * sample value for each band.
+ */
public SinglePixelPackedSampleModel(int dataType, int w, int h,
int[] bitMasks)
{
this(dataType, w, h, w, bitMasks);
}
+ /**
+ * Creates a new <code>SinglePixelPackedSampleModel</code>.
+ *
+ * @param dataType the data buffer type.
+ * @param w the width (in pixels).
+ * @param h the height (in pixels).
+ * @param scanlineStride the number of data elements between a pixel on one
+ * row and the corresponding pixel on the next row.
+ * @param bitMasks an array containing the bit mask used to extract the
+ * sample value for each band.
+ */
public SinglePixelPackedSampleModel(int dataType, int w, int h,
int scanlineStride, int[] bitMasks)
{
@@ -67,7 +91,8 @@
case DataBuffer.TYPE_INT:
break;
default:
- throw new IllegalArgumentException("SinglePixelPackedSampleModel
unsupported dataType");
+ throw new IllegalArgumentException(
+ "SinglePixelPackedSampleModel unsupported dataType");
}
this.scanlineStride = scanlineStride;
@@ -77,7 +102,7 @@
sampleSize = new int[numBands];
BitMaskExtent extent = new BitMaskExtent();
- for (int b=0; b<numBands; b++)
+ for (int b = 0; b < numBands; b++)
{
extent.setMask(bitMasks[b]);
sampleSize[b] = extent.bitWidth;
@@ -85,11 +110,25 @@
}
}
+ /**
+ * Returns the number of data elements.
+ *
+ * @return <code>1</code>.
+ */
public int getNumDataElements()
{
return 1;
}
+ /**
+ * 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 SampleModel createCompatibleSampleModel(int w, int h)
{
/* FIXME: We can avoid recalculation of bit offsets and sample
@@ -172,7 +211,7 @@
int[] bitMasks = new int[numBands];
- for (int b=0; b<numBands; b++)
+ for (int b = 0; b < numBands; b++)
bitMasks[b] = this.bitMasks[bands[b]];
return new SinglePixelPackedSampleModel(dataType, width, height,
@@ -191,16 +230,20 @@
}
/**
- * This is a more efficient implementation of the default implementation in
the super
- * class.
- * @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>.
+ * This is a more efficient implementation of the default implementation in
+ * the super class.
+ * @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 w The width of the pixel rectangle to store in <code>obj</code>.
* @param h The height 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 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, int, int,
java.lang.Object, java.awt.image.DataBuffer)
+ * @see java.awt.image.SampleModel#getDataElements(int, int, int, int,
+ * java.lang.Object, java.awt.image.DataBuffer)
*/
public Object getDataElements(int x, int y, int w, int h, Object obj,
DataBuffer data)
@@ -226,10 +269,11 @@
// Seems like the only sensible thing to do.
throw new ClassCastException();
}
- if(x==0 && scanlineStride == w)
+ if(x == 0 && scanlineStride == w)
{
// The full width need to be copied therefore we can copy in one shot.
- System.arraycopy(pixelData, scanlineStride*y + data.getOffset(), obj,
0, size);
+ System.arraycopy(pixelData, scanlineStride*y + data.getOffset(), obj,
+ 0, size);
}
else
{
@@ -268,7 +312,7 @@
if (iArray == null) iArray = new int[numBands];
int samples = data.getElem(offset);
- for (int b=0; b<numBands; b++)
+ for (int b = 0; b < numBands; b++)
iArray[b] = (samples & bitMasks[b]) >>> bitOffsets[b];
return iArray;
@@ -301,13 +345,13 @@
int offset = scanlineStride*y + x;
if (iArray == null) iArray = new int[numBands*w*h];
int outOffset = 0;
- for (y=0; y<h; y++)
+ for (y = 0; y < h; y++)
{
int lineOffset = offset;
- for (x=0; x<w; x++)
+ for (x = 0; x < w; x++)
{
int samples = data.getElem(lineOffset++);
- for (int b=0; b<numBands; b++)
+ for (int b = 0; b < numBands; b++)
iArray[outOffset++] = (samples & bitMasks[b]) >>> bitOffsets[b];
}
offset += scanlineStride;
@@ -337,16 +381,18 @@
}
/**
- * This method implements a more efficient way to set data elements than the
default
- * implementation of the super class. It sets the data elements line by line
instead
- * of pixel by pixel.
+ * This method implements a more efficient way to set data elements than the
+ * default implementation of the super class. It sets the data elements line
+ * by line instead of pixel by pixel.
+ *
* @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 w The width of the data elements in <code>obj</code>.
* @param h The height 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)
+ * @see java.awt.image.SampleModel#setDataElements(int, int, int, int,
+ * java.lang.Object, java.awt.image.DataBuffer)
*/
public void setDataElements(int x, int y, int w, int h,
Object obj, DataBuffer data)
@@ -457,7 +503,7 @@
int offset = scanlineStride*y + x;
int samples = 0;
- for (int b=0; b<numBands; b++)
+ for (int b = 0; b < numBands; b++)
samples |= (iArray[b] << bitOffsets[b]) & bitMasks[b];
data.setElem(offset, samples);
@@ -473,7 +519,8 @@
* @param h The height of the pixel rectangle in <code>obj</code>.
* @param iArray The primitive array containing the pixels to set.
* @param data The DataBuffer to store the pixels into.
- * @see java.awt.image.SampleModel#setPixels(int, int, int, int, int[],
java.awt.image.DataBuffer)
+ * @see java.awt.image.SampleModel#setPixels(int, int, int, int, int[],
+ * java.awt.image.DataBuffer)
*/
public void setPixels(int x, int y, int w, int h, int[] iArray,
DataBuffer data)
@@ -486,7 +533,7 @@
for (int xx=x; xx<(x+w); xx++)
{
int samples = 0;
- for (int b=0; b<numBands; b++)
+ for (int b = 0; b < numBands; b++)
samples |= (iArray[inOffset+b] << bitOffsets[b]) & bitMasks[b];
data.setElem(0, offset, samples);
inOffset += numBands;
@@ -529,9 +576,10 @@
result.append(getClass().getName());
result.append("[");
result.append("scanlineStride=").append(scanlineStride);
- for(int i=0; i < bitMasks.length; i+=1)
+ for(int i = 0; i < bitMasks.length; i+=1)
{
- result.append(",
mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i]));
+ result.append(", mask[").append(i).append("]=0x").append(
+ Integer.toHexString(bitMasks[i]));
}
result.append("]");