public abstract class MemoryByteChannelImage extends java.lang.Object implements ByteChannelImage
ByteChannelImage that stores image channels as
byte[] arrays in memory.
An image can have an arbitrary number of channels.
This class is abstract because it is merely a data container.
It takes a subclass like MemoryGray8Image to give meaning to the values.
| Modifier and Type | Field and Description |
|---|---|
private byte[][] |
data |
private byte[] |
firstChannel |
private int |
height |
private int |
numChannels |
private int |
numPixels |
private int |
width |
| Constructor and Description |
|---|
MemoryByteChannelImage(int numChannels,
int width,
int height)
Create an image of byte channels.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkPositionAndNumber(int channel,
int x,
int y,
int w,
int h)
Throws an exception if the arguments do not form a valid horizontal
sequence of samples.
|
void |
clear(byte newValue)
Sets all samples of the first channel to the argument byte value.
|
void |
clear(int newValue)
Sets all samples in the first channel to the argument value.
|
void |
clear(int channelIndex,
byte newValue)
Sets all samples of one channel to a new value.
|
void |
clear(int channelIndex,
int newValue)
Sets all samples of the
channelIndex'th channel to newValue. |
abstract PixelImage |
createCompatibleImage(int width,
int height)
Creates an instance of the same class as this one, with width and height
given by the arguments.
|
PixelImage |
createCopy()
Creates an new image object that will be of the same type as this one,
with the same image data, using entirely new resources.
|
long |
getAllocatedMemory()
Returns the number of bytes that were dynamically allocated for
this image object.
|
int |
getBitsPerPixel()
Returns the number of bits per pixel of this image.
|
byte |
getByteSample(int x,
int y)
Returns a single byte sample from the first channel and the specified position.
|
byte |
getByteSample(int channel,
int x,
int y)
Returns a single byte sample from the image.
|
void |
getByteSamples(int channel,
int x,
int y,
int w,
int h,
byte[] dest,
int destOffset)
Copies samples from this image to a byte array.
|
int |
getHeight()
Returns the vertical resolution of the image in pixels.
|
int |
getMaxSample(int channel)
Returns the maximum value for one of the image's channels.
|
int |
getNumChannels()
Returns the number of channels in this image.
|
int |
getSample(int x,
int y)
Returns one sample of the first channel (index 0).
|
int |
getSample(int channel,
int x,
int y)
Returns one sample, specified by its channel index and location.
|
void |
getSamples(int channel,
int x,
int y,
int w,
int h,
int[] dest,
int destOffs)
Copies a number of samples from this image to an
int[] object. |
int |
getWidth()
Returns the horizontal resolution of the image in pixels.
|
void |
putByteSample(int x,
int y,
byte newValue)
Sets one byte sample in the first channel (index
0) to a new value. |
void |
putByteSample(int channel,
int x,
int y,
byte newValue)
Sets one byte sample in one channel to a new value.
|
void |
putByteSamples(int channel,
int x,
int y,
int w,
int h,
byte[] src,
int srcOffset)
Copies a number of samples from the argument array to this image.
|
void |
putSample(int x,
int y,
int newValue)
This method sets one sample of the first channel (index 0) to a new value.
|
void |
putSample(int channel,
int x,
int y,
int newValue)
This method sets one sample to a new value.
|
void |
putSamples(int channel,
int x,
int y,
int w,
int h,
int[] src,
int srcOffs)
Copies a number of samples from an
int[] array to this image. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetImageTypeprivate final byte[][] data
private final byte[] firstChannel
private final int numChannels
private final int width
private final int height
private final int numPixels
public MemoryByteChannelImage(int numChannels,
int width,
int height)
width * height * numChannels bytes.
Note that the data will not be initialized, so you should not assume
anything about its content.numChannels - the number of channels in this image, must be
non-zero and positivewidth - the horizontal resolution, must be non-zero and positiveheight - the vertical resolution, must be non-zero and positivejava.lang.IllegalArgumentException - if any of the parameters are invalid
or if width times height exceeds two GBOutOfMemoryException - if there is not enough free memory for
the specified resolutionprotected void checkPositionAndNumber(int channel,
int x,
int y,
int w,
int h)
public void clear(byte newValue)
ByteChannelImageclear(0, newValue);.clear in interface ByteChannelImagenewValue - all samples in the first channel are set to this valueByteChannelImage.clear(int, byte),
IntegerImage.clear(int),
IntegerImage.clear(int, int)public void clear(int channelIndex,
byte newValue)
ByteChannelImageclear in interface ByteChannelImagechannelIndex - zero-based index of the channel to be cleared (must be smaller than PixelImage.getNumChannels()newValue - all samples in the channel will be set to this valuepublic void clear(int newValue)
IntegerImageclear(0, newValue);:clear in interface IntegerImagepublic void clear(int channelIndex,
int newValue)
IntegerImagechannelIndex'th channel to newValue.clear in interface IntegerImagepublic abstract PixelImage createCompatibleImage(int width, int height)
PixelImagecreateCompatibleImage in interface PixelImagewidth - the horizontal resolution of the new imageheight - the vertical resolution of the new imagepublic PixelImage createCopy()
PixelImagecreateCopy in interface PixelImagepublic long getAllocatedMemory()
PixelImagegetAllocatedMemory in interface PixelImagepublic int getBitsPerPixel()
PixelImagegetBitsPerPixel in interface PixelImagepublic byte getByteSample(int channel,
int x,
int y)
ByteChannelImageByteChannelImage.getByteSamples(int, int, int, int, int, byte[], int)).getByteSample in interface ByteChannelImagechannel - the number of the channel of the sample; must be from 0 to PixelImage.getNumChannels() - 1x - the column of the sample to be returned; must be from 0 to PixelImage.getWidth() - 1y - the row of the sample; must be from 0 to PixelImage.getHeight() - 1ByteChannelImage.getByteSamples(int, int, int, int, int, byte[], int)public byte getByteSample(int x,
int y)
ByteChannelImagegetByteSample(0, x, y).getByteSample in interface ByteChannelImagex - horizontal position of the sample to be returned (must be between 0 and PixelImage.getWidth() - 1y - vertical position of the sample to be returned (must be between 0 and PixelImage.getHeight() - 1public void getByteSamples(int channel,
int x,
int y,
int w,
int h,
byte[] dest,
int destOffset)
ByteChannelImagenum samples in row y of channel
channel, starting at horizontal offset x.
Data will be written to the dest array, starting at
offset destOffset.
Data will be copied from one row only, so a maximum of
getWidth()
samples can be copied with a call to this method.getByteSamples in interface ByteChannelImagechannel - the index of the channel to be copied from; must be
from 0 to getNumChannels() - 1x - the horizontal offset where copying will start; must be from
0 to getWidth() - 1y - the row from which will be copied; must be from
0 to getHeight() - 1w - the number of columns to be copiedh - the number of rows to be copieddest - the array where the data will be copied to; must have a
length of at least destOffset + numdestOffset - the offset into dest where this method
will start copying datapublic final int getHeight()
PixelImagegetHeight in interface PixelImagepublic int getMaxSample(int channel)
IntegerImage0.getMaxSample in interface IntegerImagechannel - zero-based index of the channel, from 0 to PixelImage.getNumChannels() - 1public int getNumChannels()
PixelImagegetNumChannels in interface PixelImagepublic final int getSample(int x,
int y)
IntegerImagegetSample(0, x, y);.getSample in interface IntegerImagex - the horizontal position of the sample, from 0 to PixelImage.getWidth() - 1y - the vertical position of the sample, from 0 to PixelImage.getHeight() - 1public final int getSample(int channel,
int x,
int y)
IntegerImagegetSample in interface IntegerImagechannel - the number of the channel, from 0 to PixelImage.getNumChannels() - 1x - the horizontal position of the sample, from 0 to PixelImage.getWidth() - 1y - the vertical position of the sample, from 0 to PixelImage.getHeight() - 1public void getSamples(int channel,
int x,
int y,
int w,
int h,
int[] dest,
int destOffs)
IntegerImageint[] object.
A rectangular part of one channel is copied.
The channel index is given by - the upper left corner of
that rectangle is given by the point x / y.
Width and height of that rectangle are given by w and h.
Each sample will be stored as one int value dest,
starting at index destOffs.getSamples in interface IntegerImagechannel - zero-based index of the channel from which data is to be copied (valid values: 0 to PixelImage.getNumChannels() - 1)x - horizontal position of upper left corner of the rectangle to be copiedy - vertical position of upper left corner of the rectangle to be copiedw - width of rectangle to be copiedh - height of rectangle to be copieddest - int array to which the samples will be copieddestOffs - int index into the dest array for the position to which the samples will be copiedpublic final int getWidth()
PixelImagegetWidth in interface PixelImagepublic final void putByteSample(int channel,
int x,
int y,
byte newValue)
ByteChannelImageputByteSample in interface ByteChannelImagepublic final void putByteSample(int x,
int y,
byte newValue)
ByteChannelImage0) to a new value.
Result is equal to putByteSample(0, x, y, newValue);.putByteSample in interface ByteChannelImagepublic void putByteSamples(int channel,
int x,
int y,
int w,
int h,
byte[] src,
int srcOffset)
ByteChannelImageputByteSamples in interface ByteChannelImagepublic void putSamples(int channel,
int x,
int y,
int w,
int h,
int[] src,
int srcOffs)
IntegerImageint[] array to this image.
A rectangular part of one channel is copied - the upper left corner of
that rectangle is given by the point x / y.
Width and height of that rectangle are given by w and h.
Each sample will be stored as one int value src,
starting at index srcOffset.putSamples in interface IntegerImagechannel - int (from 0 to getNumChannels() - 1) to indicate the channel to which data is copiedx - horizontal position of upper left corner of the rectangle to be copiedy - vertical position of upper left corner of the rectangle to be copiedw - width of rectangle to be copiedh - height of rectangle to be copiedsrc - int array from which the samples will be copiedsrcOffs - int index into the src array for the position from which the samples will be copiedpublic final void putSample(int x,
int y,
int newValue)
IntegerImageputSample(0, x, y).
The sample location is given by the spatial coordinates, x and y.putSample in interface IntegerImagex - the horizontal position of the sample, from 0 to PixelImage.getWidth() - 1y - the vertical position of the sample, from 0 to PixelImage.getHeight() - 1newValue - the new value of the samplepublic final void putSample(int channel,
int x,
int y,
int newValue)
IntegerImageputSample in interface IntegerImagechannel - the number of the channel, from 0 to PixelImage.getNumChannels() - 1x - the horizontal position of the sample, from 0 to PixelImage.getWidth() - 1y - the vertical position of the sample, from 0 to PixelImage.getHeight() - 1newValue - the new value of the sample