Imported GNU Classpath 0.92
2006-08-14 Mark Wielaard <mark@klomp.org> Imported GNU Classpath 0.92 * HACKING: Add more importing hints. Update automake version requirement. * configure.ac (gconf-peer): New enable AC argument. Add --disable-gconf-peer and --enable-default-preferences-peer to classpath configure when gconf is disabled. * scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and gnu/java/awt/dnd/peer/gtk to bc. Classify gnu/java/security/Configuration.java as generated source file. * gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java, gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java, gnu/java/lang/management/VMClassLoadingMXBeanImpl.java, gnu/java/lang/management/VMRuntimeMXBeanImpl.java, gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java, gnu/java/lang/management/VMThreadMXBeanImpl.java, gnu/java/lang/management/VMMemoryMXBeanImpl.java, gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub classes. * java/lang/management/VMManagementFactory.java: Likewise. * java/net/VMURLConnection.java: Likewise. * gnu/java/nio/VMChannel.java: Likewise. * java/lang/Thread.java (getState): Add stub implementation. * java/lang/Class.java (isEnum): Likewise. * java/lang/Class.h (isEnum): Likewise. * gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed. * javax/naming/spi/NamingManager.java: New override for StackWalker functionality. * configure, sources.am, Makefile.in, gcj/Makefile.in, include/Makefile.in, testsuite/Makefile.in: Regenerated. From-SVN: r116139
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2004, 2005, Free Software Foundation
|
||||
/* Copyright (C) 2004, 2005, 2006, Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -36,10 +36,11 @@ exception statement from your version. */
|
||||
|
||||
package java.awt.image;
|
||||
|
||||
import gnu.java.awt.Buffers;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* {@link DataBuffer}.
|
||||
*
|
||||
* @author Jerry Quinn (jlquinn@optonline.net)
|
||||
*/
|
||||
@@ -61,17 +62,61 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>BandedSampleModel</code>.
|
||||
*
|
||||
* @param dataType the data buffer type.
|
||||
* @param w the width (in pixels).
|
||||
* @param h the height (in pixels).
|
||||
* @param numBands the number of bands.
|
||||
*/
|
||||
public BandedSampleModel(int dataType, int w, int h, int numBands)
|
||||
{
|
||||
this(dataType, w, h, w, createBankArray(numBands), new int[numBands]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>BandedSampleModel</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 from a pixel in one
|
||||
* row to the corresponding pixel in the next row.
|
||||
* @param bankIndices the bank indices.
|
||||
* @param bandOffsets the band offsets.
|
||||
*/
|
||||
public BandedSampleModel(int dataType, int w, int h, int scanlineStride,
|
||||
int[] bankIndices, int[] bandOffsets)
|
||||
{
|
||||
super(dataType, w, h, 1, scanlineStride, bankIndices, bandOffsets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new data buffer that is compatible with this sample model.
|
||||
*
|
||||
* @return The new data buffer.
|
||||
*/
|
||||
public DataBuffer createDataBuffer()
|
||||
{
|
||||
int size = scanlineStride * height;
|
||||
return Buffers.createBuffer(getDataType(), size, numBanks);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, must be greater than zero).
|
||||
* @param h the height (in pixels, must be greater than zero).
|
||||
*
|
||||
* @return The new sample model.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>w</code> or <code>h</code> is
|
||||
* not greater than zero.
|
||||
* @throws IllegalArgumentException if <code>w * h</code> exceeds
|
||||
* <code>Integer.MAX_VALUE</code>.
|
||||
*/
|
||||
public SampleModel createCompatibleSampleModel(int w, int h)
|
||||
{
|
||||
// NOTE: blackdown 1.4.1 sets all offsets to 0. Sun's 1.4.2 docs
|
||||
@@ -80,32 +125,32 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
// 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++)
|
||||
if (bankIndices[order[i]] > bankIndices[order[j]]
|
||||
|| (bankIndices[order[i]] == bankIndices[order[j]]
|
||||
&& bandOffsets[order[i]] > bandOffsets[order[j]]))
|
||||
{
|
||||
int t = order[i]; order[i] = order[j]; order[j] = t;
|
||||
}
|
||||
for (int i = 0; i < bandOffsets.length; i++)
|
||||
for (int j = i + 1; j < bandOffsets.length; j++)
|
||||
if (bankIndices[order[i]] > bankIndices[order[j]]
|
||||
|| (bankIndices[order[i]] == bankIndices[order[j]]
|
||||
&& bandOffsets[order[i]] > bandOffsets[order[j]]))
|
||||
{
|
||||
int t = order[i]; order[i] = order[j]; order[j] = t;
|
||||
}
|
||||
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)
|
||||
{
|
||||
bank = bankIndices[order[i]];
|
||||
offset = 0;
|
||||
}
|
||||
newoffsets[order[i]] = offset;
|
||||
offset += w * scanlineStride;
|
||||
if (bankIndices[order[i]] != bank)
|
||||
{
|
||||
bank = bankIndices[order[i]];
|
||||
offset = 0;
|
||||
}
|
||||
newoffsets[order[i]] = offset;
|
||||
offset += w * scanlineStride;
|
||||
}
|
||||
|
||||
return new BandedSampleModel(dataType, w, h, scanlineStride, bankIndices, newoffsets);
|
||||
return new BandedSampleModel(dataType, w, h, w, bankIndices, newoffsets);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +162,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
+" 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];
|
||||
@@ -134,57 +179,64 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
* 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)
|
||||
{
|
||||
if (x < 0 || y < 0)
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"x and y must not be less than 0.");
|
||||
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;
|
||||
}
|
||||
@@ -195,10 +247,27 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the samples for the pixel at location <code>(x, y)</code>
|
||||
* stored in the specified data buffer.
|
||||
*
|
||||
* @param x the x-coordinate.
|
||||
* @param y the y-coordinate.
|
||||
* @param iArray an array that will be populated with the sample values and
|
||||
* returned as the result. The size of this array should be equal to the
|
||||
* number of bands in the model. If the array is <code>null</code>, a new
|
||||
* array is created.
|
||||
* @param data the data buffer (<code>null</code> not permitted).
|
||||
*
|
||||
* @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 (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;
|
||||
@@ -228,7 +297,11 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
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 (x < 0 || y < 0)
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"x and y must not be less than 0.");
|
||||
if (iArray == null)
|
||||
iArray = new int[w * h * numBands];
|
||||
int outOffset = 0;
|
||||
int maxX = x + w;
|
||||
int maxY = y + h;
|
||||
@@ -247,18 +320,64 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
return iArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a 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 int getSample(int x, int y, int b, DataBuffer data)
|
||||
{
|
||||
int offset = bandOffsets[b] + y * scanlineStride + x;
|
||||
return data.getElem(bankIndices[b], offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a 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)
|
||||
{
|
||||
int offset = bandOffsets[b] + y * scanlineStride + x;
|
||||
return data.getElemFloat(bankIndices[b], offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
int offset = bandOffsets[b] + y * scanlineStride + x;
|
||||
@@ -288,7 +407,11 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
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 (x < 0 || y < 0)
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"x and y must not be less than 0.");
|
||||
if (iArray == null)
|
||||
iArray = new int[w * h];
|
||||
int outOffset = 0;
|
||||
int maxX = x + w;
|
||||
int maxY = y + h;
|
||||
@@ -304,7 +427,6 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
return iArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the pixel at x, y to the value in the first element of the primitive
|
||||
* array obj.
|
||||
@@ -338,7 +460,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -346,7 +468,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -354,7 +476,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -362,7 +484,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -370,7 +492,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -378,7 +500,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -388,26 +510,54 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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++)
|
||||
for (int b = 0; b < numBands; b++)
|
||||
data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
|
||||
iArray[b]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
@@ -417,7 +567,7 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
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++]);
|
||||
}
|
||||
@@ -425,24 +575,83 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample value for band <code>b</code> of the pixel at location
|
||||
* <code>(x, y)</code> in the specified data buffer.
|
||||
*
|
||||
* @param x the x-coordinate.
|
||||
* @param y the y-coordinate.
|
||||
* @param b the band index.
|
||||
* @param s the sample value.
|
||||
* @param data the data buffer (<code>null</code> not permitted).
|
||||
*
|
||||
* @see #getSample(int, int, int, DataBuffer)
|
||||
*/
|
||||
public void setSample(int x, int y, int b, int s, DataBuffer data)
|
||||
{
|
||||
data.setElem(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
|
||||
data.setElemFloat(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
|
||||
s);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x, s);
|
||||
data.setElemDouble(bankIndices[b], bandOffsets[b] + y * scanlineStride + x,
|
||||
s);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
if (x < 0 || y < 0)
|
||||
throw new ArrayIndexOutOfBoundsException(
|
||||
"x and y must not be less than 0.");
|
||||
int inOffset = 0;
|
||||
|
||||
switch (getTransferType())
|
||||
@@ -537,9 +746,10 @@ public final class BandedSampleModel extends ComponentSampleModel
|
||||
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("]");
|
||||
|
||||
@@ -100,11 +100,33 @@ public class BufferedImage extends Image
|
||||
Vector observers;
|
||||
|
||||
/**
|
||||
* Creates a new buffered image.
|
||||
* Creates a new <code>BufferedImage</code> with the specified width, height
|
||||
* and type. Valid <code>type</code> values are:
|
||||
*
|
||||
* @param w the width.
|
||||
* @param h the height.
|
||||
* @param type the image type (see the constants defined by this class).
|
||||
* <ul>
|
||||
* <li>{@link #TYPE_INT_RGB}</li>
|
||||
* <li>{@link #TYPE_INT_ARGB}</li>
|
||||
* <li>{@link #TYPE_INT_ARGB_PRE}</li>
|
||||
* <li>{@link #TYPE_INT_BGR}</li>
|
||||
* <li>{@link #TYPE_3BYTE_BGR}</li>
|
||||
* <li>{@link #TYPE_4BYTE_ABGR}</li>
|
||||
* <li>{@link #TYPE_4BYTE_ABGR_PRE}</li>
|
||||
* <li>{@link #TYPE_USHORT_565_RGB}</li>
|
||||
* <li>{@link #TYPE_USHORT_555_RGB}</li>
|
||||
* <li>{@link #TYPE_BYTE_GRAY}</li>
|
||||
* <li>{@link #TYPE_USHORT_GRAY}</li>
|
||||
* <li>{@link #TYPE_BYTE_BINARY}</li>
|
||||
* <li>{@link #TYPE_BYTE_INDEXED}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param w the width (must be > 0).
|
||||
* @param h the height (must be > 0).
|
||||
* @param type the image type (see the list of valid types above).
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>w</code> or <code>h</code> is
|
||||
* less than or equal to zero.
|
||||
* @throws IllegalArgumentException if <code>type</code> is not one of the
|
||||
* specified values.
|
||||
*/
|
||||
public BufferedImage(int w, int h, int type)
|
||||
{
|
||||
@@ -181,13 +203,15 @@ public class BufferedImage extends Image
|
||||
case TYPE_4BYTE_ABGR_PRE:
|
||||
bits = bits4;
|
||||
break;
|
||||
case TYPE_BYTE_GRAY:
|
||||
bits = bits1byte;
|
||||
break;
|
||||
case TYPE_USHORT_GRAY:
|
||||
bits = bits1ushort;
|
||||
dataType = DataBuffer.TYPE_USHORT;
|
||||
break;
|
||||
case TYPE_BYTE_GRAY:
|
||||
bits = bits1byte;
|
||||
cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
|
||||
break;
|
||||
case TYPE_USHORT_GRAY:
|
||||
bits = bits1ushort;
|
||||
cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
|
||||
dataType = DataBuffer.TYPE_USHORT;
|
||||
break;
|
||||
}
|
||||
cm = new ComponentColorModel(cs, bits, alpha, premultiplied,
|
||||
alpha ?
|
||||
@@ -203,6 +227,8 @@ public class BufferedImage extends Image
|
||||
String msg2 = "type not implemented yet";
|
||||
throw new UnsupportedOperationException(msg2);
|
||||
// FIXME: build color-cube and create color model
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown image type " + type);
|
||||
}
|
||||
|
||||
init(cm,
|
||||
@@ -504,7 +530,10 @@ public class BufferedImage extends Image
|
||||
int[] pixels = getRGB(x, y,
|
||||
width, height,
|
||||
(int[])null, offset, stride);
|
||||
ColorModel model = getColorModel();
|
||||
// We already convert the color to RGB in the getRGB call, so
|
||||
// we pass a simple RGB color model to the consumers.
|
||||
ColorModel model = new DirectColorModel(32, 0xff0000, 0xff00, 0xff,
|
||||
0xff000000);
|
||||
|
||||
consumers.add(ic);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* BufferedImageOp.java --
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 2002, 2006, Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -43,13 +43,65 @@ import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/**
|
||||
* NEEDS DOCUMENTATION
|
||||
* An operation that is performed on one <code>BufferedImage</code> (the
|
||||
* source) producing a new <code>BufferedImage</code> (the destination).
|
||||
*/
|
||||
public interface BufferedImageOp
|
||||
{
|
||||
/**
|
||||
* Performs an operation on the source image, returning the result in a
|
||||
* <code>BufferedImage</code>. If <code>dest</code> is <code>null</code>, a
|
||||
* new <code>BufferedImage</code> will be created by calling the
|
||||
* {@link #createCompatibleDestImage} method. If <code>dest</code>
|
||||
* is not <code>null</code>, the result is written to <code>dest</code> then
|
||||
* returned (this avoids creating a new <code>BufferedImage</code> each
|
||||
* time this method is called).
|
||||
*
|
||||
* @param src the source image.
|
||||
* @param dst the destination image (<code>null</code> permitted).
|
||||
*
|
||||
* @return The filterd image.
|
||||
*/
|
||||
BufferedImage filter(BufferedImage src, BufferedImage dst);
|
||||
|
||||
/**
|
||||
* Returns the bounds of the destination image on the basis of this
|
||||
* <code>BufferedImageOp</code> being applied to the specified source image.
|
||||
*
|
||||
* @param src the source image.
|
||||
*
|
||||
* @return The destination bounds.
|
||||
*/
|
||||
Rectangle2D getBounds2D(BufferedImage src);
|
||||
|
||||
/**
|
||||
* Returns a new <code>BufferedImage</code> that can be used by this
|
||||
* <code>BufferedImageOp</code> as the destination image when filtering
|
||||
* the specified source image.
|
||||
*
|
||||
* @param src the source image.
|
||||
* @param dstCM the color model for the destination image.
|
||||
*
|
||||
* @return A new image that can be used as the destination image.
|
||||
*/
|
||||
BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM);
|
||||
|
||||
/**
|
||||
* Returns the point on the destination image that corresponds to the given
|
||||
* point on the source image.
|
||||
*
|
||||
* @param src the source point.
|
||||
* @param dst the destination point (<code>null</code> permitted).
|
||||
*
|
||||
* @return The destination point.
|
||||
*/
|
||||
Point2D getPoint2D(Point2D src, Point2D dst);
|
||||
|
||||
/**
|
||||
* Returns the rendering hints for this operation.
|
||||
*
|
||||
* @return The rendering hints.
|
||||
*/
|
||||
RenderingHints getRenderingHints();
|
||||
} // interface BufferedImageOp
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ByteLookupTable.java -- Java class for a pixel translation table.
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -60,14 +60,20 @@ public class ByteLookupTable extends LookupTable
|
||||
* components.
|
||||
*
|
||||
* @param offset Offset to be subtracted.
|
||||
* @param data Array of lookup tables.
|
||||
* @param data Array of lookup tables (<code>null</code> not permitted).
|
||||
* @exception IllegalArgumentException if offset < 0 or data.length < 1.
|
||||
*/
|
||||
public ByteLookupTable(int offset, byte[][] data)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
super(offset, data.length);
|
||||
this.data = data;
|
||||
|
||||
// tests show that Sun's implementation creates a new array to store the
|
||||
// references from the incoming 'data' array - not sure why, but we'll
|
||||
// match that behaviour just in case it matters...
|
||||
this.data = new byte[data.length][];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
this.data[i] = data[i];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,13 +83,16 @@ public class ByteLookupTable extends LookupTable
|
||||
* table. The same table is applied to all pixel components.
|
||||
*
|
||||
* @param offset Offset to be subtracted.
|
||||
* @param data Lookup table for all components.
|
||||
* @param data Lookup table for all components (<code>null</code> not
|
||||
* permitted).
|
||||
* @exception IllegalArgumentException if offset < 0.
|
||||
*/
|
||||
public ByteLookupTable(int offset, byte[] data)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
super(offset, 1);
|
||||
if (data == null)
|
||||
throw new NullPointerException("Null 'data' argument.");
|
||||
this.data = new byte[][] {data};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ColorModel.java --
|
||||
Copyright (C) 2004 Free Software Foundation
|
||||
/* ColorConvertOp.java --
|
||||
Copyright (C) 2004, 2006 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -177,8 +177,7 @@ public class ColorConvertOp implements BufferedImageOp, RasterOp
|
||||
ColorModel scm = src.getColorModel();
|
||||
for (int i = 0; i < spaces.length; i++)
|
||||
{
|
||||
ColorModel cm = scm.cloneColorModel(spaces[i]);
|
||||
BufferedImage tmp = createCompatibleDestImage(src, cm);
|
||||
BufferedImage tmp = createCompatibleDestImage(src, scm);
|
||||
copyimage(src, tmp);
|
||||
src = tmp;
|
||||
}
|
||||
@@ -189,6 +188,7 @@ public class ColorConvertOp implements BufferedImageOp, RasterOp
|
||||
|
||||
// Apply final conversion
|
||||
copyimage(src, dst);
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
@@ -287,7 +287,12 @@ public class ColorConvertOp implements BufferedImageOp, RasterOp
|
||||
private void copyimage(BufferedImage src, BufferedImage dst)
|
||||
{
|
||||
Graphics2D gg = dst.createGraphics();
|
||||
gg.setRenderingHints(hints);
|
||||
|
||||
// If no hints are set there is no need to call
|
||||
// setRenderingHints on the Graphics2D object.
|
||||
if (hints != null)
|
||||
gg.setRenderingHints(hints);
|
||||
|
||||
gg.drawImage(src, 0, 0, null);
|
||||
gg.dispose();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ColorModel.java --
|
||||
Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation
|
||||
Copyright (C) 1999, 2000, 2002, 2003, 2004, 2006 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -43,7 +43,6 @@ import gnu.java.awt.Buffers;
|
||||
import java.awt.Point;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@@ -163,32 +162,6 @@ public abstract class ColorModel implements Transparency
|
||||
this.transparency = transparency;
|
||||
this.transferType = transferType;
|
||||
}
|
||||
|
||||
// This is a hook for ColorConvertOp to create a colormodel with
|
||||
// a new colorspace
|
||||
ColorModel cloneColorModel(ColorSpace cspace)
|
||||
{
|
||||
Class cls = this.getClass();
|
||||
ColorModel cm;
|
||||
try {
|
||||
// This constructor will exist.
|
||||
Constructor ctor =
|
||||
cls.getConstructor(new Class[]{int.class, int[].class,
|
||||
ColorSpace.class, boolean.class,
|
||||
boolean.class, int.class, int.class});
|
||||
cm = (ColorModel)ctor.
|
||||
newInstance(new Object[]{new Integer(pixel_bits),
|
||||
bits, cspace, Boolean.valueOf(hasAlpha),
|
||||
Boolean.valueOf(isAlphaPremultiplied),
|
||||
new Integer(transparency),
|
||||
new Integer(transferType)});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return cm;
|
||||
}
|
||||
|
||||
public void finalize()
|
||||
{
|
||||
|
||||
@@ -272,9 +272,7 @@ public class ComponentSampleModel extends SampleModel
|
||||
// Maybe this value should be precalculated in the constructor?
|
||||
int highestOffset = 0;
|
||||
for (int b = 0; b < numBands; b++)
|
||||
{
|
||||
highestOffset = Math.max(highestOffset, bandOffsets[b]);
|
||||
}
|
||||
highestOffset = Math.max(highestOffset, bandOffsets[b]);
|
||||
int size = pixelStride * (width - 1) + scanlineStride * (height - 1)
|
||||
+ highestOffset + 1;
|
||||
|
||||
@@ -678,6 +676,9 @@ public class ComponentSampleModel extends SampleModel
|
||||
*/
|
||||
public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
|
||||
{
|
||||
if (x < 0 || x >= width || y < 0 || y >= height)
|
||||
throw new ArrayIndexOutOfBoundsException("Pixel (" + x + ", " + y
|
||||
+ ") is out of bounds.");
|
||||
int offset = pixelStride * x + scanlineStride * y;
|
||||
if (iArray == null)
|
||||
iArray = new int[numBands];
|
||||
@@ -736,10 +737,16 @@ public class ComponentSampleModel extends SampleModel
|
||||
*
|
||||
* @return The sample value.
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException if <code>(x, y)</code> is outside
|
||||
* the bounds <code>[0, 0, width, height]</code>.
|
||||
*
|
||||
* @see #setSample(int, int, int, int, DataBuffer)
|
||||
*/
|
||||
public int getSample(int x, int y, int b, DataBuffer data)
|
||||
{
|
||||
if (x < 0 || x >= width || y < 0 || y >= height)
|
||||
throw new ArrayIndexOutOfBoundsException("Sample (" + x + ", " + y
|
||||
+ ") is out of bounds.");
|
||||
return data.getElem(bankIndices[b], getOffset(x, y, b));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ConvolveOp.java --
|
||||
Copyright (C) 2004, 2005 Free Software Foundation -- ConvolveOp
|
||||
Copyright (C) 2004, 2005, 2006, Free Software Foundation -- ConvolveOp
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -42,7 +42,6 @@ import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Convolution filter.
|
||||
@@ -190,112 +189,101 @@ public class ConvolveOp implements BufferedImageOp, RasterOp
|
||||
* @see java.awt.image.RasterOp#filter(java.awt.image.Raster,
|
||||
* java.awt.image.WritableRaster)
|
||||
*/
|
||||
public final WritableRaster filter(Raster src, WritableRaster dest) {
|
||||
public final WritableRaster filter(Raster src, WritableRaster dest)
|
||||
{
|
||||
if (src == dest)
|
||||
throw new IllegalArgumentException();
|
||||
if (src.getWidth() < kernel.getWidth() ||
|
||||
src.getHeight() < kernel.getHeight())
|
||||
throw new ImagingOpException(null);
|
||||
|
||||
throw new IllegalArgumentException("src == dest is not allowed.");
|
||||
if (kernel.getWidth() > src.getWidth()
|
||||
|| kernel.getHeight() > src.getHeight())
|
||||
throw new ImagingOpException("The kernel is too large.");
|
||||
if (dest == null)
|
||||
dest = createCompatibleDestRaster(src);
|
||||
else if (src.numBands != dest.numBands)
|
||||
throw new ImagingOpException(null);
|
||||
else if (src.getNumBands() != dest.getNumBands())
|
||||
throw new ImagingOpException("src and dest have different band counts.");
|
||||
|
||||
// Deal with bottom edge
|
||||
if (edge == EDGE_ZERO_FILL)
|
||||
{
|
||||
float[] zeros = new float[src.getNumBands() * src.getWidth()
|
||||
* (kernel.getYOrigin() - 1)];
|
||||
Arrays.fill(zeros, 0);
|
||||
dest.setPixels(src.getMinX(), src.getMinY(), src.getWidth(),
|
||||
kernel.getYOrigin() - 1, zeros);
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] vals = new float[src.getNumBands() * src.getWidth()
|
||||
* (kernel.getYOrigin() - 1)];
|
||||
src.getPixels(src.getMinX(), src.getMinY(), src.getWidth(),
|
||||
kernel.getYOrigin() - 1, vals);
|
||||
dest.setPixels(src.getMinX(), src.getMinY(), src.getWidth(),
|
||||
kernel.getYOrigin() - 1, vals);
|
||||
}
|
||||
// calculate the borders that the op can't reach...
|
||||
int kWidth = kernel.getWidth();
|
||||
int kHeight = kernel.getHeight();
|
||||
int left = kernel.getXOrigin();
|
||||
int right = Math.max(kWidth - left - 1, 0);
|
||||
int top = kernel.getYOrigin();
|
||||
int bottom = Math.max(kHeight - top - 1, 0);
|
||||
|
||||
// Handle main section
|
||||
// process the region that is reachable...
|
||||
int regionW = src.width - left - right;
|
||||
int regionH = src.height - top - bottom;
|
||||
float[] kvals = kernel.getKernelData(null);
|
||||
float[] tmp = new float[kWidth * kHeight];
|
||||
|
||||
float[] tmp = new float[kernel.getWidth() * kernel.getHeight()];
|
||||
for (int y = src.getMinY() + kernel.getYOrigin();
|
||||
y < src.getMinY() + src.getHeight() - kernel.getYOrigin() / 2; y++)
|
||||
{
|
||||
// Handle unfiltered edge pixels at start of line
|
||||
float[] t1 = new float[(kernel.getXOrigin() - 1) * src.getNumBands()];
|
||||
if (edge == EDGE_ZERO_FILL)
|
||||
Arrays.fill(t1, 0);
|
||||
else
|
||||
src.getPixels(src.getMinX(), y, kernel.getXOrigin() - 1, 1, t1);
|
||||
dest.setPixels(src.getMinX(), y, kernel.getXOrigin() - 1, 1, t1);
|
||||
|
||||
for (int x = src.getMinX(); x < src.getWidth() + src.getMinX(); x++)
|
||||
for (int x = 0; x < regionW; x++)
|
||||
{
|
||||
// FIXME: This needs a much more efficient implementation
|
||||
for (int b = 0; b < src.getNumBands(); b++)
|
||||
{
|
||||
float v = 0;
|
||||
src.getSamples(x, y, kernel.getWidth(), kernel.getHeight(), b, tmp);
|
||||
for (int i=0; i < tmp.length; i++)
|
||||
v += tmp[i] * kvals[i];
|
||||
dest.setSample(x, y, b, v);
|
||||
}
|
||||
for (int y = 0; y < regionH; y++)
|
||||
{
|
||||
// FIXME: This needs a much more efficient implementation
|
||||
for (int b = 0; b < src.getNumBands(); b++)
|
||||
{
|
||||
float v = 0;
|
||||
src.getSamples(x, y, kWidth, kHeight, b, tmp);
|
||||
for (int i = 0; i < tmp.length; i++)
|
||||
v += tmp[tmp.length - i - 1] * kvals[i];
|
||||
// FIXME: in the above line, I've had to reverse the order of
|
||||
// the samples array to make the tests pass. I haven't worked
|
||||
// out why this is necessary.
|
||||
dest.setSample(x + kernel.getXOrigin(), y + kernel.getYOrigin(),
|
||||
b, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle unfiltered edge pixels at end of line
|
||||
float[] t2 = new float[(kernel.getWidth() / 2) * src.getNumBands()];
|
||||
if (edge == EDGE_ZERO_FILL)
|
||||
Arrays.fill(t2, 0);
|
||||
else
|
||||
src.getPixels(src.getMinX() + src.getWidth()
|
||||
- (kernel.getWidth() / 2),
|
||||
y, kernel.getWidth() / 2, 1, t2);
|
||||
dest.setPixels(src.getMinX() + src.getWidth() - (kernel.getWidth() / 2),
|
||||
y, kernel.getWidth() / 2, 1, t2);
|
||||
}
|
||||
for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
|
||||
for (int x = src.getMinX(); x< src.getWidth() + src.getMinX(); x++)
|
||||
{
|
||||
|
||||
}
|
||||
for (int y = src.getMinY(); y < src.getHeight() + src.getMinY(); y++)
|
||||
for (int x = src.getMinX(); x< src.getWidth() + src.getMinX(); x++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Handle top edge
|
||||
if (edge == EDGE_ZERO_FILL)
|
||||
{
|
||||
float[] zeros = new float[src.getNumBands() * src.getWidth() *
|
||||
(kernel.getHeight() / 2)];
|
||||
Arrays.fill(zeros, 0);
|
||||
dest.setPixels(src.getMinX(),
|
||||
src.getHeight() + src.getMinY() - (kernel.getHeight() / 2),
|
||||
src.getWidth(), kernel.getHeight() / 2, zeros);
|
||||
}
|
||||
else
|
||||
{
|
||||
float[] vals = new float[src.getNumBands() * src.getWidth() *
|
||||
(kernel.getHeight() / 2)];
|
||||
src.getPixels(src.getMinX(),
|
||||
src.getHeight() + src.getMinY()
|
||||
- (kernel.getHeight() / 2),
|
||||
src.getWidth(), kernel.getHeight() / 2, vals);
|
||||
dest.setPixels(src.getMinX(),
|
||||
src.getHeight() + src.getMinY()
|
||||
- (kernel.getHeight() / 2),
|
||||
src.getWidth(), kernel.getHeight() / 2, vals);
|
||||
}
|
||||
|
||||
return dest;
|
||||
// fill in the top border
|
||||
fillEdge(src, dest, 0, 0, src.width, top, edge);
|
||||
|
||||
// fill in the bottom border
|
||||
fillEdge(src, dest, 0, src.height - bottom, src.width, bottom, edge);
|
||||
|
||||
// fill in the left border
|
||||
fillEdge(src, dest, 0, top, left, regionH, edge);
|
||||
|
||||
// fill in the right border
|
||||
fillEdge(src, dest, src.width - right, top, right, regionH, edge);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills a range of pixels (typically at the edge of a raster) with either
|
||||
* zero values (if <code>edgeOp</code> is <code>EDGE_ZERO_FILL</code>) or the
|
||||
* corresponding pixel values from the source raster (if <code>edgeOp</code>
|
||||
* is <code>EDGE_NO_OP</code>). This utility method is called by the
|
||||
* {@link #fillEdge(Raster, WritableRaster, int, int, int, int, int)} method.
|
||||
*
|
||||
* @param src the source raster.
|
||||
* @param dest the destination raster.
|
||||
* @param x the x-coordinate of the top left pixel in the range.
|
||||
* @param y the y-coordinate of the top left pixel in the range.
|
||||
* @param w the width of the pixel range.
|
||||
* @param h the height of the pixel range.
|
||||
* @param edgeOp indicates how to determine the values for the range
|
||||
* (either {@link #EDGE_ZERO_FILL} or {@link #EDGE_NO_OP}).
|
||||
*/
|
||||
private void fillEdge(Raster src, WritableRaster dest, int x, int y, int w,
|
||||
int h, int edgeOp)
|
||||
{
|
||||
if (w <= 0)
|
||||
return;
|
||||
if (h <= 0)
|
||||
return;
|
||||
if (edgeOp == EDGE_ZERO_FILL) // fill region with zeroes
|
||||
{
|
||||
float[] zeros = new float[src.getNumBands() * w * h];
|
||||
dest.setPixels(x, y, w, h, zeros);
|
||||
}
|
||||
else // copy pixels from source
|
||||
{
|
||||
float[] pixels = new float[src.getNumBands() * w * h];
|
||||
src.getPixels(x, y, w, h, pixels);
|
||||
dest.setPixels(x, y, w, h, pixels);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -114,8 +114,7 @@ public abstract class DataBuffer
|
||||
*/
|
||||
protected DataBuffer(int dataType, int size)
|
||||
{
|
||||
this.dataType = dataType;
|
||||
this.size = size;
|
||||
this(dataType, size, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,9 +131,7 @@ public abstract class DataBuffer
|
||||
* @param numBanks the number of data banks.
|
||||
*/
|
||||
protected DataBuffer(int dataType, int size, int numBanks) {
|
||||
this(dataType, size);
|
||||
banks = numBanks;
|
||||
offsets = new int[numBanks];
|
||||
this(dataType, size, numBanks, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,11 +150,14 @@ public abstract class DataBuffer
|
||||
* @param offset the offset to the first element for all banks.
|
||||
*/
|
||||
protected DataBuffer(int dataType, int size, int numBanks, int offset) {
|
||||
this(dataType, size, numBanks);
|
||||
|
||||
java.util.Arrays.fill(offsets, offset);
|
||||
|
||||
banks = numBanks;
|
||||
this.dataType = dataType;
|
||||
this.size = size;
|
||||
this.offset = offset;
|
||||
|
||||
offsets = new int[ numBanks ];
|
||||
for(int i = 0; i < numBanks; i++ )
|
||||
offsets[i] = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,10 +179,11 @@ public abstract class DataBuffer
|
||||
* <code>numBanks != offsets.length</code>.
|
||||
*/
|
||||
protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) {
|
||||
this(dataType, size);
|
||||
if (numBanks != offsets.length)
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
|
||||
|
||||
this.dataType = dataType;
|
||||
this.size = size;
|
||||
banks = numBanks;
|
||||
this.offsets = offsets;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Kernel.java -- Java class for an image processing kernel
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -44,21 +44,32 @@ package java.awt.image;
|
||||
* values representing a 2-dimensional array in row-major order.
|
||||
*
|
||||
* @author Jerry Quinn (jlquinn@optonline.net)
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Kernel implements Cloneable
|
||||
{
|
||||
/** The kernel width. */
|
||||
private final int width;
|
||||
|
||||
/** The kernel height. */
|
||||
private final int height;
|
||||
|
||||
/** Internal storage for the kernel's values. */
|
||||
private final float[] data;
|
||||
|
||||
/**
|
||||
* Creates a new <code>Kernel</code> instance.
|
||||
* Creates a new <code>Kernel</code> instance with the specified dimensions
|
||||
* and values. The first <code>width * height</code> values in the specified
|
||||
* <code>data</code> array are copied to internal storage.
|
||||
*
|
||||
* @param width The 2D width of data.
|
||||
* @param height The 2D height of data.
|
||||
* @param data The source data array.
|
||||
* @exception IllegalArgumentException if width * height < data.length.
|
||||
* @param width the kernel width.
|
||||
* @param height the kernel height.
|
||||
* @param data the source data array (<code>null</code> not permitted).
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>data.length</code> is less than
|
||||
* <code>width * height</code>.
|
||||
* @throws IllegalArgumentException if <code>width</code> or
|
||||
* <code>height</code> is less than zero.
|
||||
* @throws NullPointerException if <code>data</code> is <code>null</code>.
|
||||
*/
|
||||
public Kernel(int width, int height, float[] data)
|
||||
throws IllegalArgumentException
|
||||
@@ -72,7 +83,10 @@ public class Kernel implements Cloneable
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the X origin: (width - 1) / 2
|
||||
* Returns the x-origin for the kernel, which is calculated as
|
||||
* <code>(width - 1) / 2</code>.
|
||||
*
|
||||
* @return The x-origin for the kernel.
|
||||
*/
|
||||
public final int getXOrigin()
|
||||
{
|
||||
@@ -80,7 +94,10 @@ public class Kernel implements Cloneable
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Y origin: (height - 1) / 2
|
||||
* Returns the y-origin for the kernel, which is calculated as
|
||||
* <code>(height - 1) / 2</code>.
|
||||
*
|
||||
* @return The y-origin for the kernel.
|
||||
*/
|
||||
public final int getYOrigin()
|
||||
{
|
||||
@@ -88,6 +105,8 @@ public class Kernel implements Cloneable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kernel width (as supplied to the constructor).
|
||||
*
|
||||
* @return The kernel width.
|
||||
*/
|
||||
public final int getWidth()
|
||||
@@ -96,6 +115,8 @@ public class Kernel implements Cloneable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kernel height (as supplied to the constructor).
|
||||
*
|
||||
* @return The kernel height.
|
||||
*/
|
||||
public final int getHeight()
|
||||
@@ -104,20 +125,25 @@ public class Kernel implements Cloneable
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the kernel data.
|
||||
* Returns an array containing a copy of the kernel data. If the
|
||||
* <code>data</code> argument is non-<code>null</code>, the kernel values
|
||||
* are copied into it and then <code>data</code> is returned as the result.
|
||||
* If the <code>data</code> argument is <code>null</code>, this method
|
||||
* allocates a new array then populates and returns it.
|
||||
*
|
||||
* If data is null, allocates a new array and returns it. Otherwise, the
|
||||
* kernel values are copied into data.
|
||||
*
|
||||
* @param data Array to copy values into, or null.
|
||||
* @param data an array to copy the return values into (if
|
||||
* <code>null</code>, a new array is allocated).
|
||||
*
|
||||
* @return The array with copied values.
|
||||
* @exception IllegalArgumentException if data != null and too small.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>data.length</code> is less than
|
||||
* the kernel's <code>width * height</code>.
|
||||
*/
|
||||
public final float[] getKernelData(float[] data)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (data == null)
|
||||
return (float[])this.data.clone();
|
||||
return (float[]) this.data.clone();
|
||||
|
||||
if (data.length < this.data.length)
|
||||
throw new IllegalArgumentException();
|
||||
@@ -127,13 +153,15 @@ public class Kernel implements Cloneable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a clone of this kernel.
|
||||
*
|
||||
* @return a clone of this Kernel.
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.clone();
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2004 Free Software Foundation
|
||||
/* Copyright (C) 2004, 2006, Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -56,12 +56,43 @@ public class MultiPixelPackedSampleModel extends SampleModel
|
||||
private int numberOfBits;
|
||||
private int numElems;
|
||||
|
||||
/**
|
||||
* Creates a new <code>MultiPixelPackedSampleModel</code> with the specified
|
||||
* data type, which should be one of:
|
||||
* <ul>
|
||||
* <li>{@link DataBuffer#TYPE_BYTE};</li>
|
||||
* <li>{@link DataBuffer#TYPE_USHORT};</li>
|
||||
* <li>{@link DataBuffer#TYPE_INT};</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param dataType the data type.
|
||||
* @param w the width (in pixels).
|
||||
* @param h the height (in pixels).
|
||||
* @param numberOfBits the number of bits per pixel (must be a power of 2).
|
||||
*/
|
||||
public MultiPixelPackedSampleModel(int dataType, int w, int h,
|
||||
int numberOfBits)
|
||||
{
|
||||
this(dataType, w, h, numberOfBits, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>MultiPixelPackedSampleModel</code> with the specified
|
||||
* data type, which should be one of:
|
||||
* <ul>
|
||||
* <li>{@link DataBuffer#TYPE_BYTE};</li>
|
||||
* <li>{@link DataBuffer#TYPE_USHORT};</li>
|
||||
* <li>{@link DataBuffer#TYPE_INT};</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param dataType the data type.
|
||||
* @param w the width (in pixels).
|
||||
* @param h the height (in pixels).
|
||||
* @param numberOfBits the number of bits per pixel (must be a power of 2).
|
||||
* @param scanlineStride the number of data elements from a pixel on one
|
||||
* row to the corresponding pixel in the next row.
|
||||
* @param dataBitOffset the offset to the first data bit.
|
||||
*/
|
||||
public MultiPixelPackedSampleModel(int dataType, int w, int h,
|
||||
int numberOfBits, int scanlineStride,
|
||||
int dataBitOffset)
|
||||
@@ -101,7 +132,7 @@ public class MultiPixelPackedSampleModel extends SampleModel
|
||||
|
||||
// Compute scan line large enough for w pixels.
|
||||
if (scanlineStride == 0)
|
||||
scanlineStride = ((dataBitOffset + w * numberOfBits) / elemBits);
|
||||
scanlineStride = ((dataBitOffset + w * numberOfBits) - 1) / elemBits + 1;
|
||||
this.scanlineStride = scanlineStride;
|
||||
|
||||
|
||||
@@ -118,6 +149,16 @@ public class MultiPixelPackedSampleModel extends SampleModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>MultiPixelPackedSample</code> model with the same
|
||||
* data type and bits per pixel as this model, but with the specified
|
||||
* dimensions.
|
||||
*
|
||||
* @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
|
||||
@@ -126,78 +167,163 @@ public class MultiPixelPackedSampleModel extends SampleModel
|
||||
return new MultiPixelPackedSampleModel(dataType, w, h, numberOfBits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a DataBuffer for holding pixel data in the format and
|
||||
* layout described by this SampleModel. The returned buffer will
|
||||
* consist of one single bank.
|
||||
*
|
||||
* @return A new data buffer.
|
||||
*/
|
||||
public DataBuffer createDataBuffer()
|
||||
{
|
||||
int size;
|
||||
|
||||
// FIXME: The comment refers to SinglePixelPackedSampleModel. See if the
|
||||
// same can be done for MultiPixelPackedSampleModel.
|
||||
// We can save (scanlineStride - width) pixels at the very end of
|
||||
// the buffer. The Sun reference implementation (J2SE 1.3.1 and
|
||||
// 1.4.1_01) seems to do this; tested with Mauve test code.
|
||||
size = scanlineStride * height;
|
||||
|
||||
int size = scanlineStride * height;
|
||||
if (dataBitOffset > 0)
|
||||
size += (dataBitOffset - 1) / elemBits + 1;
|
||||
return Buffers.createBuffer(getDataType(), size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of data elements required to transfer a pixel in the
|
||||
* get/setDataElements() methods.
|
||||
*
|
||||
* @return <code>1</code>.
|
||||
*/
|
||||
public int getNumDataElements()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing the size (in bits) of the samples in each
|
||||
* band. The <code>MultiPixelPackedSampleModel</code> class supports only
|
||||
* one band, so this method returns an array with length <code>1</code>.
|
||||
*
|
||||
* @return An array containing the size (in bits) of the samples in band zero.
|
||||
*
|
||||
* @see #getSampleSize(int)
|
||||
*/
|
||||
public int[] getSampleSize()
|
||||
{
|
||||
return sampleSize;
|
||||
return (int[]) sampleSize.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the samples in the specified band. Note that the
|
||||
* <code>MultiPixelPackedSampleModel</code> supports only one band -- this
|
||||
* method ignored the <code>band</code> argument, and always returns the size
|
||||
* of band zero.
|
||||
*
|
||||
* @param band the band (this parameter is ignored).
|
||||
*
|
||||
* @return The size of the samples in band zero.
|
||||
*
|
||||
* @see #getSampleSize()
|
||||
*/
|
||||
public int getSampleSize(int band)
|
||||
{
|
||||
return sampleSize[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index in the data buffer that stores the pixel at (x, y).
|
||||
*
|
||||
* @param x the x-coordinate.
|
||||
* @param y the y-coordinate.
|
||||
*
|
||||
* @return The index in the data buffer that stores the pixel at (x, y).
|
||||
*
|
||||
* @see #getBitOffset(int)
|
||||
*/
|
||||
public int getOffset(int x, int y)
|
||||
{
|
||||
return scanlineStride * y + ((dataBitOffset + x*numberOfBits) / elemBits);
|
||||
return scanlineStride * y + ((dataBitOffset + x * numberOfBits) / elemBits);
|
||||
}
|
||||
|
||||
/**
|
||||
* The bit offset (within an element in the data buffer) of the pixels with
|
||||
* the specified x-coordinate.
|
||||
*
|
||||
* @param x the x-coordinate.
|
||||
*
|
||||
* @return The bit offset.
|
||||
*/
|
||||
public int getBitOffset(int x)
|
||||
{
|
||||
return (dataBitOffset + x*numberOfBits) % elemBits;
|
||||
return (dataBitOffset + x * numberOfBits) % elemBits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset to the first data bit.
|
||||
*
|
||||
* @return The offset to the first data bit.
|
||||
*/
|
||||
public int getDataBitOffset()
|
||||
{
|
||||
return dataBitOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of data elements from a pixel in one row to the
|
||||
* corresponding pixel in the next row.
|
||||
*
|
||||
* @return The scanline stride.
|
||||
*/
|
||||
public int getScanlineStride()
|
||||
{
|
||||
return scanlineStride;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bits per pixel.
|
||||
*
|
||||
* @return The number of bits per pixel.
|
||||
*/
|
||||
public int getPixelBitStride()
|
||||
{
|
||||
return numberOfBits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the transfer type, which is one of the following (depending on
|
||||
* the number of bits per sample for this model):
|
||||
* <ul>
|
||||
* <li>{@link DataBuffer#TYPE_BYTE};</li>
|
||||
* <li>{@link DataBuffer#TYPE_USHORT};</li>
|
||||
* <li>{@link DataBuffer#TYPE_INT};</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return The transfer type.
|
||||
*/
|
||||
public int getTransferType()
|
||||
{
|
||||
if (numberOfBits <= DataBuffer.getDataTypeSize(DataBuffer.TYPE_BYTE))
|
||||
return DataBuffer.TYPE_BYTE;
|
||||
else if (numberOfBits <= DataBuffer.getDataTypeSize(DataBuffer.TYPE_USHORT))
|
||||
return DataBuffer.TYPE_USHORT;
|
||||
return DataBuffer.TYPE_INT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normally this method returns a sample model for accessing a subset of
|
||||
* bands of image data, but since <code>MultiPixelPackedSampleModel</code>
|
||||
* only supports a single band, this overridden implementation just returns
|
||||
* a new instance of <code>MultiPixelPackedSampleModel</code>, with the same
|
||||
* attributes as this instance.
|
||||
*
|
||||
* @param bands the bands to include in the subset (this is ignored, except
|
||||
* that if it is non-<code>null</code> a check is made to ensure that the
|
||||
* array length is equal to <code>1</code>).
|
||||
*
|
||||
* @throws RasterFormatException if <code>bands</code> is not
|
||||
* <code>null</code> and <code>bands.length != 1</code>.
|
||||
*/
|
||||
public SampleModel createSubsetSampleModel(int[] bands)
|
||||
{
|
||||
int numBands = bands.length;
|
||||
if (numBands != 1)
|
||||
if (bands != null && bands.length != 1)
|
||||
throw new RasterFormatException("MultiPixelPackedSampleModel only"
|
||||
+ " supports one band");
|
||||
|
||||
return new MultiPixelPackedSampleModel(dataType, width, height,
|
||||
numberOfBits, scanlineStride,
|
||||
dataBitOffset);
|
||||
+ " supports one band");
|
||||
return new MultiPixelPackedSampleModel(dataType, width, height,
|
||||
numberOfBits, scanlineStride, dataBitOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,68 +333,82 @@ public class MultiPixelPackedSampleModel extends SampleModel
|
||||
* array obj, since there is only one band. 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, Object,
|
||||
* 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:
|
||||
if (obj == null) obj = new byte[1];
|
||||
((byte[])obj)[0] = (byte)pixel;
|
||||
return obj;
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
if (obj == null) obj = new short[1];
|
||||
((short[])obj)[0] = (short)pixel;
|
||||
return obj;
|
||||
case DataBuffer.TYPE_INT:
|
||||
if (obj == null) obj = new int[1];
|
||||
((int[])obj)[0] = pixel;
|
||||
return obj;
|
||||
default:
|
||||
// Seems like the only sensible thing to do.
|
||||
throw new ClassCastException();
|
||||
}
|
||||
{
|
||||
case DataBuffer.TYPE_BYTE:
|
||||
if (obj == null)
|
||||
obj = new byte[1];
|
||||
((byte[]) obj)[0] = (byte) pixel;
|
||||
return obj;
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
if (obj == null)
|
||||
obj = new short[1];
|
||||
((short[]) obj)[0] = (short) pixel;
|
||||
return obj;
|
||||
case DataBuffer.TYPE_INT:
|
||||
if (obj == null)
|
||||
obj = new int[1];
|
||||
((int[]) obj)[0] = pixel;
|
||||
return obj;
|
||||
default:
|
||||
// Seems like the only sensible thing to do.
|
||||
throw new ClassCastException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array (of length 1) containing the sample 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 value 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 An array containing the pixel sample value.
|
||||
*
|
||||
* @throws NullPointerException if <code>data</code> is <code>null</code>.
|
||||
*/
|
||||
public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
|
||||
{
|
||||
if (iArray == null) iArray = new int[1];
|
||||
if (iArray == null)
|
||||
iArray = new int[1];
|
||||
iArray[0] = getSample(x, y, 0, data);
|
||||
|
||||
return iArray;
|
||||
}
|
||||
|
||||
public int[] getPixels(int x, int y, int w, int h, int[] iArray,
|
||||
DataBuffer data)
|
||||
{
|
||||
int offset = getOffset(x, y);
|
||||
if (iArray == null) iArray = new int[w*h];
|
||||
int outOffset = 0;
|
||||
for (y=0; y<h; y++)
|
||||
{
|
||||
int lineOffset = offset;
|
||||
for (x=0; x<w;)
|
||||
{
|
||||
int samples = data.getElem(lineOffset++);
|
||||
for (int b=0; b<numElems && x<w; b++)
|
||||
{
|
||||
iArray[outOffset++] = (samples & bitMasks[b]) >>> bitOffsets[b];
|
||||
x++;
|
||||
}
|
||||
}
|
||||
offset += scanlineStride;
|
||||
}
|
||||
return iArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int getSample(int x, int y, int b, DataBuffer data)
|
||||
{
|
||||
int pos =
|
||||
@@ -286,72 +426,82 @@ public class MultiPixelPackedSampleModel extends SampleModel
|
||||
* @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 = getOffset(x, y);
|
||||
|
||||
try
|
||||
{
|
||||
switch (transferType)
|
||||
{
|
||||
case DataBuffer.TYPE_BYTE:
|
||||
{
|
||||
DataBufferByte out = (DataBufferByte) data;
|
||||
byte[] in = (byte[]) obj;
|
||||
out.getData()[offset] = in[0];
|
||||
return;
|
||||
}
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
{
|
||||
DataBufferUShort out = (DataBufferUShort) data;
|
||||
short[] in = (short[]) obj;
|
||||
out.getData()[offset] = in[0];
|
||||
return;
|
||||
}
|
||||
case DataBuffer.TYPE_INT:
|
||||
{
|
||||
DataBufferInt out = (DataBufferInt) data;
|
||||
int[] in = (int[]) obj;
|
||||
out.getData()[offset] = in[0];
|
||||
return;
|
||||
}
|
||||
default:
|
||||
throw new ClassCastException("Unsupported data type");
|
||||
}
|
||||
switch (transferType)
|
||||
{
|
||||
case DataBuffer.TYPE_BYTE:
|
||||
{
|
||||
byte[] in = (byte[]) obj;
|
||||
setSample(x, y, 0, in[0] & 0xFF, data);
|
||||
return;
|
||||
}
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
{
|
||||
short[] in = (short[]) obj;
|
||||
setSample(x, y, 0, in[0] & 0xFFFF, data);
|
||||
return;
|
||||
}
|
||||
case DataBuffer.TYPE_INT:
|
||||
{
|
||||
int[] in = (int[]) obj;
|
||||
setSample(x, y, 0, in[0], data);
|
||||
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);
|
||||
String msg = "While writing data elements" +
|
||||
", x=" + x + ", y=" + y +
|
||||
", width=" + width + ", height=" + height +
|
||||
", scanlineStride=" + scanlineStride +
|
||||
", offset=" + getOffset(x, y) +
|
||||
", data.getSize()=" + data.getSize() +
|
||||
", data.getOffset()=" + data.getOffset() +
|
||||
": " + aioobe;
|
||||
throw new ArrayIndexOutOfBoundsException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample value for the pixel at (x, y) in the specified data
|
||||
* buffer to the specified value.
|
||||
*
|
||||
* @param x the x-coordinate of the pixel.
|
||||
* @param y the y-coordinate of the pixel.
|
||||
* @param iArray the sample value (<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>.
|
||||
*
|
||||
* @see #setSample(int, int, int, int, DataBuffer)
|
||||
*/
|
||||
public void setPixel(int x, int y, int[] iArray, DataBuffer data)
|
||||
{
|
||||
setSample(x, y, 0, iArray[0], 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, int s, DataBuffer data)
|
||||
{
|
||||
int bitpos =
|
||||
@@ -366,6 +516,70 @@ public class MultiPixelPackedSampleModel extends SampleModel
|
||||
data.setElem(offset, sample);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests this sample model for equality with an arbitrary object. This
|
||||
* method returns <code>true</code> if and only if:
|
||||
* <ul>
|
||||
* <li><code>obj</code> is not <code>null</code>;
|
||||
* <li><code>obj</code> is an instance of
|
||||
* <code>MultiPixelPackedSampleModel</code>;
|
||||
* <li>both models have the same:
|
||||
* <ul>
|
||||
* <li><code>dataType</code>;
|
||||
* <li><code>width</code>;
|
||||
* <li><code>height</code>;
|
||||
* <li><code>numberOfBits</code>;
|
||||
* <li><code>scanlineStride</code>;
|
||||
* <li><code>dataBitOffsets</code>.
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param obj the object (<code>null</code> permitted)
|
||||
*
|
||||
* @return <code>true</code> if this model is equal to <code>obj</code>, and
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (! (obj instanceof MultiPixelPackedSampleModel))
|
||||
return false;
|
||||
MultiPixelPackedSampleModel that = (MultiPixelPackedSampleModel) obj;
|
||||
if (this.dataType != that.dataType)
|
||||
return false;
|
||||
if (this.width != that.width)
|
||||
return false;
|
||||
if (this.height != that.height)
|
||||
return false;
|
||||
if (this.numberOfBits != that.numberOfBits)
|
||||
return false;
|
||||
if (this.scanlineStride != that.scanlineStride)
|
||||
return false;
|
||||
if (this.dataBitOffset != that.dataBitOffset)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code for this <code>MultiPixelPackedSampleModel</code>.
|
||||
*
|
||||
* @return A hash code.
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
// this hash code won't match Sun's, but that shouldn't matter...
|
||||
int result = 193;
|
||||
result = 37 * result + dataType;
|
||||
result = 37 * result + width;
|
||||
result = 37 * result + height;
|
||||
result = 37 * result + numberOfBits;
|
||||
result = 37 * result + scanlineStride;
|
||||
result = 37 * result + dataBitOffset;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a String with some information about this SampleModel.
|
||||
* @return A String describing this SampleModel.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/* RasterOp.java --
|
||||
Copyright (C) 2000, 2002, 2004, 2005 Free Software Foundation
|
||||
Copyright (C) 2000, 2002, 2004, 2005, 2006, Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -42,16 +42,64 @@ import java.awt.RenderingHints;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/**
|
||||
* An operation that is performed on one raster (the source) producing a new
|
||||
* raster (the destination).
|
||||
*/
|
||||
public interface RasterOp
|
||||
{
|
||||
/**
|
||||
* Performs an operation on the source raster, returning the result in a
|
||||
* writable raster. If <code>dest</code> is <code>null</code>, a new
|
||||
* <code>WritableRaster</code> will be created by calling the
|
||||
* {@link #createCompatibleDestRaster(Raster)} method. If <code>dest</code>
|
||||
* is not <code>null</code>, the result is written to <code>dest</code> then
|
||||
* returned (this avoids creating a new <code>WritableRaster</code> each
|
||||
* time this method is called).
|
||||
*
|
||||
* @param src the source raster.
|
||||
* @param dest the destination raster (<code>null</code> permitted).
|
||||
*
|
||||
* @return The filtered raster.
|
||||
*/
|
||||
WritableRaster filter(Raster src, WritableRaster dest);
|
||||
|
||||
/**
|
||||
* Returns the bounds of the destination raster on the basis of this
|
||||
* <code>RasterOp</code> being applied to the specified source raster.
|
||||
*
|
||||
* @param src the source raster.
|
||||
*
|
||||
* @return The destination bounds.
|
||||
*/
|
||||
Rectangle2D getBounds2D(Raster src);
|
||||
|
||||
/**
|
||||
* Returns a raster that can be used by this <code>RasterOp</code> as the
|
||||
* destination raster when operating on the specified source raster.
|
||||
*
|
||||
* @param src the source raster.
|
||||
*
|
||||
* @return A new writable raster that can be used as the destination raster.
|
||||
*/
|
||||
WritableRaster createCompatibleDestRaster(Raster src);
|
||||
|
||||
/**
|
||||
* Returns the point on the destination raster that corresponds to the given
|
||||
* point on the source raster.
|
||||
*
|
||||
* @param srcPoint the source point.
|
||||
* @param destPoint the destination point (<code>null</code> permitted).
|
||||
*
|
||||
* @return The destination point.
|
||||
*/
|
||||
Point2D getPoint2D(Point2D srcPoint, Point2D destPoint);
|
||||
|
||||
/**
|
||||
* Returns the rendering hints for this operation.
|
||||
*
|
||||
* @return The rendering hints.
|
||||
*/
|
||||
RenderingHints getRenderingHints();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* ShortLookupTable.java -- Java class for a pixel translation table.
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -67,7 +67,13 @@ public class ShortLookupTable extends LookupTable
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
super(offset, data.length);
|
||||
this.data = data;
|
||||
|
||||
// tests show that Sun's implementation creates a new array to store the
|
||||
// references from the incoming 'data' array - not sure why, but we'll
|
||||
// match that behaviour just in case it matters...
|
||||
this.data = new short[data.length][];
|
||||
for (int i = 0; i < data.length; i++)
|
||||
this.data[i] = data[i];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,17 +83,25 @@ public class ShortLookupTable extends LookupTable
|
||||
* table. The same table is applied to all pixel components.
|
||||
*
|
||||
* @param offset Offset to be subtracted.
|
||||
* @param data Lookup table for all components.
|
||||
* @param data Lookup table for all components (<code>null</code> not
|
||||
* permitted).
|
||||
* @exception IllegalArgumentException if offset < 0.
|
||||
*/
|
||||
public ShortLookupTable(int offset, short[] data)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
super(offset, 1);
|
||||
if (data == null)
|
||||
throw new NullPointerException("Null 'data' argument.");
|
||||
this.data = new short[][] {data};
|
||||
}
|
||||
|
||||
/** Return the lookup tables. */
|
||||
/**
|
||||
* Return the lookup tables. This is a reference to the actual table, so
|
||||
* modifying the contents of the returned array will modify the lookup table.
|
||||
*
|
||||
* @return The lookup table.
|
||||
*/
|
||||
public final short[][] getTable()
|
||||
{
|
||||
return data;
|
||||
@@ -117,11 +131,11 @@ public class ShortLookupTable extends LookupTable
|
||||
dst = new int[src.length];
|
||||
|
||||
if (data.length == 1)
|
||||
for (int i=0; i < src.length; i++)
|
||||
dst[i] = data[0][src[i] - offset];
|
||||
for (int i = 0; i < src.length; i++)
|
||||
dst[i] = data[0][src[i] - offset];
|
||||
else
|
||||
for (int i=0; i < src.length; i++)
|
||||
dst[i] = data[i][src[i] - offset];
|
||||
for (int i = 0; i < src.length; i++)
|
||||
dst[i] = data[i][src[i] - offset];
|
||||
|
||||
return dst;
|
||||
}
|
||||
@@ -142,6 +156,7 @@ public class ShortLookupTable extends LookupTable
|
||||
* @param src Component values of a pixel.
|
||||
* @param dst Destination array for values, or null.
|
||||
* @return Translated values for the pixel.
|
||||
*
|
||||
*/
|
||||
public short[] lookupPixel(short[] src, short[] dst)
|
||||
throws ArrayIndexOutOfBoundsException
|
||||
@@ -150,11 +165,11 @@ public class ShortLookupTable extends LookupTable
|
||||
dst = new short[src.length];
|
||||
|
||||
if (data.length == 1)
|
||||
for (int i=0; i < src.length; i++)
|
||||
dst[i] = data[0][((int)src[i]) - offset];
|
||||
for (int i = 0; i < src.length; i++)
|
||||
dst[i] = data[0][((int) src[i]) - offset];
|
||||
else
|
||||
for (int i=0; i < src.length; i++)
|
||||
dst[i] = data[i][((int)src[i]) - offset];
|
||||
for (int i = 0; i < src.length; i++)
|
||||
dst[i] = data[i][((int) src[i]) - offset];
|
||||
|
||||
return dst;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2000, 2002, 2003, 2004 Free Software Foundation
|
||||
/* Copyright (C) 2000, 2002, 2003, 2004, 2006, Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -36,10 +36,16 @@ exception statement from your version. */
|
||||
|
||||
package java.awt.image;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import gnu.java.awt.BitMaskExtent;
|
||||
import gnu.java.awt.Buffers;
|
||||
|
||||
/**
|
||||
* A <code>SampleModel</code> used when all samples are stored in a single
|
||||
* data element in the {@link DataBuffer}, and each data element contains
|
||||
* samples for one pixel only.
|
||||
*
|
||||
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
|
||||
*/
|
||||
public class SinglePixelPackedSampleModel extends SampleModel
|
||||
@@ -49,12 +55,32 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
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 +93,8 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
case DataBuffer.TYPE_INT:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("SinglePixelPackedSampleModel unsupported dataType");
|
||||
throw new IllegalArgumentException(
|
||||
"SinglePixelPackedSampleModel unsupported dataType");
|
||||
}
|
||||
|
||||
this.scanlineStride = scanlineStride;
|
||||
@@ -77,19 +104,35 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
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;
|
||||
bitOffsets[b] = extent.leastSignificantBit;
|
||||
// the mask is an unsigned integer
|
||||
long mask = bitMasks[b] & 0xFFFFFFFFL;
|
||||
extent.setMask(mask);
|
||||
sampleSize[b] = extent.bitWidth;
|
||||
bitOffsets[b] = extent.leastSignificantBit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -103,6 +146,8 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
* Creates a DataBuffer for holding pixel data in the format and
|
||||
* layout described by this SampleModel. The returned buffer will
|
||||
* consist of one single bank.
|
||||
*
|
||||
* @return The data buffer.
|
||||
*/
|
||||
public DataBuffer createDataBuffer()
|
||||
{
|
||||
@@ -116,17 +161,40 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
return Buffers.createBuffer(getDataType(), size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array containing the size (in bits) for each band accessed by
|
||||
* the <code>SampleModel</code>.
|
||||
*
|
||||
* @return An array.
|
||||
*
|
||||
* @see #getSampleSize(int)
|
||||
*/
|
||||
public int[] getSampleSize()
|
||||
{
|
||||
return sampleSize;
|
||||
return (int[]) sampleSize.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int getSampleSize(int band)
|
||||
{
|
||||
return sampleSize[band];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index in the data buffer that stores the pixel at (x, y).
|
||||
*
|
||||
* @param x the x-coordinate.
|
||||
* @param y the y-coordinate.
|
||||
*
|
||||
* @return The index in the data buffer that stores the pixel at (x, y).
|
||||
*/
|
||||
public int getOffset(int x, int y)
|
||||
{
|
||||
return scanlineStride*y + x;
|
||||
@@ -142,20 +210,40 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
return bitMasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of data elements from a pixel in one row to the
|
||||
* corresponding pixel in the next row.
|
||||
*
|
||||
* @return The scanline stride.
|
||||
*/
|
||||
public int getScanlineStride()
|
||||
{
|
||||
return scanlineStride;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>SinglePixelPackedSampleModel</code> that accesses
|
||||
* the specified subset of bands.
|
||||
*
|
||||
* @param bands an array containing band indices (<code>null</code> not
|
||||
* permitted).
|
||||
*
|
||||
* @return A new sample model.
|
||||
*
|
||||
* @throws NullPointerException if <code>bands</code> is <code>null</code>.
|
||||
* @throws RasterFormatException if <code>bands.length</code> is greater
|
||||
* than the number of bands in this model.
|
||||
*/
|
||||
public SampleModel createSubsetSampleModel(int[] bands)
|
||||
{
|
||||
// FIXME: Is this the right way to interpret bands?
|
||||
if (bands.length > numBands)
|
||||
throw new RasterFormatException("Too many bands.");
|
||||
|
||||
int numBands = bands.length;
|
||||
|
||||
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,
|
||||
@@ -174,16 +262,20 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@@ -209,10 +301,11 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
// 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
|
||||
{
|
||||
@@ -229,32 +322,68 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
int offset = scanlineStride*y + x;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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;
|
||||
@@ -262,6 +391,20 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
return iArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int getSample(int x, int y, int b, DataBuffer data)
|
||||
{
|
||||
int offset = scanlineStride*y + x;
|
||||
@@ -270,16 +413,18 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@@ -373,12 +518,24 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
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);
|
||||
@@ -394,7 +551,8 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
* @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)
|
||||
@@ -407,7 +565,7 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
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;
|
||||
@@ -416,7 +574,19 @@ public class SinglePixelPackedSampleModel extends 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 void setSample(int x, int y, int b, int s, DataBuffer data)
|
||||
{
|
||||
int offset = scanlineStride*y + x;
|
||||
@@ -427,6 +597,76 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
data.setElem(offset, samples);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests this sample model for equality with an arbitrary object. This
|
||||
* method returns <code>true</code> if and only if:
|
||||
* <ul>
|
||||
* <li><code>obj</code> is not <code>null</code>;
|
||||
* <li><code>obj</code> is an instance of
|
||||
* <code>SinglePixelPackedSampleModel</code>;
|
||||
* <li>both models have the same:
|
||||
* <ul>
|
||||
* <li><code>dataType</code>;
|
||||
* <li><code>width</code>;
|
||||
* <li><code>height</code>;
|
||||
* <li><code>numBands</code>;
|
||||
* <li><code>scanlineStride</code>;
|
||||
* <li><code>bitMasks</code>;
|
||||
* <li><code>bitOffsets</code>.
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param obj the object (<code>null</code> permitted)
|
||||
*
|
||||
* @return <code>true</code> if this model is equal to <code>obj</code>, and
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (! (obj instanceof SinglePixelPackedSampleModel))
|
||||
return false;
|
||||
SinglePixelPackedSampleModel that = (SinglePixelPackedSampleModel) obj;
|
||||
if (this.dataType != that.dataType)
|
||||
return false;
|
||||
if (this.width != that.width)
|
||||
return false;
|
||||
if (this.height != that.height)
|
||||
return false;
|
||||
if (this.numBands != that.numBands)
|
||||
return false;
|
||||
if (this.scanlineStride != that.scanlineStride)
|
||||
return false;
|
||||
if (!Arrays.equals(this.bitMasks, that.bitMasks))
|
||||
return false;
|
||||
if (!Arrays.equals(this.bitOffsets, that.bitOffsets))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code for this <code>SinglePixelPackedSampleModel</code>.
|
||||
*
|
||||
* @return A hash code.
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
// this hash code won't match Sun's, but that shouldn't matter...
|
||||
int result = 193;
|
||||
result = 37 * result + dataType;
|
||||
result = 37 * result + width;
|
||||
result = 37 * result + height;
|
||||
result = 37 * result + numBands;
|
||||
result = 37 * result + scanlineStride;
|
||||
for (int i = 0; i < bitMasks.length; i++)
|
||||
result = 37 * result + bitMasks[i];
|
||||
for (int i = 0; i < bitOffsets.length; i++)
|
||||
result = 37 * result + bitOffsets[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a String with some information about this SampleModel.
|
||||
* @return A String describing this SampleModel.
|
||||
@@ -438,9 +678,10 @@ public class SinglePixelPackedSampleModel extends SampleModel
|
||||
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("]");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2000, 2002, 2003 Free Software Foundation
|
||||
/* Copyright (C) 2000, 2002, 2003, 2006, Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
@@ -41,61 +41,98 @@ import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* A raster with methods to support updating pixel values.
|
||||
*
|
||||
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
|
||||
*/
|
||||
public class WritableRaster extends Raster
|
||||
{
|
||||
/**
|
||||
* Creates a new <code>WritableRaster</code>.
|
||||
*
|
||||
* @param sampleModel the sample model.
|
||||
* @param origin the origin.
|
||||
*/
|
||||
protected WritableRaster(SampleModel sampleModel, Point origin)
|
||||
{
|
||||
this(sampleModel, sampleModel.createDataBuffer(), origin);
|
||||
}
|
||||
|
||||
protected WritableRaster(SampleModel sampleModel,
|
||||
DataBuffer dataBuffer, Point origin)
|
||||
/**
|
||||
* Creates a new <code>WritableRaster</code> instance.
|
||||
*
|
||||
* @param sampleModel the sample model.
|
||||
* @param dataBuffer the data buffer.
|
||||
* @param origin the origin.
|
||||
*/
|
||||
protected WritableRaster(SampleModel sampleModel, DataBuffer dataBuffer,
|
||||
Point origin)
|
||||
{
|
||||
this(sampleModel, dataBuffer,
|
||||
new Rectangle(origin != null ? origin.x : 0,
|
||||
new Rectangle(origin != null ? origin.x : 0,
|
||||
origin != null ? origin.y : 0,
|
||||
sampleModel.getWidth(), sampleModel.getHeight()),
|
||||
origin,
|
||||
null);
|
||||
sampleModel.getWidth(), sampleModel.getHeight()),
|
||||
origin, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>WritableRaster</code> instance.
|
||||
*
|
||||
* @param sampleModel the sample model.
|
||||
* @param dataBuffer the data buffer.
|
||||
* @param aRegion the raster's bounds.
|
||||
* @param sampleModelTranslate the translation.
|
||||
* @param parent the parent.
|
||||
*/
|
||||
protected WritableRaster(SampleModel sampleModel,
|
||||
DataBuffer dataBuffer,
|
||||
Rectangle aRegion,
|
||||
Point sampleModelTranslate,
|
||||
WritableRaster parent)
|
||||
DataBuffer dataBuffer,
|
||||
Rectangle aRegion,
|
||||
Point sampleModelTranslate,
|
||||
WritableRaster parent)
|
||||
{
|
||||
super(sampleModel, dataBuffer, aRegion, sampleModelTranslate,
|
||||
parent);
|
||||
super(sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raster's parent, cast as a {@link WritableRaster}.
|
||||
*
|
||||
* @return The raster's parent.
|
||||
*/
|
||||
public WritableRaster getWritableParent()
|
||||
{
|
||||
return (WritableRaster) getParent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param childMinX
|
||||
* @param childMinY
|
||||
* @return
|
||||
*/
|
||||
public WritableRaster createWritableTranslatedChild(int childMinX,
|
||||
int childMinY)
|
||||
int childMinY)
|
||||
{
|
||||
// This mirrors the code from the super class
|
||||
int tcx = sampleModelTranslateX - minX + childMinX;
|
||||
int tcy = sampleModelTranslateY - minY + childMinY;
|
||||
|
||||
return new WritableRaster(sampleModel, dataBuffer,
|
||||
new Rectangle(childMinX, childMinY,
|
||||
width, height),
|
||||
new Point(tcx, tcy),
|
||||
this);
|
||||
new Rectangle(childMinX, childMinY, width, height),
|
||||
new Point(tcx, tcy), this);
|
||||
}
|
||||
|
||||
public WritableRaster createWritableChild(int parentX,
|
||||
int parentY,
|
||||
int w, int h,
|
||||
int childMinX,
|
||||
int childMinY,
|
||||
int[] bandList)
|
||||
/**
|
||||
*
|
||||
* @param parentX
|
||||
* @param parentY
|
||||
* @param w
|
||||
* @param h
|
||||
* @param childMinX
|
||||
* @param childMinY
|
||||
* @param bandList
|
||||
* @return
|
||||
*/
|
||||
public WritableRaster createWritableChild(int parentX, int parentY,
|
||||
int w, int h, int childMinX, int childMinY, int[] bandList)
|
||||
{
|
||||
// This mirrors the code from the super class
|
||||
|
||||
@@ -106,51 +143,52 @@ public class WritableRaster extends Raster
|
||||
sampleModel :
|
||||
sampleModel.createSubsetSampleModel(bandList);
|
||||
|
||||
return new
|
||||
WritableRaster(sm, dataBuffer,
|
||||
new Rectangle(childMinX, childMinY,
|
||||
w, h),
|
||||
new Point(sampleModelTranslateX+childMinX-parentX,
|
||||
sampleModelTranslateY+childMinY-parentY),
|
||||
this);
|
||||
return new WritableRaster(sm, dataBuffer,
|
||||
new Rectangle(childMinX, childMinY, w, h),
|
||||
new Point(sampleModelTranslateX + childMinX - parentX,
|
||||
sampleModelTranslateY + childMinY - parentY),
|
||||
this);
|
||||
}
|
||||
|
||||
public void setDataElements(int x, int y, Object inData)
|
||||
{
|
||||
sampleModel.setDataElements(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
inData, dataBuffer);
|
||||
sampleModel.setDataElements(x - sampleModelTranslateX,
|
||||
y - sampleModelTranslateY, inData, dataBuffer);
|
||||
}
|
||||
|
||||
public void setDataElements(int x, int y, Raster inRaster)
|
||||
{
|
||||
Object dataElements = getDataElements(0, 0,
|
||||
inRaster.getWidth(),
|
||||
inRaster.getHeight(),
|
||||
null);
|
||||
Object dataElements = getDataElements(0, 0, inRaster.getWidth(),
|
||||
inRaster.getHeight(), null);
|
||||
setDataElements(x, y, dataElements);
|
||||
}
|
||||
|
||||
public void setDataElements(int x, int y, int w, int h,
|
||||
Object inData)
|
||||
public void setDataElements(int x, int y, int w, int h, Object inData)
|
||||
{
|
||||
sampleModel.setDataElements(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
w, h, inData, dataBuffer);
|
||||
sampleModel.setDataElements(x - sampleModelTranslateX,
|
||||
y - sampleModelTranslateY, w, h, inData, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param srcRaster
|
||||
*/
|
||||
public void setRect(Raster srcRaster)
|
||||
{
|
||||
setRect(0, 0, srcRaster);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dx
|
||||
* @param dy
|
||||
* @param srcRaster
|
||||
*/
|
||||
public void setRect(int dx, int dy, Raster srcRaster)
|
||||
{
|
||||
Rectangle targetUnclipped = new Rectangle(srcRaster.getMinX()+dx,
|
||||
srcRaster.getMinY()+dy,
|
||||
srcRaster.getWidth(),
|
||||
srcRaster.getHeight());
|
||||
|
||||
Rectangle targetUnclipped = new Rectangle(srcRaster.getMinX() + dx,
|
||||
srcRaster.getMinY() + dy, srcRaster.getWidth(), srcRaster.getHeight());
|
||||
|
||||
Rectangle target = getBounds().intersection(targetUnclipped);
|
||||
|
||||
if (target.isEmpty()) return;
|
||||
@@ -169,97 +207,225 @@ public class WritableRaster extends Raster
|
||||
But this is probably not the place to consider such
|
||||
optimizations.*/
|
||||
|
||||
int[] pixels = srcRaster.getPixels(sx, sy,
|
||||
target.width, target.height,
|
||||
(int[]) null);
|
||||
int[] pixels = srcRaster.getPixels(sx, sy, target.width, target.height,
|
||||
(int[]) null);
|
||||
|
||||
setPixels(target.x, target.y, target.width, target.height, pixels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the samples for the pixel at (x, y) in the raster 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).
|
||||
*
|
||||
* @throws NullPointerException if <code>iArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setPixel(int x, int y, int[] iArray)
|
||||
{
|
||||
sampleModel.setPixel(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
iArray, dataBuffer);
|
||||
sampleModel.setPixel(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
iArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the samples for the pixel at (x, y) in the raster 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).
|
||||
*
|
||||
* @throws NullPointerException if <code>fArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setPixel(int x, int y, float[] fArray)
|
||||
{
|
||||
sampleModel.setPixel(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
fArray, dataBuffer);
|
||||
sampleModel.setPixel(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
fArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the samples for the pixel at (x, y) in the raster 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).
|
||||
*
|
||||
* @throws NullPointerException if <code>dArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setPixel(int x, int y, double[] dArray)
|
||||
{
|
||||
sampleModel.setPixel(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
dArray, dataBuffer);
|
||||
sampleModel.setPixel(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
dArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample values for the pixels in the region specified by
|
||||
* (x, y, w, h) in the raster. 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).
|
||||
*
|
||||
* @throws NullPointerException if <code>iArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setPixels(int x, int y, int w, int h, int[] iArray)
|
||||
{
|
||||
sampleModel.setPixels(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
w, h, iArray, dataBuffer);
|
||||
sampleModel.setPixels(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
w, h, iArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample values for the pixels in the region specified by
|
||||
* (x, y, w, h) in the raster. 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).
|
||||
*
|
||||
* @throws NullPointerException if <code>fArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setPixels(int x, int y, int w, int h, float[] fArray)
|
||||
{
|
||||
sampleModel.setPixels(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
w, h, fArray, dataBuffer);
|
||||
sampleModel.setPixels(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
w, h, fArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample values for the pixels in the region specified by
|
||||
* (x, y, w, h) in the raster. 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).
|
||||
*
|
||||
* @throws NullPointerException if <code>dArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setPixels(int x, int y, int w, int h, double[] dArray)
|
||||
{
|
||||
sampleModel.setPixels(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
w, h, dArray, dataBuffer);
|
||||
sampleModel.setPixels(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
w, h, dArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample value for a band for the pixel at (x, y) in the raster.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public void setSample(int x, int y, int b, int s)
|
||||
{
|
||||
sampleModel.setSample(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
b, s, dataBuffer);
|
||||
sampleModel.setSample(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
b, s, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample value for a band for the pixel at (x, y) in the raster.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public void setSample(int x, int y, int b, float s)
|
||||
{
|
||||
sampleModel.setSample(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
b, s, dataBuffer);
|
||||
sampleModel.setSample(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
b, s, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample value for a band for the pixel at (x, y) in the raster.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public void setSample(int x, int y, int b, double s)
|
||||
{
|
||||
sampleModel.setSample(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
b, s, dataBuffer);
|
||||
sampleModel.setSample(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
b, s, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample values for one band for the pixels in the region
|
||||
* specified by (x, y, w, h) in the raster.
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
* @throws NullPointerException if <code>iArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setSamples(int x, int y, int w, int h, int b,
|
||||
int[] iArray)
|
||||
int[] iArray)
|
||||
{
|
||||
sampleModel.setSamples(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
w, h, b, iArray, dataBuffer);
|
||||
sampleModel.setSamples(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
w, h, b, iArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample values for one band for the pixels in the region
|
||||
* specified by (x, y, w, h) in the raster.
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
* @throws NullPointerException if <code>fArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setSamples(int x, int y, int w, int h, int b,
|
||||
float[] fArray)
|
||||
float[] fArray)
|
||||
{
|
||||
sampleModel.setSamples(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
w, h, b, fArray, dataBuffer);
|
||||
sampleModel.setSamples(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
w, h, b, fArray, dataBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sample values for one band for the pixels in the region
|
||||
* specified by (x, y, w, h) in the raster.
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
* @throws NullPointerException if <code>dArray</code> is <code>null</code>.
|
||||
*/
|
||||
public void setSamples(int x, int y, int w, int h, int b,
|
||||
double[] dArray)
|
||||
double[] dArray)
|
||||
{
|
||||
sampleModel.setSamples(x-sampleModelTranslateX,
|
||||
y-sampleModelTranslateY,
|
||||
w, h, b, dArray, dataBuffer);
|
||||
sampleModel.setSamples(x - sampleModelTranslateX, y - sampleModelTranslateY,
|
||||
w, h, b, dArray, dataBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user