net.sourceforge.jiu.data

Class MemoryByteChannelImage

Implemented Interfaces:
ByteChannelImage, IntegerImage, PixelImage
Known Direct Subclasses:
MemoryGray8Image, MemoryPaletted8Image, MemoryRGB24Image

public abstract class MemoryByteChannelImage
extends java.lang.Object
implements ByteChannelImage

An implementation of 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.

Author:
Marco Schmidt

Field Summary

private byte[][]
data
private byte[]
firstChannel
private int
height
private int
numChannels
private int
numPixels
private int
width

Constructor Summary

MemoryByteChannelImage(int numChannels, int width, int height)
Create an image of byte channels.

Method Summary

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)
PixelImage
createCopy()
long
getAllocatedMemory()
int
getBitsPerPixel()
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()
int
getMaxSample(int channel)
Returns the maximum value for one of the image's channels.
int
getNumChannels()
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()
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.

Field Details

data

private final byte[][] data

firstChannel

private final byte[] firstChannel

height

private final int height

numChannels

private final int numChannels

numPixels

private final int numPixels

width

private final int width

Constructor Details

MemoryByteChannelImage

public MemoryByteChannelImage(int numChannels,
                              int width,
                              int height)
Create an image of byte channels. Image data will be completely in memory, so memory requirements are width * height * numChannels bytes. Note that the data will not be initialized, so you should not assume anything about its content.
Parameters:
numChannels - the number of channels in this image, must be non-zero and positive
width - the horizontal resolution, must be non-zero and positive
height - the vertical resolution, must be non-zero and positive

Method Details

checkPositionAndNumber

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. To be valid, all of the following requirements must be met:

clear

public void clear(byte newValue)
Sets all samples of the first channel to the argument byte value. Equal to clear(0, newValue);.
Specified by:
clear in interface ByteChannelImage
Parameters:
newValue - all samples in the first channel are set to this value
See Also:
ByteChannelImage.clear(int,byte), clear(int), clear(int, int)

clear

public void clear(int newValue)
Sets all samples in the first channel to the argument value. Equal to clear(0, newValue);:
Specified by:
clear in interface IntegerImage

clear

public void clear(int channelIndex,
                  byte newValue)
Sets all samples of one channel to a new value.
Specified by:
clear in interface ByteChannelImage
Parameters:
channelIndex - zero-based index of the channel to be cleared (must be smaller than getNumChannels()
newValue - all samples in the channel will be set to this value

clear

public void clear(int channelIndex,
                  int newValue)
Sets all samples of the channelIndex'th channel to newValue.
Specified by:
clear in interface IntegerImage

createCompatibleImage

public abstract PixelImage createCompatibleImage(int width,
                                                 int height)
Specified by:
createCompatibleImage in interface PixelImage

createCopy

public PixelImage createCopy()
Specified by:
createCopy in interface PixelImage

getAllocatedMemory

public long getAllocatedMemory()
Specified by:
getAllocatedMemory in interface PixelImage

getBitsPerPixel

public int getBitsPerPixel()
Specified by:
getBitsPerPixel in interface PixelImage

getByteSample

public byte getByteSample(int x,
                          int y)
Returns a single byte sample from the first channel and the specified position. A call to this method is the same as getByteSample(0, x, y).
Specified by:
getByteSample in interface ByteChannelImage
Parameters:
x - horizontal position of the sample to be returned (must be between 0 and getWidth() - 1
y - vertical position of the sample to be returned (must be between 0 and getHeight() - 1
Returns:
the requested byte sample

getByteSample

public byte getByteSample(int channel,
                          int x,
                          int y)
Specified by:
getByteSample in interface ByteChannelImage
Parameters:
channel - the number of the channel of the sample; must be from 0 to getNumChannels() - 1
x - the column of the sample to be returned; must be from 0 to getWidth() - 1
y - the row of the sample; must be from 0 to getHeight() - 1
Returns:
the sample, a single byte value

getByteSamples

public 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. Copies num 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.
Specified by:
getByteSamples in interface ByteChannelImage
Parameters:
x - the horizontal offset where copying will start; must be from 0 to getWidth() - 1
y - the row from which will be copied; must be from 0 to getHeight() - 1
w - the number of columns to be copied
h - the number of rows to be copied
dest - the array where the data will be copied to; must have a length of at least destOffset + num
destOffset - the offset into dest where this method will start copying data

getHeight

public final int getHeight()
Specified by:
getHeight in interface PixelImage

getMaxSample

public int getMaxSample(int channel)
Returns the maximum value for one of the image's channels. The minimum value is always 0.
Specified by:
getMaxSample in interface IntegerImage
Parameters:
channel - zero-based index of the channel, from 0 to getNumChannels() - 1
Returns:
maximum allowed sample value

getNumChannels

public int getNumChannels()
Specified by:
getNumChannels in interface PixelImage

getSample

public final int getSample(int x,
                           int y)
Returns one sample of the first channel (index 0). A call to this method must have the same result as the call getSample(0, x, y);.
Specified by:
getSample in interface IntegerImage
Parameters:
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
Returns:
the desired sample

getSample

public final int getSample(int channel,
                           int x,
                           int y)
Returns one sample, specified by its channel index and location.
Specified by:
getSample in interface IntegerImage
Parameters:
channel - the number of the channel, from 0 to IntegerImage - 1
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
Returns:
the desired sample

getSamples

public 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. 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.
Specified by:
getSamples in interface IntegerImage
Parameters:
x - horizontal position of upper left corner of the rectangle to be copied
y - vertical position of upper left corner of the rectangle to be copied
w - width of rectangle to be copied
h - height of rectangle to be copied
dest - int array to which the samples will be copied
destOffs - int index into the dest array for the position to which the samples will be copied

getWidth

public final int getWidth()
Specified by:
getWidth in interface PixelImage

putByteSample

public final void putByteSample(int x,
                                int y,
                                byte newValue)
Sets one byte sample in the first channel (index 0) to a new value. Result is equal to putByteSample(0, x, y, newValue);.
Specified by:
putByteSample in interface ByteChannelImage

putByteSample

public final void putByteSample(int channel,
                                int x,
                                int y,
                                byte newValue)
Sets one byte sample in one channel to a new value.
Specified by:
putByteSample in interface ByteChannelImage

putByteSamples

public 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.
Specified by:
putByteSamples in interface ByteChannelImage

putSample

public final void putSample(int x,
                            int y,
                            int newValue)
This method sets one sample of the first channel (index 0) to a new value. This call must have the same result as the call putSample(0, x, y). The sample location is given by the spatial coordinates, x and y.
Specified by:
putSample in interface IntegerImage
Parameters:
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
newValue - the new value of the sample

putSample

public final void putSample(int channel,
                            int x,
                            int y,
                            int newValue)
This method sets one sample to a new value. The sample location is given by the channel index and the spatial coordinates, x and y.
Specified by:
putSample in interface IntegerImage
Parameters:
channel - the number of the channel, from 0 to IntegerImage - 1
x - the horizontal position of the sample, from 0 to IntegerImage - 1
y - the vertical position of the sample, from 0 to IntegerImage - 1
newValue - the new value of the sample

putSamples

public 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. 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.
Specified by:
putSamples in interface IntegerImage
Parameters:
channel - int (from 0 to getNumChannels() - 1) to indicate the channel to which data is copied
x - horizontal position of upper left corner of the rectangle to be copied
y - vertical position of upper left corner of the rectangle to be copied
w - width of rectangle to be copied
h - height of rectangle to be copied
src - int array from which the samples will be copied