This class represents image data which is stored in a band interleaved
fashion and for
which each sample of a pixel occupies one data element of the DataBuffer.
It subclasses ComponentSampleModel but provides a more efficent
implementation for accessing band interleaved image data than is provided
by ComponentSampleModel. This class should typically be used when working
with images which store sample data for each band in a different bank of the
DataBuffer. Accessor methods are provided so that image data can be
manipulated directly. Pixel stride is the number of
data array elements between two samples for the same band on the same
scanline. The pixel stride for a BandedSampleModel is one.
Scanline stride is the number of data array elements between
a given sample and the corresponding sample in the same column of the next
scanline. Band offsets denote the number
of data array elements from the first data array element of the bank
of the DataBuffer holding each band to the first sample of the band.
The bands are numbered from 0 to N-1.
Bank indices denote the correspondence between a bank of the data buffer
and a band of image data. This class supports
TYPE_BYTE
,
TYPE_USHORT
,
TYPE_SHORT
,
TYPE_INT
,
TYPE_FLOAT
, and
TYPE_DOUBLE
datatypes
Constructs a BandedSampleModel with the specified parameters.
The pixel stride will be one data element. The scanline stride
will be the same as the width. Each band will be stored in
a separate bank and all band offsets will be zero.
Constructs a BandedSampleModel with the specified parameters.
The number of bands will be inferred from the lengths of the
bandOffsets bankIndices arrays, which must be equal. The pixel
stride will be one data element.
Creates a new BandedSampleModel with the specified
width and height. The new BandedSampleModel will have the same
number of bands, storage data type, and bank indices
as this BandedSampleModel. The band offsets will be compressed
such that the offset between bands will be w*pixelStride and
the minimum of all of the band offsets is zero.
Creates a DataBuffer that corresponds to this BandedSampleModel,
The DataBuffer's data type, number of banks, and size
will be consistent with this BandedSampleModel.
Creates a new BandedSampleModel with a subset of the bands of this
BandedSampleModel. The new BandedSampleModel can be
used with any DataBuffer that the existing BandedSampleModel
can be used with. The new BandedSampleModel/DataBuffer
combination will represent an image with a subset of the bands
of the original BandedSampleModel/DataBuffer combination.
Returns the band offset for all bands.
Returns the bank indices for all bands.
Returns the runtime class of an object. That Class
object is the object that is locked by static synchronized
methods of the represented class.
Returns the pixel data for the specified rectangle of pixels in a
primitive array of type TransferType.
For image data supported by the Java 2D API, this
will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
thus increasing efficiency for data transfers. Generally, obj
should be passed in as null, so that the Object will be created
automatically and will be of the right primitive data type.
The following code illustrates transferring data for a rectangular
region of pixels from
DataBuffer db1
, whose storage layout is described by
SampleModel sm1
, to DataBuffer db2
, whose
storage layout is described by SampleModel sm2
.
The transfer will generally be more efficient than using
getPixels/setPixels.
SampleModel sm1, sm2;
DataBuffer db1, db2;
sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w,
h, null, db1), db2);
Using getDataElements/setDataElements to transfer between two
DataBuffer/SampleModel pairs is legitimate if the SampleModels have
the same number of bands, corresponding bands have the same number of
bits per sample, and the TransferTypes are the same.
If obj is non-null, it should be a primitive array of type TransferType.
Otherwise, a ClassCastException is thrown. An
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds, or if obj is non-null and is not large enough to hold
the pixel data.
Returns data for a single pixel in a primitive array of type
TransferType. For a BandedSampleModel, this will be the same
as the data type, and samples will be returned one per array
element. Generally, obj
should be passed in as null, so that the Object will be created
automatically and will be of the right primitive data type.
The following code illustrates transferring data for one pixel from
DataBuffer db1
, whose storage layout is described by
BandedSampleModel bsm1
, to DataBuffer db2
,
whose storage layout is described by
BandedSampleModel bsm2
.
The transfer will generally be more efficient than using
getPixel/setPixel.
BandedSampleModel bsm1, bsm2;
DataBufferInt db1, db2;
bsm2.setDataElements(x, y, bsm1.getDataElements(x, y, null, db1),
db2);
Using getDataElements/setDataElements to transfer between two
DataBuffer/SampleModel pairs is legitimate if the SampleModels have
the same number of bands, corresponding bands have the same number of
bits per sample, and the TransferTypes are the same.
If obj is non-null, it should be a primitive array of type TransferType.
Otherwise, a ClassCastException is thrown. An
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds, or if obj is non-null and is not large enough to hold
the pixel data.
Returns the data type of the DataBuffer storing the pixel data.
Returns the height in pixels.
Returns the total number of bands of image data.
Returns the number of data elements needed to transfer a pixel
with the
and
methods.
For a
ComponentSampleModel
, this is identical to the
number of bands.
Gets the offset for the first band of pixel (x,y).
A sample of the first band can be retrieved from a
DataBuffer
data
with a
ComponentSampleModel
csm
as
data.getElem(csm.getOffset(x, y));
Gets the offset for band b of pixel (x,y).
A sample of band
b
can be retrieved from a
DataBuffer
data
with a
ComponentSampleModel
csm
as
data.getElem(csm.getOffset(x, y, b));
Returns the samples for the specified pixel in an array of double.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the samples for the specified pixel in an array of float.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns all samples for the specified pixel in an int array.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns all samples for a rectangle of pixels in a double
array, one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns all samples for a rectangle of pixels in a float
array, one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns all samples for the specified rectangle of pixels in
an int array, one sample per data array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the pixel stride of this ComponentSampleModel.
Returns as int the sample in a specified band for the pixel
located at (x,y).
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the sample in a specified band
for a pixel located at (x,y) as a double.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the sample in a specified band
for the pixel located at (x,y) as a float.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the samples for a specified band for a specified rectangle
of pixels in a double array, one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the samples for a specified band for the specified rectangle
of pixels in a float array, one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the samples in a specified band for the specified rectangle
of pixels in an int array, one sample per data array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns the number of bits per sample for all bands.
Returns the number of bits per sample for the specified band.
Returns the scanline stride of this ComponentSampleModel.
Returns the TransferType used to transfer pixels via the
getDataElements and setDataElements methods. When pixels
are transferred via these methods, they may be transferred in a
packed or unpacked format, depending on the implementation of the
SampleModel. Using these methods, pixels are transferred as an
array of getNumDataElements() elements of a primitive type given
by getTransferType(). The TransferType may or may not be the same
as the storage DataType. The TransferType will be one of the types
defined in DataBuffer.
Returns the width in pixels.
Wakes up a single thread that is waiting on this object's
monitor. If any threads are waiting on this object, one of them
is chosen to be awakened. The choice is arbitrary and occurs at
the discretion of the implementation. A thread waits on an object's
monitor by calling one of the
wait
methods.
The awakened thread will not be able to proceed until the current
thread relinquishes the lock on this object. The awakened thread will
compete in the usual manner with any other threads that might be
actively competing to synchronize on this object; for example, the
awakened thread enjoys no reliable privilege or disadvantage in being
the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. A thread becomes the owner of the
object's monitor in one of three ways:
- By executing a synchronized instance method of that object.
- By executing the body of a
synchronized
statement
that synchronizes on the object.
- For objects of type
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
Wakes up all threads that are waiting on this object's monitor. A
thread waits on an object's monitor by calling one of the
wait
methods.
The awakened threads will not be able to proceed until the current
thread relinquishes the lock on this object. The awakened threads
will compete in the usual manner with any other threads that might
be actively competing to synchronize on this object; for example,
the awakened threads enjoy no reliable privilege or disadvantage in
being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
Sets the data for a rectangle of pixels in the specified DataBuffer
from a primitive array of type TransferType. For image data supported
by the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
may be in a packed format, thus increasing efficiency for data
transfers.
The following code illustrates transferring data for a rectangular
region of pixels from
DataBuffer db1
, whose storage layout is described by
SampleModel sm1
, to DataBuffer db2
, whose
storage layout is described by SampleModel sm2
.
The transfer will generally be more efficient than using
getPixels/setPixels.
SampleModel sm1, sm2;
DataBuffer db1, db2;
sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w, h,
null, db1), db2);
Using getDataElements/setDataElements to transfer between two
DataBuffer/SampleModel pairs is legitimate if the SampleModels have
the same number of bands, corresponding bands have the same number of
bits per sample, and the TransferTypes are the same.
obj must be a primitive array of type TransferType. Otherwise,
a ClassCastException is thrown. An
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds, or if obj is not large enough to hold the pixel data.
Sets the data for a single pixel in the specified DataBuffer from a
primitive array of type TransferType. For a BandedSampleModel,
this will be the same as the data type, and samples are transferred
one per array element.
The following code illustrates transferring data for one pixel from
DataBuffer db1
, whose storage layout is described by
BandedSampleModel bsm1
, to DataBuffer db2
,
whose storage layout is described by
BandedSampleModel bsm2
.
The transfer will generally be more efficient than using
getPixel/setPixel.
BandedSampleModel bsm1, bsm2;
DataBufferInt db1, db2;
bsm2.setDataElements(x, y, bsm1.getDataElements(x, y, null, db1),
db2);
Using getDataElements/setDataElements to transfer between two
DataBuffer/SampleModel pairs is legitimate if the SampleModels have
the same number of bands, corresponding bands have the same number of
bits per sample, and the TransferTypes are the same.
obj must be a primitive array of type TransferType. Otherwise,
a ClassCastException is thrown. An
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds, or if obj is not large enough to hold the pixel data.
Sets a pixel in the DataBuffer using a double array of samples
for input.
Sets a pixel in the DataBuffer using a float array of samples for input.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets a pixel in the DataBuffer using an int array of samples for input.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets all samples for a rectangle of pixels from a double array
containing one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets all samples for a rectangle of pixels from a float array containing
one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets all samples for a rectangle of pixels from an int array containing
one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets a sample in the specified band for the pixel located at (x,y)
in the DataBuffer using a double for input.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets a sample in the specified band for the pixel located at (x,y)
in the DataBuffer using a float for input.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets a sample in the specified band for the pixel located at (x,y)
in the DataBuffer using an int for input.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets the samples in the specified band for the specified rectangle
of pixels from a double array containing one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets the samples in the specified band for the specified rectangle
of pixels from a float array containing one sample per array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Sets the samples in the specified band for the specified rectangle
of pixels from an int array containing one sample per data array element.
ArrayIndexOutOfBoundsException may be thrown if the coordinates are
not in bounds.
Returns a string representation of the object. In general, the
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Causes current thread to wait until another thread invokes the
method or the
method for this object.
In other words, this method behaves exactly as if it simply
performs the call
wait(0).
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are
possible, and this method should always be used in a loop:
synchronized (obj) {
while (<condition does not hold>)
obj.wait();
... // Perform action appropriate to condition
}
This method should only be called by a thread that is the owner
of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
Causes current thread to wait until either another thread invokes the
method or the
method for this object, or a
specified amount of time has elapsed.
The current thread must own this object's monitor.
This method causes the current thread (call it T) to
place itself in the wait set for this object and then to relinquish
any and all synchronization claims on this object. Thread T
becomes disabled for thread scheduling purposes and lies dormant
until one of four things happens:
- Some other thread invokes the notify method for this
object and thread T happens to be arbitrarily chosen as
the thread to be awakened.
- Some other thread invokes the notifyAll method for this
object.
- Some other thread interrupts
thread T.
- The specified amount of real time has elapsed, more or less. If
timeout is zero, however, then real time is not taken into
consideration and the thread simply waits until notified.
The thread
T is then removed from the wait set for this
object and re-enabled for thread scheduling. It then competes in the
usual manner with other threads for the right to synchronize on the
object; once it has gained control of the object, all its
synchronization claims on the object are restored to the status quo
ante - that is, to the situation as of the time that the
wait
method was invoked. Thread
T then returns from the
invocation of the
wait method. Thus, on return from the
wait method, the synchronization state of the object and of
thread
T is exactly as it was when the
wait method
was invoked.
A thread can also wake up without being notified, interrupted, or
timing out, a so-called spurious wakeup. While this will rarely
occur in practice, applications must guard against it by testing for
the condition that should have caused the thread to be awakened, and
continuing to wait if the condition is not satisfied. In other words,
waits should always occur in loops, like this one:
synchronized (obj) {
while (<condition does not hold>)
obj.wait(timeout);
... // Perform action appropriate to condition
}
(For more information on this topic, see Section 3.2.3 in Doug Lea's
"Concurrent Programming in Java (Second Edition)" (Addison-Wesley,
2000), or Item 50 in Joshua Bloch's "Effective Java Programming
Language Guide" (Addison-Wesley, 2001).
If the current thread is
interrupted
by another thread
while it is waiting, then an InterruptedException is thrown.
This exception is not thrown until the lock status of this object has
been restored as described above.
Note that the wait method, as it places the current thread
into the wait set for this object, unlocks only this object; any
other objects on which the current thread may be synchronized remain
locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
Causes current thread to wait until another thread invokes the
method or the
method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the
method
of one argument. In particular,
wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until either of the
following two conditions has occurred:
- Another thread notifies threads waiting on this object's monitor
to wake up either through a call to the
notify
method
or the notifyAll
method.
- The timeout period, specified by
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the
monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are
possible, and this method should always be used in a loop:
synchronized (obj) {
while (<condition does not hold>)
obj.wait(timeout, nanos);
... // Perform action appropriate to condition
}
This method should only be called by a thread that is the owner
of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.